PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

RBG stuff

hi there ! this is for a good understanding of all that concern the video buffer...

if you set a pixel to a value, this value must be an unsigned short = 16 bits

if you want to set it from a RGB value of 8 bits by channel you get 3x8 = 24 bits

i suppose all the stuff is to reduce from 24 to 16, to do so, we often find this code:

Code:

#define rgb(r,g,b) ((((r)>>3)<<11)|(((g)>>2)<<5)|((b)>>3))


what i just realised is that we take only 5 higher bits of red and blue but 6 of green !!!

do this mean that the PPC pixel structure is:
5 bits of red, 6 bits of green, 5 of blue ???

or is there a more "rationnal" (slower :oops: ) way to get a better pix definition by 24bits rvb ???

thanks all
That's correct. Most Pocket PCs use RGB 565 encoding, which assigns the bits to the individual color elements in just that way (RRRRR GGGGGG BBBBB). On most computing hardware data must at least be evenly aligned. Thus you would store an RGB color value in either 32 bits / 4 bytes (even if only 24 of the bits are actually used), or 16 bits / 2 bytes (I'm ignoring palettized, grayscale, etc). Obviously 16 is not evenly divisible by 3, so either one color element gets twice the precision as the others, or you ignore one bit completly. The latter is what is done with RGB 555 encoding. I don't know of any Pocket PCs that use RGB 555.

So Yes, you have to go through an algorithm similar to what you posted to convert RGB 24 to RGB 565, and yes, information is lost in the conversion, and yes, green has twice the precision as red and blue in RGB 565.

Dan East
Lewil · 01 Mar 2002, 10:11 UTC — huhu
Thanks for lesson :)
i hope this will be usefull...