SRL Archive - Help and Support

SimilarColor source? Or ways to do it?


R0b0t1

2007-11-21 13:52:23

Well, I've looked at the SimilarColor source and I haven't found a way to translate it into C++ compatible code…




So. Uh… Any help?

JuKKa

2007-11-21 14:54:22



Function iSimilarColors(Color1, Color2, Tol: Integer): Boolean;
Var
Tole: Integer;
R1, G1, B1, R2, G2, B2: Integer;
RGBC: Array [1..3] Of Integer;
Begin
ColorToRGB(Color1, R1, G1, B1);
ColorToRGB(Color2, R2, G2, B2);

If(R1 > R2)Then
RGBC[1] := R1 - R2
Else RGBC[1] := R2 - R1;

If(G1 > G2)Then
RGBC[2] := G1 - G2
Else RGBC[2] := G2 - G1;

If(B1 > B2)Then
RGBC[3] := B1 - B2
Else RGBC[3] := B2 - B1;

Tole := AMax(RGBC);

If(Tol >= Tole)Then
Result := True;
End;

Begin
If(iSimilarColors(200, 233, 33))Then
Writeln('lol');
End.

Something like that..

pwnaz0r

2007-11-21 15:38:37

I can get you the source in delphi.

Freddy's source:

function ColorRGB(SColor, i: Integer): Extended;
var
Color: TColor;
begin
Color := ColorToRGB(SColor);
Result:= 0;
case i of
1:result:= GetRValue(Color);
2:result:= GetGValue(Color);
3:result:= GetBValue(Color);
end;
end;

function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean;
begin
Result:=False;
if(Abs(Round(ColorRGB(Color1, 1))-Round(ColorRGB(Color2, 1)))<=Tolerance)then
begin
if(Abs(Round(ColorRGB(Color1, 2))-Round(ColorRGB(Color2, 2)))<=Tolerance)then
begin
if(Abs(Round(ColorRGB(Color1, 3))-Round(ColorRGB(Color2, 3)))<=Tolerance)then
begin
Result:= True;
end;
end;
end;
end;

R0b0t1

2007-11-21 15:47:45

<3


My hero. I saw that on Freddy's old site, but didn't know what ColorRGB was.



But anyway, GetRValue and so on is just a macro in C++…


EDIT:


bool SimilarColors(Color1, Color2, Tole){
if(abs(GetRValue(Color1) - GetRValue(Color2)) <= Tole)
if(abs(GetGValue(Color1) - GetGValue(Color2)) <= Tole)
if(abs(GetBValue(Color1) - GetBValue(Color2)) <=Tole)
return true;
else return false;
else return false;
else return false;
}

Thanks ^.^

mastaraymond

2007-11-21 17:06:52

R := Color and $ff;
G := Color shr 8 and $ff;
B := Color shr 16 and $ff;

Faster.

Wanted

2007-11-21 17:15:44

From: mastaraymond
R := Color and $ff;
G := Color shr 8 and $ff;
B := Color shr 16 and $ff;

Faster.


Yes a much faster version:

function SimilarColors(Color1, Color2, Tolerance: Integer): Boolean;
begin
Result := ((Abs((Color1 and $ff) - (Color2 and $ff)) <= Tolerance) and
(Abs(((Color1 and $ff00) shr 8) - ((Color2 and $ff00) shr 8)) <= Tolerance) and
(Abs(((Color1 and $ff0000) shr 16) - ((Color2 and $ff0000) shr 16)) <= Tolerance));
end;

Markus

2007-11-22 10:12:57

Well remember that that is CTS 0, not CTS 1.

R0b0t1

2007-11-23 12:13:30

IceFire, a macro in C++ is a keyword that tells the compiler to replace it with something else.

But I guess using binary operators looks leet.