Archived

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

How to convert 16 bit data to 15 bit

This topic is 6079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Unfortunately this is a very difficult question to answer, unless you know WHICH 16 bit format you are dealing with. There are at least 4 (note that each number represents the bits used for each color): 5:5:5:1 RGBA, 6:5:5 RGB, 5:6:5 RGB, 5:5:6 RGB. So the first thing you have to do is find out what format you are dealing with. You can then extact the value of each color by performing a logical and (&&) with the appropriate bitmask. When you do this, drop the least significant bit of the 6 bit color. Then shift the values of each color (>>) as necessary so that they will line up with the appropriate place in the 15 bit color, and or (||) the three colors together to get your 15 bit color.

example:

note the lower case ''g'' will get dropped, so all the R''s and all the G''s will have to move over 1 to the right. The B''s stay right where they are:

16bit: RRRRRGGGGGgBBBBB 5:6:5 RGB
15bit: 0RRRRRGGGGGBBBBB 5:5:5 RGB

red15 = (color16 && 0xF800) >> 1;
green15 = (color16 && 0x07E0) >> 1;
blue15 = (color16 && 0x001F);

color15 = (red15 || green15 || blue15);

double check my bitmasks, just in case. Hope this helps. Of course if you are using windows, just have GDI Blt the 16 bit DIB bitmap to the 15bit target and the conversion is done for you.

Share this post


Link to post
Share on other sites