Portable Anymap
Portable Anymap ( PNM for short ) is a family of simple file formats used to store raster graphics .
The PNM formats include the following 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 range of values or the word length and can be available as decimally coded values in ASCII format or in binary code .
history
The PNM formats were developed in the 1980s for easy transfer of bitmaps between different computer systems. Together with the later developed PAM (Portable Arbitrary Map) file format , the PNM formats form the Netpbm format family.
File format
Header data
The file header is structured as follows:
- Magic value : Identifies the format of the image data
- White space
- Width of the image (coded in decimal ASCII)
- White space
- Height of the image (decimally coded in ASCII)
- White space
For grayscale (PGM) and color images (PPM) also:
- Maximum value for the brightness (decimally coded in ASCII)
- White space
Eligible white space is a string of characters 1..n of the following four options: space , tab , carriage return ( carriage return ) and LF ( line feed ).
Comment lines can also be placed in the file header. You must start with a hash mark ( #
to be identified) at beginning of line.
Permissible values for the file type (Magic Number) are:
Magic Number | File type | Coding |
---|---|---|
P1
|
Portable bitmap | ASCII |
P2
|
Portable graymap | ASCII |
P3
|
Portable Pixmap | ASCII |
P4
|
Portable bitmap | Binary |
P5
|
Portable graymap | Binary |
P6
|
Portable Pixmap | Binary |
P7
|
Portable Anymap | Binary |
Image data
The header area is followed by the actual image data in the form of individual pixels, either decimally coded in ASCII or binary.
Permissible value ranges are:
File type | Max. Permissible range of values | Number of bits in binary coding |
---|---|---|
Portable bitmap | 0 and 1 | 1 bit |
Portable graymap | 0… 255 or 0… 65535 | 8 bit or 16 bit |
Portable Pixmap | 0… 255 or 0… 65535 | 24 or 48 bit |
If the maximum value is less than 256, only 8 bits per channel are used for binary storage, otherwise 16 bits in Big-Endian format.
ASCII
Each pixel is noted in decimal and saved in ASCII coded. Before and after each value there must be a space.
A line should not be longer than 70 characters.
Example:
0 1 2 3 4 5 6 7 8 9 …
Binary
If the image points are saved in binary, they immediately follow the file header. Line breaks or other text formatting are therefore not permitted because they are interpreted as pixels.
Example: (shown as a hexdump )
00000000 20 41 42 43 44 45 46 47 48 |.ABCDEFG| 00000008 49 … |H… |
Examples
bitmap
P1 #Bitmap # Beispiel für das Bild des Buchstabens "J" 6 10 #Breite des Bildes, Leerstelle, Höhe des Bildes 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
Graymap
P2 # Das Wort "FEEP" in verschiedenen Graustufen (Beispiel von der Netpbm-Man-Page) 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
Pixmap
P3 # Ein Farbbild der Größe 3 × 2 Pixel, maximaler Helligkeit 255. # Darauf folgen die RGB-Tripel. 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0
Web links
- FileFormat.info: PBM, PGM, PNM, and PPM File Format Summary
- PBM
- PGM
- PPM
- PAM