Reference: DDPDOC / MM / IMAGE / FMT / 0004

Document TitleDraft

PNG File Format

Document Control Number: 050009

Date: 20051221

Reference: DDPDOC / MM / IMAGE / FMT / 0004

Author:DDP

Approval:

1

Document TitleDraft

DOCUMENT REVISION HISTORY
ISSUE / DATE / STATUS / AUTHOR / COMMENTS
0.00 / 20051221 / Draft / DDP / Creation

Note

CONTENT

1Glossary

2References

3Overview

4File Organization

4.1Signature

4.2Chunk

4.2.1Critical chunks

4.2.1.1IHDR

4.2.1.2PLTE

4.2.1.3IDAT

4.2.1.4IEND

4.2.2Ancillary chunks

4.2.3Additional chunks

5Q&A

6Suggestion

7Change History

1

Document TitleDraft

1Glossary

PNGPortable Network Graphics

CRCCyclic Redundancy Code

2References

[1].Portable Network Graphics (PNG) Specification (Second Edition), Information technology — Computer graphics and image processing — Portable Network Graphics (PNG): Functional specification. ISO/IEC 15948:2003 (E)

3Overview

The Portable Network Graphics is one of the picture organization formats. It was designed from 1990s and aimed to replace the older and simpler GIF format and, to some extent, the much more complex TIFF format. The PNG file can store both grayscale and chromatic pictures. It can record 16-bit depth for grayscale pixels and 48-bit depth for chromatic pixels. It also supports an alpha channel for pixel overlapping. The LZ77 lossless compression is used in PNG files.

4File Organization

A PNG file consists of a PNG signature followed by a series of chunks. The signature field identifies the PNG file format from the other pictures. The picture info and data as well as the operation info are recorded in the chunks beginning with anIHDR chunk and ending with an IEND chunk.

4.1Signature

The first eight bytes of a PNG file always contain the following values:

(Decimal) / 137 / 80 / 78 / 71 / 13 / 10 / 26 / 10
(Hexadecimal) / 89 / 50 / 4e / 47 / 0d / 0a / 1a / 0a
(ASCII C notation) / \211 / P / N / G / \r / \n / \032 / \n

This signature both identifies the file as a PNG file and provides for immediate detection of common file-transfer problems.

4.2Chunk

The chunk records the picture info or compressed data. Each chunk consists three or four fields, among which the data field may be empty.

Length / A four-byte unsigned integer giving the number of bytes in the chunk's data field. The length counts only the data field, not itself, the chunk type, or the CRC. Zero is a valid length. Although encoders and decoders should treat the length as unsigned, its value shall not exceed 231-1 bytes.
Chunk Type / A sequence of four bytes defining the chunk type. Each byte of a chunk type is restricted to the decimal values 65 to 90 and 97 to 122. These correspond to the uppercase and lowercase ISO 646 letters (A-Z and a-z) respectively for convenience in description and examination of PNG datastreams.
Chunk Data / The data bytes appropriate to the chunk type. This field can be of zero length.
CRC / A four-byte CRC (Cyclic Redundancy Code) calculated on the preceding bytes in the chunk, including the chunk type field and chunk data fields, but not including the length field. The CRC can be used to check for corruption of the data. The CRC is always present, even for chunks containing no data.

The organization order of chunks is strictly specified as the table below.

Critical chunks (shall appear in this order, except PLTE is optional)
Chunk name / Multiple allowed / Ordering constraints
IHDR / No / Shall be first
PLTE / No / Before first IDAT
IDAT / Yes / Multiple IDAT chunks shall be consecutive
IEND / No / Shall be last
Ancillary chunks(need not appear in this order)
Chunk name / Multiple allowed / Ordering constraints
cHRM / No / Before PLTE and IDAT
gAMA / No / Before PLTE and IDAT
iCCP / No / Before PLTE and IDAT. If the iCCP chunk is present, the sRGB chunk should not be present.
sBIT / No / Before PLTE and IDAT
sRGB / No / Before PLTE and IDAT. If the sRGB chunk is present, the iCCP chunk should not be present.
bKGD / No / After PLTE; before IDAT
hIST / No / After PLTE; before IDAT
tRNS / No / After PLTE; before IDAT
pHYs / No / Before IDAT
sPLT / Yes / Before IDAT
tIME / No / None
iTXt / Yes / None
tEXt / Yes / None
zTXt / Yes / None

4.2.1Critical chunks

Critical chunks are those chunks that are absolutely required in the PNG file. A valid PNG file shall begin with a PNG signature, immediately followed by an IHDR chunk, then one or more IDAT chunks, and shallend with an IEND chunk. Only one IHDR chunk and one IEND chunk are allowed in a PNG file.

4.2.1.1IHDR

The IHDR chunk shall be the first chunk in the PNG file. It defines the basic image info as an image header. The four-byte chunk type field contains the decimal values [73, 72, 68, 82]. It contains,

Field / Length / Description
Width / 4 bytes / Width and height are four-byte unsigned integers giving the image dimensions in pixels. Zero is an invalid value.
Height / 4 bytes
Bit depth / 1 byte / Bit depth is a single-byte integer giving the number of bits per sample or per palette index. Valid values are 1, 2, 4, 8, and 16, although not all values are allowed for all color types.
Color type / 1 byte / Color type is a single-byte integer that defines the PNG image type. Valid values are 0, 2, 3, 4, and 6.
Compression method / 1 byte / Compression method is a single-byte integer that indicates the method used to compress the image data. Only compression method 0 is defined in this International Standard.
Filter method / 1 byte / Filter method is a single-byte integer that indicates the preprocessing method applied to the image data before compression. Only filter method 0is defined in this International Standard.
Interlace method / 1 byte / Interlace method is a single-byte integer indicateing the transmission order of the image data. Two values are defined in this International Standard, 0 (no interlace) or 1 (Adam7 interlace).

Bit depth restrictions for each color type are imposed to simplify implementations and to prohibit combinations that do not compress well.

PNG image type / Color type / Allowedbit depths / Interpretation
Grayscale / 0 / 1, 2, 4, 8, 16 / Each pixel is a grayscale sample
Truecolor / 2 / 8, 16 / Each pixel is an R,G,and B triple
Indexed-color / 3 / 1, 2, 4, 8 / Each pixel is a palette index; a PLTE chunk shall appear.
Grayscale with alpha / 4 / 8, 16 / Each pixel is a grayscale sample followed by an alpha sample.
Truecolor with alpha / 6 / 8, 16 / Each pixel is an R,G,and B triple followed by an alpha sample.

The sample depth is the same as the bit depth except in the case of indexed-color images (color type 3), in which the sample depth is always 8 bits.

4.2.1.2PLTE

The PLTE chunk describes the color palette for the indexed-color images. The four-byte chunk type field contains the decimal values [80, 76, 84, 69]. The chunk contains from 1 to 256 palette entries, each a three-byte series of the form,

Red / 1 byte / Green / 1 byte / Blue / 1 byte

The number of entries is determined from the chunk length. A chunk length not divisible by 3 is an error. This chunk shall appear for color type 3, and may appear for color types 2 and 6; it shall not appear for color types 0 and 4. There shall not be more than one PLTE chunk in a PNG file.

For color type 3 (indexed-color), the PLTE chunk is required. The number of palette entries shall not exceed the range that can be represented in the image bit depth (for example, 24 = 16 for a bit depth of 4). It is permissible to have fewer entries than the bit depth would allow. In that case, any out-of-range pixel value found in the image data is an error.

For color types 2 and 6 (truecolor and truecolor with alpha), the PLTE chunk is optional. If present, it provides a suggested set of colors (from 1 to 256) to which the truecolor image can be quantized if it cannot be displayed directly. It is, however, recommended that the sPLT chunk be used for this purpose, rather than the PLTE chunk. If neither PLTE nor sPLT chunks are present, northe image cannot be displayed directly, quantization has to be done by the viewing system. However, it is often preferable for the selection of colors to be done once by the PNG encoder.

4.2.1.3IDAT

The IDAT chunk contains the actual image data, which is the output of the compression algorithm. The four-byte chunk type field contains the decimal values [73, 68, 65, 84]. There may be multiple IDAT chunks; if so, they shall appear consecutively with no other intervening chunks. The compressed data is then the concatenation of the contents of the data fields of all the IDAT chunks.

4.2.1.4IEND

The IEND chunk marks the end of the PNG file. The four-byte chunk type field contains the decimal values [73, 69, 78, 68]. The chunk's data field is empty.

4.2.2Ancillary chunks

Ancillary chunks records the action info for ancillary processing. The decoder can ignore the ancillary chunks. For each ancillary chunk, the actions described are under the assumption that the decoder is not ignoring the chunk.

The details of the chunk description can be referred to [1].

4.2.3Additional chunks

The provisions of this International Standard may be extended by adding new chunk types, which may be either private or public. Applications can use private chunk types to carry data that is not of interest to other people's applications. As a result, decoders shall be prepared to encounter unrecognized public or private chunk types.

The details of the chunk description can be referred to [1].

5Q&A

N/A

6Suggestion

N/A

7Change History

20051229DDPFinish creations

1