How to convert bitmap.....

Started by
1 comment, last by lemonlam 22 years, 6 months ago
How to convert bitmap(*.bmp) 16bit to 24 bit using c/c++. Help me! Thx.
Advertisement
It depends what pixel format you have for 16 bit. If you have 5-6-5, then you use a different method than 5-5-5. (red-green-blue bits)

If you have 5-5-5, something like this will work:
red = (color16 >> 10) & 0x1F;
green = (color16 >> 5) & 0x1F;
blue = color 16 & 0x1F;

color24 = (red << 19) | (green << 11) | (blue << 3);

I believe that is about right. You basically want to take the five bits of each color component and put it into the highest five bits of your 24 bit color components.
You may wish to replace the upper bits of the 5-bit/6-bit value into the lower bits of the 8-bit value. Otherwise you are sitting them to 0 which will slighly darken brighter colors.

i.e., the birghtest red/green/blue/white in 5-bit color is 11111, which when conveted to 8-bits is 11111000, which is darker than 11111111 !!

-Matt P
Developer AoE/AoK/???
-Mp(Developer on AoE/AoK/AoM, and a host of canceled projects)

This topic is closed to new replies.

Advertisement