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



If the original poster was refering to the Windows COLORREF type (which
is the core Win API color type), it is stored as a double word type (32
bits, 24 significant bits). The organization is as follows:
	       High Word                  Low Word
	High Byte     Low Byte     High Byte     Low Byte
	Unused        Blue         Green         Red
These values are unsigned, single byte, 8 bit (did I really need to make
that explicit, oh well) values. Thus they range from 0 to 255.

The GDKColor structure provides for storage of the RGB values as
unsigned short ints using 16 bits. Thus the potential range is from 0 to
65535. To successfully convert you would have to scale from one to the
other, which easily enough can be done using bit shifts. When converting
from COLORREF, you only maintain 256 shades of each color value, and
they scale in the high byte only. When converting from GDKColor, you
lose the lower 8 bits of data.

When converting to GDKColor, if you added the original color value after
shifting, you would end up with a shifted color palette that was
weighted towards fuller intensity.

However, keep in mind that the COLORREF is the core structure for
painting windows, borders, brushes, etc. There are other structures
available through other API's and libraries that provide deeper color
levels (DirectX for one). Most of the object oriented libraries provide
for their own encapsulation of color as well such as MFC's CColor and
OWL's TColor classes.

Example:
	COLORREF WindowsColor;
	unsigned WindowsRed;
	GDKColor gdkColor;

	WindowsRed = (unsigned) WindowsColor & 255;
	gdkColor.red = (gushort) WindowsRed << 8;
	

> 
>    This is not enough.  You then need to add the original value.  I.e.
> 
>            new_value = (old_value << 8) + old_value;
> 
>    Assuming old_value is in [0, 255].
> 
> I thought I understood gdkcolors until now.  I have always been under
> the impression that a gdkcolor simply uses a 16-bit value for each of
> red, green, and blue, and that it was converted for whatever hardware
> you were to run on by dividing (so, to run on something with 8-bit
> DACs, you'd right-shift by (16-8) == 8).
> 
> You seem to be saying that a gdkcolor is just an eight-bit value
> repeated twice.  What's the point?

-- 

Rick L. Vinyard, Jr.



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