Original Post
I am trying to write some code that will take a 24bit bmp and convert it to a 16bit bmp.
Most of what I have is from Andre LaMothe''s "Tricks of the Game Programming Gurus"...
Obviously this is not complete. The RGB16BIT565 macro looks like this...
so as far as my understanding goes that macro creates a 16 bit color word. Now I know that in the code above I am not getting all the info I need into the USHORT color because it is in a for loop and I am just writing over itself with each iteration. Now an obvious solution would be to use an array. What I am not sure how to do though is if I do make a USHORT array how do I pass all of the data from the array to my UCHAR * buffer16bit?
Am I going about this the best way? Am I on the right track? I got this code on page 355 of Andre LaMothe''s "Tricks of the Game Programming Gurus"...
He actually says there that he will be sure to write a 24-bit to 16-bit bitmap converter, but I cannot seem to find it anywhere.
void Bitmap_Convert(BITMAP_FILE_PTR bitmap, UCHAR * buffer16bit)
{
int n_padding = 0;
int image_size = (bitmap->bitmapinfoheader.biSizeImage)/3;
UCHAR blue = NULL,
green = NULL,
red = NULL;
USHORT color = NULL;
for(int index = 0; index<=image_size; index++)
{
n_padding = index * 3;
blue = (bitmap->buffer[n_padding]);
green = (bitmap->buffer[n_padding + 1]);
red = (bitmap->buffer[n_padding + 2]);
//color += _RGB16BIT565(red, green, blue);
color = _RGB16BIT565(red, green, blue);
}
buffer16bit = (UCHAR *)color;
}
|
#define _RGB16BIT565(r,gb) ((b%32) + ((g%64) << 6) + ((r%32) << 11)) |
