Netpbm format

Netpbm format
Portable pixmap
Filename extension .ppm, .pgm, .pbm, .pnm
Internet media type image/x-portable-pixmap, -graymap, -bitmap, -anymap all unofficial
Developed by Jef Poskanzer
Type of format Image file formats

The phrase Netpbm format commonly refers to any or all of the members of a set of closely related graphics formats used and defined by the Netpbm project. The portable pixmap format (PPM), the portable graymap format (PGM) and the portable bitmap format (PBM) are image file formats originally designed to be easily exchanged between platforms. They are also sometimes referred to collectively as the portable anymap format (PNM).[1]

Contents

History

The PBM format was invented by Jef Poskanzer in the 1980s as a format for monochrome bitmaps that could be transmitted within an email message as plain ASCII text, allowing it to survive any changes in text formatting.

The first library of tools to handle the PBM format was Pbmplus. It was developed by the format's creator and released in 1988. It mainly contained tools to convert between PBM and other graphics formats. By the end of 1988, Jef Poskanzer had developed the PGM and PPM formats along with their associated tools and added them to Pbmplus. The final release of Pbmplus was December 10, 1991.

In 1993, the Netpbm library was developed to replace the unmaintained Pbmplus. It was simply a repackaging of Pbmplus with additions and fixes submitted by people all over the world.[2]

File format description

Each format differs in what colors it is designed to represent:

  • PBM is for bitmaps (black and white, no grays)[3]
  • PGM is for grayscale
  • PPM is for "pixmaps" which represent full RGB color.[4]

Each file starts with a two-byte magic number (in ASCII) that explains the type of file it is (PBM, PGM, and PPM) and its encoding (ASCII or binary). The magic number is a capital P followed by a single digit number.

Magic Number Type Encoding
P1 Portable bitmap ASCII
P2 Portable graymap ASCII
P3 Portable pixmap ASCII
P4 Portable bitmap Binary
P5 Portable graymap Binary
P6 Portable pixmap Binary

The ASCII based formats allow for human-readability and easy transport to other platforms (so long as those platforms understand ASCII), while the binary formats are more efficient both at saving space in the file, as well as being easier to parse due to the lack of whitespace.

When using the binary formats, PBM uses 1 bit per pixel, PGM uses 8 bits per pixel, and PPM uses 24 bits per pixel: 8 for red, 8 for green, 8 for blue.

PBM example

A simple example of the PBM format is as follows (There is a newline character at the end of each line.):

P1
# This is an example bitmap 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

The string P1 identifies the file format. The hash sign introduces a comment. The next two numbers give the width and the height. Then follows the matrix with the pixel values (in the monochrome case here, only zeros and ones).

Here is the resulting image: Example of ASCII-art turned into a bitmap.pbm.png

Here it is again magnified 20 times:

Example of ASCII-art turned into a bitmap scale20.pbm.png

PGM example

C++ program creating pgm file

The PGM and PPM formats (both ASCII and binary versions) have an additional parameter for the maximum value (numbers of grey between black and white) after the X and Y dimensions and before the actual pixel data. Black is 0 and max value is white. There is a newline character at the end of each line.

P2
# Shows the word "FEEP" (example from Netpbm main page on PGM)
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

Example (magnified):

Feep netbpm p2 pgm example.png

PPM example

This is an example of a color RGB image stored in PPM format. There is a newline character at the end of each line.

P3
# The P3 means colors are in ASCII, then 3 columns and 2 rows,
# then 255 for max color, then RGB triplets
3 2
255
255   0   0     0 255   0     0   0 255
255 255   0   255 255 255     0   0   0

The image (magnified): Tiny6pixel.png

The P6 binary format of the same image will store each color component of each pixel with one byte (thus three bytes per pixel) in the order red, green, then blue. The file will be smaller but the color information will not be readable by humans.

The PPM format is not compressed, and thus requires more space and bandwidth than a compressed format would require. For example, the above 192x128 PNG image has a file size of 166 bytes. When converted to a 192x128 PPM image, the file size is 73,848 bytes. The PPM format is generally an intermediate format used for image work before converting to a more efficient format, for example the PNG (Portable Network Graphics) format, without any loss of information in the intermediate step.

16-bit extensions

The original definition of the PGM and the PPM binary formats (the P5 and P6 formats) did not allow bit depths greater than 8 bits. One can of course use the ASCII format, but this format both slows down reading and makes the files much larger. Accordingly, many programmers have attempted to extend the format to allow higher bit depths. Using higher bit depths encounters the problem of having to decide on the endianness of the file. Unfortunately it appears that the various implementations could not agree on which byte order to use, and some connected the 16-bit endianness to the pixel packing order.[5] In Netpbm, the de facto standard implementation of the PNM formats, the most significant byte is first.

See also

References

  1. ^ PBM, PGM, PNM, and PPM: Summary
  2. ^ "Netpbm history". http://netpbm.sourceforge.net/history.html. Retrieved March 17, 2010. 
  3. ^ PBM file format specification
  4. ^ PPM file format specification
  5. ^ "Pnmtotiff User Manual". netpbm doc at SourceForge. 27 March 2005. http://netpbm.sourceforge.net/doc/pnmtotiff.html. 

External links

Examples of ppm files in various formats



Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Netpbm — Developer(s) Bryan Henderson Stable release 10.40 / September 26, 2007 Written in C, Perl, Unix Shell Operating system …   Wikipedia

  • PAM graphics format — The PAM ( Portable Arbitrary Map [1]) graphics format of the Netpbm package generalises all the features of the previous formats (PBM, PGM and PPM) and provides for extending them. As well as width, height and maximum value, which are found in… …   Wikipedia

  • Image file formats — are standardized means of organising and storing images. This entry is about digital image formats used to store photographic and other images; (for disk image file formats see Disk image). Image files are composed of either pixel or vector… …   Wikipedia

  • X BitMap — Infobox file format name = X BitMap extension = .xbm mime = image/x xbitmapunofficial image/x xbmunofficial owner = creatorcode = XBM genre = Image file formats containerfor = containedby = extendedfrom = extendedto = XPMIn computer graphics, the …   Wikipedia

  • PBM — may refer to: Johan Adolf Pengel International Airport, IATA airport code PBM Mariner, a flying boat by Martin PBM (band) Personal Broadband Mobile, the gaming, multimedia, entertainment, and communications that individuals can access via the… …   Wikipedia

  • Binary image — A binary image is a digital image that has only two possible values for each pixel. cite news |url=http://www.codersource.net/csharp color image to binary.aspx |title=Conversion of a Color Image to a Binary Image |publisher=CoderSource.net… …   Wikipedia

  • Portable pixmap — Extension .ppm, .pgm, .pbm, .pnm Type MIME image/x portable pixmap, graymap, bitmap, anymap all unofficial Développé par Jef Poskanzer Type de format Format de fichier graphique Origine de XPM …   Wikipédia en Français

  • Portable anymap — Portable pixmap Расширение .ppm, .pgm, .pbm, .pnm MIME image/x portable pixmap, graymap, bitmap, anymap все неофициальные Разработан Джеф Посканзер Тип формата Графические форматы У этого термина сущ …   Википедия

  • XEphem — 3.7.3: Epizykelbahn des Mars im Sternbild Krebs Ende 2009 / Anfang 2010 Basisdaten …   Deutsch Wikipedia

  • Compresión fractal — La compresión fractal es un método de compresión con pérdida para imágenes digitales, basado en fractales. El método es el más apropiado para texturas e imágenes naturales, basándose en el hecho de que partes de una imagen, a menudo, se parecen a …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”