Should be able to use it for anything, but I want someone to test it along with me, so I can improve it
.
SCAR Code:
program New;
function AutoColorThisColor(ThisColor, PrefTol, Accry: Integer): Integer;
Var
DidFind: Boolean;
I, x1, y1, Cnt, FirstCorr: Integer;
X, Y, Z, Xc, Yc, Zc: Extended;
AX, AY, AZ: Array [1..20] of Extended;
ColorAr: Array [0..21] of Integer;
SkipAr: Array [0..19] of TPoint;
begin
ColorAr[0]:= ThisColor;
For I:= 1 to 20 do
begin
DidFind:= FindColorSkipCoordsTolerance(x1, y1, ThisColor, MSX1, MSY1, MSX2, MSY2, 50, SkipAr);
If (DidFind) Then
begin
ColorAr[I]:= GetColor(x1, y1);
SkipAr[I].x:= x1;
SkipAr[I].y:= y1;
ColorToXYZ(ColorAr[I], AX[I], AY[I], AZ[I])
end;
end;
If (Accry > GetArrayLength(ColorAr)) Then
Accry:= GetArrayLength(ColorAr);
X:= AMaxE(AX);
Y:= AMaxE(AY);
Z:= AMaxE(AZ);
Xc:= X - AMinE(AX);
Yc:= Y - AMinE(AY);
Zc:= Z - AMinE(AZ);
FirstCorr:= 2;
For I:= 0 to (GetArrayLength(ColorAr) - 1) do
begin
If (AX[I] > (Xc - StrToFloat(IntToStr(PrefTol)))) and
(AX[I] < (X + StrToFloat(IntToStr(PrefTol)))) and
(AY[I] > (Yc - StrToFloat(IntToStr(PrefTol)))) and
(AY[I] < (Y + StrToFloat(IntToStr(PrefTol)))) and
(AZ[I] > (Zc - StrToFloat(IntToStr(PrefTol)))) and
(AZ[I] < (Z + StrToFloat(IntToStr(PrefTol)))) Then
begin
If (FirstCorr >= I) Then
FirstCorr:= I;
inc(Cnt);
end;
If (Cnt >= Accry) Then
Result:= XYZToColor(AX[FirstCorr], AY[FirstCorr], AZ[FirstCorr])
else
Result:= 0
end;
begin
end.