mirror of
https://github.com/moparisthebest/Simba
synced 2024-11-30 12:52:16 -05:00
Merge branch 'cts-rework' into cts-3
Conflicts: Units/MMLCore/finder.pas
This commit is contained in:
commit
edf11bd6db
@ -449,7 +449,6 @@ function Create_CTSInfo(cts: integer; Color, Tol: Integer;
|
||||
hueMod, satMod: extended): Pointer; overload;
|
||||
var
|
||||
R, G, B: Integer;
|
||||
H, S, L: Integer;
|
||||
X, Y, Z: Extended;
|
||||
begin
|
||||
case cts of
|
||||
@ -509,7 +508,24 @@ begin
|
||||
raise Exception.Create('Free_CTSInfo: Invalid TCTSInfo passed');
|
||||
end;
|
||||
|
||||
{ TODO: Not universal, mainly for DTM }
|
||||
function Create_CTSInfoArray(cts: integer; color, tolerance: array of integer;
|
||||
hueMod, satMod: extended): TCTSInfoArray;
|
||||
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
if length(color) <> length(tolerance) then
|
||||
raise Exception.Create('Create_CTSInfoArray: Length(Color) <>'
|
||||
+' Length(Tolerance');
|
||||
SetLength(Result, Length(color));
|
||||
|
||||
for i := High(result) downto 0 do
|
||||
result := Create_CTSInfo(cts, color[i], tolerance[i], hueMod, satMod);
|
||||
end;
|
||||
|
||||
|
||||
{ TODO: Not universal, mainly for Bitmap }
|
||||
function Create_CTSInfo2DArray(cts, w, h: integer; data: TPRGB32Array;
|
||||
Tolerance: Integer; hueMod, satMod: Extended): TCTSInfo2DArray;
|
||||
var
|
||||
@ -519,11 +535,9 @@ begin
|
||||
|
||||
for y := 0 to h do
|
||||
for x := 0 to w do
|
||||
begin
|
||||
Result[y][x] := Create_CTSInfo(cts,
|
||||
data[y][x].R, data[y][x].G, data[y][x].B,
|
||||
Tolerance, hueMod, satMod);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure Free_CTSInfoArray(i: TCTSInfoArray);
|
||||
@ -531,7 +545,7 @@ var
|
||||
c: integer;
|
||||
begin
|
||||
for c := high(i) downto 0 do
|
||||
Free_CTSInfo(i[c]);
|
||||
Free_CTSInfo(i[c]);
|
||||
SetLength(i, 0);
|
||||
end;
|
||||
|
||||
@ -628,7 +642,6 @@ var
|
||||
PtrData: TRetData;
|
||||
Ptr: PRGB32;
|
||||
PtrInc: Integer;
|
||||
clR, clG, clB : byte;
|
||||
dX, dY, xx, yy: Integer;
|
||||
|
||||
compare: TCTSCompareFunction;
|
||||
@ -1063,7 +1076,7 @@ var
|
||||
PtrData: TRetData;
|
||||
Ptr: PRGB32;
|
||||
PtrInc: Integer;
|
||||
dX, dY, clR, clG, clB: Integer;
|
||||
dX, dY: Integer;
|
||||
xx, yy: integer;
|
||||
compare: TCTSCompareFunction;
|
||||
ctsinfo: TCTSInfo;
|
||||
@ -1208,7 +1221,7 @@ var
|
||||
PtrData: TRetData;
|
||||
Ptr: PRGB32;
|
||||
PtrInc,C: Integer;
|
||||
dX, dY, clR, clG, clB: Integer;
|
||||
dX, dY: Integer;
|
||||
|
||||
xx, yy: integer;
|
||||
compare: TCTSCompareFunction;
|
||||
@ -1781,8 +1794,6 @@ var
|
||||
xBmp,yBmp : integer;
|
||||
tmpY : integer;
|
||||
dX, dY, i,HiSpiral: Integer;
|
||||
CCTS : integer;
|
||||
H,S,L,HMod,SMod : extended;
|
||||
SkipCoords : T2DBoolArray;
|
||||
|
||||
ctsinfoarray: TCTSInfo2DArray;
|
||||
@ -1859,8 +1870,6 @@ var
|
||||
tmpY : integer;
|
||||
dX, dY, i,HiSpiral: Integer;
|
||||
FoundC : integer;
|
||||
CCTS : integer;
|
||||
H,S,L,HMod,SMod : extended;
|
||||
SkipCoords : T2DBoolArray;
|
||||
|
||||
ctsinfoarray: TCTSInfo2DArray;
|
||||
@ -2074,16 +2083,9 @@ end;
|
||||
//MaxToFind, if it's < 1 it won't stop looking
|
||||
function TMFinder.FindDTMs(DTM: TMDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
|
||||
var
|
||||
//Cache DTM stuff
|
||||
Len : integer; //Len of the points
|
||||
DPoints : PMDTMPoint; //DTM Points
|
||||
// Colours of DTMs
|
||||
clR,clG,clB : array of byte;
|
||||
|
||||
//Similar colors stuff
|
||||
hh,ss,ll: array of extended;
|
||||
hmod,smod: extended;
|
||||
Ccts : integer;
|
||||
//Cache DTM stuff
|
||||
Len : integer; //Len of the points
|
||||
DPoints : PMDTMPoint; //DTM Points
|
||||
|
||||
// Bitwise
|
||||
b: Array of Array of Integer;
|
||||
@ -2111,11 +2113,13 @@ var
|
||||
|
||||
goodPoints: Array of Boolean;
|
||||
|
||||
col_arr, tol_arr: Array of Integer;
|
||||
ctsinfoarray: TCTSInfoArray;
|
||||
compare: TCTSCompareFunction;
|
||||
|
||||
label theEnd;
|
||||
label AnotherLoopEnd;
|
||||
|
||||
|
||||
|
||||
begin
|
||||
// Is the area valid?
|
||||
DefaultOperations(x1, y1, x2, y2);
|
||||
@ -2146,26 +2150,22 @@ begin
|
||||
FillChar(b[i][0], SizeOf(Integer) * (H+1), 0);
|
||||
end;
|
||||
|
||||
// C = DTM.C
|
||||
SetLength(clR,Len);
|
||||
SetLength(clG,Len);
|
||||
SetLength(clB,Len);
|
||||
for i := 0 to Len - 1 do
|
||||
ColorToRGB(DPoints[i].c,clR[i],clG[i],clB[i]);
|
||||
|
||||
SetLength(hh,Len);
|
||||
SetLength(ss,Len);
|
||||
SetLength(ll,Len);
|
||||
for i := 0 to Len - 1 do
|
||||
ColorToHSL(DPoints[i].c,hh[i],ss[i],ll[i]);
|
||||
|
||||
GetToleranceSpeed2Modifiers(hMod, sMod);
|
||||
|
||||
ccts := CTS;
|
||||
|
||||
// Retreive Client Data.
|
||||
PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
|
||||
|
||||
SetLength(col_arr, Len);
|
||||
SetLength(tol_arr, Len);
|
||||
// C = DTM.C
|
||||
for i := 0 to Len - 1 do
|
||||
begin
|
||||
col_arr[i] := DPoints[i].c;
|
||||
tol_arr[i] := DPoints[i].t;
|
||||
end;
|
||||
|
||||
ctsinfoarray := Create_CTSInfoArray(Self.CTS,
|
||||
col_arr, tol_arr, self.hueMod, self.satMod);
|
||||
compare := Get_CTSCompare(Self.CTS);
|
||||
|
||||
cd := CalculateRowPtrs(PtrData, h + 1);
|
||||
//CD starts at 0,0.. We must adjust the MA, since this is still based on the xs,ys,xe,ye box.
|
||||
MA.x1 := MA.x1 - x1;
|
||||
@ -2199,7 +2199,7 @@ begin
|
||||
// Checking point i now. (Store that we matched it)
|
||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
||||
// if SimilarColors(dtm.c[i], rgbtocolor(cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B), DPoints[i].t) then
|
||||
if ColorSame(ccts,DPoints[i].t,clR[i],clG[i],clB[i],cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B,hh[i],ss[i],ll[i],hmod,smod) then
|
||||
if compare(ctsinfoarray[i], @cd[yyy][xxx]) then
|
||||
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
||||
end;
|
||||
|
||||
@ -2228,6 +2228,8 @@ begin
|
||||
AnotherLoopEnd:
|
||||
end;
|
||||
TheEnd:
|
||||
|
||||
Free_CTSInfoArray(ctsinfoarray);
|
||||
TClient(Client).IOManager.FreeReturnData;
|
||||
|
||||
SetLength(Points, pc);
|
||||
@ -2244,14 +2246,15 @@ var
|
||||
begin
|
||||
FindDTMsRotated(dtm, P, x1, y1, x2, y2, sAngle, eAngle, aStep, F,Alternating,1);
|
||||
if Length(P) = 0 then
|
||||
exit(false);
|
||||
exit(False);
|
||||
aFound := F[0][0];
|
||||
x := P[0].x;
|
||||
y := P[0].y;
|
||||
Exit(True);
|
||||
end;
|
||||
|
||||
procedure RotPoints_DTM(const P: TPointArray;var RotTPA : TPointArray; const A: Extended);
|
||||
procedure RotPoints_DTM(const P: TPointArray;var RotTPA : TPointArray; const A:
|
||||
Extended); inline;
|
||||
var
|
||||
I, L: Integer;
|
||||
begin
|
||||
@ -2265,18 +2268,11 @@ end;
|
||||
|
||||
function TMFinder.FindDTMsRotated(DTM: TMDTM; out Points: TPointArray; x1, y1, x2, y2: Integer; sAngle, eAngle, aStep: Extended; out aFound: T2DExtendedArray;Alternating : boolean; maxToFind: Integer): Boolean;
|
||||
var
|
||||
//Cached variables
|
||||
Len : integer;
|
||||
DPoints : PMDTMPoint;
|
||||
DTPA : TPointArray;
|
||||
RotTPA: TPointArray;
|
||||
// Colours of DTMs
|
||||
clR,clG,clB : array of byte;
|
||||
|
||||
//Similar colors stuff
|
||||
hh,ss,ll: array of extended;
|
||||
hmod,smod: extended;
|
||||
Ccts : integer;
|
||||
//Cached variables
|
||||
Len : integer;
|
||||
DPoints : PMDTMPoint;
|
||||
DTPA : TPointArray;
|
||||
RotTPA: TPointArray;
|
||||
|
||||
// Bitwise
|
||||
b: Array of Array of Integer;
|
||||
@ -2306,11 +2302,14 @@ var
|
||||
|
||||
// point count
|
||||
pc: Integer = 0;
|
||||
ac: Integer = 0;
|
||||
|
||||
goodPoints: Array of Boolean;
|
||||
s: extended;
|
||||
|
||||
col_arr, tol_arr: Array of Integer;
|
||||
ctsinfoarray: TCTSInfoArray;
|
||||
compare: TCTSCompareFunction;
|
||||
|
||||
label theEnd;
|
||||
label AnotherLoopEnd;
|
||||
|
||||
@ -2346,20 +2345,6 @@ begin
|
||||
FillChar(ch[i][0], SizeOf(Integer) * (H+1), 0);
|
||||
end;
|
||||
|
||||
// Convert colors to there components
|
||||
SetLength(clR,Len);
|
||||
SetLength(clG,Len);
|
||||
SetLength(clB,Len);
|
||||
for i := 0 to Len - 1 do
|
||||
ColorToRGB(DPoints[i].c,clR[i],clG[i],clB[i]);
|
||||
//Compiler hints
|
||||
|
||||
SetLength(hh,Len);
|
||||
SetLength(ss,Len);
|
||||
SetLength(ll,Len);
|
||||
for i := 0 to Len - 1 do
|
||||
ColorToHSL(DPoints[i].c,hh[i],ss[i],ll[i]);
|
||||
|
||||
{
|
||||
When we search for a rotated DTM, everything is the same, except the coordinates..
|
||||
Therefore we create a TPA of the 'original' DTM, containing all the Points.
|
||||
@ -2369,12 +2354,22 @@ begin
|
||||
for i := 0 to len-1 do
|
||||
DTPA[i] := Point(DPoints[i].x,DPoints[i].y);
|
||||
|
||||
GetToleranceSpeed2Modifiers(hMod, sMod);
|
||||
ccts := CTS;
|
||||
|
||||
// Retreive Client Data.
|
||||
PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
|
||||
|
||||
SetLength(col_arr, Len);
|
||||
SetLength(tol_arr, Len);
|
||||
// C = DTM.C
|
||||
for i := 0 to Len - 1 do
|
||||
begin
|
||||
col_arr[i] := DPoints[i].c;
|
||||
tol_arr[i] := DPoints[i].t;
|
||||
end;
|
||||
|
||||
ctsinfoarray := Create_CTSInfoArray(Self.CTS,
|
||||
col_arr, tol_arr, self.hueMod, self.satMod);
|
||||
compare := Get_CTSCompare(Self.CTS);
|
||||
|
||||
cd := CalculateRowPtrs(PtrData, h + 1);
|
||||
SetLength(aFound, 0);
|
||||
SetLength(Points, 0);
|
||||
@ -2420,7 +2415,7 @@ begin
|
||||
// Checking point i now. (Store that we matched it)
|
||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
||||
|
||||
if ColorSame(ccts,DPoints[i].t,clR[i],clG[i],clB[i],cd[yyy][xxx].R, cd[yyy][xxx].G, cd[yyy][xxx].B,hh[i],ss[i],ll[i],hmod,smod) then
|
||||
if compare(ctsinfoarray[i], @cd[yyy][xxx]) then
|
||||
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
||||
end;
|
||||
|
||||
@ -2452,7 +2447,6 @@ begin
|
||||
goto theEnd;
|
||||
AnotherLoopEnd:
|
||||
end;
|
||||
ac := 0;
|
||||
if Alternating then
|
||||
begin
|
||||
if AngleSteps mod 2 = 0 then //This means it's an even number, thus we must add a positive step
|
||||
@ -2464,7 +2458,10 @@ begin
|
||||
s := s + aStep;
|
||||
end;
|
||||
TheEnd:
|
||||
TClient(Client).IOManager.FreeReturnData;
|
||||
|
||||
Free_CTSInfoArray(ctsinfoarray);
|
||||
TClient(Client).IOManager.FreeReturnData;
|
||||
|
||||
Result := (pc > 0);
|
||||
{ Don't forget to pre calculate the rotated points at the start.
|
||||
Saves a lot of rotatepoint() calls. }
|
||||
|
Loading…
Reference in New Issue
Block a user