Netpbm

From Wikipedia, the free encyclopedia
  (Redirected from Portable anymap)
Jump to navigation Jump to search
Netpbm
Developer(s)Bryan Henderson[citation needed]
Initial release1988; 32 years ago (1988)
Stable release
10.47.61 / 9 May 2016; 3 years ago (2016-05-09)
Repository Edit this at Wikidata
Written inC, Perl, Unix Shell
Operating systemCross-platform
LicenseVarious, believed to be DFSG free
Websitenetpbm.sourceforge.net Edit this at Wikidata

Netpbm is an open-source package of graphics programs and a programming library. It is used mainly in the Unix world, where one can find it included in all major open-source operating system distributions, but also works on Microsoft Windows, macOS, and other operating systems.[citation needed]

File formats[edit]

Portable pixmap
Filename extension.pbm, .pgm, .ppm, .pnm
Internet media typeimage/x‑portable‑bitmap,[1] image/x‑portable‑graymap,[2] image/x‑portable‑pixmap,[3] image/x‑portable‑anymap[4]
Uniform Type Identifier (UTI)public.pbm
Developed byJef Poskanzer
Type of formatImage file formats
Extended toPortable Arbitrary Map (PAM)
Open format?yes

Several graphics formats are 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][5] not to be confused with the related portable arbitrary map format.

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]

Description[edit]

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.

Type Magic number Extension Colors
ASCII Binary
Portable BitMap[1] P1 P4 .pbm 0–1 (white & black)
Portable GrayMap[2] P2 P5 .pgm 0–255 (gray scale), 0–65535 (gray scale), variable
Portable PixMap[3] P3 P6 .ppm 16777216 (0–255 for each RGB channel)

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 or 16 bits per pixel, and PPM uses 24 bits per pixel: 8 for red, 8 for green, 8 for blue.

Conventionally PGM stores values in linear color space, but depending on application, it often use sRGB or simplified gamma representation. The file data doesn't store information which color space it is using, and must be cared of by the user or other software. 16-bit PGM almost always is stored as linear, as gamma correction is usually as advantageous as in 8-bit formats.

Usually 8-bit PPM format stores colors in nonlinear format, conventionally CIE Rec. 709 for red, green and blue, adjusted by the CIE Rec. 709 gamma transfer function. However it is very common to store color using sRGB color space, or sometimes using linear color space. There is no metadata in the file to indicate which format is being used.

PBM example[edit]

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:

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

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[edit]

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.

Example (magnified)
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[edit]

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

Image (magnified)
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  # red
  0 255   0  # green
  0   0 255  # blue
255 255   0  # yellow
255 255 255  # white
  0   0   0  # black

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 header remains in ASCII and the arguments are still separated by a whitespace. The binary image information comes after the header (which ends with a whitespace).

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 1
1 0 0   0 1 0   0 0 1
1 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[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 size and thus slows read and write operations. 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).[citation needed]

Programs[edit]

Netpbm contains over 220 separate programs in the package, most of which have "pbm", "pgm", "ppm", "pam", or "pnm" in their names. For example, one might use pamscale 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 with pnmquant.

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 picture in the PBM format into a .bmp file:

pgmtoppm "#FFFFFF" somepic.pbm  > somepic.ppm
ppmtobmp somepic.ppm > somepic.bmp

This is more commonly done as a pipeline, to save execution time and to avoid leaving a temporary somepic.ppm file around:

pgmtoppm "#FFFFFF" somepic.pbm | 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 Macintosh PICT file, but one can do this by running xwdtopnm, then ppmtopict. (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×48 XBM to Ikon and eventually X-Face.[11]

History[edit]

The PBM (black and white) format was invented by Jef 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-bit ASCII in email often resulted in data corruption. PBM was designed to allow images to be sent via email without being corrupted. Poskanzer released the forerunner of Netpbm, called Pbmplus 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.[12]

The name Netpbm came from the program developers collaborating over the Internet, which was notable at the time; the NetBSD operating system and NetHack game got their names similarly. (Unlike with the later, more widespread Portable 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 typeimage/x-portable-arbitrarymap[13]
Developed byBryan Henderson
Type of formatImage file formats
Extended fromPortable aNy Map (PNM)
Open format?yes

Portable Arbitrary Map (PAM) is an extension of the older binary P4…P6 graphics formats. PAM generalises all features of PBM, PGM and PPM, and provides for extensions. PAM defines two new attributes; depth and tuple type:

  1. The depth attribute defines the number of channels in the image, such as 1 for greyscale images and 3 for RGB images.
  2. The tuple 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 by XnView and FFmpeg.[14][15] As specified the TUPLTYPE 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. Line ends in a PAM header are significant; for PNM, line ends are white space.

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
TUPLTYPE MAXVAL DEPTH comment
BLACKANDWHITE 1 1 special case of GRAYSCALE
GRAYSCALE 2...65535 1 2 bytes per pixel for MAXVAL > 255
RGB 1...65535 3 6 bytes per pixel for MAXVAL > 255
BLACKANDWHITE_ALPHA 1 2 2 bytes per pixel
GRAYSCALE_ALPHA 2...65535 2 4 bytes per pixel for MAXVAL > 255
RGB_ALPHA 1...65535 4 8 bytes per pixel for MAXVAL > 255

Transparency[edit]

All of the basic tuple types (BLACKANDWHITE, GRAYSCALE, and RGB) have a variant with an opacity 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.

An example in the BMP article shows an RGBA 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 in BGRA order. For PAM, this bitmap has to be given in RGBA 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 example 0000FFFF 00FF00FF FF0000FF FFFFFFFF 0000FF7F 00FF007F FF00007F FFFFFF7F). The PAM header for this example could be:

Bmp format2.svg0,0: blue 0000FF FF0,1: green 00FF00 FF0,2: red FF0000 FF0,3: white FFFFFF FF1,0: blue 0000FF 7F, half transparent1,1: green 00FF00 7F, half transparent1,2: red FF0000 7F, half transparent1,3: white FFFFFF 7F, half transparent
About this image
P7
WIDTH 4
HEIGHT 2
DEPTH 4
MAXVAL 255
TUPLTYPE RGB_ALPHA
ENDHDR

Extensions[edit]

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

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

See also[edit]

References[edit]

  1. ^ a b .pbm MIME type not registered at IANA
  2. ^ a b .pgm MIME type not registered at IANA
  3. ^ a b .ppm MIME type not registered at IANA
  4. ^ a b .pnm MIME type not registered at IANA
  5. ^ a b Murray, James D.; van Ryper, William (April 1996). "Encyclopedia of Graphics File Formats, Second Edition". O'Reilly. ISBN 1-56592-161-5. Retrieved 2014-02-27.
  6. ^ "Netpbm history". Retrieved March 17, 2010.
  7. ^ "Layout of the PAM file format".
  8. ^ "Pnmtotiff User Manual". netpbm doc at SourceForge. 27 March 2005.
  9. ^ "pamendian man page". netpbm doc at SourceForge. 10 October 2012.
  10. ^ "Image Formats". FFmpeg General Documentation. 2014. Retrieved 2014-02-23.
  11. ^ Jeff Dairiki. "Online X-Face Converter". Retrieved 2014-03-02.
  12. ^ http://netpbm.sourceforge.net/doc/pam.html
  13. ^ MIME type not registered at IANA: PAM format specification
  14. ^ Pierre-Emmanuel Gougelet (2015-02-19). "XnView 2.30". XnView. Retrieved 2015-02-20. PAM format added
  15. ^ "Image Formats". FFmpeg General Documentation. 2014. Retrieved 2014-02-23.

External links[edit]