Know RGB from color index

View: New views
2 Messages — Rating Filter:   Alert me  

Know RGB from color index

by Alberto Cruz Vivero :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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?


Re: Know RGB from color index

by ygfz4v902 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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 plua@..., "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?
>