How to convert 16 bit data to 15 bit

Started by
0 comments, last by darkworldgames 22 years, 12 months ago
does anyone known how to convert a 16 bit pixel data to a 15 bit pixel data? thanks!
a leader of game development studio in china
Advertisement
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.

This topic is closed to new replies.

Advertisement