From 2e1e786d0ece69dc3e42fb92106a71dce0faf975 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Thu, 16 Jun 2011 15:11:17 +0200 Subject: [PATCH] FindBitmapToleranceIn now works. --- Units/MMLCore/bitmaps.pas | 8 ++++---- Units/MMLCore/finder.pas | 14 ++++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Units/MMLCore/bitmaps.pas b/Units/MMLCore/bitmaps.pas index f04effa..80ad422 100644 --- a/Units/MMLCore/bitmaps.pas +++ b/Units/MMLCore/bitmaps.pas @@ -884,13 +884,13 @@ var begin ValidatePoint(xs,ys); ValidatePoint(xe,ye); - setlength(result,xe-xs+1,ye-ys+1); + setlength(result,ye-ys+1,xe-xs+1); for y := ys to ye do for x := xs to xe do - begin + begin { REWRITE THIS } RGBToHSL(FData[y*w+x].R, FData[y*w+x].G, FData[y*w+x].B, - Result[x-xs][y-ys].H, Result[x-xs][y-ys].S, - Result[x-xs][y-ys].L); + Result[y-ys][x-xs].H, Result[y-ys][x-xs].S, + Result[y-ys][x-xs].L); end; end; diff --git a/Units/MMLCore/finder.pas b/Units/MMLCore/finder.pas index d54af95..37e1bc0 100644 --- a/Units/MMLCore/finder.pas +++ b/Units/MMLCore/finder.pas @@ -353,12 +353,12 @@ begin Result := (Sqrt(sqr(R1-R2) + sqr(G1-G2) + sqr(B1-B2)) <= Tolerance); end; -function ColorSame_cts2(Tolerance: Integer; H1,S1,L1,H2,S2,L2, hueMod, satMod: extended): +function ColorSame_cts2(Tolerance: Integer; H1, S1, L1, H2,S2,L2, hueMod, satMod: extended): boolean; inline; begin result := ((abs(H1 - H2) <= (hueMod * Tolerance)) and - (abs(S2-S1) <= (satMod * Tolerance)) - and (abs(L1-L2) <= Tolerance)); + (abs(S1 - S2) <= (satMod * Tolerance)) + and (abs(L1 - L2) <= Tolerance)); end; procedure TMFinder.UpdateCachedValues(NewWidth, NewHeight: integer); @@ -1657,14 +1657,14 @@ var end; function cts2: tpoint; - var H1, S1, L1, H2, S2, L2, HMod, SMod: extended; + var H2, S2, L2, HMod, SMod: extended; xx, yy, xBmp, yBmp, tmpY: integer; HSLRows: T2DHSLArray; label NotFoundBmp; begin - HSLRows := bitmap.GetHSLValues(0, 0, BmpW - 1, BmpH - 1); + HSLRows := bitmap.GetHSLValues(0, 0, BmpW, BmpH); for yy := 0 to dY do for xx := 0 to dX do @@ -1678,7 +1678,9 @@ var RGBToHSL(MainRowdata[tmpY][xBmp + xx].R, MainRowdata[tmpY][xBmp + xx].G, MainRowdata[tmpY][xBmp + xx].B, H2, S2, L2); - if not ColorSame_cts2(Tolerance, HSLRows[yBmp][xBmp].H, HSLRows[yBmp][xBmp].S, HSLRows[yBmp][xBmp].L, + if not ColorSame_cts2(Tolerance, HSLRows[yBmp][xBmp].H, + HSLRows[yBmp][xBmp].S, HSLRows[yBmp][xBmp].L, + //if not ColorSame_cts2(Tolerance, HSLRows[yBmp][xBmp].H, HSLRows[yBmp][xBmp].S, HSLRows[yBmp][xBmp].L, H2, S2, L2, hueMod, satMod) then goto NotFoundBmp; end;