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 In the raster, the sample values are 'nonlinear.' They are pro‐
88 portional to the intensity of the ITU-R Recommendation BT.709
89 red, green, and blue in the pixel, adjusted by the BT.709 gamma
90 transfer function. (That transfer function specifies a gamma
91 number of 2.2 and has a linear section for small intensities).
92 A value of Maxval for all three samples represents CIE D65 white
93 and the most intense color in the color universe of which the
94 image is part (the color universe is all the colors in all
95 images to which this image might be compared).
96
97 ITU-R Recommendation BT.709 is a renaming of the former CCIR
98 Recommendation 709. When CCIR was absorbed into its parent
99 organization, the ITU, ca. 2000, the standard was renamed. This
100 document once referred to the standard as CIE Rec. 709, but it
101 isn't clear now that CIE ever sponsored such a standard.
102
103 Note that another popular color space is the newer sRGB. A com‐
104 mon variation on PPM is to substitute this color space for the
105 one specified.
106
107 Note that a common variation on the PPM format is to have the
108 sample values be 'linear,' i.e. as specified above except with‐
109 out the gamma adjustment. pnmgamma takes such a PPM variant as
110 input and produces a true PPM as output.
111
112
113
114 Strings starting with '#' may be comments, the same as with PBM(1).
115
116 Note that you can use pamdepth to convert between a the format with 1
117 byte per sample and the one with 2 bytes per sample.
118
119 There is actually another version of the PPM format that is fairly
120 rare: 'plain' PPM format. The format above, which generally considered
121 the normal one, is known as the 'raw' PPM format. See pbm(1)for‐
122 somecommentaryonhowplain and raw formats relate to one another and how
123 to use them.
124
125 The difference in the plain format is:
126
127
128
129 - There is exactly one image in a file.
130
131 - The magic number is P3 instead of P6.
132
133 - Each sample in the raster is represented as an ASCII decimal
134 number (of arbitrary size).
135
136 - Each sample in the raster has white space before and after it.
137 There must be at least one character of white space between any
138 two samples, but there is no maximum. There is no particular
139 separation of one pixel from another -- just the required sepa‐
140 ration between the blue sample of one pixel from the red sample
141 of the next pixel.
142
143 - No line should be longer than 70 characters.
144
145
146 Here is an example of a small image in this format.
147 P3
148 # feep.ppm
149 4 4
150 15
151 0 0 0 0 0 0 0 0 0 15 0 15
152 0 0 0 0 15 7 0 0 0 0 0 0
153 0 0 0 0 0 0 0 15 7 0 0 0
154 15 0 15 0 0 0 0 0 0 0 0 0
155
156 There is a newline character at the end of each of these lines.
157
158 Programs that read this format should be as lenient as possible,
159 accepting anything that looks remotely like a PPM image.
160
161 All characters referred to herein are encoded in ASCII. 'newline'
162 refers the the character known in ASCII as Line Feed or LF. A 'white
163 space' character is space, CR, LF, TAB, VT, or FF (I.e. what the ANSI
164 standard C isspace() function calls white space).
165
166
167
169 Before April 2000, a raw format PPM file could not have a maxval
170 greater than 255. Hence, it could not have more than one byte per sam‐
171 ple. Old programs may depend on this.
172
173 Before July 2000, there could be at most one image in a PPM file. As a
174 result, most tools to process PPM files ignore (and don't read) any
175 data after the first image.
176
177
179 pnm(1), pgm(1), pbm(1), pam(1), programsthatprocessPPM[1m(1)
180
181
182
183netpbm documentation 03 October 2003 PPM Format Specification(5)