File formats
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), not to be confused with the related portable arbitrary map format (PAM). The "magic number" (Px) at the beginning of a file determines the type, not the file extension, although it is best practice to use the right extension if possible. 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. 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.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/"plain" or binary/"raw"). The magic number is a capital P followed by a single-digit number. A value ofP7
refers to the PAM file format that is covered as well by the netpbm library.
The ASCII ("plain") formats allow for human readability and easy transfer to other platforms; the binary ("raw") 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. Some readers and writers may support 48 bits per pixel (16 each for R,G,B), but this is still rare.
Conventionally PGM stores values in linear color space, but depending on the application, it can often use
either 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: :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.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 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 0White 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. 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. In Netpbm, the '' de facto'' standard implementation of the PNM formats, the most significant byte is first.32-bit extensions
The PFM (Portable Floatmap) is the unofficial four byte IEEE 754 single precision floating point extension. A color file is identified with the ASCII text "PF" in the first line of the header and a gray-scale with "Pf". The next ASCII text line contains the width and height, separated by the space character hex 20 and 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. 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. There are no comments. After the header the file proceeds with floating point numbers for each pixel, specified in left to right, bottom to top order. Some programs suggest PF4 as an additional extension for the RGBA format. It's supported by the programs Photoshop,Programs
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 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 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 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.
History
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. The name Netpbm came from the program developers collaborating over the Internet, which was notable at the time; thePAM graphics format
Portable Arbitrary Map (PAM) is an extension of the older binary P4...P6 graphics 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'' and ''tuple'' type: #The ''depth'' attribute defines the number of channels in the image, such as 1 for greyscale images and 3 for RGB images. #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.,TUPLTYPE
is optional; however, FFmpeg requires it.
Differences from the older formats
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").
Transparency
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. AnFF00007F 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:
Extensions
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 allows 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.Licensing
Netpbm consists of hundreds of different tools, each with a license of their own. An analysis bySee also
*References
External links
*