Advertisement

How to convert 24bit to 16?

Started by February 03, 2000 08:47 AM
2 comments, last by Magan 25 years, 1 month ago
How do I convert a 25bit bitmap to 16bit? If (RGB) R is one byte in the original image and I want to make it 5 bits, which bits am I going to copy and how do I convert it to be the same color on my 16-bit screen? /Magan
To convert from 24bit being 8 bits per red,green,blue to 16 bit either 555 or 565 depending on the video card you just have to either do some divides or shifts depending on how you want to do it.

here is some code as an example so you can get the idea

unsigned char red( 255 );
unsigned char newRed( 0 );
unsigned char green( 255 );
unsigned char newGreen( 0 );
unsigned char newBlue( 0 );
unsigned short endColor( 0 );

newRed = red/8; // dividing by 8 will put newRed in the
// 0 - 32 range.
// or you could
newRed = red>>3;//2^3 = 8, same as dividing by 8
// if you need to convert to 6 bits then
newGreen = green/4; // from 0 - 255 to new range of 0 - 64
// or
newGreen = green>>2;

//once you have your new red,green and blue values you
//will have to shift and or them into a 16bit value.
endColor = ( endBlue << 10 )/( endGreen << 5 )/( endRed );

// I'm assuming you're using directX for this last part.
// remember that the green could be 5 or 6 bits. so creating
// the new endColor will vary depending on that. You will
// have to figure out the pixel format by getting the
// surface desc. structure and looking at the
// ddpfPixelFormat structure which has the Red, Green and
// Blue bit mask values.


Edited by - ao on 2/3/00 1:17:52 PM
Play free Java games at: www.infinitepixels.com
Advertisement
I don''t know if this is the problem you''re having but in my game I don''t bother converting to 16 bit. The game itself is in 16 bit and all the graphics are 24 bit BMPs.
Brian
BrianNaughton, if you have 24bit images to draw on 16bit screen, there has to be a conversion done one time or another. it makes so much more sense to convert it upon loading your graphics than to do it in real-time!

This topic is closed to new replies.

Advertisement