RGB and 256-color palette matching 
Author Message
 RGB and 256-color palette matching

Hi! i am in need of an algorithm to match a given R, G, B bytes values
into one of the entries in a 256-color palette. Say the 256-color
palette is already set with all the range covered. What I want to do
here is to match a given byte values, R, G, B, into one of the colors
of the palette. In short, determine the nearest possible RGB color out
of the 256 possible colors available for the system. anyway, thanks!!!

Dexter Tad-y

Sent via Deja.com
http://www.*-*-*.com/



Sun, 08 Jun 2003 00:18:27 GMT  
 RGB and 256-color palette matching

Quote:

>Hi! i am in need of an algorithm to match a given R, G, B bytes values
>into one of the entries in a 256-color palette. Say the 256-color
>palette is already set with all the range covered. What I want to do
>here is to match a given byte values, R, G, B, into one of the colors
>of the palette. In short, determine the nearest possible RGB color out
>of the 256 possible colors available for the system. anyway, thanks!!!

IIRC this can be done by taking the sum of the squares of the differences
and finding the smallest. That is to compare two rgb values like x and
y, you calculate sqr(x.r-y.r)+sqr(x.g-y.g)+sqr(x.b-y.b). Then find the
color for which the above is smallest. There are better alternatives but
that should be good enough for most cases. Remember to use a signed type
like integer or even longint.

Also you should really use dithering with it.{*filter*}choose the color then
disperse the error and move to the next pixel.

Osmo



Sun, 08 Jun 2003 01:44:57 GMT  
 RGB and 256-color palette matching
Why don't you use SetRGBPalette for any color, which yoou want to use?

regards, frank
www.freenet.de/frashman



Quote:
> Hi! i am in need of an algorithm to match a given R, G, B bytes values
> into one of the entries in a 256-color palette. Say the 256-color
> palette is already set with all the range covered. What I want to do
> here is to match a given byte values, R, G, B, into one of the colors
> of the palette. In short, determine the nearest possible RGB color out
> of the 256 possible colors available for the system. anyway, thanks!!!

> Dexter Tad-y

> Sent via Deja.com
> http://www.deja.com/



Wed, 11 Jun 2003 21:52:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. RGB 256-color palette problem

2. 256 color palette

3. Please Help Me with 256 color Palette !!

4. 256 color palette in TP7

5. - 256 Color Palette Blues

6. 256 color image on a 16 color screen?

7. 24-bit color to 256 color's source

8. 256 Colour Palette Generator

9. Problem with 256-Palette

10. Help with Palette [RGB]

11. Reading in RGB Palette Successfully in TP 6.0

12. How do I print 256 color graphics?

 

 
Powered by phpBB® Forum Software