PNG Image

From XentaxWiki
Jump to: navigation, search

Back to index | Edit this page

PNG


Format Specifications

// PNG Image file format

// big endian

// header
8 bytes - signature // "89 50 4E 47 0D 0A 1A 0A" (PNG)

// chunks
num_of_chunks *
{
   4 bytes (uint32) - chunk data size
   4 bytes (char) - chunk type  // e.g. "IHDR"
   x bytes - chunk data
   4 bytes - CRC
}

Critical chunks

IHDR chunk data

This chunk have to occur as the first one in the PNG file, right after header.

4 bytes (uint32) - image width
4 bytes (uint32) - image height
1 byte (uint8) - image depth  // valid values are 1, 2, 4, 8, or 16
                              // e.g. 8bpp
1 byte (uint8) - color type  // It is sum of the following values: 
                             // 1 (palette used) 
                             // 2 (color used) 
                             // 4 (alpha channel used) 
                             // Valid values are 0, 2, 3, 4, and 6.
1 byte (uint8) - compression method  // "0" - deflate
                                     // Note: deflate is mandatory for all standard PNG files
1 byte (uint8) - filther method  // "0" - adaptive filtering with five basic filter types
1 byte (uint8) - interlace method  // "0" - no interlace
                                   // "1" - Adam7 interlace

PLTE chunk data

num_of_palette_entries *
{
   1 byte - red color // 0-255
   1 byte - green color // 0-255
   1 byte - blue color // 0-255
}

This chunk is semi-optional.
Table below shows if chunk should appear for specified color type:

Color Type Appearence
0 (none) It must NOT appear
2 (color used) It can appear
3 (color used and palette used) It MUST appear
4 (alpha channel used) It must NOT appear
6 (color used and alpha channel used) It can appear

IDAT chunk data

x bytes - image data  // compressed with deflate (zlib)

IEND chunk data

// Note: This chunk is empty.
// It is used only to mark the end of PNG datastream.



Ancillary chunks

tEXt chunk data

x bytes - keyword   // up to 79 bytes
1 byte - null separator
x bytes - text  // uses ISO/IEC 8859-1 (Latin-1) character set

zTXt chunk data

x bytes - keyword   // up to 79 bytes, e.g. "Raw profile type iptc"
1 byte - null separator
1 byte - compression method   // "0" - deflate (zlib)
x bytes - compressed text

iTXt chunk data

x bytes - keyword   // up to 79 bytes
1 byte - null separator
1 byte - compression method   // "0" - deflate (zlib)
x bytes - language tag  
1 byte - null separator
x bytes - translated keyword
1 byte - null separator
x bytes - text  // uses UTF-8

sPLT chunk data

x bytes - palette name  // up to 79 bytes
1 byte - null separator
1 byte (uint8) - sample depth  // must be 8 or 16

num_of_palette_entries *
{
   1-2 bytes - red color
   1-2 bytes - green color
   1-2 bytes - blue color
   1-2 bytes - alpha
   2 bytes (uint16) - frequency
}


// TODO - add more ancillary chunk descriptions

Metadata

PNG supports storing metadata information like Exif, XMP and IPTC.
Metadata can be easily edited with tools like TweakPNG, ExifTool, Exif Pilot, Exiv2 or Metadata++.
Comparsion of all editors can be found here.

Metadata can be stored in text chunks like tEXt, iTXt and zTXt.
For example GIMP saves IPTC metadata inside zTXt chunk.


Below table represents list of known metadata tags inside text chunks:

Tag ID Tag Name
Artist Artist
Author Author
Comment Comment
Copyright Copyright
CreationTime CreationTime
Description Description
Disclaimer Disclaimer
Document Document
Label Label
Make Make
Model Model
Raw profile type APP1 APP1_Profile
Raw profile type exif EXIF_Profile
Raw profile type icc ICC_Profile
Raw profile type icm ICC_Profile
Raw profile type iptc IPTC_Profile
Raw profile type xmp XMP_Profile
Software Software
Source Source
TimeStamp TimeStamp
Title Title
URL URL
Warning PNGWarning
XML:com.adobe.xmp XMP

MultiEx BMS Script

Not written yet.

Notes and Comments

None.

Compatible Programs

  • IrfanView
  • GIMP
  • MS Paint

Games

List of games using this file format:

  • Ragnarok Journey
  • Styx: Shards of Darkness
  • The Fall of Lazarus
  • The Tribez
  • Hamsterball
  • Many more...

See Also