PPM is the portable pixel map format. It is a simple RGB color image description. The definition is as follows:
- A "magic number" for identifying the file type. A PPM file's magic number is the two characters "P3".
- Whitespace (blanks, TABs, CRs, LFs).
- A width, formatted as ASCII characters in decimal.
- Whitespace.
- A height, again in ASCII decimal.
- Whitespace.
- The maximum color-component value, again in ASCII decimal.
- Whitespace.
- Width * height pixels, each three ASCII decimal values between 0 and the specified maximum value, starting at the top-left corner of the pixmap, proceeding in normal English reading order. The three values for each pixel represent red, green, and blue, respectively; a value of 0 means that color is off, and the maximum value means that color is maxed out.
There is also a variant on the format, available by setting the RAWBITS option at compile time. This variant is different in the following ways:
- The "magic number" is "P6" instead of "P3".
- The pixel values are stored as plain bytes, instead of ASCII decimal.
- No whitespace is allowed in the pixel section, and only a single character of whitespace (typically a newline) is allowed after the MAXVAL.
EXAMPLE:
P3 # feep.ppm 4 4 15 0 0 0 0 0 0 0 0 0 15 0 15 0 0 0 0 15 7 0 0 0 0 0 0 0 0 0 0 0 0 0 15 7 0 0 0 15 0 15 0 0 0 0 0 0 0 0 0
PPM files are:
- ASCII or BINARY
- RGB color
- 2D
- No compression
- 1 image
-
Reference:
Programs to view a PPM file include:
- The AVS module read_any_image can read a PPM file.
- GIMP
- The ImageVision program imgview can display a PPM file.
- XV
Routines to read or write a PPM file:
Programs to convert a PPM file to another format:
- GIMP can read a PPM file and write out a copy in a variety of formats.
- PPMA_2_BMP converts an ASCII PPM file to BMP format.
- XV can read a PPM file and write out a copy in BMP, FIT, GIF, JPG, PBM/PGM, RGB or TIF format.
Programs to convert a file to PPM format:
- BMP_2_PPMA
- GIMP can read a file in a variety of formats, and write it out as a PPM file.
- XV can read a file in a BMP, FIT, GIF, JPG, PBM/PGM, RGB or TIF format, and write it out as a PPM file.
Files you may copy:
- feep.ppm, a simple example.
- blackbuck.ppm, a picture of a buck.
- snail.ppm, a picture of a snail.
Back to the data home page.