semmixcolor and perception

Interlacing

On a slow connection an image stored row by row appears from the top, strip by strip. Interlacing reorders the data so the whole picture shows first at low resolution and then gradually sharpens.

Interlacing in GIF: four passes

A GIF with interlacing on (a bit in the image descriptor) stores rows in four passes:

PassRowsWhat is visible after it
10, 8, 16, 24, ...every 8th row (1/8 of the data)
24, 12, 20, 28, ...every 4th row (1/4)
32, 6, 10, 14, ...every 2nd row (1/2)
41, 3, 5, 7, ...all rows

For an image with 10 rows the order in the file is:

pass 1: 0, 8 pass 2: 4 pass 3: 2, 6 pass 4: 1, 3, 5, 7, 9 row in file: 0 1 2 3 4 5 6 7 8 9 row in image: 0 8 4 2 6 1 3 5 7 9

After the first pass a browser usually repeats each row downward to fill the gaps, so a blurry but complete picture appears at once. Interlacing only affects row order. The data are the same and LZW compression works on them the same way, though the file can be slightly larger because rows adjacent in the stream are less alike.

Adam7 in PNG

PNG interlaces columns as well as rows. The Adam7 scheme divides the image into 8 × 8 squares and stores pixels in seven passes:

1 6 4 6 2 6 4 6 7 7 7 7 7 7 7 7 5 6 5 6 5 6 5 6 7 7 7 7 7 7 7 7 3 6 4 6 3 6 4 6 7 7 7 7 7 7 7 7 5 6 5 6 5 6 5 6 7 7 7 7 7 7 7 7

The number in each cell is the pass in which that pixel goes into the file. After the first pass 1/64 of the pixels is there, after the fourth 1/8, after the sixth half. The picture becomes recognizable much earlier than with GIF, but an interlaced PNG is usually several to over ten percent larger, because compression copes worse with scattered pixels.

Progressive JPEG

JPEG does not interlace pixels but frequency coefficients. It first stores the average color of each 8 × 8 block, then successive detail. The effect is similar: a blurry image first, then sharper and sharper. Unlike PNG, a progressive JPEG is often even slightly smaller than a baseline one.

When interlacing makes sense