Is there any purpose to InfoHeader.ImageSize
when InfoHeader.Compression
is set to zero?
It seems the required size of the image data (when compression is not used) can be directly calculated from the BitCount
, Width
, and Height
fields? If true, I’d start by rejecting files where this is set to an invalid value (not zero and not expected value). If it’s always invalid, then it should be ignored…
I'd recommend starting with lots of restrictions on the image format....
For example, refuse to load unless:
- Header.Signature is
BM
- Header.FileSize is >= sizeof header + sizeof InfoHeader
- InfoHeader.size == 40
- InfoHeader.Width == BP5 display width
- InfoHeader.Heigth == BP5 display height
- InfoHeader.Planes == 1
- InfoHeader.BitCount == 16 or 1 (useful to limit supported formats initially… choose one or two to support?)
- InfoHeader.Compression == 0 (can of worms … avoid it for now)
- InfoHeader.ColorsUsed consistent with InfoHeader.BitCount
Then check that remaining data is avialable:
- FileSize is >= sizeof header + sizeof InfoHeader + sizeof ColorTable + sizeof RasterData (have to parse InfoHeader to know this)
Finally, read in the raster data … have a separate function per InfoHeader.BitCount to deal with monochrome vs. 16-bit RGB? (also allows low-impact adding support for other formats later).
Whatever format is supported, it’d be great for documentation to indicate how to convert a bitmap of the appropriate size to a supported format. E.g., using free CLI tool for graphics manipulation (name escaping me at the moment).