1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-29 12:32:14 -05:00

There u go.. Latest WizzyPlugin ported.

git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@388 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Raymond 2010-01-10 13:07:08 +00:00
parent 3ff440acc1
commit baf574c414
4 changed files with 193 additions and 53 deletions

View File

@ -24,6 +24,7 @@
Sender.Comp.AddConstantN('AppPath','string').SetString(CurrThread.AppPath); Sender.Comp.AddConstantN('AppPath','string').SetString(CurrThread.AppPath);
Sender.Comp.AddConstantN('ScriptPath','string').SetString(CurrThread.ScriptPath); Sender.Comp.AddConstantN('ScriptPath','string').SetString(CurrThread.ScriptPath);
Sender.Comp.AddTypeS('TIntegerArray', 'Array of integer'); Sender.Comp.AddTypeS('TIntegerArray', 'Array of integer');
Sender.Comp.AddTypeS('TExtendedArray','Array of extended');
Sender.Comp.AddTypeS('TBoolArray', 'Array of Boolean'); Sender.Comp.AddTypeS('TBoolArray', 'Array of Boolean');
Sender.Comp.AddTypes('TBox', 'record X1,Y1,X2,Y2 : Integer; end;'); Sender.Comp.AddTypes('TBox', 'record X1,Y1,X2,Y2 : Integer; end;');
Sender.Comp.AddTypeS('TPointArray','Array of TPoint'); Sender.Comp.AddTypeS('TPointArray','Array of TPoint');

View File

@ -196,4 +196,57 @@ AddFunction(@DrawATPABitmapEx,'procedure DrawATPABitmapEx(bitmap : integer; ATPA
{tpa} {tpa}
SetCurrSection('TPA'); SetCurrSection('TPA');
AddFunction(@tSwap,'procedure tSwap(var a, b: TPoint);');
AddFunction(@tpaSwap,'procedure tpaSwap(var a, b: TPointArray);');
AddFunction(@SwapE,'procedure SwapE(var a, b: Extended);');
AddFunction(@RAaSTPAEx,'procedure RAaSTPAEx(var a: TPointArray; const w, h: Integer);');
AddFunction(@RAaSTPA,'procedure RAaSTPA(var a: TPointArray; const Dist: Integer);');
AddFunction(@NearbyPointInArrayEx,'function NearbyPointInArrayEx(const P: TPoint; w, h:Integer; a: TPointArray): Boolean;');
AddFunction(@NearbyPointInArray,'function NearbyPointInArray(const P: TPoint; Dist:Integer; a: TPointArray): Boolean;');
AddFunction(@ReArrangeandShortenArrayEx,'function ReArrangeandShortenArrayEx(a: TPointArray; w, h: Integer): TPointArray;');
AddFunction(@ReArrangeandShortenArray,'function ReArrangeandShortenArray(a: TPointArray; Dist: Integer): TPointArray;');
AddFunction(@TPAtoATPAEx,'function TPAtoATPAEx(TPA: TPointArray; w, h: Integer): T2DPointArray;');
AddFunction(@TPAtoATPA,'function TPAtoATPA(TPA: TPointArray; Dist: Integer): T2DPointArray;');
AddFunction(@QuickTPASort,'procedure QuickTPASort(var A: TIntegerArray; var B: TPointArray; iLo, iHi: Integer; SortUp: Boolean);');
AddFunction(@QuickATPASort,'procedure QuickATPASort(var A: TIntegerArray; var B: T2DPointArray; iLo, iHi: Integer; SortUp: Boolean);');
AddFunction(@SortTPAFrom,'procedure SortTPAFrom(var a: TPointArray; const From: TPoint);');
AddFunction(@SortATPAFrom,'procedure SortATPAFrom(var a: T2DPointArray; const From: TPoint);');
AddFunction(@SortATPAFromFirstPoint,'procedure SortATPAFromFirstPoint(var a: T2DPointArray; const From: TPoint);');
AddFunction(@InvertTPA,'procedure InvertTPA(var a: TPointArray);');
AddFunction(@InvertATPA,'procedure InvertATPA(var a: T2DPointArray);');
AddFunction(@MiddleTPAEx,'function MiddleTPAEx(TPA: TPointArray; var x, y: Integer): Boolean;');
AddFunction(@MiddleTPA,'function MiddleTPA(tpa: TPointArray): TPoint;');
AddFunction(@SortATPASize,'procedure SortATPASize(var a: T2DPointArray; const BigFirst: Boolean);');
AddFunction(@SortATPAFromSize,'procedure SortATPAFromSize(var a: T2DPointArray; const Size: Integer; CloseFirst: Boolean);');
AddFunction(@CombineTPA,'function CombineTPA(Ar1, Ar2: TPointArray): TPointArray;');
AddFunction(@CombineIntArray,'function CombineIntArray(Ar1, Ar2: TIntegerArray): TIntegerArray;');
AddFunction(@InIntArrayEx,'function InIntArrayEx(a: TIntegerArray; var Where: Integer; const Number: Integer): Boolean;');
AddFunction(@InIntArray,'function InIntArray(a: TIntegerArray; Number: Integer): Boolean;');
AddFunction(@ClearSameIntegers,'procedure ClearSameIntegers(var a: TIntegerArray);');
AddFunction(@ClearSameIntegersAndTPA,'procedure ClearSameIntegersAndTPA(var a: TIntegerArray; var p: TPointArray);');
AddFunction(@SplitTPAEx,'function SplitTPAEx(arr: TPointArray; w, h: Integer): T2DPointArray;'); AddFunction(@SplitTPAEx,'function SplitTPAEx(arr: TPointArray; w, h: Integer): T2DPointArray;');
AddFunction(@SplitTPA,'function SplitTPA(arr: TPointArray; Dist: Integer): T2DPointArray;');
AddFunction(@FilterPointsPie,'procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);');
AddFunction(@RemoveDistTPointArray,'function RemoveDistTPointArray(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;');
AddFunction(@GetATPABounds,'function GetATPABounds(ATPA: T2DPointArray): TBox;');
AddFunction(@GetTPABounds,'function GetTPABounds(TPA: TPointArray): TBox;');
AddFunction(@FindTPAinTPA,'function FindTPAinTPA(SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;');
AddFunction(@FindTextTPAinTPA,'function FindTextTPAinTPA(Height : integer; SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;');
AddFunction(@FindGapsTPA,'function FindGapsTPA(TPA: TPointArray; MinPixels: Integer): T2DPointArray;');
AddFunction(@SortCircleWise,'procedure SortCircleWise(var tpa: TPointArray; const cx, cy, StartDegree: Integer; SortUp, ClockWise: Boolean);');
AddFunction(@LinearSort,'procedure LinearSort(var tpa: TPointArray; cx, cy, sd: Integer; SortUp: Boolean);');
AddFunction(@MergeATPA,'Function MergeATPA(ATPA : T2DPointArray) : TPointArray;');
AddFunction(@TPAFromBox,'function TPAFromBox(const Box : TBox) : TPointArray;');
AddFunction(@RotatePoints,'Function RotatePoints(Const P: TPointArray; A, cx, cy: Extended): TPointArray ;');
AddFunction(@RotatePoint,'Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint; inline;');
AddFunction(@FindTPAEdges,'function FindTPAEdges(p: TPointArray): TPointArray;');
AddFunction(@PointInTPA,'function PointInTPA(p: TPoint; arP: TPointArray): Boolean;');
AddFunction(@ClearTPAFromTPA,'function ClearTPAFromTPA(arP, ClearPoints: TPointArray): TPointArray;');
AddFunction(@ClearDoubleTPA,'procedure ClearDoubleTPA(var TPA: TPointArray);');
AddFunction(@ReturnPointsNotInTPA,'Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; const Box: TBox): TPointArray;');
AddFunction(@TPACountSort,'Procedure TPACountSort(Var TPA: TPointArray;const max: TPoint;Const SortOnX : Boolean);');
AddFunction(@TPACountSortBase,'Procedure TPACountSortBase(Var TPA: TPointArray;const maxx, base: TPoint; const SortOnX : Boolean);');
AddFunction(@InvertTIA,'procedure InvertTIA(var tI: TIntegerArray);');
AddFunction(@SumIntegerArray,'function SumIntegerArray(Ints : TIntegerArray): Integer;');
AddFunction(@AverageTIA,'function AverageTIA(tI: TIntegerArray): Integer;');
AddFunction(@AverageExtended,'function AverageExtended(tE: TExtendedArray): Extended;');

View File

@ -79,9 +79,13 @@ function FindTPAEdges(p: TPointArray): TPointArray;
function PointInTPA(p: TPoint; arP: TPointArray): Boolean; function PointInTPA(p: TPoint; arP: TPointArray): Boolean;
function ClearTPAFromTPA(arP, ClearPoints: TPointArray): TPointArray; function ClearTPAFromTPA(arP, ClearPoints: TPointArray): TPointArray;
procedure ClearDoubleTPA(var TPA: TPointArray); procedure ClearDoubleTPA(var TPA: TPointArray);
Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; Box: TBox): TPointArray; Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; const Box: TBox): TPointArray;
Procedure TPACountSort(Var TPA: TPointArray;const max: TPoint;Const SortOnX : Boolean); Procedure TPACountSort(Var TPA: TPointArray;const max: TPoint;Const SortOnX : Boolean);
Procedure TPACountSortBase(Var TPA: TPointArray;const maxx, base: TPoint; const SortOnX : Boolean); Procedure TPACountSortBase(Var TPA: TPointArray;const maxx, base: TPoint; const SortOnX : Boolean);
procedure InvertTIA(var tI: TIntegerArray);
function SumIntegerArray(Ints : TIntegerArray): Integer;
function AverageTIA(tI: TIntegerArray): Integer;
function AverageExtended(tE: TExtendedArray): Extended;
implementation implementation
@ -222,21 +226,15 @@ procedure RAaSTPAEx(var a: TPointArray; const w, h: Integer);
var var
i, c, NoTP, l: Integer; i, c, NoTP, l: Integer;
t: TPoint; t: TPoint;
b: boolean;
begin begin
b:=false;
NoTP := 0; NoTP := 0;
l := High(a); l := High(a);
for i := 0 to l do for i := 0 to l do
begin begin
for c := 0 to NoTP - 1 do for c := 0 to NoTP - 1 do
if (Abs(a[i].x - a[c].x) <= w) and (Abs(a[i].y - a[c].y) <= h) then if (Abs(a[i].x - a[c].x) <= w) and (Abs(a[i].y - a[c].y) <= h) then
begin
b := true;
Break; Break;
end; if (c >= NoTP) then
if not b then
begin begin
t := a[i]; t := a[i];
a[i] := a[NoTP]; a[i] := a[NoTP];
@ -255,20 +253,14 @@ procedure RAaSTPA(var a: TPointArray; const Dist: Integer);
var var
i, c, NoTP, l: Integer; i, c, NoTP, l: Integer;
t: TPoint; t: TPoint;
b: boolean;
begin begin
b := false;
NoTP := 0; NoTP := 0;
l := High(a); l := High(a);
for i := 0 to l do for i := 0 to l do
begin begin
for c := 0 to NoTP - 1 do for c := 0 to NoTP - 1 do
if (Round(fSqrt(Sqr(a[i].x - a[c].x) + Sqr(a[i].y - a[c].y))) <= Dist) then if (Round(fSqrt(Sqr(a[i].x - a[c].x) + Sqr(a[i].y - a[c].y))) <= Dist) then
begin
b:=true;
Break; Break;
end;
if (c >= NoTP) then if (c >= NoTP) then
begin begin
t := a[i]; t := a[i];
@ -545,16 +537,12 @@ var
i, l: Integer; i, l: Integer;
DistArr: TIntegerArray; DistArr: TIntegerArray;
begin begin
//writeln('hoi0');
l := High(a); l := High(a);
if (l < 0) then Exit; if (l < 0) then Exit;
//writeln('hoi1');
SetLength(DistArr, l + 1); SetLength(DistArr, l + 1);
for i := 0 to l do for i := 0 to l do
DistArr[i] := Round(Sqr(From.x - a[i][0].x) + Sqr(From.y - a[i][0].y)); DistArr[i] := Round(Sqr(From.x - a[i][0].x) + Sqr(From.y - a[i][0].y));
//writeln('hoi2');
QuickATPASort(DistArr, a, 0, l, True); QuickATPASort(DistArr, a, 0, l, True);
//writeln('hoi3');
end; end;
{/\ {/\
@ -866,7 +854,7 @@ begin
t2 := 0; t2 := 0;
while (t2 <= (l - ec)) do while (t2 <= (l - ec)) do
begin begin
if (Round(Sqrt(Sqr(Result[c][t1].x - tpa[t2].x) + Sqr(Result[c][t1].y - tpa[t2].y))) <= Dist) then if (Round(fSqrt(Sqr(Result[c][t1].x - tpa[t2].x) + Sqr(Result[c][t1].y - tpa[t2].y))) <= Dist) then
begin begin
SetLength(Result[c], tc +1); SetLength(Result[c], tc +1);
Result[c][tc] := tpa[t2]; Result[c][tc] := tpa[t2];
@ -1341,11 +1329,16 @@ end;
Merges the TPointArrays of the T2DPointArray ATPA in to one TPA. Merges the TPointArrays of the T2DPointArray ATPA in to one TPA.
/\} /\}
Function MergeATPA(ATPA : T2DPointArray) : TPointArray; Function MergeATPA(ATPA: T2DPointArray): TPointArray;
var var
I,II, Len, TempL,CurrentL : integer; I, II, Len, TempL, CurrentL: integer;
begin; begin;
Len := High(ATPA); Len := High(ATPA);
if Len < 0 then
begin
SetLength(Result, 0);
Exit;
end;
CurrentL := 0; CurrentL := 0;
For I:= 0 to Len do For I:= 0 to Len do
begin; begin;
@ -1399,14 +1392,14 @@ Begin
Result[I].X := Trunc(cx + cos(A) * (p[i].x - cx) - sin(A) * (p[i].y - cy)); Result[I].X := Trunc(cx + cos(A) * (p[i].x - cx) - sin(A) * (p[i].y - cy));
Result[I].Y := Trunc(cy + sin(A) * (p[i].x - cx) + cos(A) * (p[i].y - cy)); Result[I].Y := Trunc(cy + sin(A) * (p[i].x - cx) + cos(A) * (p[i].y - cy));
End; End;
// I recon its faster than Point(). // I recon it's faster than Point().
End; End;
{/\ {/\
Rotate the given Point with A radians. Rotate the given Point with A radians.
/\} /\}
Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint; inline; Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;
Begin Begin
Result.X := Trunc(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my)); Result.X := Trunc(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
@ -1467,10 +1460,16 @@ var
i, l: Integer; i, l: Integer;
begin begin
l := High(arP); l := High(arP);
if l < 0 then
begin
Result := False;
Exit;
end;
Result := True;
for i := 0 to l do for i := 0 to l do
if (arP[i].x = p.x) and (arP[i].y = p.y) then if (arP[i].x = p.x) and (arP[i].y = p.y) then
Break; Exit;
Result := i <> Length(arP); Result := False;
end; end;
{/\ {/\
@ -1526,31 +1525,40 @@ end;
\\ If you pass this all the colors of the background, it will returns the points of the object. \\ If you pass this all the colors of the background, it will returns the points of the object.
/\} /\}
Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; Box: TBox): TPointArray; Function ReturnPointsNotInTPA(Const TotalTPA: TPointArray; const Box: TBox): TPointArray;
var
Var x, y, w, h, i, l: integer;
X, Y, I: Integer; B: Array of Array of Boolean;
B: Array Of Array Of Boolean; begin;
w := Box.x2 - Box.x1;
Begin h := Box.y2 - Box.y1;
SetLength(Result, ((Box.X2 - Box.X1 + 1) * (Box.Y2 - Box.Y1 + 1)) - Length(TotalTPA)); if (w = 0) and (h = 0) then
Exit;
SetLength(B, Box.X2 - Box.X1 + 1, Box.Y2 - Box.Y1 + 1); SetLength(b, w + 1, h + 1);
l := High(TotalTPA);
For I := 0 To High(TotalTPA) Do x := 0;
B[TotalTPA[I].X - Box.X1][TotalTPA[I].Y - Box.Y1] := True; for i := 0 to l do
if ((TotalTPA[i].x >= Box.x1) and (TotalTPA[i].x <= Box.x2) and
I := 0; (TotalTPA[i].y >= Box.y1) and (TotalTPA[i].y <= Box.y2)) then
For X := 0 To Box.X2 - Box.X1 Do begin;
For Y := 0 To Box.Y2 - Box.Y1 Do Inc(x);
If Not B[X][Y] Then B[TotalTPA[i].x-Box.x1][TotalTPA[i].y-Box.y1] := True;
Begin end;
Result[I].X := X + Box.X1; if x = 0 then
Result[I].Y := Y + Box.Y1; Exit;
I := I + 1; SetLength(result,(w + 1) * (h + 1) - x);
End; i := 0;
SetLength(B, 0); for x := 0 to w do
End; for y := 0 to h do
if not B[x][y] then
try
Result[i].x := x + Box.x1;
Result[i].y := y + Box.y1;
Inc(i);
except end;
SetLength(b, 0);
SetLength(Result, i);
end;
{/\ {/\
Sorts a TPointArray by either X or Y. You have to define the max Point as well. Sorts a TPointArray by either X or Y. You have to define the max Point as well.
@ -1596,6 +1604,7 @@ Begin
end; end;
End; End;
{/\ {/\
Sorts a TPointArray by either X or Y. Allows one to pass a Base. Sorts a TPointArray by either X or Y. Allows one to pass a Base.
/\} /\}
@ -1644,5 +1653,59 @@ Begin
end; end;
End; End;
{/\
Returns the sum of all integers in the array
/\}
function SumIntegerArray(Ints : TIntegerArray): Integer;
var
I, H: Integer;
begin
Result := 0;
H := High(Ints);
for I := 0 to H do
Result := Result + Ints[I];
end;
{/\
Inverts the IntegerArray, last becomes first etc..
/\}
procedure InvertTIA(var tI: TIntegerArray);
var
Temp: TIntegerArray;
i, h: Integer;
begin
h := High(tI);
Temp := tI;
for i := 0 to h do
tI[i] := Temp[h - i];
end;
{/\
Results the Average of an IntegerArray
/\}
function AverageTIA(tI: TIntegerArray): Integer;
begin
try Result := (SumIntegerArray(tI) div Length(tI)); except Result := 0; end;
end;
{/\
Results the Average of an ExtendedArray
/\}
function AverageExtended(tE: TExtendedArray): Extended;
var
i, h: Integer;
begin
Result := 1;
try
h := High(tE);
for i := 0 to h do
Result := (Result * tE[i]);
Result := Power(Result, 1/(h + 1));
except
Result := 0.0;
end;
end;
end. end.

View File

@ -56,6 +56,7 @@ type
procedure DrawATPA(ATPA : T2DPointArray; Colors : TIntegerArray);overload; procedure DrawATPA(ATPA : T2DPointArray; Colors : TIntegerArray);overload;
procedure DrawATPA(ATPA : T2DPointArray);overload; procedure DrawATPA(ATPA : T2DPointArray);overload;
procedure DrawTPA(TPA : TPointArray; Color : TColor); procedure DrawTPA(TPA : TPointArray; Color : TColor);
function CreateTPA(SearchCol : TColor) : TPointArray;
function FastGetPixel(x,y : integer) : TColor; function FastGetPixel(x,y : integer) : TColor;
function FastGetPixels(TPA : TPointArray) : TIntegerArray; function FastGetPixels(TPA : TPointArray) : TIntegerArray;
Procedure SetTransparentColor(Col : TColor); Procedure SetTransparentColor(Col : TColor);
@ -114,7 +115,7 @@ implementation
uses uses
Windowutil,paszlib,DCPbase64,math, Windowutil,paszlib,DCPbase64,math,
colour_conv,window,mufasatypesutil; colour_conv,window,mufasatypesutil,tpa;
function Min(a,b:integer) : integer; function Min(a,b:integer) : integer;
begin begin
@ -552,6 +553,28 @@ begin
DrawATPA(ConvArr([TPA]),ConvArr([Color])); DrawATPA(ConvArr([TPA]),ConvArr([Color]));
end; end;
function TMufasaBitmap.CreateTPA(SearchCol: TColor): TPointArray;
var
x,y,L,I : Integer;
StartPtr : PRGB32;
Search : TRGB32;
begin
SetLength(Result,self.Width * Self.Height);
L := 0;
Search := RGBToBGR(SearchCol);
StartPtr := Self.FData;
For y := 0 to Self.h - 1 do
For x := 0 to self.w - 1 do
if LongWord(StartPtr^) = LongWord(SearchCol) then
begin;
L := L + 1;
Result[L].x := x;
Result[L].y := y;
end;
SetLength(Result,L + 1);
end;
function TMufasaBitmap.FastGetPixel(x, y: integer): TColor; function TMufasaBitmap.FastGetPixel(x, y: integer): TColor;