Archived

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

load_bitmap_file

DirectDraw Bitmap Help

Recommended Posts

I have been stuck on this problem for a week and am extremely frustrated for (int y=0; y < 480; y++) { memcpy(&back_buffer[y*(ddsd.lPitch/4)], &bitmap16bit.buffer[y*640*2], 640*2); // bytes to copy } ^ Does anyone know how to change the above code to correctly copy a 16-bit bitmap to a secondary surface in 640 x 480 x 32 bit resolution? When I blit the image to the display, the image is distorted and the colors are screwed up. Please Help!

Share this post


Link to post
Share on other sites
NeonGE    140
The thing here is that you are trying to copy two pixels into one, what you have to do is first extract the RGB values from your 16 bits image and traduce them into a 32 bits color, the copy this to your secondary buffer.

Hope this help

---------------------------------------------
If God with me, Who against me?
Sitio de desarrollo de videojuegos en español
Digital Moon Studio...

There is no spoon

[edited by - NeonGE on August 13, 2003 3:12:38 PM]

Share this post


Link to post
Share on other sites
Thanks for replying ! You cleared up a lot of questions I had. Also, I found out the bitmap was 24-bit, not 16-bit, and the when loading it, it was converted to 16-bit.

The following code is taken from the Load_Bitmap_File() function:

for (index=0; indexbitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
//converts each 24 bit RGB value into a 16 bit value
UCHAR red = (temp_buffer[index*3 + 2] >> 3), // 5 bits
green = (temp_buffer[index*3 + 1] >> 2), // 6 bits
blue = (temp_buffer[index*3 + 0] >> 3); // 5 bits
USHORT color = _RGB16BIT565(red,green,blue);

((USHORT *)bitmap->buffer)[index] = color;
}

note that _RGB16BIT565() is defined as:
#define _RGB16BIT565(r,g,b) ((b & 31) + ((g & 63) << 5) + ((r & 31) << 11))

Does anyone know how to change the above code to convert each 24-bit value to a 32-bit value instead? Please reply !

Share this post


Link to post
Share on other sites
NeonGE    140
Well this is prety simple, note that 24 bits is exactly 3 bytes

when you have a 16 bits color, in memory you have something like this (Format 565):

16bits = 2Bytes = R5 G6 B5
11111000 00011111

And in 24 bits you have this:

24bits = 3Bytes = R8 G8 B8
11111111 00000000 11111111

But in a 32bits color the things change because of the alpha chanel, so the only thing that you have to do is move your shift your bits

32bit = 4Bytes = A8 R8 G8 B8
11111111 11111111 00000000 11111111

This function most do the trick:
#define RGB32BITS(r,g,b) ((DWORD)(((0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))

Hope this help

---------------------------------------------
If God with me, Who against me?
Sitio de desarrollo de videojuegos en español
Digital Moon Studio...

There is no spoon

Share this post


Link to post
Share on other sites
Thanks for replying again! So now with the 32-bit definition you provided me, I''m guessing I need to change some of the code from before:

for (index=0; indexbitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
//converts each 24 bit RGB value into a 32 bit value
UCHAR red = (temp_buffer[index*3 + 2] >> 3), // 5 bits
green = (temp_buffer[index*3 + 1] >> 2), // 6 bits
blue = (temp_buffer[index*3 + 0] >> 3); // 5 bits

USHORT color = RGB32BITS(red,green,blue);

((USHORT *)bitmap->buffer)[index] = color;
}

I replaced the original _RGB16BIT565() with the RGB32BITS(). Since it''s 32 bit now, the UCHAR red, green, and blue values have to change as well right? How would I need to go about doing that? Thanks a lot for your replies!

Share this post


Link to post
Share on other sites
NeonGE    140
Yep, something like that, just remember that now you are using 32 bits variables so now your bitmap will use 1 byte more per pixel in the image, and remember that RGB32BITS return a 32 bits variable (DWORD) and you are truncating into 16 bits (USHORT)

So i recomend that all this stuff create a new buffer or DWORD´s to store the new 32 bits bitmap

---------------------------------------------
If God with me, Who against me?
Sitio de desarrollo de videojuegos en español
Digital Moon Studio...

There is no spoon

Share this post


Link to post
Share on other sites
Hmm, I changed all the index*3''s to index*4''s and all the USHORT variables to DWORD variables. The program crashes whenever I try to run it. Am I using the DWORD correctly? Are the UCHAR red, green, and blue values incorrect?

for (index=0; indexbitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
UCHAR red = (temp_buffer[index*4 + 2] >> 3),
green = (temp_buffer[index*4 + 1] >> 2),
blue = (temp_buffer[index*4 + 0] >> 3);

DWORD color = RGB32BITS(red,green,blue);

((DWORD *)bitmap->buffer)[index] = color;

}

bitmap->bitmapinfoheader.biBitCount=16;

Also, there''s the ^ above piece of code later on. I should change it to = 32 because of 32-bit right?

Finally, (sorry for so many questions!) once all the above is correct, is the following code to copy the bitmap to the secondary buffer correct?:

for (int y=0; y < SCREEN_HEIGHT; y++)
{
memcpy(&back_buffer[y*(ddsd.lPitch/4)],
&bitmap16bit.buffer[y*640*4],
640*4); // bytes to copy
}

I should ddsd.lPitch/4 because the display''s set at 32-bit, but after converting the 24-bit bitmap RGB values to 32-bit, will the bitmap have 4 bytes per pixel, hence 640 (the width) * 4? I''m sorry for asking so many questions. Once again, thanks for everything!


Share this post


Link to post
Share on other sites