Daub Logo
Products Downloads Buy Company Community my Daubnet

Products

Business Software:   Home and Family:
Load! - Container Optimization   Ages! - Family Tree Software
 

File Format Specification Index

 

 

Basic Description

PBMs, PGMs and PPMs are a family of bitmap formats, where PBMs store black+white images, PGMs store grayscale images and PPMs store color images.
 
 
 

Basic File Format

Since PGMs are not binary files (as most other bitmap formats), but ASCII files, "fields" are not determined by a length in bytes, but seperated by whitespace. Note that there can be comments, which are considered as whitespace, and that no line should be longer than 70 characters. The CRs and LFs in the file do not have to correspond to the end of a pixel row.
Name Description
Header Signature 2 byte format signature:
"P1" (ASCII codes 80 and 49): PBM ASCII black+white
"P2" (ASCII codes 80 and 50): PGM ASCII grayscale
"P3" (ASCII codes 80 and 51): PPM ASCII colored
"P4" (ASCII codes 80 and 52): PBM RAW black + white
"P5" (ASCII codes 80 and 53): PGM RAW grayscale
"P6" (ASCII codes 80 and 54): PPM RAW colored
(Whitespace)
Width Bitmap Width
(Whitespace)
Height Bitmap Height
Data Precision present in PGM and PPM files, but not in PBM
  (Whitespace)  
  MaxValue PBM: not present
PGM: Value to be considered as white.
PPM: Value to be considered as max. for all three color components.
This value needs to be >0, and can be >255 if in ASCII format!
Raster Data Block see below
 
Definition of
  • Whitespace: one or more characters from the following set: TAB, LF, CR, SPACE. (= ASCII codes: 8, 10, 13, 32)
  • Comment: The caracter "#" (ASCII code 35) followed by any number of characters, up to a LF or CR.
 
 
 

Raster Data encoding

PBM ASCII black + white. (Signature=P1)

Name Description
   (Whitespace)  
   Pixel ASCII pixel. 0 (ASCII 48) =white, 1 (ASCII 49) = black.
  repeated Width times
repeated Height times
 

PGM ASCII grayscale. (Signature=P2)

Name Description
   (Whitespace)  
   Pixel A pixel's gray value.
Must be between 0 and Header.MaxValue
  repeated Width times
repeated Height times
 

PPM ASCII color. (Signature=P3)

Name Description
   (Whitespace)  
   Pixel Red A pixel's red component. Must be between 0 and Header.MaxValue
   (Whitespace)  
   Pixel Green A pixel's green component. Must be between 0 and Header.MaxValue
   (Whitespace)  
   Pixel Blue A pixel's blue component. Must be between 0 and Header.MaxValue
  repeated Width times
repeated Height times
 

PBM RAW black + white. (Signature=P4)

There cannot be any whitespace or comments in between pixels, as they would be interpreted as pixels.
Name Size Description
Seperator 1 byte A single byte of whitespace (preferably a LF) that seperates MaxValue from the Pixel data
  PixelData 1 byte A single byte with the pixel data for 8 pixels. Within each byte every bit represents one pixel
   1 bit (bit 7) leftmost pixel
   ...  
   1 bit (bit 0) rightmost pixel. Pixels wrap along lines, so this pixel could already actualy be on then next line.
repeated (Width*Height+7) div 8 times. (where div is integer division)
 

PGM RAW grayscale. (Signature=P5)

There cannot be any whitespace or comments in between pixels, as they would be interpreted as pixels. MaxValue cannot be more than 255.
Name Size Description
Seperator 1 byte A single byte of whitespace (preferably a LF) that seperates MaxValue from the Pixel data
   Pixel 1 byte A single byte with the pixel's gray value.
  repeated Width times
repeated Height times
 

PPM RAW color. (Signature=P6)

There cannot be any whitespace or comments in between pixels, as they would be interpreted as pixels. MaxValue cannot be more than 255.
Name Size Description
Seperator 1 byte A single byte of whitespace (preferably a LF) that seperates MaxValue from the Pixel data
   Red 1 byte A single byte with the pixel's red component.
   Green 1 byte A single byte with the pixel's green component.
   Blue 1 byte A single byte with the pixel's blue component.
  repeated Width times
repeated Height times
 

Example:

A grayscale bitmap with 24x7 pixels, where 15 is white (equivalent to 5 bits color depth)
P2
24 7
15
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 3 3 3 3 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 15 0
0 3 3 3 0 0 0 7 7 7 0 0 0 11 11 11 0 0 0 15 15 15 15 0
0 3 0 0 0 0 0 7 0 0 0 0 0 11 0 0 0 0 0 15 0 0 0 0
0 3 0 0 0 0 0 7 7 7 7 0 0 11 11 11 11 0 0 15 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0