1PPM Format Specification(5) File Formats Manual PPM Format Specification(5)
2
3
4
6 PPM - Netpbm color image format
7
8
10 This program is part of Netpbm(1).
11
12 The PPM format is a lowest common denominator color image file format.
13
14 It should be noted that this format is egregiously inefficient. It is
15 highly redundant, while containing a lot of information that the human
16 eye can't even discern. Furthermore, the format allows very little
17 information about the image besides basic color, which means you may
18 have to couple a file in this format with other independent information
19 to get any decent use out of it. However, it is very easy to write and
20 analyze programs to process this format, and that is the point.
21
22 It should also be noted that files often conform to this format in
23 every respect except the precise semantics of the sample values. These
24 files are useful because of the way PPM is used as an intermediary for‐
25 mat. They are informally called PPM files, but to be absolutely pre‐
26 cise, you should indicate the variation from true PPM. For example,
27 'PPM using the red, green, and blue colors that the scanner in question
28 uses.'
29
30 The name "PPM" is an acronym derived from "Portable Pixel Map." Images
31 in this format (or a precursor of it) were once also called "portable
32 pixmaps."
33
34 The format definition is as follows. You can use the libnetpbm(1)Csub‐
35 routinelibrarytoreadand interpret the format conveniently and accu‐
36 rately.
37
38 A PPM file consists of a sequence of one or more PPM images. There are
39 no data, delimiters, or padding before, after, or between images.
40
41 Each PPM image consists of the following:
42
43
44
45 · A 'magic number' for identifying the file type. A ppm image's
46 magic number is the two characters 'P6'.
47
48 ·
49
50 Whitespace (blanks, TABs, CRs, LFs).
51
52 ·
53
54 A width, formatted as ASCII characters in decimal.
55
56 ·
57
58 Whitespace.
59
60 ·
61
62 A height, again in ASCII decimal.
63
64 ·
65
66 Whitespace.
67
68 ·
69
70 The maximum color value (Maxval), again in ASCII decimal. Must
71 be less than 65536 and more than zero.
72
73
74 · A single whitespace character (usually a newline).
75
76
77 · A raster of Height rows, in order from top to bottom. Each row
78 consists of Width pixels, in order from left to right. Each
79 pixel is a triplet of red, green, and blue samples, in that
80 order. Each sample is represented in pure binary by either 1 or
81 2 bytes. If the Maxval is less than 256, it is 1 byte. Other‐
82 wise, it is 2 bytes. The most significant byte is first.
83
84 A row of an image is horizontal. A column is vertical. The
85 pixels in the image are square and contiguous.
86
87
88 · In the raster, the sample values are 'nonlinear.' They are pro‐
89 portional to the intensity of the ITU-R Recommendation BT.709
90 red, green, and blue in the pixel, adjusted by the BT.709 gamma
91 transfer function. (That transfer function specifies a gamma
92 number of 2.2 and has a linear section for small intensities).
93 A value of Maxval for all three samples represents CIE D65 white
94 and the most intense color in the color universe of which the
95 image is part (the color universe is all the colors in all
96 images to which this image might be compared).
97
98 ITU-R Recommendation BT.709 is a renaming of the former CCIR
99 Recommendation 709. When CCIR was absorbed into its parent
100 organization, the ITU, ca. 2000, the standard was renamed. This
101 document once referred to the standard as CIE Rec. 709, but it
102 isn't clear now that CIE ever sponsored such a standard.
103
104 Note that another popular color space is the newer sRGB. A com‐
105 mon variation on PPM is to subsitute this color space for the
106 one specified.
107
108
109 ·
110
111 Note that a common variation on the PPM format is to have the
112 sample values be 'linear,' i.e. as specified above except with‐
113 out the gamma adjustment. pnmgamma takes such a PPM variant as
114 input and produces a true PPM as output.
115
116
117 · Strings starting with '#' may be comments, the same as with
118 PBM(1).
119
120
121
122 Note that you can use pamdepth to convert between a the format with 1
123 byte per sample and the one with 2 bytes per sample.
124
125 There is actually another version of the PPM format that is fairly
126 rare: 'plain' PPM format. The format above, which generally considered
127 the normal one, is known as the 'raw' PPM format. See pbm(1)for‐
128 somecommentaryonhowplain and raw formats relate to one another and how
129 to use them.
130
131 The difference in the plain format is:
132
133
134
135 - There is exactly one image in a file.
136
137 - The magic number is P3 instead of P6.
138
139 - Each sample in the raster is represented as an ASCII decimal
140 number (of arbitrary size).
141
142 - Each sample in the raster has white space before and after it.
143 There must be at least one character of white space between any
144 two samples, but there is no maximum. There is no particular
145 separation of one pixel from another -- just the required sepa‐
146 ration between the blue sample of one pixel from the red sample
147 of the next pixel.
148
149 - No line should be longer than 70 characters.
150
151
152 Here is an example of a small image in this format.
153 P3
154 # feep.ppm
155 4 4
156 15
157 0 0 0 0 0 0 0 0 0 15 0 15
158 0 0 0 0 15 7 0 0 0 0 0 0
159 0 0 0 0 0 0 0 15 7 0 0 0
160 15 0 15 0 0 0 0 0 0 0 0 0
161
162 There is a newline character at the end of each of these lines.
163
164 Programs that read this format should be as lenient as possible,
165 accepting anything that looks remotely like a PPM image.
166
167 All characters referred to herein are encoded in ASCII. 'newline'
168 refers the the character known in ASCII as Line Feed or LF. A 'white
169 space' character is space, CR, LF, TAB, VT, or FF (I.e. what the ANSI
170 standard C isspace() function calls white space).
171
172
173
175 Before April 2000, a raw format PPM file could not have a maxval
176 greater than 255. Hence, it could not have more than one byte per sam‐
177 ple. Old programs may depend on this.
178
179 Before July 2000, there could be at most one image in a PPM file. As a
180 result, most tools to process PPM files ignore (and don't read) any
181 data after the first image.
182
183
185 pnm(1), pgm(1), pbm(1), pam(1), programsthatprocessPPM[1m(1)
186
187
188
189netpbm documentation 03 October 2003 PPM Format Specification(5)