# TColor almost = to TColor?

Based on the help in
http://www.experts-exchange.com/jsp/qShow.jsp?ta=delphi&qid=10220366

I now have a average color (Colora) and inverted color (Colori). however; if the Colors are near grey then Colora and Colori are almost =. If I choose to use the Colori, then it will look identical to the Colora.

I want to be able to tell when Colora and Colori are visually close to each other and choose another color say white or Black.

Does anyone have a code segment or function that will tell me if the colors are close visually?

John
###### Who is Participating?

Commented:
The colors will be visually close together when the vector in the 3d color space the TColor represents is short.

Function ColorCloseness(c1, c2 : TColor) : Double;

Function B(C:TColor):Byte;
begin
Result := (C SHR 16) AND \$ff;
end;

Function G(C:TColor):Byte;
begin
Result := (C SHR 8) AND \$ff;
end;

Function R(C:TColor):Byte;
begin
Result := C AND \$ff;
end;

begin
Result := sqrt(sqr(R(C1)-R(C2)) + sqr(G(C1)-G(C2)) + SQR(B(C1)-B(C2)));
end;

A value of 10 (or so) or less from this function would indicate the colours are very close. Obviously you should experiment to arrive at an appropriate threshold for youy application.

Cheers,

Raymond.
0

Commented:
Following...®
0

Author Commented:
Raymond,
Thanks... I should have thought of this simple solution being an engineer... but I never thought of colors as modelled in 3D space.
John
0

Commented:
This question was awarded, but never cleared due to the JSP-500 errors of that time.  It was "stuck" against userID -1 versus the intended expert whom you awarded.  This corrects the problem and the expert will now receive these points; points verified.

Please click on your Member Profile and select "View Question History" to navigate through any open or locked questions you may have to update and finalize them.  If you are an EE Pro user, you can also choose Power Search to find all your open questions.

This is the Community Support link, if help is needed, along with the link to All Topics which reflects many TAs recently added.

http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
http://www.experts-exchange.com/jsp/zonesAll.jsp

Thank you,
Moondancer
Moderator @ Experts Exchange
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.