Reputation: 11
Embedded bitmap resources are missing BITMAPFILEHEADER ("correctly not returning the BITMAPFILEHEADER" according to Raymond Chen's article). Whether it is missing or correctly not returning, a routine is necessary for embedded bitmap resources. There are many workaround examples that fills bfOffBits like below.
bmfHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER);
However, bfOffBits is the offset, i.e. starting address, of the byte where the bitmap image data (pixel array) can be found. So in case of indexed bitmaps, or bitmaps having palettes, must include the size of palette as well. Therefore, I think the above is wrong, and correct workaround for calculating bfOffBits is
// paletteEntrySize == 3 if three DWORD color masks per entry
// paletteEntrySize == 4 if four DWORD color masks per entry
bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + (paletteEntrySize * bitmapInfoHeader.biClrUsed);
However, in msdn example, sizeof(RGBQUAD), which is always 4, is used. This confuses me whether size of palette entry is always 4.
hdr.bfOffBits = (DWORD) sizeof(BITMAPFILEHEADER) +
pbih->biSize + pbih->biClrUsed
* sizeof (RGBQUAD);
If anyone explains correctly calculating bfOffBits, it will be really appreciated.
Upvotes: 0
Views: 36