Jeremy
2004-01-02 03:10:37 UTC
This may be in the wrong newsgroup, so let me apologize first.
I would like to ask if anyone else has had a problem attempting to load bitmap files without the aid of the VCL. This is code taken directly from my project, and the output beneath it: (in is defined as an ifstream)
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
in.read((char *)&bfh,sizeof(BITMAPFILEHEADER));
in.read((char *)&bih,sizeof(BITMAPINFOHEADER));
cout << "Width: " << bih.biWidth << endl;
cout << "Height: " << bih.biHeight << endl;
cout << "sizeof(BITMAPFILEHEADER) = " << sizeof(BITMAPFILEHEADER) << endl;
cout << "sizeof(BITMAPINFOHEADER) = " << sizeof(BITMAPINFOHEADER) << endl;
Output:
Width: 1141120
Height: 65536
sizeof(BITMAPFILEHEADER) = 16
sizeof(BITMAPINFOHEADER) = 40
That's quite a huge bitmap! The main problem is with sizeof(BITMAPFILEHEADER) though. In wingdi.h (line 769), BITMAPFILEHEADER is defined as such:
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
Assuming that a word is 2 bytes and a dword is 4 bytes, this comes to 14, not 16. I'm guessing the compiler is padding everything so that it aligns correctly; however, the information is still wrong, and causes serious problems. I'm wondering, has anyone else run into this problem and knows a fix for it? I'm not adverse to using the actual sizes instead of sizeof(), but it's a hassle. Thanks!
BTW, when I use 14 instead of sizeof(BITMAPFILEHEADER), everything works. :)
I would like to ask if anyone else has had a problem attempting to load bitmap files without the aid of the VCL. This is code taken directly from my project, and the output beneath it: (in is defined as an ifstream)
BITMAPFILEHEADER bfh;
BITMAPINFOHEADER bih;
in.read((char *)&bfh,sizeof(BITMAPFILEHEADER));
in.read((char *)&bih,sizeof(BITMAPINFOHEADER));
cout << "Width: " << bih.biWidth << endl;
cout << "Height: " << bih.biHeight << endl;
cout << "sizeof(BITMAPFILEHEADER) = " << sizeof(BITMAPFILEHEADER) << endl;
cout << "sizeof(BITMAPINFOHEADER) = " << sizeof(BITMAPINFOHEADER) << endl;
Output:
Width: 1141120
Height: 65536
sizeof(BITMAPFILEHEADER) = 16
sizeof(BITMAPINFOHEADER) = 40
That's quite a huge bitmap! The main problem is with sizeof(BITMAPFILEHEADER) though. In wingdi.h (line 769), BITMAPFILEHEADER is defined as such:
typedef struct tagBITMAPFILEHEADER {
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER, FAR *LPBITMAPFILEHEADER, *PBITMAPFILEHEADER;
Assuming that a word is 2 bytes and a dword is 4 bytes, this comes to 14, not 16. I'm guessing the compiler is padding everything so that it aligns correctly; however, the information is still wrong, and causes serious problems. I'm wondering, has anyone else run into this problem and knows a fix for it? I'm not adverse to using the actual sizes instead of sizeof(), but it's a hassle. Thanks!
BTW, when I use 14 instead of sizeof(BITMAPFILEHEADER), everything works. :)