Know RGB from color index

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Know RGB from color index

Bugzilla from ibelcomputing@yahoo.com.mx
My question is, exactly as title says, is there any way to know the R,
G and B values of a color given its index?

Reply | Threaded
Open this post in threaded view
|

Re: Know RGB from color index

ygfz4v902
Absolutely. The "index" of a color (what is returned from
screen.rgb(r,g,b)) is simply this:

(r << 16) + (g << 8) + b

This is easy to see if you print out the index values in hexadecimal.
For instance screen.rgb(255,0,0) returns 16711680 which is 0xFF0000.
You can read it right off: FF (i.e. 255) red, 0 blue, 0 green.

--- In [hidden email], "ibelcomputing" <ibelcomputing@...> wrote:
>
> My question is, exactly as title says, is there any way to know the R,
> G and B values of a color given its index?
>