Dr Malcolm McLean said:
Three problems with BMP. Firstly the line-padding rules. Since most
images are units of 8 pixels wide, these often grab ypu unexpectedly.
The second one is that all the documentation assumes you will be
running the code on a Windows machine. In fact it is not possible to
portably define the headers in terms of structures. However it's easy
eanought o write a fucntionto read a little-endian integer from the
file.
Yes, the header is some 54 bytes I think, while scanlines are a multiple of
4 bytes. That means the entire image data, and any palette, are at an odd
2-byte alignment in the file, and in memory if you just load the whole thing
as one block.
(BMP was also used at one time for combining multiple icons in a single BMP
image. Each scanline row is padded to a 4n bytes, so the natural way to do
this is to combine these vertically.
So that if the icon is, say, 20x20 1-bit pixels, the 3rd icon starts at row
41 in the composite file. But it was decided to pack these horizontally
instead. Now the start of any row in the 3rd icon, starts at some bit offset
in the middle of the 2nd dword! Who designs this stuff?)
The third one is the BGR, upside down raster format. It's just a
little bit of tinkering, but it's a nuisance, and it tempts you to
give your loader a cluntzy interface.
I think the palette uses RGB, and the image data might use BGR. Or is it the
other way. (Palettes and 24-bit image data do not co-exist, doesn't help
though).
But on the whole, compared with some file formats, BMP is fairly
straightforward.