Jump to content
  • Advertisement

Archived

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

Codedummie

Getting the nearest palette entry

This topic is 5894 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
Advertisement
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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!