PAM is a fourth Netpbm format, more general than PBM, PGM and PPM. It can carry the same
images and more, such as an alpha plane. Netpbm programs that read the older formats also
read equivalent PAM files. Files usually have the extension .pam, and the
informal media type is image/x-portable-arbitrarymap.
Header
The header is the two characters P7 and a newline, then lines of text,
each ended by a newline. A line starting with # is a comment. Any other
line is a sequence of whitespace-separated tokens, and a line with no tokens is allowed
and means nothing. The rest of the header is what tells a PAM file from an
xv thumbnail, which also starts P7.
| Line | Times | Value | Description |
|---|---|---|---|
WIDTH | exactly 1 | at least 1 | Columns. |
HEIGHT | exactly 1 | at least 1 | Rows. |
DEPTH | exactly 1 | at least 1 | Samples per tuple: the number of planes or channels. |
MAXVAL | exactly 1 | 1 to 65535 | The largest sample value. The limit was written into the specification in October 2005, though programs had long kept to it. |
TUPLTYPE | 0 or more | text | The rest of the line, taken literally, without leading or trailing whitespace. Several lines are joined in order with a single space. With none, the tuple type is the empty string. |
ENDHDR | exactly 1 | none | Must be the last header line. The raster starts on the next byte. |
No maximum is defined for the width, height or depth, though programs often have their own limits.
Tuple types
The tuple type names the meaning of the samples for visual images. It never changes
the encoding and never sets the depth: decoders use DEPTH for the layout,
and may check that it matches. Accepting and ignoring extra higher-numbered planes is
considered good practice.
| Tuple type | Depth | Maxval | Meaning |
|---|---|---|---|
BLACKANDWHITE | 1 | 1 | Bilevel image. 0 is black, the opposite of PBM. |
GRAYSCALE | 1 | any | Greyscale image. |
RGB | 3 | any | Colour image; planes are red, green, blue. |
BLACKANDWHITE_ALPHA | 2 | 1 | Bilevel with an opacity plane last. |
GRAYSCALE_ALPHA | 2 | any | Greyscale with an opacity plane last. |
RGB_ALPHA | 4 | any | Colour with an opacity plane last. |
Opacity values are a fraction of maxval and are not gamma-adjusted.
Raster
Rows run top to bottom, tuples left to right, and samples within a tuple in order, with no delimiters anywhere. Each sample is an unsigned integer in pure binary, most significant byte first, in the smallest whole number of bytes that can hold maxval. So a tuple is depth × that many bytes. PAM has no plain form.
A file may hold several images back to back, each with its own header, with no extra data, delimiters or padding.
Example
P7
WIDTH 2
HEIGHT 1
DEPTH 4
MAXVAL 255
TUPLTYPE RGB_ALPHA
ENDHDR
The raster for this header is 8 bytes: FF 00 00 FF for an opaque red
pixel, then 00 00 FF 80 for a half-transparent blue one.