I have two BMP files, a windows screenshot and a linux generated file using GIMP. What I noticed is that all the data in the headers is stored in big endian format.
The biWidth
, biHeight
and biPlanes
fields of the DIB header are all in big endian, also "the size of the BMP file in bytes" (the second field from Bitmap File Header) is big endian, which contradicts wikipedia, where it says: "All of the integer values are stored in little-endian format"
I looked into GIMP's source code and I found a function that converts data from little to big endian: https://git.gnome.org/browse/gimp/tree/plug-ins/file-bmp/bmp-write.c#n81
That FromL
function is used to write the file size in bytes in the Bitmap File Header:
https://git.gnome.org/browse/gimp/tree/plug-ins/file-bmp/bmp-write.c#n431
So everything is in big endian, the question is why?
Why would one want to convert to big endian on write and to convert from big to little endian when reading, when one could simply read and write that data in little endian?
What am I missing?