1
0
mirror of https://github.com/moparisthebest/Simba synced 2024-11-30 12:52:16 -05:00

Finder: More rework and cleanups.

This commit is contained in:
Merlijn Wajer 2011-07-07 11:59:15 +02:00
parent 79021409d0
commit f5c9690bee

View File

@ -69,7 +69,7 @@ type
function FindColorSpiralTolerance(var x, y: Integer; color, xs, ys, xe, ye,Tol: Integer): Boolean; function FindColorSpiralTolerance(var x, y: Integer; color, xs, ys, xe, ye,Tol: Integer): Boolean;
function FindColorTolerance(out x, y: Integer; Color, xs, ys, xe, ye, tol: Integer): Boolean; function FindColorTolerance(out x, y: Integer; Color, xs, ys, xe, ye, tol: Integer): Boolean;
function FindColorsTolerance(out Points: TPointArray; Color, xs, ys, xe, ye, Tol: Integer): Boolean; function FindColorsTolerance(out Points: TPointArray; Color, xs, ys, xe, ye, Tol: Integer): Boolean;
function FindColorsSpiralTolerance(x, y: Integer; out Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer) : boolean; function FindColorsSpiralTolerance(x, y: Integer; out Points: TPointArray; color, xs, ys, xe, ye: Integer; Tol: Integer) : boolean;
function FindColors(var TPA: TPointArray; Color, xs, ys, xe, ye: Integer): Boolean; function FindColors(var TPA: TPointArray; Color, xs, ys, xe, ye: Integer): Boolean;
function FindColoredArea(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea: Integer): Boolean; function FindColoredArea(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea: Integer): Boolean;
function FindColoredAreaTolerance(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea, tol: Integer): Boolean; function FindColoredAreaTolerance(var x, y: Integer; color, xs, ys, xe, ye: Integer; MinArea, tol: Integer): Boolean;
@ -1205,6 +1205,7 @@ begin
SetLength(Points, C); SetLength(Points, C);
Move(ClientTPA[0], Points[0], C * SizeOf(TPoint)); Move(ClientTPA[0], Points[0], C * SizeOf(TPoint));
Result := C > 0; Result := C > 0;
Free_CTSInfo(ctsinfo); Free_CTSInfo(ctsinfo);
TClient(Client).IOManager.FreeReturnData; TClient(Client).IOManager.FreeReturnData;
end; end;
@ -1340,63 +1341,17 @@ begin
end; end;
function TMFinder.FindColorsSpiralTolerance(x, y: Integer; function TMFinder.FindColorsSpiralTolerance(x, y: Integer;
out Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer out Points: TPointArray; color, xs, ys, xe, ye: Integer; Tol: Integer
): boolean; ): boolean;
var var
PtrData: TRetData; PtrData: TRetData;
c : integer; c : integer;
RowData : TPRGB32Array; RowData : TPRGB32Array;
dX, dY, clR, clG, clB, SpiralHi: Integer; dX, dY, SpiralHi, i: Integer;
procedure cts0; compare: TCTSCompareFunction;
var i: integer; ctsinfo: Pointer;
begin
for i := 0 to SpiralHi do
if ((abs(clB-RowData[ClientTPA[i].y][ClientTPA[i].x].B) <= Tolerance) and
(abs(clG-RowData[ClientTPA[i].y][ClientTPA[i].x].G) <= Tolerance) and
(Abs(clR-RowData[ClientTPA[i].y][ClientTPA[i].x].R) <= Tolerance)) then
begin;
ClientTPA[c].x := ClientTPA[i].x + xs;
ClientTPA[c].y := ClientTPA[i].y + ys;
inc(c);
end;
end;
procedure cts1;
var i: integer;
begin
for i := 0 to SpiralHi do
if (Sqrt(sqr(clR - RowData[ClientTPA[i].y][ClientTPA[i].x].R) +
sqr(clG - RowData[ClientTPA[i].y][ClientTPA[i].x].G) +
sqr(clB - RowData[ClientTPA[i].y][ClientTPA[i].x].B)) <= Tolerance) then
begin;
ClientTPA[c].x := ClientTPA[i].x + xs;
ClientTPA[c].y := ClientTPA[i].y + ys;
inc(c);
end;
end;
procedure cts2;
var i: integer;
H1, S1, L1, H2, S2, L2, HueXTol, SatXTol: Extended;
begin
ColorToHSL(Color, H1, S1, L1);
HueXTol := hueMod * Tolerance;
SatXTol := satMod * Tolerance;
for i := 0 to SpiralHi do
begin;
RGBToHSL(RowData[ClientTPA[i].y][ClientTPA[i].x].R,
RowData[ClientTPA[i].y][ClientTPA[i].x].G,
RowData[ClientTPA[i].y][ClientTPA[i].x].B,
H2,S2,L2);
if ((abs(H1 - H2) <= (HueXTol)) and (abs(S1 - S2) <= (satXTol)) and (abs(L1 - L2) <= Tolerance)) then
begin;
ClientTPA[c].x := ClientTPA[i].x + xs;
ClientTPA[c].y := ClientTPA[i].y + ys;
inc(c);
end;
end;
end;
begin begin
Result := false; Result := false;
DefaultOperations(xs,ys,xe,ye); DefaultOperations(xs,ys,xe,ye);
@ -1404,25 +1359,34 @@ begin
dX := xe - xs; dX := xe - xs;
dY := ye - ys; dY := ye - ys;
//next, convert the color to r,g,b //next, convert the color to r,g,b
ColorToRGB(Color, clR, clG, clB);
PtrData := TClient(Client).IOManager.ReturnData(xs, ys, dX + 1, dY + 1); PtrData := TClient(Client).IOManager.ReturnData(xs, ys, dX + 1, dY + 1);
c := 0; c := 0;
ctsinfo := Create_CTSInfo(Self.CTS, Color, Tol, hueMod, satMod);
compare := Get_CTSCompare(Self.CTS);
//Load rowdata //Load rowdata
RowData:= CalculateRowPtrs(ptrdata,dy+1); RowData:= CalculateRowPtrs(ptrdata,dy+1);
//Load the spiral path //Load the spiral path
LoadSpiralPath(x-xs,y-ys,0,0,dx,dy); LoadSpiralPath(x-xs,y-ys,0,0,dx,dy); { Fills ClientTPA with Spiral path }
SpiralHi := (dx + 1) * (dy + 1) - 1; SpiralHi := (dx + 1) * (dy + 1) - 1;
case CTS of for i := 0 to SpiralHi do
0: cts0(); if compare(ctsinfo, @RowData[ClientTPA[i].y][ClientTPA[i].x]) then
1: cts1(); begin;
2: cts2(); { We can re-use the ClientTPA to store results. }
end; ClientTPA[c].x := ClientTPA[i].x + xs;
ClientTPA[c].y := ClientTPA[i].y + ys;
inc(c);
end;
SetLength(Points, C); SetLength(Points, C);
Move(ClientTPA[0], Points[0], C * SizeOf(TPoint)); Move(ClientTPA[0], Points[0], C * SizeOf(TPoint));
Result := C > 0; Result := C > 0;
Free_CTSInfo(ctsinfo);
TClient(Client).IOManager.FreeReturnData; TClient(Client).IOManager.FreeReturnData;
end; end;