Game Development Reference
In-Depth Information
this by converting the BITMAPINFOHEADER into another structure called
a BITMAPINFO, which combines a BITMAPINFOHEADER with a palette
containing initially just a single palette entry. If we were creating a 256
colour bitmap then we would allocate memory for 256 entries in the
'bmiColors' array.
typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD
bmiColors[1];
} BITMAPINFO;
Since we are only loading 24-bit, uncompressed files, we only need to
read the pixel data directly into a buffer of the correct size. The code you
will need to load this type of file is as follows:
// Load a Windows bitmap from an open file.
BOOL CBmp::Load(Cfile &bmpFile)
{
BITMAPINFO *bmi = NULL;
BYTE* bits = NULL;
BITMAPINFOHEADER bmiHdr;
//Get the current file position.
DWORD fileStart = bmpFile.GetPosition();
BITMAPFILEHEADER bmpFileHdr;
int bytesRead;
bytesRead = bmpFile.Read(&bmpFileHdr,
sizeof(BITMAPFILEHEADER));
if (bytesRead != sizeof(BITMAPFILEHEADER)) {
TRACE(”CBmp::Load>> Failed to read file header”);
goto abortBmpLoad;
}
// Check that we have the magic 'BM' at the start.
if (bmpFileHdr.bfType != 0x4D42) {
TRACE(”CBmp::Load>> Not a bitmap file”);
goto abortBmpLoad;
}
bytesRead = bmpFile.Read(&bmiHdr, sizeof(BITMAPINFOHEADER));
Search Nedrilad ::




Custom Search