mirror of
https://github.com/moparisthebest/Simba
synced 2025-02-19 20:41:48 -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;
|
hueMod, satMod: extended): Pointer; overload;
|
||||||
var
|
var
|
||||||
R, G, B: Integer;
|
R, G, B: Integer;
|
||||||
H, S, L: Integer;
|
|
||||||
X, Y, Z: Extended;
|
X, Y, Z: Extended;
|
||||||
begin
|
begin
|
||||||
case cts of
|
case cts of
|
||||||
@ -509,7 +508,24 @@ begin
|
|||||||
raise Exception.Create('Free_CTSInfo: Invalid TCTSInfo passed');
|
raise Exception.Create('Free_CTSInfo: Invalid TCTSInfo passed');
|
||||||
end;
|
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;
|
function Create_CTSInfo2DArray(cts, w, h: integer; data: TPRGB32Array;
|
||||||
Tolerance: Integer; hueMod, satMod: Extended): TCTSInfo2DArray;
|
Tolerance: Integer; hueMod, satMod: Extended): TCTSInfo2DArray;
|
||||||
var
|
var
|
||||||
@ -519,11 +535,9 @@ begin
|
|||||||
|
|
||||||
for y := 0 to h do
|
for y := 0 to h do
|
||||||
for x := 0 to w do
|
for x := 0 to w do
|
||||||
begin
|
|
||||||
Result[y][x] := Create_CTSInfo(cts,
|
Result[y][x] := Create_CTSInfo(cts,
|
||||||
data[y][x].R, data[y][x].G, data[y][x].B,
|
data[y][x].R, data[y][x].G, data[y][x].B,
|
||||||
Tolerance, hueMod, satMod);
|
Tolerance, hueMod, satMod);
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure Free_CTSInfoArray(i: TCTSInfoArray);
|
procedure Free_CTSInfoArray(i: TCTSInfoArray);
|
||||||
@ -628,7 +642,6 @@ var
|
|||||||
PtrData: TRetData;
|
PtrData: TRetData;
|
||||||
Ptr: PRGB32;
|
Ptr: PRGB32;
|
||||||
PtrInc: Integer;
|
PtrInc: Integer;
|
||||||
clR, clG, clB : byte;
|
|
||||||
dX, dY, xx, yy: Integer;
|
dX, dY, xx, yy: Integer;
|
||||||
|
|
||||||
compare: TCTSCompareFunction;
|
compare: TCTSCompareFunction;
|
||||||
@ -1063,7 +1076,7 @@ var
|
|||||||
PtrData: TRetData;
|
PtrData: TRetData;
|
||||||
Ptr: PRGB32;
|
Ptr: PRGB32;
|
||||||
PtrInc: Integer;
|
PtrInc: Integer;
|
||||||
dX, dY, clR, clG, clB: Integer;
|
dX, dY: Integer;
|
||||||
xx, yy: integer;
|
xx, yy: integer;
|
||||||
compare: TCTSCompareFunction;
|
compare: TCTSCompareFunction;
|
||||||
ctsinfo: TCTSInfo;
|
ctsinfo: TCTSInfo;
|
||||||
@ -1208,7 +1221,7 @@ var
|
|||||||
PtrData: TRetData;
|
PtrData: TRetData;
|
||||||
Ptr: PRGB32;
|
Ptr: PRGB32;
|
||||||
PtrInc,C: Integer;
|
PtrInc,C: Integer;
|
||||||
dX, dY, clR, clG, clB: Integer;
|
dX, dY: Integer;
|
||||||
|
|
||||||
xx, yy: integer;
|
xx, yy: integer;
|
||||||
compare: TCTSCompareFunction;
|
compare: TCTSCompareFunction;
|
||||||
@ -1781,8 +1794,6 @@ var
|
|||||||
xBmp,yBmp : integer;
|
xBmp,yBmp : integer;
|
||||||
tmpY : integer;
|
tmpY : integer;
|
||||||
dX, dY, i,HiSpiral: Integer;
|
dX, dY, i,HiSpiral: Integer;
|
||||||
CCTS : integer;
|
|
||||||
H,S,L,HMod,SMod : extended;
|
|
||||||
SkipCoords : T2DBoolArray;
|
SkipCoords : T2DBoolArray;
|
||||||
|
|
||||||
ctsinfoarray: TCTSInfo2DArray;
|
ctsinfoarray: TCTSInfo2DArray;
|
||||||
@ -1859,8 +1870,6 @@ var
|
|||||||
tmpY : integer;
|
tmpY : integer;
|
||||||
dX, dY, i,HiSpiral: Integer;
|
dX, dY, i,HiSpiral: Integer;
|
||||||
FoundC : integer;
|
FoundC : integer;
|
||||||
CCTS : integer;
|
|
||||||
H,S,L,HMod,SMod : extended;
|
|
||||||
SkipCoords : T2DBoolArray;
|
SkipCoords : T2DBoolArray;
|
||||||
|
|
||||||
ctsinfoarray: TCTSInfo2DArray;
|
ctsinfoarray: TCTSInfo2DArray;
|
||||||
@ -2077,13 +2086,6 @@ var
|
|||||||
//Cache DTM stuff
|
//Cache DTM stuff
|
||||||
Len : integer; //Len of the points
|
Len : integer; //Len of the points
|
||||||
DPoints : PMDTMPoint; //DTM 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;
|
|
||||||
|
|
||||||
// Bitwise
|
// Bitwise
|
||||||
b: Array of Array of Integer;
|
b: Array of Array of Integer;
|
||||||
@ -2111,11 +2113,13 @@ var
|
|||||||
|
|
||||||
goodPoints: Array of Boolean;
|
goodPoints: Array of Boolean;
|
||||||
|
|
||||||
|
col_arr, tol_arr: Array of Integer;
|
||||||
|
ctsinfoarray: TCTSInfoArray;
|
||||||
|
compare: TCTSCompareFunction;
|
||||||
|
|
||||||
label theEnd;
|
label theEnd;
|
||||||
label AnotherLoopEnd;
|
label AnotherLoopEnd;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
// Is the area valid?
|
// Is the area valid?
|
||||||
DefaultOperations(x1, y1, x2, y2);
|
DefaultOperations(x1, y1, x2, y2);
|
||||||
@ -2146,26 +2150,22 @@ begin
|
|||||||
FillChar(b[i][0], SizeOf(Integer) * (H+1), 0);
|
FillChar(b[i][0], SizeOf(Integer) * (H+1), 0);
|
||||||
end;
|
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.
|
// Retreive Client Data.
|
||||||
PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
|
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 := 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.
|
//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;
|
MA.x1 := MA.x1 - x1;
|
||||||
@ -2199,7 +2199,7 @@ begin
|
|||||||
// Checking point i now. (Store that we matched it)
|
// Checking point i now. (Store that we matched it)
|
||||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
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 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);
|
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2228,6 +2228,8 @@ begin
|
|||||||
AnotherLoopEnd:
|
AnotherLoopEnd:
|
||||||
end;
|
end;
|
||||||
TheEnd:
|
TheEnd:
|
||||||
|
|
||||||
|
Free_CTSInfoArray(ctsinfoarray);
|
||||||
TClient(Client).IOManager.FreeReturnData;
|
TClient(Client).IOManager.FreeReturnData;
|
||||||
|
|
||||||
SetLength(Points, pc);
|
SetLength(Points, pc);
|
||||||
@ -2244,14 +2246,15 @@ var
|
|||||||
begin
|
begin
|
||||||
FindDTMsRotated(dtm, P, x1, y1, x2, y2, sAngle, eAngle, aStep, F,Alternating,1);
|
FindDTMsRotated(dtm, P, x1, y1, x2, y2, sAngle, eAngle, aStep, F,Alternating,1);
|
||||||
if Length(P) = 0 then
|
if Length(P) = 0 then
|
||||||
exit(false);
|
exit(False);
|
||||||
aFound := F[0][0];
|
aFound := F[0][0];
|
||||||
x := P[0].x;
|
x := P[0].x;
|
||||||
y := P[0].y;
|
y := P[0].y;
|
||||||
Exit(True);
|
Exit(True);
|
||||||
end;
|
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
|
var
|
||||||
I, L: Integer;
|
I, L: Integer;
|
||||||
begin
|
begin
|
||||||
@ -2270,13 +2273,6 @@ var
|
|||||||
DPoints : PMDTMPoint;
|
DPoints : PMDTMPoint;
|
||||||
DTPA : TPointArray;
|
DTPA : TPointArray;
|
||||||
RotTPA: 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;
|
|
||||||
|
|
||||||
// Bitwise
|
// Bitwise
|
||||||
b: Array of Array of Integer;
|
b: Array of Array of Integer;
|
||||||
@ -2306,11 +2302,14 @@ var
|
|||||||
|
|
||||||
// point count
|
// point count
|
||||||
pc: Integer = 0;
|
pc: Integer = 0;
|
||||||
ac: Integer = 0;
|
|
||||||
|
|
||||||
goodPoints: Array of Boolean;
|
goodPoints: Array of Boolean;
|
||||||
s: extended;
|
s: extended;
|
||||||
|
|
||||||
|
col_arr, tol_arr: Array of Integer;
|
||||||
|
ctsinfoarray: TCTSInfoArray;
|
||||||
|
compare: TCTSCompareFunction;
|
||||||
|
|
||||||
label theEnd;
|
label theEnd;
|
||||||
label AnotherLoopEnd;
|
label AnotherLoopEnd;
|
||||||
|
|
||||||
@ -2346,20 +2345,6 @@ begin
|
|||||||
FillChar(ch[i][0], SizeOf(Integer) * (H+1), 0);
|
FillChar(ch[i][0], SizeOf(Integer) * (H+1), 0);
|
||||||
end;
|
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..
|
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.
|
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
|
for i := 0 to len-1 do
|
||||||
DTPA[i] := Point(DPoints[i].x,DPoints[i].y);
|
DTPA[i] := Point(DPoints[i].x,DPoints[i].y);
|
||||||
|
|
||||||
GetToleranceSpeed2Modifiers(hMod, sMod);
|
|
||||||
ccts := CTS;
|
|
||||||
|
|
||||||
// Retreive Client Data.
|
// Retreive Client Data.
|
||||||
PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
|
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 := CalculateRowPtrs(PtrData, h + 1);
|
||||||
SetLength(aFound, 0);
|
SetLength(aFound, 0);
|
||||||
SetLength(Points, 0);
|
SetLength(Points, 0);
|
||||||
@ -2420,7 +2415,7 @@ begin
|
|||||||
// Checking point i now. (Store that we matched it)
|
// Checking point i now. (Store that we matched it)
|
||||||
ch[xxx][yyy]:= ch[xxx][yyy] or (1 shl i);
|
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);
|
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2452,7 +2447,6 @@ begin
|
|||||||
goto theEnd;
|
goto theEnd;
|
||||||
AnotherLoopEnd:
|
AnotherLoopEnd:
|
||||||
end;
|
end;
|
||||||
ac := 0;
|
|
||||||
if Alternating then
|
if Alternating then
|
||||||
begin
|
begin
|
||||||
if AngleSteps mod 2 = 0 then //This means it's an even number, thus we must add a positive step
|
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;
|
s := s + aStep;
|
||||||
end;
|
end;
|
||||||
TheEnd:
|
TheEnd:
|
||||||
|
|
||||||
|
Free_CTSInfoArray(ctsinfoarray);
|
||||||
TClient(Client).IOManager.FreeReturnData;
|
TClient(Client).IOManager.FreeReturnData;
|
||||||
|
|
||||||
Result := (pc > 0);
|
Result := (pc > 0);
|
||||||
{ Don't forget to pre calculate the rotated points at the start.
|
{ Don't forget to pre calculate the rotated points at the start.
|
||||||
Saves a lot of rotatepoint() calls. }
|
Saves a lot of rotatepoint() calls. }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user