The BMHD chunk, the bitmap header, is the one chunk every PBM file must
have. It comes first in the FORM, and it
says how big the picture is and how the pixel
data is stored. It is the same 20-byte structure as the ILBM’s, called
BitMapHeader in Electronic Arts’ ILBM document; PBM uses some of its fields
differently.
Fields
Offsets are from the start of the chunk’s data, after its 8-byte header. All numbers are big-endian.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 2 | UWORD | w | The width in pixels. |
| 2 | 2 | UWORD | h | The height in pixels. |
| 4 | 2 | WORD | x | Where the picture sits on the page, from the left. 0 in the files seen. |
| 6 | 2 | WORD | y | Where the picture sits on the page, from the top. 0 in the files seen. |
| 8 | 1 | UBYTE | nPlanes | The number of bits in a pixel’s colour number: 8 in every file seen, for 256 colours. The pixels are a byte each whatever it says. |
| 9 | 1 | UBYTE | masking | How transparency is given; see Masking. |
| 10 | 1 | UBYTE | compression | How the BODY is packed; see Compression. |
| 11 | 1 | UBYTE | pad1 | Unused, 0. |
| 12 | 2 | UWORD | transparentColor | The colour number that is transparent, with masking 2. |
| 14 | 1 | UBYTE | xAspect | The pixel aspect ratio, width part; see Aspect ratio. |
| 15 | 1 | UBYTE | yAspect | The pixel aspect ratio, height part. |
| 16 | 2 | WORD | pageWidth | The width of the screen the picture was made on, in pixels. |
| 18 | 2 | WORD | pageHeight | The height of that screen. |
The explorer reads exactly 20 bytes. Bytes beyond them in a longer BMHD
are shown as unused and reported. A BMHD shorter than 20 bytes cannot be
read, and the explorer turns the file down as a PBM.
Masking
| Value | Name | Meaning in a PBM |
|---|---|---|
| 0 | mskNone | No transparency. |
| 1 | mskHasMask | In an ILBM, a mask plane in every row. A PBM has no planes, and no PBM file seen uses it; the explorer ignores it. |
| 2 | mskHasTransparentColor | Every pixel of colour transparentColor is transparent. |
| 3 | mskLasso | The transparent colour is transparent only where it joins the edge of the picture. Not seen in a PBM. |
The names are those of the ILBM document. How the explorer applies masking 2 and 3 is on the colour map page.
Compression
| Value | Name | Meaning |
|---|---|---|
| 0 | cmpNone | The rows are stored as they are. |
| 1 | cmpByteRun1 | Each row is packed on its own with ByteRun1. |
Most files use 1. The files seen with 0 are tiny 1 × 1 pictures that hold only a palette. The explorer does not read the rows of a PBM with any other value.
Aspect ratio
xAspect and yAspect say that a pixel is
xAspect wide for every yAspect high. Every PBM file seen has
5:6, the shape of a pixel on a 320 × 200 VGA screen shown on a 4:3 monitor, and a page
of 320 × 200. Only the ratio matters; to compare it with another, test
xAspect × yDesiredAspect = yAspect × xDesiredAspect
Examples
0000000C 42 4D 48 44 00 00 00 14 01 40 00 37 00 00 00 00
0000001C 08 00 01 00 00 00 05 06 01 40 00 C8
The width is 320 (01 40) and the height 55 (00 37). There
are 8 planes, masking is 0 and compression 1 (ByteRun1). The transparent colour is 0,
the aspect ratio 5:6, and the page 320 × 200.
0000000C 42 4D 48 44 00 00 00 14 00 01 00 01 00 00 00 00
0000001C 08 02 00 00 00 FF 05 06 01 40 00 C8
A picture of a single pixel, with masking 2 and colour 255 transparent, and no
compression. Its point is its 256-colour CMAP: the file serves as a
palette. That is an inference from its name and size.