_ChArMz
2010-01-27 22:18:00
type
PRGBQuadArray = ^TRGBQuadArray;
TRGBQuadArray = array [0..0] of TRGBQuad;
function FindColorTolerance(Client: HDC; Color: Integer; var dx, dy: Integer; x1, y1, x2, y2, Tolerance: Integer): Boolean;
const
Offset: array [0..0] of Integer = (1);
var
Color_rgbRed, Color_rgbGreen, Color_rgbBlue: Integer;
bmpW, bmpH: Integer;
bmi: TBitmapInfo;
DIBHandle: HBitmap;
CompDC: HDC;
PrevObj: HGDIOBJ;
Pixels: PRGBQuadArray;
I, H, L, HW: Integer;
J: Integer;
begin
Result := False;
Color_rgbRed := Color; //(Color and $ff);
Color_rgbGreen := Color shr 8; //(Color and $ff00) shr 8;
Color_rgbBlue := Color shr 16; //(Color and $ff0000) shr 16;
bmpW := x2 - x1 + 1;
bmpH := y2 - y1 + 1;
FillMemory(@bmi, SizeOf(TBitmapInfo), 0);
with bmi.bmiHeader do
begin
biSize := SizeOf(TBitmapInfoHeader);
biWidth := bmpW;
biHeight := -bmpH;
biPlanes := 1;
biBitCount := 32;
biCompression := BI_RGB;
end;
try
DIBHandle := CreateDIBSection(0, bmi, DIB_RGB_COLORS, Pointer(Pixels), 0, 0);
CompDC := CreateCompatibleDC(Client);
PrevObj := SelectObject(CompDC, DIBHandle);
BitBlt(CompDC, 0, 0, bmpW, bmpH, Client, x1, y1, SRCCOPY);
H := High(Offset);
L := Length(OffSet);
HW := (bmpH - 1) * (bmpW - 1);
Tolerance := Sqr(Tolerance);
for J := 0 to H do
begin
if Result then
Break;
I := 0 - OffSet[J];
while ( i < HW - OffSet[J] ) do
begin
Inc(I, L);
if Tolerance >= (Sqr(Color_rgbRed - Pixels^[I].rgbRed)
+Sqr(Color_rgbGreen - Pixels^[I].rgbGreen)
+Sqr(Color_rgbBlue - Pixels^[I].rgbBlue)) then
begin
dx := x1 + (I mod bmpW);
dy := y1 + (I div bmpW);
Result := True;
Break;
end;
end;
end;
finally
PrevObj := SelectObject(CompDC, PrevObj);
DeleteDC(CompDC);
DeleteObject(DIBHandle);
end;
end;this would be for the windows end of the findcolor functions
tell me what you guys think, I have been trying to match scars findcolor speed for some time
any benchmarks/input is welcome
i see that the current findcolor functions use just bitblt and bmbits, but i think this may be faster?