Re: [gtk-list] Re: how to convert windows RGB color to GdkColor



> >    Adding in the old value is a fast way to scale the values properly, so 0xFF
> >    becomes 0xFFFF.  You can multiply by 257.0 if you prefer :)
> >
> 
> Why it doesnt ? :
> 
> old color       new color
> dec  hex        dec hex
>  0   00          0   0000
>  1   01         257  0101
>  2   02         514  0202
> ...
> 63   3f        16191  3f3f
> ...
> 254  fe        65278  fefe
> 255  ff        65535  ffff
> 

Any of the color values, whether 8-bit or 16-bit represents the
brightness within the allowed range. For 8-bit color values it's
[0,255]. For 16-bit color values it's [0,65535]. 

Each degree of brightness in an 8-bit value represents 257 degrees of
brightness for 16-bit values (65535/255 = 257). To maintain the same
degree of brightness, each 8-bit value should be multiplied by 257. The
bit shift and addition is a way to do that and avoid the MUL op.

-- 

Rick L. Vinyard, Jr.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]