This topic is now archived and is closed to further replies.


splitting a pixel into an RGB triplet

Recommended Posts

i can''t figure out how to acurately split up a 16-bit color pixel into an RGB triplet. it seems like there is a loss in color info when i create the pixel from an RGB triplet that prevents me from retrieving it acurately. i''m using directx, so i''ve got the RBitMask, GBitMask, and BBitMask, and i thought i could just go & each mask with the pixel and then shift it. But i only get top five bits of acuracy, and the last three are all 0. any help?
_________________Gecko___ Gecko Design

Share this post

Link to post
Share on other sites
yeah i knew that already, that''s my problem. as stated above, i want to know how (if there IS a way) to more acurately split the pixel into the RGB triplet. any ideas?

Gecko Design

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
Obviously, if you take a 24 bit RGB color, cram it into 15 (or 16) bits, you will lose some accuracy.

However, there is one thing you can do to get closer to the initial color back out.

In this example, I will convert a RGB888 into a RGB444 (since the hex math is much more clear with 4 bits per pixel than 5).

Start with 0xFFFFFF (pure white)
Convert to 0xFFF (pure white) with 4 bits per gun with a right shift.

Now, if you just "reverse" the operation, and use a left shift you end up with 0xF0F0F0, which is somewhat dimmer than the initial color. The trick is to "repeat" the color component bits in the low bits after the left shift. Then you get 0xFFFFFF back from 0xFFF (however, in general, you _can''t_ get the exact same value back all of the time). This makes sense if you consier one gun at a time:

8 bit -> 4 bit
00 0
11 1
22 2
33 3
ee e
ff f

This maintains the "full range" of each color space.

In the case of 6 bits to 8 bits, you just repeat the 2 highest bits in the 2 lowest bits after the left shift by 2.

E.g. : 10010 (binary 6 bit component) becomes 1001010 (8-bit)
and 01001 becomes 0100101

Hope this makes sense (its late).

Share this post

Link to post
Share on other sites