请输入您要查询的百科知识:

 

词条 Netpbm format
释义

  1. History

  2. File format description

      PBM example    PGM example    PPM example  

  3. 16-bit extensions

  4. See also

  5. References

  6. External links

{{mergeto|Netpbm|discuss=Talk:Netpbm#Merger proposal|date=November 2018}}{{Infobox file format
| name = Portable pixmap
| extension = .pbm, .pgm, .ppm, .pnm
| mime = image/x‑portable‑bitmap,[1] image/x‑portable‑graymap,[2] image/x‑portable‑pixmap,[3] image/x‑portable‑anymap[4]
| owner = Jef Poskanzer
| creatorcode =
| genre = Image file formats
| containerfor =
| containedby =
| extendedfrom =
| extendedto = Portable Arbitrary Map (PAM)
| free = yes
}}

A Netpbm format is any graphics format 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 designed to be easily exchanged between platforms. They are also sometimes referred to collectively as the portable anymap format (PNM),[4][6] not to be confused with the related portable arbitrary map format.

History

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

Poskanzer developed the first library of tools to handle the PBM format, Pbmplus, released in 1988. It mainly contained tools to convert between PBM and other graphics formats. By the end of 1988, 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.[6]

File format description

Each file starts with a two-byte magic number (in ASCII) that identifies 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.

TypeMagic numberExtensionColors
ASCII Binary
Portable BitMap[1] P1 P4 .pbm 0–1 (white & black)
Portable GrayMap[2] P2 P5 .pgm 0–255 (gray scale)
Portable PixMap[3] P3 P6 .ppm 0–255 (RGB)

A value of P7 refers to the PAM file format that is covered as well by the netpbm library.[7]

The ASCII formats allow for human readability and easy transfer to other platforms; the binary formats are more efficient in file size but may have native byte-order issues.

In 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 number 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).

It is not required that pixels are nicely lined up, the format ignores whitespaces and linefeeds in the data section, although it's recommended that no line is longer than 76 characters. The following displays the same image:

 P1 # This is an example bitmap of the letter "J" 6 10 000010000010000010000010000010000010100010011100000000000000

Here is the resulting image:

Here it is again magnified 20 times:

Note that a 0 signifies a white pixel, and a 1 signifies a black pixel. This is in contrast to the other formats, where higher values signify brighter pixels.

The P4 binary format of the same image represents each pixel with a single bit, packing 8 pixels per byte, with the first pixel as the most significant bit. Extra bits are added at the end of each row to fill a whole byte.

PGM example

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 man 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

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 3 2 255 # The part above is the header # "P3" means this is a RGB color image in ASCII # "3 2" is the width and height of the image in pixels # "255" is the maximum value for each color # The part below is image data: RGB triplets 255   0   0     0 255   0     0   0 255 255 255   0   255 255 255     0   0   0

The P6 binary format of the same image represents each color component of each pixel with one byte (thus three bytes per pixel) in the order red, green, then blue. The file is smaller, but the color information is difficult to read by humans.

The PPM format is not compressed, and thus requires more space and bandwidth than a compressed format would. For example, the above 192×128 PNG (Portable Network Graphics) image has a file size of 166 bytes. When converted to a 192×128 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 format, without any loss of information in the intermediate step.

The image shown above using only 0 or the maximal value for the red-green-blue channels can be also encoded as:

P3# The same image with width 3 and height 2,# using 0 or 1 per color (red, green, blue)3 2 11 0 0   0 1 0   0 0 11 1 0   1 1 1   0 0 0

White space including line ends and comment lines is syntactically equivalent to a single space within the PNM headers. For the plain formats P1…P3 this also affects the pixmap lines; in fact lines should be limited to 70 characters:

P3 3 2 1  1 0 0   0 1 0   0 0 1  1 1 0   1 1 1   0 0 0

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 extended the format to allow higher bit depths. Using higher bit depths encounters the problem of having to decide on the endianness of the file. The various implementations could not agree on which byte order to use, and some connected the 16-bit endianness to the pixel packing order.[8] In Netpbm, the de facto standard implementation of the PNM formats, the most significant byte is first.[9]

Common RGB color depths include 24 = (3 × 8), 30 = (3 × 10), 32 = (4 × 8), 36 = (3 × 12), 48 = (3 × 16), and 64 = (4 × 16) (with three red–green–blue channels, and a fourth unused or RGBA alpha channel, respectively). Classic XnView can read rgb48be PPM, FFmpeg can also create rgb48be PPM.[10]

While 30 = (3 × 10) could fit into 32 bits, this is not supported by the binary PNM and PAM formats. All PPM bit depths with more than 8 bits are encoded in 48 bits. More than 8 gray bits end up as 16 bits without transparency (FFmpeg PGM or PAM pix_fmt gray16be).

PGMYUV is a PGM variant only used by FFmpeg.{{citation needed|date=February 2014}}

See also

  • X PixMap (comparison of PBM and XPM)
  • pfm: the PFM graphic image file format as understood by the Netpbm

References

1. ^.pbm MIME type not registered at IANA
2. ^.pgm MIME type not registered at IANA
3. ^.ppm MIME type not registered at IANA
4. ^.pnm MIME type not registered at IANA
5. ^{{cite web|title=Encyclopedia of Graphics File Formats, Second Edition|date=April 1996|authors=James D. Murray, William vanRyper|isbn= 1-56592-161-5|publisher=O'Reilly|url=https://www.fileformat.info/format/pbm/egff.htm|accessdate=2014-02-27}}
6. ^{{Cite web| title = Netpbm history| url = http://netpbm.sourceforge.net/history.html| accessdate = March 17, 2010}}
7. ^Layout of the PAM file format, netpbm documentation
8. ^{{cite web | title = Pnmtotiff User Manual | url = http://netpbm.sourceforge.net/doc/pnmtotiff.html | work = netpbm doc at SourceForge | date = 27 March 2005}}
9. ^{{cite web | title = pamendian man page | url=http://netpbm.sourceforge.net/doc/pamendian.html | work = netpbm doc at SourceForge | date = 10 October 2012}}
10. ^{{cite web|url=http://www.ffmpeg.org/general.html#Image-Formats|title=Image Formats|work=FFmpeg General Documentation|year=2014|accessdate=2014-02-23}}

External links

  • Examples of ppm files in various formats
{{Graphics file formats}}{{DEFAULTSORT:Netpbm Format}}

1 : Graphics file formats

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/11/16 7:10:44