Archived

This topic is now archived and is closed to further replies.

Getting the nearest palette entry

This topic is 5592 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have a color given in RGB-format and a palette. How do I find out the palette entry that matches the given color best? And I don''t want to put something on the screen, just the math for that. Thanks

Share this post


Link to post
Share on other sites
You can use this simple method:
min=0xffff;
for (i=0;i{
delta=(abs(color.r-Yourcolor.r)+
abs(color[i].g-Yourcolor.g)+
abs(color[i].b-Yourcolor.b));
if (delta {
min=delta;
nearestcol=i;
}
}

but human eye don't sense rgb in ratio 1:1:1 so you can add the correct ratio to the function(i don't know it know)





[edited by - Cifko on August 27, 2002 1:41:09 PM]

Share this post


Link to post
Share on other sites