开发者

PNG file format endianness?

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 b开发者_Go百科e:

10 00 00 00

Is this true or is there something I am missing?


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


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

See: the spec.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜