Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PNG file format endianness?

Tags:

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?

like image 474
Marlon Avatar asked Mar 05 '10 02:03

Marlon


People also ask

Is PNG big-endian or little-endian?

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

What is the endian format?

Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first, at the lowest storage address. Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first.

What is PNG format image?

What is a PNG file? PNG is short for Portable Network Graphic, a type of raster image file. It's particularly popular file type with web designers because it can handle graphics with transparent or semi-transparent backgrounds.

Does PNG support 16 bit?

As with RGB and gray+alpha, PNG supports 8 and 16 bits per sample for RGBA or 32 and 64 bits per pixel, respectively. Pixels are always stored in RGBA order, and the alpha channel is not premultiplied.


2 Answers

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

like image 115
ja. Avatar answered Sep 28 '22 01:09

ja.


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

See: the spec.

like image 27
Seth Avatar answered Sep 28 '22 02:09

Seth