an introduction of ppm files

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.
Characters from a "#" to the next end-of-line are ignored (comments). No line should be longer than 70 characters.

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.
The files are smaller and many times faster to read and write. Note that this raw format can only be used for MAXVAL less than or equal to 255. If you use the PPM library and try to write a file with a larger MAXVAL, it will automatically fall back on the slower but more general plain format.

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:

  • PBMLIB, FORTRAN routines.
  • PBMPAK C routines

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.

你可能感兴趣的:(an introduction of ppm files)