Jump to content
  • Advertisement

Archived

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

Century

Loading a 24bit Bitmap

This topic is 5220 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I know this is a very simple question for some of you, but I''m having real problems loading 24-bit bitmaps from a file. I''m using LaMothe''s "Tricks for the Window''s Game blah blah blah", and I''m happy with loading an 8-bit bitmap. I''m also just loading up single-bitmap files, rather than templates, just to keep things simple. Right, I know that I''m supposed to extract the file pixel-by-pixel and convert it into 32-bit format, so that it''s in a.8.8.8 format. But where does this code go? I''ve managed to get it working when the whole loading structure is based around this concept. But when LaMothe later adds separate Load_Bitmap_File() and similar functions, I have no idea where this conversion code goes. Anybody able to help?

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure how the books code works, but you can always use D3DXCreateTextureFromFile. It can read many different formats, including all kinds of .bmp files.

Otherwise, you may have to post the code in question because it''s very difficult for someone to figure out where your code is messing up without actually seeing it.

neneboricua

Share this post


Link to post
Share on other sites
The only problem with that being that I wouldn't know which part of the code to put up!

The code recommended for the conversion is:

///////////////////////////////////

// MACROS:
// Build a 32 bit colour value in a.8.8.8 format
#define _RGB32BIT(a,r,g,b) ((b)+((g)<<8)+((r)<<16)+((a)<<24))

#define unsigned char UCHAR;

...

// TYPES:
// This is a structure to hold bitmaps
typedef struct BITMAP_FILE_TAG
{
BITMAPFILEHEADER bitmapfileheader; // bitmapfile header
BITMAPINFOHEADER bitmapinfoheader; // All info
PALETTEENTRY palette[256]; // Store palette
UCHAR *buffer; // Pointer to the data
} BITMAP_FILE, *BITMAP_FILE_PTR;

BITMAP_FILE bitmap;

...

// And then the actual conversion code
// It assumes "index" is pointing to the next pixel
UCHAR blue = (bitmap.buffer[index*3 + 0]);
UCHAR green = (bitmap.buffer[index*3 + 1]);
UCHAR red = (bitmap.buffer[index*3 + 2]);

// Build a 32 bit colour value with that macro ^
_RGB32BIT(0,red,green,blue);

/////////////////////////////////////


I'm just wondering where the conversion code should go. In one example, this code was tailored for the program, so it was easy to see where it went. But now I'm trying to implement it in a more complicatd program, I've no idea what to do with it.

[edited by - Century on February 5, 2004 6:26:17 PM]

[edited by - Century on February 5, 2004 6:27:48 PM]

Share this post


Link to post
Share on other sites
If you are truely trying to understand the BMP image format and pixel formats, then you should go ahead with what you are doing

However if you are just trying to get an image into a DDraw surface or a Texture, use the previous D3DX function mentioned, or just use the Windows GDI and HDCs (Hardware Device Context I think?), and the Windows API "Blit" to copy the data. It automatically takes care of colour conversion etc.

Share this post


Link to post
Share on other sites
quote:
Original post by AndyTX
If you are truely trying to understand the BMP image format and pixel formats, then you should go ahead with what you are doing

However if you are just trying to get an image into a DDraw surface or a Texture, use the previous D3DX function mentioned, or just use the Windows GDI and HDCs (Hardware Device Context I think?), and the Windows API "Blit" to copy the data. It automatically takes care of colour conversion etc.


I think I could do without all the overheads of understanding exactly what I''m doing! :S

I guess I''ll plump for the Blit functions. That sounds like the safest for me at the moment.

Thanx, guys 8)

Share this post


Link to post
Share on other sites
quote:
Original post by Toonkides
HDC also means memory context device



Actually...you both are incorrect. HDC, in Windows API terms means "Handle to Device Context".

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!