Figure 4.6 — Possible PNG image pixel types
4.4 PNG image
The transformation of the reference image results in one of five types of PNG image (see figure 4.6) :
a. Truecolour with alpha: each pixel consists of four samples: red, green, blue, and alpha.
b. Greyscale with alpha: each pixel consists of two samples: grey and alpha.
c. Truecolour: each pixel consists of three samples: red, green, and blue. The alpha channel may be represented by a single pixel value. Matching
pixels are fully transparent, and all others are fully opaque. If the alpha channel is not represented in this way, all pixels are fully opaque.
d. Greyscale: each pixel consists of a single sample: grey. The alpha channel may be represented by a single pixel value as in the previous case. If
the alpha channel is not represented in this way, all pixels are fully opaque.
e. Indexed-colour: each pixel consists of an index into a palette (and into an associated table of alpha values, if present).
The format of each pixel depends on the PNG image type and the bit depth. For PNG image types other than indexed-colour, the bit depth specifies the
number of bits per sample, not the total number of bits per pixel. For indexed-colour images, the bit depth specifies the number of bits in each palette
index, not the sample depth of the colours in the palette or alpha table. Within the pixel the samples appear in the following order, depending on the PNG
image type.
a. Truecolour with alpha: red, green, blue, alpha.
b. Greyscale with alpha: grey, alpha.
c. Truecolour: red, green, blue.
d. Greyscale: grey.
e. Indexed-colour: palette index.
4.5 Encoding the PNG image
4.5.1 Introduction
A conceptual model of the process of encoding a PNG image is given in figure 4.7. The steps refer to the operations on the array of pixels or indices in the
PNG image. The palette and alpha table are not encoded in this way.
a. Pass extraction: to allow for progressive display, the PNG image pixels can be rearranged to form several smaller images called reduced images or
passes.
b. Scanline serialization: the image is serialized a scanline at a time. Pixels are ordered left to right in a scanline and scanlines are ordered top to
bottom.
c. Filtering: each scanline is transformed into a filtered scanline using one of the defined filter types to prepare the scanline for image compression.
d. Compression: occurs on all the filtered scanlines in the image.
e. Chunking: the compressed image is divided into conveniently sized chunks. An error detection code is added to each chunk.
f. Datastream construction: the chunks are inserted into the datastream.
4.5.2 Pass extraction
Pass extraction (see figure 4.8) splits a PNG image into a sequence of reduced images where the first image defines a coarse view and subsequent
images enhance this coarse view until the last image completes the PNG image. The set of reduced images is also called an interlaced PNG image. Two
interlace methods are defined in this International Standard. The first method is a null method; pixels are stored sequentially from left to right and scanlines
from top to bottom. The second method makes multiple scans over the image to produce a sequence of seven reduced images. The seven passes for a
sample image are illustrated in figure 4.8. See clause 8: Interlacing and pass extraction.