PNG file format endianness?

安稳与你 提交于 2019-12-29 08:26:23

问题


Im not sure if endian is the right word but..

I have been parsing through a PNG file and I have noticed that all of the integer values are in big endian. Is this true?

For example, the width and height are stored in the PNG file as 32bit unsigned integers. My image is 16x16 and in the file its stored as:

00 00 00 10

when it should be:

10 00 00 00

Is this true or is there something I am missing?


回答1:


Yes, according to the specification, integers must be in network byte order (big endian):

All integers that require more than one byte shall be in network byte order: the most significant byte comes first, then the less significant bytes in descending order of significance (MSB LSB for two-byte integers, MSB B2 B1 LSB for four-byte integers). The highest bit (value 128) of a byte is numbered bit 7; the lowest bit (value 1) is numbered bit 0. Values are unsigned unless otherwise noted. Values explicitly noted as signed are represented in two's complement notation.

http://www.w3.org/TR/2003/REC-PNG-20031110/#7Integers-and-byte-order




回答2:


Integers in PNG are in network byte order (big endian).

See: the spec.



来源:https://stackoverflow.com/questions/2384111/png-file-format-endianness

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