Mail Archives: djgpp/1998/02/11/17:29:30
Anders Clerwall writes:
>Hi,, I have tried to convert rgb values to a color value in 800x600
>(64k cols) using the formula: (r << 11) | (g << 5) | b; what's
>wrong?!.. when I put in for example the rgb values 60,60, 60.. the
>pixel on the screen is blue!.. it should be white, no?
In a 64k color mode you have 5 bits of red and blue and six bits of
green, giving you ranges of 0-31 and 0-63 respectively. Your values of
60, 60, 60 will overflow the red and blue components, and even if you
made them smaller the result won't be white because you have only half
as much green as the other colors.
Also, if any of your input variables are char types you should be
careful to cast them so they won't overflow during the shift.
--
Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
"Pigs use it for a tambourine" - Frank Zappa
- Raw text -