The image data starts straight after the header, at twice the header length in bytes, and runs to the end of the file. It is always compressed, with four kinds of item.
Lines and planes
The picture is stored one scan line at a time, top line first. Each line is stored as one row of bytes per plane, plane 0 first: a four-plane picture holds line 0 plane 0, line 0 planes 1, 2 and 3, then line 1 plane 0 and so on. Each plane row is ceil(width / 8) bytes, one bit per pixel with the most significant bit leftmost; the bits past the right edge are padding.
A pixel’s colour number takes its lowest bit from plane 0, the next from plane 1, and
so on. This is the GEM VDI’s device-independent layout, which a GEM program turns
into its screen’s own layout with the VDI call vr_trnfm().
Each plane row is compressed on its own: no item continues from one row into the next.
Items
| Bytes | Item | Output |
|---|---|---|
00 00 FF n | vertical replication | the line that follows, with all its planes, appears n times in all |
00 n pattern | pattern run | the pattern, which is pattern-length bytes long, repeated n times |
80 n data | bit string | the next n bytes, copied as they are |
b: 01–7F | solid run, clear | b bytes of 00 |
b: 81–FF | solid run, set | b − 128 bytes of FF |
Every count is in bytes, never in pixels: a solid run of 83 is three bytes
of FF, 24 pixels. In a one-plane picture a set bit is black, so the set and
clear solid runs are black and white. The pattern length comes from word 3 of the
header.
The bytes 00 and 80 are the markers for the other items, so a
solid run is 1 to 127 bytes long.
Vertical replication
A vertical replication item may only come at the start of a line, before plane 0.
The line that follows it is decoded once and then used n times in all, so
00 00 FF 05 makes five identical lines. Netpbm’s
gemtopnm and xloadimage both read the count this way. The Encyclopedia of
Graphics File Formats says instead that a count of 1 gives two lines; files written
to that reading would come out one line short in the common readers.
Some old files have no replication items at all, and a reader must accept lines that start directly with another item.
Example
One line of a 640-pixel, one-plane picture with a pattern length of 2. A plane row is 640 / 8 = 80 bytes.
| Bytes | Item | Output |
|---|---|---|
83 | solid run, set | 3 bytes of FF: 24 black pixels |
80 02 F0 0F | bit string | F0 0F |
00 03 AA 55 | pattern run | AA 55 AA 55 AA 55, 6 bytes |
45 | solid run, clear | 69 bytes of 00 |
3 + 2 + 6 + 69 = 80 bytes, the whole row. Ten blank lines of the same picture take
five bytes: 00 00 FF 0A 50, a vertical replication of 10 and a white run
of 80 bytes.