Merge CTS 3.

Algorithm may change over time and will stabilize on release of 0.98,
there is room for speed improvements.
This commit is contained in:
Merlijn Wajer 2011-10-01 15:22:24 +02:00
parent 1f4ddd9ddd
commit b339f58027
2 changed files with 35 additions and 1 deletions

View File

@ -65,7 +65,7 @@ begin
col := 16777215; tol := 30;
for c := 0 to 2 do // benchmark all CTS'es
for c := 0 to 3 do // benchmark all CTS'es
begin
MMLClient.MFinder.SetToleranceSpeed(c);
t2 := gettickcount;

View File

@ -127,6 +127,12 @@ type
end;
PCTS2Info = ^TCTS2Info;
TCTS3Info = record
L, A, B: extended;
Tol: Integer; { Squared }
end;
PCTS3Info = ^TCTS3Info;
TCTSInfo = Pointer;
TCTSInfoArray = Array of TCTSInfo;
TCTSInfo2DArray = Array of TCTSInfoArray;
@ -420,12 +426,30 @@ begin
and (abs(l - i.L) <= i.Tol);
end;
function ColorSame_cts3(ctsInfo: Pointer; C2: PRGB32): boolean;
var
i: TCTS3Info;
X, Y, Z, L, A, B: Extended;
begin
i := PCTS3Info(ctsInfo)^;
RGBToXYZ(C2^.R, C2^.G, C2^.B, X, Y, Z); // inline this
XYZToCIELab(X, Y, Z, L, A, B);
L := L - i.L;
A := A - i.A;
B := B - i.B;
Result := (L*L + A*A + B*B) < i.Tol;
end;
{ }
function Create_CTSInfo(cts: integer; Color, Tol: Integer;
hueMod, satMod: extended): Pointer; overload;
var
R, G, B: Integer;
X, Y, Z: Extended;
begin
case cts of
0:
@ -453,6 +477,15 @@ begin
PCTS2Info(Result)^.satMod := Tol * satMod;
PCTS2Info(Result)^.Tol := Tol;
end;
3:
begin
Result := AllocMem(SizeOf(TCTS3Info));
ColorToRGB(Color, R, G, B);
RGBToXYZ(R, G, B, X, Y, Z);
XYZToCIELab(X, Y, Z, PCTS3Info(Result)^.L, PCTS3Info(Result)^.A,
PCTS3Info(Result)^.B);
PCTS3Info(Result)^.Tol := Tol*Tol;
end;
end;
end;
@ -533,6 +566,7 @@ begin
0: Result := @ColorSame_cts0;
1: Result := @ColorSame_cts1;
2: Result := @ColorSame_cts2;
3: Result := @ColorSame_cts3;
end;
end;