The PNG format (Portable Network Graphics or Ping format) is a bitmap (raster) graphic file format. It was developed in 1995 in order to provide a free alternative to the GIF format, which is a proprietary format whose rights are held by Unisys (proprietor of the LZW compression algorithm), to whom all software publishers using this type of format are under obligation to pay royalties. Thus, PNG is also a recursive acronym for PNG Not GIF.
Characteristics of the PNG format
The PNG format makes it possible to store images in black and white (a color depth of 16 bits per pixel), true color (a color depth of 48 bits per pixel), as well as indexed images, using a palette of 256 colors.
Moreover, it supports alpha channel transparency, i.e. the possibility of defining 256 levels of transparency, while the GIF format only allows one color of the pallet to be defined as transparent. It also has an interlacing function which makes it possible to show the image gradually.
The compression offered by this format is a (lossless compression) 5 to 25% better than GIF compression.
Finally, PNG stores image gamma information, which makes a gamma correction possible and allows it to become display-device-independent. Error correction mechanisms are also stored in the file in order to guarantee its integrity.
Structure of a PNG file
A PNG file comprises a signature, making it possible to indicate that it is a PNG file, followed by a series of elements called chunks. The signature of a PNG file (in decimal notation) is the following:
137 80 78 71 13 10 26 10
The same signature in hexadecimal notation is:
89 50 4E 47 0D 0A 1A 0A
Each chunk comprises 4 parts :
- The size, a non-signed 4-byte integer, describing the size of the chunk
- The chunk type: a 4-character (4-bytes) code comprised by ASCII alphanumeric characters (A-Z, a-z, 65 to 90 and 97 to 122) allowing the nature of the chunk to be established
- The chunk data
- The CRC (cyclic redundancy check), a 4-byte correcting code which allows the integrity of the chunk to be checked
The chunks can be present in any order except that they must start with the header chunk (IHDR chunk) and finish with the end chunk (IEND chunk)
The main chunks (called critical chunks) are:
- IHDR bitmap information header
- PLTE Palette
- IDAT Image data
- IEND Image trailer
The other chunks (called ancillary chunks) are the following:
- bKGD Background color
- cHRM Primary chromaticities and white point
- gAMA Image gamma
- hIST Image histogram
- pHYs Physical pixel dimensions
- sBIT Significant bits
- tEXt Textual data
- tIME Image last-modification time
- tRNS Transparency
- zTXt Compressed textual data