BMP file format contradiction between little and big endian

╄→尐↘猪︶ㄣ 提交于 2019-12-10 23:37:11

问题


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?

来源:https://stackoverflow.com/questions/17113827/bmp-file-format-contradiction-between-little-and-big-endian

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!