Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Netpbm

From Wikipedia, the free encyclopedia
Toolkit for manipulation of images
Netpbm
DevelopersJef Poskanzer, Bryan Henderson, Akira F Urushibata[1]
Initial release1988; 37 years ago (1988)
Stable release
11.02.16[2] Edit this on Wikidata / 30 April 2025; 6 months ago (30 April 2025)
Repository
Written inC,Perl,Unix Shell
Operating systemCross-platform
LicenseVarious, seebelow
Websitenetpbm.sourceforge.netEdit this at Wikidata

Netpbm (formerly Pbmplus) is anopen-source package of graphics programs and a programming library. It is used primarily inUnix, where it is found in all major open-sourceoperating system distributions, but also works onMicrosoft Windows,macOS, and other operating systems.[3]

File formats

[edit]
Portable pixmap
Filename extension
.pbm, .pgm, .ppm, .pnm
Internet media type
image/x-portable-bitmap,[4] image/x-portable-graymap,[5] image/x-portable-pixmap,[6] image/x-portable-anymap[7]
Uniform Type Identifier (UTI)public.pbm
Developed byJef Poskanzer
Type of formatImage file format
Extended toPortable Arbitrary Map (PAM)
Open format?yes

Several graphics formats are used and defined by the Netpbm project:

  • portable bitmap format (PBM)
  • portable graymap format (PGM)
  • portable pixmap format (PPM)

PBM, PGM and PPM, sometimes collectively referred to as theportable anymap format (PNM) areimage file formats designed to be easily exchanged between platforms.[7][8] Themagic number at the beginning of a file determines the type. PNM files use a magic number of anASCII "P" followed by a number defining the file type.[9]

The PBM format was invented byJef Poskanzer in the 1980s. The format allowed monochrome bitmaps to be transmitted within an email message as plain ASCII text, so that it would survive any changes in text formatting.[8] The first library to handle the PBM format was released in 1988 under the name Pbmplus, containing 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.

The Netpbm library was released in 1993 to replace the then-unmaintained Pbmplus. It repackaged the original library and incorporated fixes created by other developers.[1]

Description

[edit]

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

TypeMagic numberExtensionColors
ASCII (plain)Binary (raw)
Portable BitMapP1P4.pbm2, the values 0 and 1 (white & black)
Portable GrayMapP2P5.pgmmaximum 65536 gray levels, typically in the range 0–255 or 0–65535, black-to-white range
Portable PixMapP3P6.ppmmaximum 65536 color levels for eachRGBchannel, typically in the range 0-255 or 0–65535

The Netpbm library supports an additionalPAM file format with a magic number ofP7.[10]

PNM files can be created as both plain text and raw binary. The ASCII ("plain") formats allow for human readability and easy transfer to other platforms, whereas the binary ("raw") formats are easier to parse by programs and more efficient in file size. In the binary formats, PBM uses 1 bit per pixel, PGM uses 8 or 16 bits per pixel, and PPM uses 24 or 48 bits per pixel: 8/16 for red, 8/16 for green, 8/16 for blue. Application support for the 16 bit variants is rare. In either form, the header remains in ASCII format and the arguments are separated by a whitespace.

PGM and PPM documentation defines that gray and color values use theBT.709 color space andgamma transfer function. However, depending on the application, the used color space may besRGB, linear or some othercolor space. There is no metadata in the file to indicate which color space is being used.

PBM example

[edit]

A simple example of the PBM format is as follows:

A pixelated letter J
The P1 format renders a bitmap of pixels, such as this pixelated "J"
P1# This is an example bitmap of the letter "J"6 100 0 0 0 1 00 0 0 0 1 00 0 0 0 1 00 0 0 0 1 00 0 0 0 1 00 0 0 0 1 01 0 0 0 1 00 1 1 1 0 00 0 0 0 0 00 0 0 0 0 0

The stringP1 identifies the file format. Thenumber sign introduces a comment. The next two numbers give the width and the height. The following matrix gives the pixel values. As the PBM format is monochromatic and only supports two shades, namely, black and white, the image is described in only ones and zeros. This is known as abitmap.

The matrix cells do not need to be aligned; the format ignores whitespace and line feeds in the data section. The following displays the same image:

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

A value of 0 signifies a white pixel, and a 1 signifies a black pixel. This differs from the other formats, where higher values signify brighter pixels.

The P4 binary format of the same image represents each pixel with a single bit. The width of the row in pixels is given in the header, packed to the length of 8 pixels or a byte. The first pixel in a row is the most significant bit. The extra bits used to make the length equal to a byte are ignored. The following formula can be used to calculate the number of required byteswidth / 8⌉ * height. Using the example above a⌈6 / 8⌉ * 10 grid would take 10 bytes.

P4# This is an example binary format of the letter "J" with each byte in decimal notation6 108 8 8 8 8 8 136 112 0 0

PGM example

[edit]

The PGM and PPM formats 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.

The word "FEEP" pixelated. The letters grow lighter from left to right.
The PGM format allows for pixels to be shades of grey
P2# Shows the word "FEEP"24 7150  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  00  3  3  3  3  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15 15 15 15  00  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0 15  00  3  3  3  0  0  0  7  7  7  0  0  0 11 11 11  0  0  0 15 15 15 15  00  3  0  0  0  0  0  7  0  0  0  0  0 11  0  0  0  0  0 15  0  0  0  00  3  0  0  0  0  0  7  7  7  7  0  0 11 11 11 11  0  0 15  0  0  0  00  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

[edit]

This is an example of a color RGB image stored in PPM format. (Not shown are the newline character(s) at the end of each line.)

A grid of colors: red, green, blue, yellow, white and black
The PPM format can describe colors in RGB format
P3# "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# This, up through the "255" line below are the header.# Everything after that is the image data: RGB triplets.# In order: red, green, blue, yellow, white, and black.3 2255255   0   0  0 255   0  0   0 255255 255   0255 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 more difficult to read by humans. The binary image information comes after the header (which ends with a whitespace).

In the binary format, last headerline must be like "255\n", with data immediately following it; any comment added after 255 will be taken as the start of image data, and the image will be skewed to the right (at least when opened by the image-manipulation program GIMP (December 2022)).

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. Filesize reduction factor 100 or so when converting to png is typical if the image is a line drawing; if the image is a photo, it is best converted to jpeg, which yields a greater filesize reduction.

PPM is generally used as an intermediate format for image work before converting to a more efficient format likePNG without any loss of information in the intermediate step.

The image shown above using only0 or the maximal value for the red, green and blue channels can be encoded as follows:

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 are syntactically equivalent to a single space within the PNM headers. For the plain formats (P1, P2 and P3) this is also true of the pixmap lines:

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

Extensions

[edit]

16-bit

[edit]

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. While the ASCII format can accommodate greater bit depths, it increases file sizes and slows read and write operations. Many programmers have extended the format to allow higher bit depths. When using higher bit depths, theendianness of the file matters. Various implementations have not agreed on which byte order to use, and some connected the 16-bit endianness to the pixel packing order.[11] The PGM and PPM documentation says the most significant byte is first and the Netpbm implementation uses big-endian byte order.[12]

32-bit

[edit]

The PFM (Portable Floatmap) is the unofficial four byte IEEE 754 single precision floating point extension.[13][14][15]

  1. The first line is either the ASCII text "PF", for a color file, or "Pf", for a grey-scale file.
  2. The next ASCII text line contains the width and height, separated by the space character hex 20 or sometimes with hex 0A (resulting in four lines). After each line a white space character hex 0A is written and not the Windows/DOS CR/LF combination.
  3. The third ASCII text line holds a nonzero decimal number that indicates little-endian floats for the pixel data when negative and big-endian floats when positive. The absolute value of the number indicates the range. So the third line containing -1.0 indicates little-endian format in range zero to one. (No comments may follow.)

After the header the file, each pixel is specified with a floating point number from left-to-right, bottom-to-top. Some programs suggest PF4 as an additional extension for the RGBA format.[16]

PFM is supported by the programsPhotoshop,[17]GIMP, andImageMagick. It is also supported by thede facto reference implementation netpbm.[13]

Programs

[edit]

The Netpbm package contains over 350 programs,[18] most of which have "pbm", "pgm", "ppm", "pam", or "pnm" in their names. For example, one might usepamscale to shrink an image by 10%,pamcomp to overlay one image on top of another,pbmtext to create an image of text, or reduce the number of colors in an image withpnmquant.

The programs are designed to be minimal building blocks that can be used in various combinations to do other things. The Netpbm package can, for example, use two successive conversion programs to turn a color picture in the GIF format into a.bmp file:

giftopnm somepic.gif > somepic.ppmppmtobmp somepic.ppm > somepic.bmp

This kind of operation is commonly done as apipeline to save execution time and to avoid creating a temporary file:

giftopnm somepic.gif | ppmtobmp > somepic.bmp

The Netpbm programs are frequently used as intermediates to convert between obscure formats. For instance, there may be no tool to convert an X11 window dump (XWD format) directly to a MacintoshPICT file, but one can do this by runningxwdtopnm, thenppmtopict. (Tools which say that they output PNM output either PBM, PGM, or PPM. Tools importing PNM will read any of the three formats.) As a more complex example, Netpbm tools can convert 48×48XBM toIkon and eventuallyX-Face.[19]

History

[edit]

The PBM (black and white) format was invented byJef Poskanzer in the mid-1980s. At the time, there was no standard, reliable way to send binary files in email, and attempting to send anything other than 7-bitASCII in email often resulted indata corruption. PBM was designed to allow images to be sent via email without being corrupted. Poskanzer released the forerunner of Netpbm, calledPbmplus in 1988. By the end of 1988, Poskanzer had developed the PGM (greyscale) and PPM (color) formats and released them with Pbmplus.

The last release of Pbmplus was on December 10, 1991. Poskanzer never released any further updates, and in 1993, Netpbm was developed to replace it. At first, it was nothing more than a renamed release of Pbmplus, but updates continued to occur until 1995 when the package again became abandoned. In 1999, the Netpbm package was picked up by its present maintainer, Bryan Henderson.

In 2000, PAM was added to the file formats of the Netpbm library allowing an alpha channel.[20]

The name Netpbm came from the program developers collaborating over theInternet, which was notable at the time; theNetBSD operating system andNetHack game got their names similarly. (Unlike with the later, more widespreadPortable Network Graphics (PNG) format, the "net" in the name is not actually in reference to the image itself being optimized for transfer over a network.)

PAM graphics format

[edit]
Portable Arbitrary Map
Filename extension
.pam
Internet media type
image/x-portable-arbitrarymap[21]
Developed byBryan Henderson
Type of formatImage file format
Extended fromPortable aNy Map (PNM)
Open format?yes

Portable Arbitrary Map (PAM) is an extension of the older binaryP4...P6graphics formats, introduced with netpbm version 9.7 (August 2000). PAM generalises all features of PBM, PGM, and PPM, and provides for extensions. PAM defines two new attributes;depth andtuple type:

  1. Thedepth attribute defines the number of channels in the image, such as 1 for greyscale images and 3 for RGB images.
  2. Thetuple type attribute specifies what kind of image the PAM file represents, thus enabling it to stand for the older Netpbm formats, as well as to be extended to new uses, e.g.,transparency.

PAM is supported byXnView andFFmpeg.[22][23] As specified theTUPLTYPE is optional; however, FFmpeg requires it.

Differences from the older formats

[edit]

The header for the PAM file format begins with P7, and (unlike in the other formats) ends in an explicit close: "ENDHDR" followed by a whitespace. Line ends in a PAM header are significant; for PNM, line ends are whitespace.

There is no plain (human-readable,ASCII-based) version of PAM. PAM files are always binary, and attempts to use the switch-plain with Netpbm programs that produce PAM output results in an error message.

For the black-and-white version of PAM (depth 1, tuple type BLACKANDWHITE), corresponding to PBM, PAM uses one byte per pixel, instead of PBM's use of one bit per pixel (packing eight pixels in one byte). Also, the value 1 in such a PAM image stands for white ("light on"), as opposed to black in PBM ("ink on").

PAM tuple types
TUPLTYPEMAXVALDEPTHcomment
BLACKANDWHITE11special case of GRAYSCALE
GRAYSCALE2...6553512 bytes per pixel for MAXVAL > 255
RGB1...6553536 bytes per pixel for MAXVAL > 255
BLACKANDWHITE_ALPHA122 bytes per pixel
GRAYSCALE_ALPHA2...6553524 bytes per pixel for MAXVAL > 255
RGB_ALPHA1...6553548 bytes per pixel for MAXVAL > 255

Transparency

[edit]

All of the basic tuple types (BLACKANDWHITE, GRAYSCALE, and RGB) have a variant with anopacity channel. The tuple type is created by appending "_ALPHA" as a suffix to the base tuple type.

For example, an image with a tuple type of GRAYSCALE is equivalent to PGM (portable graymap). GRAYSCALE_ALPHA with transparency is not directly possible in PGM. The specification permits MAXVAL 1 for GRAYSCALE, but it would have the same effect as BLACKANDWHITE.

Anexample in theBMP article shows anRGBA image with 4×2=8 blue, green, red, and white pixels; half transparent (0x7F) in the first lower row, opaque (0xFF) in the second upper row; hex.FF00007F 00FF007F 0000FF7F FFFFFF7F FF0000FF 00FF00FF 0000FFFF FFFFFFFF inBGRA order. For PAM, this bitmap has to be given inRGBA order, swapping the 1st and 3rd byte in each pixel. BMP rows are typically arranged bottom-up, for PAM and PNM rows are given top-down (i.e. for this example0000FFFF 00FF00FF FF0000FF FFFFFFFF 0000FF7F 00FF007F FF00007F FFFFFF7F). The PAM header for this example could be:

P7WIDTH 4HEIGHT 2DEPTH 4MAXVAL 255TUPLTYPE RGB_ALPHAENDHDR

Extensions

[edit]

PAM's tuple-type mechanism allows for many extensions. In theory, PAM can be extended to represent color models such as CMYK.

The format is not even limited to graphics, its definition allows it to be used for arbitrary three-dimensional matrices of unsigned integers. Some programs of the Netpbm package, for examplepamsummcol, function as crude matrix arithmetic processors and use the PAM format this way.

Licensing

[edit]

Netpbm consists of hundreds of different tools, each offered with a public copyright license of its own. An analysis byDebian developer Steve McIntyre from 2001 suggests mostly free software licenses, one non-commercial license (non-free) and a dozen without any license offered (thus also non-free). As mentioned in the analysis, it obviously doesn't cover changes since.[24]

See also

[edit]
Wikimedia Commons has media related toCreated with Netpbm.

References

[edit]
  1. ^ab"Netpbm history". RetrievedMarch 17, 2010.
  2. ^"Change history". Retrieved14 May 2025.
  3. ^Henderson, Bryan (2013)."Getting Netpbm".Sourceforge. Retrieved2 February 2021.
  4. ^.pbmMIME type notregistered atIANA
  5. ^.pgmMIME type notregistered atIANA
  6. ^.ppmMIME type notregistered atIANA
  7. ^ab.pnmMIME type notregistered atIANA
  8. ^abMurray, James D.; van Ryper, William (April 1996).Encyclopedia of Graphics File Formats, Second Edition.O'Reilly.ISBN 1-56592-161-5. Retrieved2014-02-27.
  9. ^"The PBM Format".User manual for Netpbm.
  10. ^"Layout of the PAM file format".
  11. ^"Pnmtotiff User Manual".netpbm doc at SourceForge. 27 March 2005.
  12. ^"pamendian man page".netpbm doc at SourceForge. 10 October 2012.
  13. ^ab"PFM Format Description".
  14. ^"PFM (Portable Float Map) - Just Solve the File Format Problem".
  15. ^"PFM Format Documentation".Archived from the original on 2019-12-31.
  16. ^"Synthetic HDR Fire Sequences".
  17. ^"File formats in Adobe Photoshop".
  18. ^"Netpbm home page". RetrievedMay 3, 2023.
  19. ^Dairiki, Jeff."Online X-Face Converter". Retrieved2014-03-02.
  20. ^"PAM format specification".
  21. ^MIME type not registered atIANA:PAM format specification
  22. ^Gougelet, Pierre-Emmanuel (2015-02-19)."XnView 2.30".XnView. Retrieved2015-02-20.PAM format added
  23. ^"Image Formats".FFmpeg General Documentation. 2014. Retrieved2014-02-23.
  24. ^"2001 analysis of Netpbm copyrights done by Steve McIntyre".

External links

[edit]
Raster
Raw
Vector
Compound
Metadata
Retrieved from "https://en.wikipedia.org/w/index.php?title=Netpbm&oldid=1320345167"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp