Netpbm format
Portable Anymap (abbreviated PNM ) is a family of simple file format for storing raster graphics.
The PNM formats include the file formats:
- Portable Bitmap ( PBM),
- Portable Graymap (PGM ) and
- Portable Pixmap (PPM )
The structure of the file header of all three file formats is identical. The image data differ in the value range or the word length and may be present as decimal coded values in ASCII format or binary encoded.
- 3.1 bitmap
- 3.2 graymap
- 3.3 pixmap
History
The PNM format was developed in the eighties for easy transfer of bitmaps between different computer systems. Together with the much later file format developed PAM (Portable Arbitrary Map) form the PNM formats, the family of the Netpbm formats.
File Format
Header data
The file header is as follows:
For grayscale (PGM ) and color images (PPM ) additionally:
Eligible empty space are the following characters: space, tab, carriage return (carriage return) and LF (line feed ).
Moreover, even comment lines can be accommodated in the file header. They shall be marked with a hash ( #) at the beginning of the line.
Allowed values for the file type ( magic number ) are:
Image data
In the head region follow the actually image data in the form of individual pixels, either in ASCII or binary coded decimal.
Allowed values are:
If a portable pixmap, the maximum value is less than 256, only 8 bits are used for binary storage, or 16 bits in big-endian format.
ASCII
Each pixel is stored in decimal listed and coded in ASCII. Before and after each value is a white space should be.
A line should not be longer than 70 characters.
Example:
0 1 2 3 4 5 6 7 8 9 ... binary
If the pixels stored in binary form, they immediately follow the header. Line breaks or other text formatting are therefore not allowed, because they are interpreted as pixels.
Example: (shown as hex dump )
00000000 20 41 42 43 44 45 46 47 48 |. ABCDEFG | 00000008 49 ... | H ... | Examples
Bitmap
P1 # Example for the image of the letter " J" 6 10 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Decoded image:
Graymap
P2 # The word " FEEP " in shades of gray (example of the Netpbm manpage ) 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 Decoded image:
Pixmap
P3 # A color image of size 3 x 2 pixels, maximum brightness 255 # This is followed by the RGB triple. 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0 Decoded image: