From 9abbe9b52e86626e2c577e5e4ee55f051ad8f432 Mon Sep 17 00:00:00 2001 From: zueuk Date: Sun, 6 Nov 2005 10:47:13 +0000 Subject: [PATCH] more assembler - more speed...(?) must test... and we really need some profiler :) --- 2.10/Source/BucketFillerThread.pas | 2 +- 2.10/Source/ControlPoint.pas | 32 +-- 2.10/Source/Editor.dfm | 2 +- 2.10/Source/Editor.pas | 66 ++--- 2.10/Source/FormRender.dfm | 8 +- 2.10/Source/FormRender.pas | 20 +- 2.10/Source/Global.pas | 2 +- 2.10/Source/Main.dfm | 8 +- 2.10/Source/Main.pas | 2 +- 2.10/Source/MyTypes.pas | 51 ---- 2.10/Source/Render.pas | 12 +- 2.10/Source/RndFlame.pas | 2 +- 2.10/Source/ScriptForm.pas | 2 +- 2.10/Source/VarEyefish.pas | 2 +- 2.10/Source/XForm.pas | 406 ++++++++++++++++++++++------- 15 files changed, 379 insertions(+), 238 deletions(-) delete mode 100644 2.10/Source/MyTypes.pas diff --git a/2.10/Source/BucketFillerThread.pas b/2.10/Source/BucketFillerThread.pas index 91944a2..8144ce9 100644 --- a/2.10/Source/BucketFillerThread.pas +++ b/2.10/Source/BucketFillerThread.pas @@ -4,7 +4,7 @@ interface uses Classes, Windows, - Controlpoint,Render; + ControlPoint, Render; type TBucketFillerThread = class(TThread) diff --git a/2.10/Source/ControlPoint.pas b/2.10/Source/ControlPoint.pas index 879674b..a1e3216 100644 --- a/2.10/Source/ControlPoint.pas +++ b/2.10/Source/ControlPoint.pas @@ -26,9 +26,10 @@ uses const EPS = 1E-10; - NXFORMS = 100; // --Z-- I don't like limitations! 8-[] + NXFORMS = 100; SUB_BATCH_SIZE = 10000; + PROP_TABLE_SIZE = 1024; PREFILTER_WHITE = (1 shl 26); FILTER_CUTOFF = 1.8; BRIGHT_ADJUST = 2.3; @@ -116,7 +117,7 @@ type pulse: array[0..1, 0..1] of double; // [i][0]=magnitute [i][1]=frequency */ wiggle: array[0..1, 0..1] of double; // frequency is /minute, assuming 30 frames/s */ - PropTable: array of Integer; + PropTable: array of ^TXForm;//Integer; FAngle: Double; FTwoColorDimensions: Boolean; private @@ -263,7 +264,7 @@ var j: integer; TotValue: double; begin - SetLength(PropTable, 1024); + SetLength(PropTable, PROP_TABLE_SIZE); totValue := 0; for i := 0 to NXFORMS - 1 do begin @@ -278,8 +279,8 @@ begin inc(j); propsum := propsum + xform[j].density; until (propsum > LoopValue) or (j = NXFORMS - 1); - PropTable[i] := j; - LoopValue := LoopValue + TotValue / 1024; + PropTable[i] := @xform[j]; + LoopValue := LoopValue + TotValue / PROP_TABLE_SIZE; end; end; @@ -300,7 +301,8 @@ begin PreparePropTable; for i := -FUSE to NrPoints - 1 do begin - with xform[PropTable[Random(1024)]] do begin + //with xform[PropTable[Random(1024)]] do begin + with PropTable[Random(PROP_TABLE_SIZE)]^ do begin // first compute the color coord s := symmetry; @@ -530,10 +532,10 @@ begin try for i := 0 to FUSE do - xform[PropTable[Random(1024)]].NextPointXY(px,py); + PropTable[Random(PROP_TABLE_SIZE)].NextPointXY(px,py); for i := 0 to NrPoints - 1 do begin - xform[PropTable[Random(1024)]].NextPointXY(px,py); + PropTable[Random(PROP_TABLE_SIZE)].NextPointXY(px,py); CurrentPoint := @Points[i]; CurrentPoint.X := px; CurrentPoint.Y := py; @@ -563,10 +565,10 @@ begin try for i := 0 to FUSE do - xform[PropTable[Random(1024)]].NextPoint(px,py,pc); + PropTable[Random(PROP_TABLE_SIZE)].NextPoint(px,py,pc); for i := 0 to NrPoints - 1 do begin - xform[PropTable[Random(1024)]].NextPoint(px,py,pc); + PropTable[Random(PROP_TABLE_SIZE)].NextPoint(px,py,pc); CurrentPoint := @Points[i]; CurrentPoint.X := px; CurrentPoint.Y := py; @@ -609,7 +611,7 @@ begin pc := 0; try - xform[PropTable[Random(1024)]].NextPoint(px,py,pt); + PropTable[Random(PROP_TABLE_SIZE)].NextPoint(px,py,pt); except on EMathError do begin exit; @@ -644,10 +646,10 @@ begin try for i := 0 to FUSE do - xform[PropTable[Random(1024)]].NextPoint2C(px, py, pc1, pc2); + PropTable[Random(PROP_TABLE_SIZE)].NextPoint2C(px, py, pc1, pc2); for i := 0 to NrPoints - 1 do begin - xform[PropTable[Random(1024)]].NextPoint2C(px, py, pc1, pc2); + PropTable[Random(PROP_TABLE_SIZE)].NextPoint2C(px, py, pc1, pc2); CurrentPoint := @Points[i]; CurrentPoint.X := px; CurrentPoint.Y := py; @@ -684,10 +686,10 @@ begin try for i := 0 to FUSE do - xform[PropTable[Random(1024)]].NextPointXY(px,py); + PropTable[Random(PROP_TABLE_SIZE)].NextPointXY(px,py); for i := 0 to NrPoints - 1 do begin - xform[PropTable[Random(1024)]].NextPointXY(px,py); + PropTable[Random(PROP_TABLE_SIZE)].NextPointXY(px,py); CurrentPoint := @Points[i]; CurrentPoint.X := px; CurrentPoint.Y := py; diff --git a/2.10/Source/Editor.dfm b/2.10/Source/Editor.dfm index 5154724..47a3c1a 100644 --- a/2.10/Source/Editor.dfm +++ b/2.10/Source/Editor.dfm @@ -171,7 +171,7 @@ object EditForm: TEditForm object tbSelect: TToolButton Left = 166 Top = 0 - Hint = 'Select triangle' + Hint = 'Select mode' Caption = 'Select' Down = True ImageIndex = 6 diff --git a/2.10/Source/Editor.pas b/2.10/Source/Editor.pas index 7797f29..217ab36 100644 --- a/2.10/Source/Editor.pas +++ b/2.10/Source/Editor.pas @@ -22,8 +22,9 @@ interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, - ExtCtrls, StdCtrls, ComCtrls, Math, Menus, ToolWin, Registry, MyTypes, - ControlPoint, Render, cmap, Grids, ValEdit, Buttons, ImgList, CustomDrawControl; + ExtCtrls, StdCtrls, ComCtrls, Math, Menus, ToolWin, Registry, + ControlPoint, Render, cmap, Grids, ValEdit, Buttons, ImgList, CustomDrawControl, + Types; const // PixelCountMax = 32768; @@ -342,13 +343,15 @@ type function GetPivot: TSPoint; overload; function GetPivot(n: integer): TSPoint; overload; - function GetTriangleColor(n: integer): TColor; +//moved to public: function GetTriangleColor(n: integer): TColor; // --Z-- functions moved from outside (?) procedure ShowSelectedInfo; procedure Scale(var fx, fy: double; x, y: integer); // procedure ReadjustWeights(var cp: TControlPoint); + procedure TriangleViewPaint(Sender: TObject); + procedure AutoZoom; public cp: TControlPoint; Render: TRenderer; @@ -357,8 +360,8 @@ type procedure UpdatePreview; procedure UpdateDisplay(PreviewOnly: boolean = false); //(?) - procedure AutoZoom; - procedure TriangleViewPaint(Sender: TObject); + + function GetTriangleColor(n: integer): TColor; end; const @@ -551,12 +554,11 @@ begin end; end; - function ColorValToColor(c: TColorMap; index: double): TColor; var i: integer; begin - i := Trunc(Index * 255); + i := Trunc(Index * 255); //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! >>TODO: check<< result := c[i][2] shl 16 + c[i][1] shl 8 + c[i][0]; end; @@ -589,7 +591,7 @@ end; procedure TEditForm.UpdateDisplay(PreviewOnly: boolean = false); var i: integer; - pw, ph: integer; +// pw, ph: integer; r: double; begin // currently EditForm does not really know if we select another @@ -1081,10 +1083,10 @@ begin try tx := ax / d1; ty := ay / d1; - for i := 1 to trkVarPreviewDepth.position do - cp.xform[SelectedTriangle].NextPoint(tx, ty, d); // d used as dummy var - a := toscreen(tx,-ty); - Pixels[a.x, a.Y] := {Pixels[a.x, a.Y] xor} tc; + for i := trkVarPreviewDepth.position downto 1 do + cp.xform[SelectedTriangle].PreviewPoint(tx, ty); + a := toscreen(tx, -ty); + Pixels[a.x, a.y] := tc; except end; end; @@ -1096,10 +1098,8 @@ begin if HelpersEnabled then begin pen.Color := HelpersColor; - //pen.Color := 0; - //brush.Color := $808080; pen.Mode := pmMerge; - pen.Style := psSolid;//psDot; + pen.Style := psSolid; a := ToScreen(Pivot.x, Pivot.y); MoveTo(a.x, 0); LineTo(a.x, Height); @@ -1119,23 +1119,20 @@ begin d := Hypot(dx, dy); for i := 1 to 2 do begin - d1 := Hypot(tx, ty); d1 := dist(Pivot.x, Pivot.y, MainTriangles[SelectedTriangle].x[i], MainTriangles[SelectedTriangle].y[i]); - if d1 > d then begin + if d1 > d then + begin + dx := dx/d*d1; + dy := dy/d*d1; d := d1; end; end; - d1 := Hypot(dx, dy); - if (d1 <> d) and (d1 <> 0) then - begin - dx := dx/d1 * d; - dy := dy/d1 * d; - end; end; //i := min( min(Width, Height), integer(round(dmax * sc))); i := integer(round(d * sc)); - if i > 4 then begin + if i > 4 then + begin pen.Color := HelpersColor; brush.Style := bsClear; Ellipse(a.x - i, a.y - i, a.x + i, a.y + i); @@ -1150,20 +1147,6 @@ begin // rotated axis LineDxDy; - { - if (dx <> 0) and (dy <> 0) then - begin - k := dy / dx; - if abs(k) < 1 then begin - MoveTo(0, round(iy - sc*(Pivot.y - ( ix/sc-GCenterX+Pivot.x)*k - GCenterY))); - LineTo(Width, round(iy - sc*(Pivot.y - (-ix/sc-GCenterX+Pivot.x)*k - GCenterY))); - end - else begin - MoveTo(round(ix + sc*(Pivot.x - (-iy/sc-GCenterY+Pivot.y)/k - GCenterX)), 0); - LineTo(round(ix + sc*(Pivot.x - ( iy/sc-GCenterY+Pivot.y)/k - GCenterX)), Height); - end; - end; - } end else if (editMode = modeScale) then // draw lines begin @@ -3424,14 +3407,9 @@ begin end; procedure TEditForm.mnuResetClick(Sender: TObject); -var - i: integer; begin MainForm.UpdateUndo; MainTriangles[SelectedTriangle] := MainTriangles[-1]; -// cp.xform[SelectedTriangle].vars[0] := 1; -// for i := 1 to NRVAR - 1 do -// cp.xform[SelectedTriangle].vars[i] := 0; UpdateFlame(True); end; @@ -3446,9 +3424,11 @@ begin SelectedTriangle := 1; MainTriangles[0] := MainTriangles[-1]; cp.xform[0].density := 0.5; + cp.xform[0].color := 0; cp.xform[0].vars[0] := 1; MainTriangles[1] := MainTriangles[-1]; cp.xform[1].density := 0.5; + cp.xform[0].color := 1; cp.xform[1].vars[0] := 1; for i := 1 to NRVAR - 1 do begin diff --git a/2.10/Source/FormRender.dfm b/2.10/Source/FormRender.dfm index 5e67175..d9ac1b0 100644 --- a/2.10/Source/FormRender.dfm +++ b/2.10/Source/FormRender.dfm @@ -323,6 +323,12 @@ object RenderForm: TRenderForm Width = 126 Height = 13 Caption = 'Available physical memory:' + Font.Charset = DEFAULT_CHARSET + Font.Color = clWindowText + Font.Height = -11 + Font.Name = 'MS Sans Serif' + Font.Style = [] + ParentFont = False end object Label9: TLabel Left = 8 @@ -465,6 +471,6 @@ object RenderForm: TRenderForm end object SaveDialog: TSaveDialog Left = 368 - Top = 256 + Top = 328 end end diff --git a/2.10/Source/FormRender.pas b/2.10/Source/FormRender.pas index baafc37..56a05e2 100644 --- a/2.10/Source/FormRender.pas +++ b/2.10/Source/FormRender.pas @@ -22,7 +22,8 @@ interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ControlPoint, RenderThread, ComCtrls, Math, Buttons, Registry, cmap, - ExtCtrls; + ExtCtrls, + Render; // 'use'd only for SizeOf() const WM_THREAD_COMPLETE = WM_APP + 5437; @@ -157,20 +158,17 @@ begin GlobalMemoryInfo.dwLength := SizeOf(GlobalMemoryInfo); GlobalMemoryStatus(GlobalMemoryInfo); PhysicalMemory := GlobalMemoryInfo.dwAvailPhys div 1048576; - ApproxMemory := 32 * Oversample * Oversample; - ApproxMemory := ApproxMemory * ImageHeight * ImageWidth; - ApproxMemory := ApproxMemory div 1048576; -// ApproxMemory := (32 * Oversample * Oversample * ImageHeight * ImageWidth) div 1048576; // or 1000000? - lblPhysical.Caption := 'Physical memory available: ' + Format('%d', [PhysicalMemory]) + ' MB'; - lblApproxMem.Caption := 'Approximate memory required: ' + Format('%d', [ApproxMemory]) + ' MB'; - if ApproxMemory > PhysicalMemory then - ; // show warning icon. + ApproxMemory := ImageHeight * ImageWidth * Oversample * Oversample * + SizeOf(TBucket) div 1048576; + lblPhysical.Caption := 'Physical memory available: ' + Format('%d', [PhysicalMemory]) + ' Mb'; + lblApproxMem.Caption := 'Approximate memory required: ' + Format('%d', [ApproxMemory]) + ' Mb'; + if ApproxMemory > PhysicalMemory then lblPhysical.Font.Color := clRed + else lblPhysical.Font.Color := clWindowText; end; procedure TRenderForm.HandleThreadCompletion(var Message: TMessage); begin - if not chkLimitMem.Checked and - cbPostProcess.checked then + if not chkLimitMem.Checked and cbPostProcess.checked then DoPostProcess; Renderer.SaveImage(RenderForm.FileName); diff --git a/2.10/Source/Global.pas b/2.10/Source/Global.pas index a46a48a..2e20670 100644 --- a/2.10/Source/Global.pas +++ b/2.10/Source/Global.pas @@ -21,7 +21,7 @@ interface uses SysUtils, Classes, SyncObjs, Controls, Graphics, Math, - cmap, MyTypes, controlpoint, Xform; + cmap, ControlPoint, Xform; type EFormatInvalid = class(Exception); diff --git a/2.10/Source/Main.dfm b/2.10/Source/Main.dfm index 4ffa3e2..bfa5c6a 100644 --- a/2.10/Source/Main.dfm +++ b/2.10/Source/Main.dfm @@ -27,7 +27,7 @@ object MainForm: TMainForm Left = 160 Top = 28 Width = 4 - Height = 554 + Height = 540 end object ToolBar: TToolBar Left = 0 @@ -284,7 +284,7 @@ object MainForm: TMainForm Left = 0 Top = 28 Width = 160 - Height = 554 + Height = 540 Align = alLeft Columns = < item @@ -303,7 +303,7 @@ object MainForm: TMainForm Left = 164 Top = 28 Width = 433 - Height = 554 + Height = 540 Align = alClient BevelInner = bvLowered BevelOuter = bvNone @@ -327,7 +327,7 @@ object MainForm: TMainForm end object StatusBar: TStatusBar Left = 0 - Top = 582 + Top = 568 Width = 597 Height = 19 Panels = < diff --git a/2.10/Source/Main.pas b/2.10/Source/Main.pas index b01c45a..c76913c 100644 --- a/2.10/Source/Main.pas +++ b/2.10/Source/Main.pas @@ -25,7 +25,7 @@ interface uses Windows, Forms, Dialogs, Menus, Controls, ComCtrls, ToolWin, StdCtrls, Classes, Messages, ExtCtrls, ImgList, controlpoint, - Jpeg, SyncObjs, SysUtils, ClipBrd, Graphics, Math, Global, MyTypes, + Jpeg, SyncObjs, SysUtils, ClipBrd, Graphics, Math, Global, Registry, RenderThread, Cmap, ExtDlgs, AppEvnts, ShellAPI, LibXmlParser, LibXmlComps, Xform, XFormMan; diff --git a/2.10/Source/MyTypes.pas b/2.10/Source/MyTypes.pas deleted file mode 100644 index f135548..0000000 --- a/2.10/Source/MyTypes.pas +++ /dev/null @@ -1,51 +0,0 @@ -{ - Apophysis Copyright (C) 2001-2004 Mark Townsend - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -} -unit MyTypes; - -interface - -{uses ControlPoint; - -type - TTriangle = record - x: array[0..2] of double; - y: array[0..2] of double; - end; - TTriangles = array[-1..NXFORMS] of TTriangle; - TSPoint = record - x: double; - y: double; - end; - TMapPalette = record - Red: array[0..255] of byte; - Green: array[0..255] of byte; - Blue: array[0..255] of byte; - end; - TColorMaps = record - Identifier: string; - UGRFile: string; - end; - pPixArray = ^TPixArray; - TPixArray = array[0..1279, 0..1023, 0..3] of integer; - pPreviewPixArray = ^TPreviewPixArray; - TPreviewPixArray = array[0..159, 0..119, 0..3] of integer; - TFileType = (ftIfs, ftFla, ftXML); -} -implementation - -end. diff --git a/2.10/Source/Render.pas b/2.10/Source/Render.pas index 9edbb18..a806a67 100644 --- a/2.10/Source/Render.pas +++ b/2.10/Source/Render.pas @@ -29,18 +29,18 @@ type type TColorMapColor = Record - Red : Int64; - Green: Int64; - Blue : Int64; + Red, + Green, + Blue: integer; //Int64; // Count: Int64; end; PColorMapColor = ^TColorMapColor; TColorMapArray = array[0..255] of TColorMapColor; TBucket = Record - Red : Int64; - Green: Int64; - Blue : Int64; + Red, + Green, + Blue, Count: Int64; end; PBucket = ^TBucket; diff --git a/2.10/Source/RndFlame.pas b/2.10/Source/RndFlame.pas index 4e57a1c..bb85dd1 100644 --- a/2.10/Source/RndFlame.pas +++ b/2.10/Source/RndFlame.pas @@ -28,7 +28,7 @@ function RandomFlame(SourceCP: TControlPoint= nil; algorithm: integer = 0): TCon implementation uses - SysUtils, Global, cmap, MyTypes, GradientHlpr, XFormMan; + SysUtils, Global, cmap, GradientHlpr, XFormMan; /////////////////////////////////////////////////////////////////////////////// procedure RandomGradient(SourceCP, DestCP: TControlPoint); diff --git a/2.10/Source/ScriptForm.pas b/2.10/Source/ScriptForm.pas index 2c44d7f..ec15192 100644 --- a/2.10/Source/ScriptForm.pas +++ b/2.10/Source/ScriptForm.pas @@ -325,7 +325,7 @@ implementation } uses Main, Editor, Adjust, Global, Mutate, Registry, Preview, - ScriptRender, ap_math, ap_classes, ap_sysutils, MyTypes, + ScriptRender, ap_math, ap_classes, ap_sysutils, SavePreset, ap_windows, ap_FileCtrl, bmdll32; {$R *.DFM} diff --git a/2.10/Source/VarEyefish.pas b/2.10/Source/VarEyefish.pas index 227806d..31a91f1 100644 --- a/2.10/Source/VarEyefish.pas +++ b/2.10/Source/VarEyefish.pas @@ -27,7 +27,7 @@ procedure TVariationEyefish.CalcFunction; var r: double; begin - r := 2 * vvar / (sqrt(FTx^ * FTx^ + FTy^ * FTy^) + 1); + r := 2 * vvar / (sqrt(sqr(FTx^) + sqr(FTy^)) + 1); FPx^ := FPx^ + r * FTx^; FPy^ := FPy^ + r * FTy^; {$else} diff --git a/2.10/Source/XForm.pas b/2.10/Source/XForm.pas index 4755695..9b66e42 100644 --- a/2.10/Source/XForm.pas +++ b/2.10/Source/XForm.pas @@ -34,14 +34,15 @@ type FSinA: double; FCosA: double; FLength: double; - CalculateAngle: boolean; -// CalculateLength: boolean; - CalculateSinCos: boolean; - - PostTransformEnabled: boolean; +// CalculateAngle, CalculateLength, CalculateSinCos: boolean; FRegVariations: array of TBaseVariation; + procedure PrecalcAngle; + procedure PrecalcSinCos; + procedure PrecalcAll; + procedure DoPostTransform; + procedure Linear; // var[0] procedure Sinusoidal; // var[1] procedure Spherical; // var[2] @@ -66,10 +67,10 @@ type procedure Rings; // var[21] procedure Fan; // var[22] - procedure Triblob; // var[23] - procedure Daisy; // var[24] - procedure Checkers; // var[25] - procedure CRot; // var[26] +// procedure Triblob; // var[23] +// procedure Daisy; // var[24] +// procedure Checkers; // var[25] +// procedure CRot; // var[26] function Mul33(const M1, M2: TMatrix): TMatrix; function Identity: TMatrix; @@ -99,9 +100,10 @@ type procedure Assign(Xform: TXForm); + procedure PreviewPoint(var px, py: double); procedure NextPoint(var px, py, pc: double); overload; procedure NextPoint(var CPpoint: TCPpoint); overload; - procedure NextPoint(var px, py, pz, pc: double); overload; +// procedure NextPoint(var px, py, pz, pc: double); overload; procedure NextPointXY(var px, py: double); procedure NextPoint2C(var px, py, pc1, pc2: double); @@ -142,6 +144,8 @@ var begin density := 0; Color := 0; + Symmetry := 0; + c[0, 0] := 1; c[0, 1] := 0; c[1, 0] := 0; @@ -155,7 +159,6 @@ begin p[1, 1] := 1; p[2, 0] := 0; p[2, 1] := 0; - Symmetry := 0; AddRegVariations; BuildFunctionlist; @@ -170,6 +173,7 @@ end; procedure TXForm.Prepare; var i: integer; + CalculateAngle, CalculateSinCos, CalculateLength: boolean; begin c00 := c[0][0]; c01 := c[0][1]; @@ -178,17 +182,6 @@ begin c20 := c[2][0]; c21 := c[2][1]; - if (p[0,0]<>1) or (p[0,1]<>0) or(p[1,0]<>0) or (p[1,1]<>1) or (p[2,0]<>0) or (p[2,1]<>0) then - begin - p00 := p[0][0]; - p01 := p[0][1]; - p10 := p[1][0]; - p11 := p[1][1]; - p20 := p[2][0]; - p21 := p[2][1]; - PostTransformEnabled := true; - end; - FNrFunctions := 0; for i := 0 to High(FRegVariations) do begin @@ -201,12 +194,42 @@ begin FRegVariations[i].prepare; end; + CalculateAngle := (vars[5] <> 0.0) or (vars[6] <> 0.0) or (vars[7] <> 0.0) or (vars[8] <> 0.0) or + (vars[12] <> 0.0) or (vars[13] <> 0.0) or (vars[21] <> 0.0) or (vars[22] <> 0.0); +// CalculateLength := False; + CalculateSinCos := (vars[9] <> 0.0) or (vars[11] <> 0.0) or (vars[19] <> 0.0) or (vars[21] <> 0.0); + + if CalculateAngle or CalculateSinCos then + begin + if CalculateAngle and CalculateSinCos then + FCalcFunctionList[FNrFunctions] := PrecalcAll + else if CalculateAngle then + FCalcFunctionList[FNrFunctions] := PrecalcAngle + else //if CalculateSinCos then + FCalcFunctionList[FNrFunctions] := PrecalcSinCos; + Inc(FNrFunctions); + end; + for i := 0 to NrVar - 1 do begin if (vars[i] <> 0.0) then begin FCalcFunctionList[FNrFunctions] := FFunctionList[i]; Inc(FNrFunctions); end; end; + + if (p[0,0]<>1) or (p[0,1]<>0) or(p[1,0]<>0) or (p[1,1]<>1) or (p[2,0]<>0) or (p[2,1]<>0) then + begin + p00 := p[0][0]; + p01 := p[0][1]; + p10 := p[1][0]; + p11 := p[1][1]; + p20 := p[2][0]; + p21 := p[2][1]; + + FCalcFunctionList[FNrFunctions] := DoPostTransform; + Inc(FNrFunctions); + end; + (* if (vars[27] <> 0.0) then begin FFunctionList[FNrFunctions] := TestScript; @@ -238,19 +261,95 @@ begin Inc(FNrFunctions); end; *) +end; - CalculateAngle := (vars[5] <> 0.0) or (vars[6] <> 0.0) or (vars[7] <> 0.0) or (vars[8] <> 0.0) or - (vars[12] <> 0.0) or (vars[13] <> 0.0) or (vars[21] <> 0.0) or (vars[22] <> 0.0); -// CalculateLength := False; - CalculateSinCos := (vars[9] <> 0.0) or (vars[11] <> 0.0) or (vars[19] <> 0.0) or (vars[21] <> 0.0); +procedure TXForm.PrecalcAngle; +asm + fld qword ptr [eax + FTx] + fld qword ptr [eax + FTy] + fpatan + fstp qword ptr [eax + FAngle] + fwait +end; +procedure TXForm.PrecalcSinCos; +asm + fld qword ptr [eax + FTx] + fld qword ptr [eax + FTy] + fld st(1) + fmul st, st + fld st(1) + fmul st, st + faddp + fsqrt + fdiv st(1), st + fdiv st(2), st + fstp qword ptr [eax + FLength] + fstp qword ptr [eax + FCosA] + fstp qword ptr [eax + FSinA] + fwait +end; + +procedure TXForm.PrecalcAll; +asm + fld qword ptr [eax + FTx] + fld qword ptr [eax + FTy] + fld st(1) + fld st(1) + fpatan + fstp qword ptr [eax + FAngle] + fld st(1) + fmul st, st + fld st(1) + fmul st, st + faddp + fsqrt + fdiv st(1), st + fdiv st(2), st + fstp qword ptr [eax + FLength] + fstp qword ptr [eax + FCosA] + fstp qword ptr [eax + FSinA] + fwait +end; + +procedure TXForm.DoPostTransform; +// x := p00 * FPx + p10 * FPy + p20; +// y := p01 * FPx + p11 * FPy + p21; +asm + fld qword ptr [eax + FPy] + fld qword ptr [eax + FPx] + fld st(1) + fmul qword ptr [eax + p10] + fld st(1) + fmul qword ptr [eax + p00] + faddp + fadd qword ptr [eax + p20] + fstp qword ptr [eax + FPx] // + px] + fmul qword ptr [eax + p01] + fld qword ptr [eax + p11] + fmulp st(2), st + faddp + fadd qword ptr [eax + p21] + fstp qword ptr [eax + FPy] // + py] + fwait end; //--0--//////////////////////////////////////////////////////////////////////// procedure TXForm.Linear; -begin - FPx := FPx + vars[0] * FTx; - FPy := FPy + vars[0] * FTy; +//begin +// FPx := FPx + vars[0] * FTx; +// FPy := FPy + vars[0] * FTy; +asm + mov edx, [eax + vars] + fld qword ptr [edx] + fld st + fmul qword ptr [eax + FTx] + fadd qword ptr [eax + FPx] + fstp qword ptr [eax + FPx] + fmul qword ptr [eax + FTy] + fadd qword ptr [eax + FPy] + fstp qword ptr [eax + FPy] + fwait end; //--1--//////////////////////////////////////////////////////////////////////// @@ -265,7 +364,7 @@ procedure TXForm.Spherical; var r: double; begin - r := vars[2] / (FTx * FTx + FTy * FTy + 1E-6); + r := vars[2] / (sqr(FTx) + sqr(FTy) + 1E-6); FPx := FPx + FTx * r; FPy := FPy + FTy * r; end; @@ -273,7 +372,7 @@ end; //--3--//////////////////////////////////////////////////////////////////////// procedure TXForm.Swirl; var - rsin, rcos: double; + sinr, cosr: double; begin { r2 := FTx * FTx + FTy * FTy; @@ -282,9 +381,20 @@ begin FPx := FPx + vars[3] * (c1 * FTx - c2 * FTy); FPy := FPy + vars[3] * (c2 * FTx + c1 * FTy); } - SinCos(FTx * FTx + FTy * FTy, rsin, rcos); - FPx := FPx + vars[3] * (rsin * FTx - rcos * FTy); - FPy := FPy + vars[3] * (rcos * FTx + rsin * FTy); +// SinCos(sqr(FTx) + sqr(FTy), rsin, rcos); + asm + fld qword ptr [eax + FTx] + fmul st, st + fld qword ptr [eax + FTy] + fmul st, st + faddp + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; + FPx := FPx + vars[3] * (sinr * FTx - cosr * FTy); + FPy := FPy + vars[3] * (cosr * FTx + sinr * FTy); end; //--4--//////////////////////////////////////////////////////////////////////// @@ -342,8 +452,22 @@ procedure TXForm.Heart; var r, sinr, cosr: double; begin - r := sqrt(sqr(FTx) + sqr(FTy)); - Sincos(r*FAngle, sinr, cosr); +// r := sqrt(sqr(FTx) + sqr(FTy)); +// Sincos(r*FAngle, sinr, cosr); + asm + fld qword ptr [eax + FTx] + fmul st, st + fld qword ptr [eax + FTy] + fmul st, st + faddp + fsqrt + fstp qword ptr [r] + fmul qword ptr [eax + FAngle] + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; r := r * vars[7]; FPx := FPx + r * sinr; FPy := FPy - r * cosr; @@ -360,7 +484,21 @@ begin // ny := FTy * PI; // r := sqrt(nx * nx + ny * ny); - SinCos(PI * sqrt(sqr(FTx) + sqr(FTy)), sinr, cosr); +// SinCos(PI * sqrt(sqr(FTx) + sqr(FTy)), sinr, cosr); + asm + fld qword ptr [eax + FTx] + fmul st, st + fld qword ptr [eax + FTy] + fmul st, st + faddp + fsqrt + fldpi + fmulp + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; r := vars[8] * FAngle / PI; FPx := FPx + sinr * r; @@ -372,9 +510,15 @@ procedure TXForm.Spiral; var r, sinr, cosr: double; begin -// r := sqrt(FTx * FTx + FTy * FTy) + 1E-6; r := Flength + 1E-6; - SinCos(r, sinr, cosr); +// SinCos(r, sinr, cosr); + asm + fld qword ptr [r] + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; r := vars[9] / r; FPx := FPx + (FCosA + sinr) * r; FPy := FPy + (FsinA - cosr) * r; @@ -398,18 +542,23 @@ begin // Now watch and learn how to do this WITHOUT calculating sin and cos: begin - FPx := FPx + vars[10] * FTx / (FTx * FTx + FTy * FTy + 1E-6); + FPx := FPx + vars[10] * FTx / (sqr(FTx) + sqr(FTy) + 1E-6); FPy := FPy + vars[10] * FTy; end; //--11--/////////////////////////////////////////////////////////////////////// procedure TXForm.Square; var -// r: double; sinr, cosr: double; begin -// r := sqrt(FTx * FTx + FTy * FTy); - SinCos(FLength, sinr, cosr); +// SinCos(FLength, sinr, cosr); + asm + fld qword ptr [eax + FLength] + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; FPx := FPx + vars[11] * FSinA * cosr; FPy := FPy + vars[11] * FCosA * sinr; end; @@ -441,7 +590,14 @@ begin a := FAngle/2 + PI else a := FAngle/2; - SinCos(a, sinr, cosr); +// SinCos(a, sinr, cosr); + asm + fld qword ptr [a] + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; r := vars[13] * sqrt(sqrt(sqr(FTx) + sqr(FTy))); //Math.power(FTx * FTx + FTy * FTy, 0.25); FPx := FPx + r * cosr; FPy := FPy + r * sinr; @@ -449,6 +605,7 @@ end; //--14--/////////////////////////////////////////////////////////////////////// procedure TXForm.Bent; +{ var nx, ny: double; begin @@ -460,6 +617,17 @@ begin ny := ny / 2; FPx := FPx + vars[14] * nx; FPy := FPy + vars[14] * ny; +} +// --Z-- This variation is kinda weird... +begin + if FTx < 0 then + FPx := FPx + vars[14] * (FTx*2) + else + FPx := FPx + vars[14] * FTx; + if FTy < 0 then + FPy := FPy + vars[14] * (FTy/2) + else + FPy := FPy + vars[14] * FTy; end; //--15--/////////////////////////////////////////////////////////////////////// @@ -476,8 +644,8 @@ begin FPy := FPy + vars[15] * ny; } begin - FPx := FPx + vars[15] * (FTx + c10 * sin(FTy / ((c20 * c20) + EPS))); - FPy := FPy + vars[15] * (FTy + c11 * sin(FTx / ((c21 * c21) + EPS))); + FPx := FPx + vars[15] * (FTx + c10 * sin(FTy / (sqr(c20) + EPS))); + FPy := FPy + vars[15] * (FTy + c11 * sin(FTx / (sqr(c21) + EPS))); end; //--16--/////////////////////////////////////////////////////////////////////// @@ -527,7 +695,16 @@ var d: double; sinr, cosr: double; begin - SinCos(PI * FTy, sinr, cosr); +// SinCos(PI * FTy, sinr, cosr); + asm + fld qword ptr [eax + FTy] + fldpi + fmulp + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; d := vars[18] * exp(FTx - 1); // --Z-- (e^x)/e = e^(x-1), isn't it?! FPx := FPx + cosr * d; FPy := FPy + sinr * d; @@ -551,16 +728,31 @@ end; //--20--/////////////////////////////////////////////////////////////////////// procedure TXForm.Cosine; var -// nx, ny: double; sinr, cosr: double; + e1, e2: double; begin - SinCos(FTx * PI, sinr, cosr); -// nx := cosr * cosh(FTy); -// ny := -sinr * sinh(FTy); -// FPx := FPx + vars[20] * nx; -// FPy := FPy + vars[20] * ny; - FPx := FPx + vars[20] * cosr * cosh(FTy); - FPy := FPy - vars[20] * sinr * sinh(FTy); +// SinCos(FTx * PI, sinr, cosr); + asm + fld qword ptr [eax + FTx] + fldpi + fmulp + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; +// FPx := FPx + vars[20] * cosr * cosh(FTy); +// FPy := FPy - vars[20] * sinr * sinh(FTy); + // --Z-- sinh() and cosh() both calculate exp(x) and exp(-x) + if FTy = 0 then + begin + FPx := FPx + vars[20] * cosr; + exit; + end; + e1 := exp(FTy); + e2 := exp(-FTy); + FPx := FPx + vars[20] * cosr * (e1 + e2)/2; + FPy := FPy - vars[20] * sinr * (e1 - e2)/2; end; //--21--/////////////////////////////////////////////////////////////////////// @@ -590,7 +782,7 @@ end; //--22--/////////////////////////////////////////////////////////////////////// procedure TXForm.Fan; var - r,t,a : double; + r, a : double; dx, dy, dx2: double; sinr, cosr: double; begin @@ -600,17 +792,24 @@ begin r := vars[22] * sqrt(sqr(FTx) + sqr(FTy)); - t := FAngle+dy - System.Int((FAngle + dy)/dx) * dx; - if (t > dx2) then + if (FAngle+dy - System.Int((FAngle + dy)/dx) * dx) > dx2 then a := FAngle - dx2 else a := FAngle + dx2; - SinCos(a, sinr, cosr); +// SinCos(a, sinr, cosr); + asm + fld qword ptr [a] + fsincos + fstp qword ptr [cosr] + fstp qword ptr [sinr] + fwait + end; FPx := FPx + r * cosr; FPy := FPy + r * sinr; end; +(* //--23--/////////////////////////////////////////////////////////////////////// procedure TXForm.Triblob; @@ -690,18 +889,40 @@ begin FPy := FPy + vars[26] * r * sinr; end; +*) + //***************************************************************************// -procedure TXForm.NextPoint(var px,py,pc: double); +procedure TXForm.PreviewPoint(var px, py: double); +var + i: Integer; +begin + FTx := c00 * px + c10 * py + c20; + FTy := c01 * px + c11 * py + c21; + + Fpx := 0; + Fpy := 0; + + for i := 0 to FNrFunctions - 1 do + FCalcFunctionList[i]; + + px := FPx; + py := FPy; +end; + +procedure TXForm.NextPoint(var px, py, pc: double); var i: Integer; begin // first compute the color coord - pc := (pc + color) * 0.5 * (1 - symmetry) + symmetry * pc; + if symmetry = 0 then + pc := (pc + color) / 2 + else + pc := (pc + color) * 0.5 * (1 - symmetry) + symmetry * pc; FTx := c00 * px + c10 * py + c20; FTy := c01 * px + c11 * py + c21; - +(* if CalculateAngle then begin if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then FAngle := arctan2(FTx, FTy) @@ -723,21 +944,15 @@ begin // if CalculateLength then begin // FLength := sqrt(FTx * FTx + FTy * FTy); // end; - +*) Fpx := 0; Fpy := 0; for i := 0 to FNrFunctions - 1 do FCalcFunctionList[i]; - if PostTransformEnabled then begin - px := p00 * FPx + p10 * FPy + p20; - py := p01 * FPx + p11 * FPy + p21; - end - else begin - px := FPx; - py := FPy; - end; + px := FPx; + py := FPy; // px := p[0,0] * FPx + p[1,0] * FPy + p[2,0]; // py := p[0,1] * FPx + p[1,1] * FPy + p[2,1]; end; @@ -748,11 +963,15 @@ var i: Integer; begin // first compute the color coord - CPpoint.c := (CPpoint.c + color) * 0.5 * (1 - symmetry) + symmetry * CPpoint.c; + if symmetry = 0 then + CPpoint.c := (CPpoint.c + color) / 2 + else + CPpoint.c := (CPpoint.c + color) * 0.5 * (1 - symmetry) + symmetry * CPpoint.c; FTx := c00 * CPpoint.x + c10 * CPpoint.y + c20; FTy := c01 * CPpoint.x + c11 * CPpoint.y + c21; +(* if CalculateAngle then begin if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then FAngle := arctan2(FTx, FTy) @@ -774,6 +993,7 @@ begin // if CalculateLength then begin // FLength := sqrt(FTx * FTx + FTy * FTy); // end; +*) Fpx := 0; Fpy := 0; @@ -781,19 +1001,14 @@ begin for i:= 0 to FNrFunctions-1 do FFunctionList[i]; - if PostTransformEnabled then begin - CPpoint.x := p00 * FPx + p10 * FPy + p20; - CPpoint.y := p01 * FPx + p11 * FPy + p21; - end - else begin - CPpoint.x := FPx; - CPpoint.y := FPy; - end; + CPpoint.x := FPx; + CPpoint.y := FPy; // CPpoint.x := p[0,0] * FPx + p[1,0] * FPy + p[2,0]; // CPpoint.y := p[0,1] * FPx + p[1,1] * FPy + p[2,1]; end; +{ /////////////////////////////////////////////////////////////////////////////// procedure TXForm.NextPoint(var px, py, pz, pc: double); var @@ -822,6 +1037,7 @@ begin FTx := c00 * tpx + c10 * tpy + c20; FTy := c01 * tpx + c11 * tpy + c21; +(* if CalculateAngle then begin if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then FAngle := arctan2(FTx, FTy) @@ -843,6 +1059,7 @@ begin // if CalculateLength then begin // FLength := sqrt(FTx * FTx + FTy * FTy); // end; +*) Fpx := 0; Fpy := 0; @@ -866,6 +1083,7 @@ begin py := FPy; end; end; +} /////////////////////////////////////////////////////////////////////////////// procedure TXForm.NextPoint2C(var px, py, pc1, pc2: double); @@ -879,6 +1097,7 @@ begin FTx := c00 * px + c10 * py + c20; FTy := c01 * px + c11 * py + c21; +(* if CalculateAngle then begin if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then FAngle := arctan2(FTx, FTy) @@ -900,6 +1119,7 @@ begin // if CalculateLength then begin // FLength := sqrt(FTx * FTx + FTy * FTy); // end; +*) Fpx := 0; Fpy := 0; @@ -907,16 +1127,8 @@ begin for i:= 0 to FNrFunctions-1 do FFunctionList[i]; -// px := FPx; -// py := FPy; - if PostTransformEnabled then begin - px := p00 * FPx + p10 * FPy + p20; - py := p01 * FPx + p11 * FPy + p21; - end - else begin - px := FPx; - py := FPy; - end; + px := FPx; + py := FPy; // px := p[0,0] * FPx + p[1,0] * FPy + p[2,0]; // py := p[0,1] * FPx + p[1,1] * FPy + p[2,1]; end; @@ -929,6 +1141,7 @@ begin FTx := c00 * px + c10 * py + c20; FTy := c01 * px + c11 * py + c21; +(* if CalculateAngle then begin if (FTx < -EPS) or (FTx > EPS) or (FTy < -EPS) or (FTy > EPS) then FAngle := arctan2(FTx, FTy) @@ -946,6 +1159,7 @@ begin FCosA := FTy/FLength; end; end; +*) Fpx := 0; Fpy := 0; @@ -953,16 +1167,8 @@ begin for i:= 0 to FNrFunctions-1 do FFunctionList[i]; -// px := FPx; -// py := FPy; - if PostTransformEnabled then begin - px := p00 * FPx + p10 * FPy + p20; - py := p01 * FPx + p11 * FPy + p21; - end - else begin - px := FPx; - py := FPy; - end; + px := FPx; + py := FPy; // px := p[0,0] * FPx + p[1,0] * FPy + p[2,0]; // py := p[0,1] * FPx + p[1,1] * FPy + p[2,1]; end;