Merge new CTS/Finder system.

Touches pretty much all the functions in finder.pas, so I expect a lot of
functions to break. Tests will have to be written and results will have to be
compared with Simba 0.97. Still, I think it's ready for merging to simba-next.

Squashed commit of the following:

commit d1e3645ee5
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 19:08:23 2011 +0200

    MML/Finder: Fix all compiler hints + bug.

commit f159f20bc2
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 19:05:03 2011 +0200

    MML/Finder: Fix FindDTMsRotated.

commit 1fc33752e4
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 19:04:16 2011 +0200

    MML/Finder: FindDTMsRotated rework.

commit a621a6e8da
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 18:13:36 2011 +0200

    MML/Finder: FindDTMs rework done.

commit 0b592eef86
Merge: 56e01c6 aaafd6b
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 16:48:09 2011 +0200

    Merge branch 'master' into cts-rework

    Conflicts:
    	Units/MMLCore/finder.pas

commit 56e01c67fa
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 16:16:19 2011 +0200

    MML/Finder: CTS: Bitmap+Color functions done.

    Only DTM to go.

commit 464b90d42b
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Aug 1 13:58:49 2011 +0200

    MMLCore/finder: Small cleanup.

commit 2414f60c08
Merge: 55b0435 a20a31a
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 31 18:12:41 2011 +0200

    Merge branch 'master' into cts-rework

commit 55b0435a4e
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 20:27:54 2011 +0200

    Tests: Update BmpBench.

commit 013daccf07
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 20:09:31 2011 +0200

    MML/Core: Cleanup.

commit 6f32e21291
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 20:08:17 2011 +0200

    MML/Core: FindBitmapToleranceIn seems to work.

commit 3b939443e8
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 19:10:10 2011 +0200

    MML/Core: FindBitmapToleranceIn is nearly finished.

    Speed is nice, results are not accurate yet.
    I probably missed something when pre-loading the data.

commit 0422f0eb5a
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 15:53:48 2011 +0200

    MML/Core: Fixes for FindBitmapToleranceIn.

commit 65f4ae16ed
Merge: daff307 353d1f3
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 14:32:46 2011 +0200

    Merge branch 'master' into cts-rework

commit daff307f3d
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 13:46:10 2011 +0200

    Tests: Add BmpBench.

commit cdb89a1802
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 13:12:21 2011 +0200

    MMLCore: FindBitmapToleranceIn cts rewrite.

commit d0bd81c2e9
Merge: 3282636 da0de6e
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 30 00:15:50 2011 +0200

    Merge branch 'master' into cts-rework

commit 3282636178
Merge: 7c86003 a8cdf77
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jul 25 16:50:43 2011 +0200

    Merge branch 'master' into cts-rework

commit 7c8600311c
Merge: 153025f e0767cb
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 24 00:14:53 2011 +0200

    Merge branch 'master' into cts-rework

    Conflicts:
    	Doc/sphinx/conf.py
    	Doc/sphinx/libmml/intro.rst

commit 153025f080
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 17 19:51:16 2011 +0200

    libMML: Changed the indentation.

commit 8abd502580
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 17 19:37:33 2011 +0200

    Documentation: Bump version to 820.

commit 031654b3d1
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 17 19:36:21 2011 +0200

    Documentation: Initial libMML documentation.

commit f91c9ffb0e
Merge: f5c9690 989d077
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jul 7 12:00:58 2011 +0200

    Merge branch 'master' into cts-rework

commit f5c9690bee
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jul 7 11:59:15 2011 +0200

    Finder: More rework and cleanups.

commit 79021409d0
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 21:34:03 2011 +0200

    Finder: CTS 2 fix.

commit cda571dcb0
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 21:06:17 2011 +0200

    Finder: Remote tolerance param. Cleanups.

commit 733a8cbf32
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 20:39:44 2011 +0200

    Finder: More fixes. :-)

commit e6b005b61f
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 18:34:49 2011 +0200

    Finder: CTS-rework fixes.

commit 6f896b56a2
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 18:15:33 2011 +0200

    Finder: Start CTS rework.

commit a630399148
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 13:01:22 2011 +0200

    Small TODO update.

commit 0e6bf83a5c
Merge: f19fd6b f2873b1
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Wed Jul 6 12:59:09 2011 +0200

    Merge branch 'master' into cts-rework

commit f19fd6bf8d
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jul 3 20:42:14 2011 +0200

    Simba/Doc: Add Raymond to doc.

commit 451ab89db3
Merge: 37183f5 35026bc
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sat Jul 2 14:48:43 2011 +0200

    Merge branch 'master' into cts-rework

commit 37183f5fd0
Merge: cca7b05 6873e72
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Tue Jun 28 22:10:02 2011 +0200

    Merge branch 'master' into cts-rework

commit cca7b05213
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jun 16 17:03:14 2011 +0200

    Add CTS 3 to FindColorsTolerance.

    Conflicts:

    	Units/MMLCore/finder.pas

commit c837d9b960
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jun 16 16:33:25 2011 +0200

    CTS 3: Fix typo.

commit 52db461f84
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 6 16:06:17 2011 +0200

    CTS 3: Now implement the formula properly.

commit 7a0db25416
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Sun Jun 5 19:44:52 2011 +0200

    Add L*a*b CTS (3).

commit 2e1e786d0e
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jun 16 15:11:17 2011 +0200

    FindBitmapToleranceIn now works.

commit 58ea6021cd
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jun 16 14:26:20 2011 +0200

    CTS work. CTS 2 is still broken for bitmaps.

commit 91d952d33a
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Thu Jun 16 12:52:10 2011 +0200

    CTS cleanups.

commit d9836a251c
Merge: 5bf7d8b bfc3f86
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 20:44:08 2011 +0200

    Merge branch 'master' into cts-rework

commit 5bf7d8beea
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 20:38:00 2011 +0200

    Completed first CTS rework.

commit 7a412d1670
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 20:21:23 2011 +0200

    CTS: Cleanups.

commit 14474a84ab
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 18:16:59 2011 +0200

    CTS rework for FindColorsTolerance.

commit b87a123701
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 17:44:04 2011 +0200

    More cleanups to CTS.

commit 9415d08100
Author: Merlijn Wajer <merlijn@wizzup.org>
Date:   Mon Jun 13 17:41:06 2011 +0200

    Finder: Trying a different CTS approach.
This commit is contained in:
Merlijn Wajer 2011-08-04 00:41:00 +02:00
parent f0fca408fd
commit 5b3e2a864b
8 changed files with 577 additions and 343 deletions

View File

@ -59,6 +59,8 @@ write - again - their own wrapper around libMML. This is what is being done with
*pyMML*, the python libMML wrapper. It is still as much in development as libMML *pyMML*, the python libMML wrapper. It is still as much in development as libMML
is, but the functionality exposed by libMML is succesfully used. is, but the functionality exposed by libMML is succesfully used.
<<<<<<< HEAD
=======
As of writing the pyMML usage looks like this, the passing around of a client As of writing the pyMML usage looks like this, the passing around of a client
may be removed in a later stage, or at least have it's behaviour changed. may be removed in a later stage, or at least have it's behaviour changed.
@ -98,3 +100,4 @@ may be removed in a later stage, or at least have it's behaviour changed.
print m.getPos() print m.getPos()
del DLL del DLL
>>>>>>> master

5
TODO
View File

@ -7,13 +7,16 @@ Simple stuff, not required, may not be possible/useful:
- CTS/finder speedups and changes [ ] - CTS/finder speedups and changes [ ]
General ideas: - Table displaying all the different performance gains and
penalties. [ ]
- General ideas:
- everything subprocedure (lots of code) - everything subprocedure (lots of code)
- jit + comparison function (per cts) generated, call in loop - jit + comparison function (per cts) generated, call in loop
- comparison function (per cts), not generated, call in loop - comparison function (per cts), not generated, call in loop
- Investigate SIMD probable speedups [ ]
- JIT (Generate comparison functions) [ ] - JIT (Generate comparison functions) [ ]
- Comparison functions for HSL/XYZ/L*a*b should check for - Comparison functions for HSL/XYZ/L*a*b should check for
match on each component before calculating the next. match on each component before calculating the next.

View File

@ -0,0 +1,25 @@
program new;
//http://farm4.static.flickr.com/3067/2612399892_7df428d482.jpg
{Make the above bitmap your target}
var
Bmp : integer;
x,y : integer;
w,h : integer;
t, i: integer;
begin
Bmp := createBitmap(15, 10);
FastDrawClear(bmp, clwhite);
GetClientDimensions(w,h);
setcolortolerancespeed(2);
t:=getsystemtime;
for i := 0 to 10 do
FindBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,500);
writeln((getsystemtime-t) / 10.0);
if FindBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,500) then
begin
writeln('found');
MoveMouse(x,y);
end;
end.

View File

@ -1,6 +1,5 @@
program new; program new;
//http://farm4.static.flickr.com/3067/2612399892_7df428d482.jpg
{Make the above bitmap your target}
var var
Bmp : integer; Bmp : integer;
x,y : integer; x,y : integer;
@ -19,11 +18,14 @@ begin
setcolortolerancespeed(c); setcolortolerancespeed(c);
t:=getsystemtime; t:=getsystemtime;
for i := 0 to 100 do for i := 0 to 10 do
findBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,10); findBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,10);
writeln((getsystemtime-t) / 100.0); writeln((getsystemtime-t) / 10.0);
if findBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,200) then if findBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,10) then
begin
writeln('found'); writeln('found');
movemouse(x,y);
end;
end; end;
{if FindBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,300) then {if FindBitmapToleranceIn(bmp,x,y,0,0,w-1,h-1,300) then

View File

@ -64,6 +64,7 @@ type
function FastGetPixel(x,y : integer) : TColor; function FastGetPixel(x,y : integer) : TColor;
function FastGetPixels(Points : TPointArray) : TIntegerArray; function FastGetPixels(Points : TPointArray) : TIntegerArray;
function GetAreaColors(xs,ys,xe,ye : integer) : T2DIntArray; function GetAreaColors(xs,ys,xe,ye : integer) : T2DIntArray;
function GetHSLValues(xs, ys, xe, ye: integer): T2DHSLArray;
procedure FastDrawClear(Color : TColor); procedure FastDrawClear(Color : TColor);
procedure FastDrawTransparent(x, y: Integer; TargetBitmap: TMufasaBitmap); procedure FastDrawTransparent(x, y: Integer; TargetBitmap: TMufasaBitmap);
procedure FastReplaceColor(OldColor, NewColor: TColor); procedure FastReplaceColor(OldColor, NewColor: TColor);
@ -876,6 +877,23 @@ begin
result[x-xs][y-ys] := BGRToRGB(FData[y*w+x]); result[x-xs][y-ys] := BGRToRGB(FData[y*w+x]);
end; end;
function TMufasaBitmap.GetHSLValues(xs, ys, xe, ye: integer): T2DHSLArray;
var
x, y: integer;
R, G, B, C: integer;
begin
ValidatePoint(xs,ys);
ValidatePoint(xe,ye);
setlength(result,ye-ys+1,xe-xs+1);
for y := ys to ye do
for x := xs to xe do
begin { REWRITE THIS }
RGBToHSL(FData[y*w+x].R, FData[y*w+x].G, FData[y*w+x].B,
Result[y-ys][x-xs].H, Result[y-ys][x-xs].S,
Result[y-ys][x-xs].L);
end;
end;
procedure TMufasaBitmap.SetTransparentColor(Col: TColor); procedure TMufasaBitmap.SetTransparentColor(Col: TColor);
begin begin
self.FTransparentSet:= True; self.FTransparentSet:= True;
@ -1406,7 +1424,7 @@ var
i,minw,minh : integer; i,minw,minh : integer;
begin begin
if (AWidth <> w) or (AHeight <> h) then if (AWidth <> w) or (AHeight <> h) then
begin; begin
if AWidth*AHeight <> 0 then if AWidth*AHeight <> 0 then
begin; begin;
NewData := GetMem(AWidth * AHeight * SizeOf(TRGB32)); NewData := GetMem(AWidth * AHeight * SizeOf(TRGB32));

View File

@ -48,7 +48,8 @@ procedure ColorToXYZ(color: Integer; out X, Y, Z: Extended); inline;
function XYZToColor(X, Y, Z: Extended): TColor; inline; function XYZToColor(X, Y, Z: Extended): TColor; inline;
function HSLToColor(H, S, L: Extended): TColor; inline; function HSLToColor(H, S, L: Extended): TColor; inline;
function BGRToRGB(BGR : TRGB32) : TColor;inline; function BGRToRGB(BGR : TRGB32) : TColor;inline;
procedure XYZtoCIELab(X, Y, Z: Extended; out L, a, b: Extended);
procedure CIELabtoXYZ(L, a, b: Extended; out X, Y, Z: Extended);
implementation implementation
@ -336,4 +337,53 @@ begin
Result := RGBToColor(r, g, b); Result := RGBToColor(r, g, b);
end; end;
procedure XYZtoCIELab(X, Y, Z: Extended; out L, a, b: Extended);
begin
X := X / 95.047;
Y := Y / 100.000;
Z := Z / 108.883;
if ( X > 0.008856 ) then
X := Power(X, 1.0/3.0)
else
X := ( 7.787 * X ) + ( 16.0 / 116.0 );
if ( Y > 0.008856 ) then
Y := Power(Y, 1.0/3.0)
else
Y := ( 7.787 * Y ) + ( 16.0 / 116.0 );
if ( Z > 0.008856 ) then
Z := Power(Z, 1.0/3.0)
else
Z := ( 7.787 * Z ) + ( 16.0 / 116.0 );
L := (116.0 * Y ) - 16.0;
a := 500.0 * ( X - Y );
b := 200.0 * ( Y - Z );
end;
procedure CIELabtoXYZ(L, a, b: Extended; out X, Y, Z: Extended);
begin
Y := ( L + 16 ) / 116.0;
X := ( a / 500.0 )+ Y;
Z := Y - ( b / 200.0 );
if ( Power(Y, 3) > 0.008856 ) then
Y := Power(Y, 3)
else
Y := ( Y - (16.0 / 116.0 )) / 7.787;
if ( Power(X, 3) > 0.008856 ) then
X := Power(X, 3)
else
X := ( X - (16.0 / 116.0) ) / 7.787;
if ( Power(Z, 3) > 0.008856 ) then
Z := Power(Z, 3)
else
Z := ( Z - (16.0 / 116.0) ) / 7.787;
X := 95.047 * X;
Y := 100.000 * Y;
Z := 108.883 * Z;
end;
end. end.

File diff suppressed because it is too large Load Diff

View File

@ -60,6 +60,14 @@ type
TRGB32Array = array of TRGB32; TRGB32Array = array of TRGB32;
TPRGB32Array = array of PRGB32; //Array of Pointers TPRGB32Array = array of PRGB32; //Array of Pointers
THSL = record
H, S, L: extended;
end;
PHSL = ^THSL;
THSLArray = array of THSL;
T2DHSLArray = array of array of THSL;
TRetData = record TRetData = record
Ptr : PRGB32; Ptr : PRGB32;
IncPtrWith : integer; IncPtrWith : integer;