In PNM images, the maximum is the header-specified upper numeric limit for each pixel sample. PGM grayscale samples range from 0 to this value; PPM uses the same range independently for red, green, and blue channels. PBM files do not use a maximum because their samples are only 0 or 1. section 12.1.1
The maximum appears after the image width and height in PGM and PPM headers. For example, a PGM header containing 10 14 followed by 9 permits sample values from 0 through 9, with 0 representing black and 9 representing white. section 12.1.1
When reading a PNM header, use the maximum to interpret the pixel data:
- Read the magic number to identify the format and encoding. section 12.1.1
- Read the width and height, then read the maximum for PGM or PPM. section 12.1.1
- Interpret each PGM sample, or each PPM RGB channel, within the range from 0 to the maximum. section 12.1.1
A PGM maximum of 9
In a P2 image, the header can specify `10 14` for the dimensions and `9` as the maximum. A later sample such as `6` is therefore a grayscale value between black (`0`) and white (`9`). section 12.1.1
Table 12.1 Overview of the magic numbers for the PNM formats
|
Format
|
Magic numbers
|
Extension
|
Image data (for one pixel)
|
|
|---|---|---|---|---|
|
ASCII
|
Binary
|
|||
|
Portable bitmap format (PBM)
|
P1
|
P4
|
.pbm
|
0 (white) or
1 (black)
|
|
Portable graymap format (PGM)
|
P2
|
P5
|
.pgm
|
From
0 to
maximum value (grayscale), where the
maximum value is given in the header
|
|
Portable pixmap format (PPM)
|
P3
|
P6
|
.ppm
|
From
0 to
maximum value for each RGB channel, where the
maximum value is given in the header
|
Compare how PBM omits a maximum while PGM and PPM use it to define their sample ranges. section 12.1.1



