2

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?

Paul
  • 20,883
  • 7
  • 57
  • 74
  • 2
    That routine looks a lot like it's writing as little-endian; the LSB is written to the lowest-indexed byte in the buffer... – Oliver Charlesworth Jun 14 '13 at 17:16
  • Are you sure? Why would all the fields be in big endian otherwise? – Paul Jun 14 '13 at 17:41
  • I have no idea. Nevertheless, that routine is writing as little-endian. – Oliver Charlesworth Jun 14 '13 at 17:44
  • 1
    So the problem was with me all the time. The files are indeed little endian, but for some reason I thought they are big endian and from there on everything was swapped for me. Oli Charlesworth, thank you for the heads up, you were right. You may want to add an answer for me to accept it? Or should I vote on closing the question? – Paul Jun 14 '13 at 19:15
  • I think closing the question is a good idea. I voted for close since the title of this question is misleading (because it's wrong :) and the question itself is irrelevant. I suggest you change the title of the question to reflect your enlightenment so others (like me) don't see it as a search result. – Martin Hennings Jan 14 '15 at 13:24

0 Answers0