Simple portable pixmap image storage formats (sometimes referred to as PNM ): color (PPM), grayscale (PGM) and black and white (PBM), define the rules for exchanging image files. These formats can provide an intermediate representation of data when converting raster graphic files of the three listed types between different platforms. Some applications support these three formats directly, defining them as the PNM format (portable anymap). The PPM format was developed by Jeff Poskanzer .
| Portable pixmap | |
|---|---|
| Expansion | , , or |
| MIME type | image / x-portable-pixmap, -graymap, -bitmap, -anymap are all unofficial |
| Developer | |
| Format type | Graphic formats |
Content
File Format Description
Let's analyze an example of a bitmap for the letter “J”:
.... X. .... X. .... X. .... X. .... X. .... XX..X. .XXX .. ...... ......
The PBM format represents this example as follows:
P1 # This is an example bit map file j.pbm 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
Line P1 defines the file format. The pound sign (#) separates the comment. The next two numbers specify the width and height. Then follows a matrix of pixel values (in the case of a monochrome image, as in this example, only zeros and ones).
Resulting Image: . It is also increased 20 times:
Netpbm Usage
The Netpbm package, for example, can use two conversion programs in series to convert this code into a BMP file:
pgmtoppm "#FFFFFF" j.pbm> j.ppm ppmtobmp j.ppm> j.bmp
Depending on the recognized file format, the portable pixmap simple graphic file system can distinguish between three similar file formats, each in two versions:
- PBM - black and white (portable bitmap) (P1 / P4) - 1 bit per pixel
- PGM - portable graymap (P2 / P5) - 8 bits per pixel
- PPM - color (portable pixmap) (P3 / P6) - 24 bits per pixel (8 per red, green and blue)
In each case, the lower version (P1, P2, or P3) refers to readable, ASCII- based formats similar to those shown in the example in this article. And the upper versions (P4, P5 and P6) refer to binary formats, less convenient for parsing, but more effective for saving file space and more convenient for parsing due to the absence of spaces.
16-bit extension
Initially, the PGM and PPM binary formats (P5 and P6) supported a bit depth of no more than 8 bits. Of course, you could use ASCII formats, but when you use them, the size increases and the reading of files slows down. As a result, many developers tried to expand the format to support greater bit depth. When using more depth, we are faced with the problem of byte order (Endianness) in the file. Different applications are not consistent in any one byte order (Endianness). When working with PNM, Netpbm uses de facto order from high to low (big-endian).
PPM Example
P3 # P3 means colors are in ASCII, # then there are numbers indicating the number of columns and rows (3 columns and 2 rows), # 255 for maximum color value, # then RGB triplets 3 2 255 255 0 0 0 255 0 0 0 255 255 255 0 255 255 255 0 0 0
Image (enlarged):
The P6 format for the same image will store each color component of the color in one byte (i.e. three bytes per pixel). The file will be smaller, but the color information when viewing such a file will not be directly perceived by humans:
P6
# comment line is possible here
3 2
255
! @ # $% ^ & * () _ + | {}: "<
The PPM format is uncompressed, so the files in it are large. For example, a PNG image of 192 × 128 may have a size of 552 bytes. After converting it to PPM, the file size will be 73,848 bytes.
The PPM format is simple enough to write code yourself that can read and write data in this format.
See also
- Netpbm
Links
- Format details for the various pnm formats: