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

 Page 1 of 1 [ 3 post ]

Relevant Pages

Powered by phpBB® Forum Software