PAM(5)
π PAM format specification(5) π
File Formats Manual
β¨ NAME β¨
pam β Netpbm common 2-dimensional bitmap format.
πΈ GENERAL πΈ
Okay so, bestie, the PAM image format is a lowest common denominator 2 dimensional map format.
It's designed to be used for any of myriad kinds of graphics, but theoretically it can be used for any kind of data that is arranged as a two dimensional rectangular array. Actually, from another perspective, it can be seen as a format for data arranged as a three dimensional array.
The name PAM is an acronym derived from Portable Arbitrary Map. This derivation makes more sense if you consider it in the context of the other Netpbm format names: PBM, PGM, and PPM.
This format does not define the meaning of the data at any particular point in the array. It could be red, green, and blue light intensities such that the array represents a visual image, or it could be the same red, green, and blue components plus a transparency component, or it could contain annual rainfalls for places on the surface of the Earth. Any process that uses the PAM format must further define the format to specify the meanings of the data.
A PAM image describes a two dimensional grid of tuples. The tuples are arranged in rows and columns. The width of the image is the number of columns. The height of the image is the number of rows. All rows are the same width and all columns are the same height. The tuples may have any degree, but all tuples have the same degree. The degree of the tuples is called the depth of the image. Each member of a tuple is called a sample. A sample is an unsigned integer which represents a locus along a scale which starts at zero and ends at a certain maximum value called the maxval. The maxval is the same for every sample in the image. The two dimensional array of all the Nth samples of each tuple is called the Nth plane or Nth channel of the image.
Though the basic format does not assign any meaning to the tuple values, it does include an optional string that describes that meaning. The contents of this string, called the tuple type, are arbitrary from the point of view of the basic PAM format, but users of the format may assign meaning to it by convention so they can identify their particular implementations of the PAM format. Some tuple types are defined as official subformats of PAM. See Defined Tuple Types.
π The Confusing Universe of Netpbm Formats π
It is easy to get confused about the relationship between the PAM format and PBM, PGM, PPM, and PNM. Here is a little enlightenment:
PNMis not really a format. It is a shorthand for thePBM,PGM, andPPMformats collectively. It is also the name of a group of library functions that can each handle all three of those formats.PAMis in fact a fourth format. But it is so general that you can represent the same information in a PAM image as you can in aPBM,PGM, orPPMimage. And in fact a program that is designed to readPBM,PGM, orPPMand does so with a recent version of the Netpbm library will read an equivalent PAM image just fine and the program will never know the difference.- To confuse things more, there is a collection of library routines called the
pamfunctions that read and write the PAM format, but also read and write thePBM,PGM, andPPMformats. They do this because the latter formats are much older and more popular, so even a new program must work with them. Having the library handle all the formats makes it convenient to write programs that use the newer PAM format as well.
π THE LAYOUT π
A convenient way to read and write the PAM format accurately is via the libnetpbm(1) C subroutine library.
A PAM file consists of a sequence of one or more PAM images. There are no data, delimiters, or padding before, after, or between images.
Each PAM image consists of a header followed immediately by a raster.
Here is an example header:
P7
WIDTH 227
HEIGHT 149
DEPTH 3
MAXVAL 255
TUPLTYPE RGB
ENDHDR
The header begins with the ASCII characters P7 followed by newline. This is the magic number.
Note:xvthumbnail images also start with theP7magic number. (This and PAM were independent extensions to the Netpbm formats). The rest of the format makes it easy to distinguish PAM from that format, though).
The header continues with an arbitrary number of lines of ASCII text. Each line ends with and is delimited by a newline character.
Each header line consists of zero or more whitespace-delimited tokens or begins with #. If it begins with # it is a comment and the rest of this specification does not apply to it.
A header line which has zero tokens is valid but has no meaning.
The type of header line is identified by its first token, which is 8 characters or less:
ENDHDRβ This is the last line in the header. The header must contain exactly one of these header lines.HEIGHTβ The second token is a decimal number representing the height of the image (number of rows). The header must contain exactly one of these header lines.WIDTHβ The second token is a decimal number representing the width of the image (number of columns). The header must contain exactly one of these header lines.DEPTHβ The second token is a decimal number representing the depth of the image (number of planes or channels). The header must contain exactly one of these header lines.MAXVALβ The second token is a decimal number representing the maxval of the image. The header must contain exactly one of these header lines.TUPLTYPEβ The header may contain any number of these header lines, including zero. The rest of the line is part of the tuple type. The rest of the line is not tokenized, but the tuple type does not include any white space immediately followingTUPLTYPEor at the very end of the line. It does not include a newline. There must be something other than white space after theTUPLTYPEtoken.
If there are multiple TUPLTYPE header lines, the tuple type is the concatenation of the values from each of them, separated by a single blank, in the order in which they appear in the header. If there are no TUPLTYPE header lines the tuple type is the null string.
The raster consists of each row of the image, in order from top to bottom, consecutive with no delimiter of any kind between, before, or after, rows.
Each row consists of every tuple in the row, in order from left to right, consecutive with no delimiter of any kind between, before, or after, tuples.
Each tuple consists of every sample in the tuple, in order, consecutive with no delimiter of any kind between, before, or after, samples.
Each sample consists of an unsigned integer in pure binary format, with the most significant byte first. The number of bytes is the minimum number of bytes required to represent the maxval of the image.
The character referred to as "newline" herein is the character known in ASCII as Line Feed or LF.
π LIMITATIONS π
- Height, width, depth, and maxval are at least 1.
- Height, width, and depth have no defined maximum, but processors and generators of images usually have their own limitations.
- The maxval of an image is never greater than 65535. (The reason it is limited is to make it easier to build an image processor, in which intermediate arithmetic values often have to fit within 31 or 32 bits). There was no specified limitation before October, 2005, but essentially all implementations have always observed it.
β¨ DEFINED TUPLE TYPES β¨
okay so some tuple types are actually spelled out right here in this spec, and they exist to define the official subformats of PAM for the applications that everyone and their mom uses. but bestie, it's not a closed club β you can define your own tuple types too, and therefore your own whole subformats. main character energy, honestly. π
the tuple type only affects the meanings of the samples (which are unsigned integers, remember) inside the tuples of the image. that's it. it does not affect how the samples or the tuples get encoded. and lowkey it can affect what a tuple's position in the array means β like, it might tell you that in a visual image, the tuple sitting in Row 1 is the one at the top of the image and not the bottom. π
and hear me out: tuple type never decides how many samples are in a tuple. that is entirely the DEPTH header line's job. you could argue tuple type kind of implies a depth, because certain tuple types are only valid when paired with certain DEPTH values β but the good-programming-practice move is to use DEPTH for the depth while you're decoding the raster, and then separately validate that the depth is consistent with the tuple type. and also? it's good practice to accept a depth that's too great and just ignore the higher numbered planes. be generous, bestie. π«Ά
π PAM Used For Visual Images
a super common use of PAM images is representing visual images β the kind of thing the older, more concrete PBM, PGM and PPM formats typically handle. so let's get into it.
π€π€ Black And White
a black and white image β the kind a PBM image would alternatively represent β has a tuple type of "BLACKANDWHITE". such a PAM image has a depth of 1 and maxval 1, where the one sample in each tuple is 0 to represent a black pixel and 1 to represent a white one. the maxval, height, width, and order of tuples in the raster bear the obvious relationship to those of the equivalent PBM image.
β οΈ okay this one trips people up: in the PBM format, a sample value of zero means white, but in PAM, zero means black. opposite vibes. do not get got. π
π«οΈ Grayscale
a grayscale image β the kind a PGM image would alternatively represent β has a tuple type of "GRAYSCALE". such a PAM image has a depth of 1. the maxval, height, width, and raster bear the obvious relationship to those of the equivalent PGM image.
πΊ Color
a color image β the kind a PPM image would alternatively represent β has a tuple type of "RGB". such a PAM image has a depth of 3. the maxval, height, width, and raster bear the obvious relationship to those of the PPM image. the first plane represents red, the second green, and the third blue. iconic. π
π¦ Transparent
each of the visual image formats we just mentioned has a variation that carries transparency info. in that variation, the tuple type has "_ALPHA" added to it (so like "RGB_ALPHA") and it gets one more plane. the highest numbered plane is the opacity plane (sometimes called an alpha plane or a transparency plane). β¨
in this kind of image, the color represented by a pixel is actually a combination of an explicitly specified foreground color and a background color that gets identified later.
the planes other than the opacity plane describe the foreground color. a sample in the opacity plane tells you how opaque the pixel is, by telling you what fraction of the pixel's light comes from the foreground color. the rest of the pixel's light comes from the (unspecified) background color.
for example, in a GRAYSCALE_ALPHA image, assume Plane 0 indicates a gray tone 60% of white and Plane 1 indicates opacity 25%. the foreground color is the 60% gray, and 25% of that contributes to the ultimate color of the pixel. the other 75% comes from some background color. so let's assume further that the background color of the pixel is full white. then the color of the pixel is 90% of white: 25% of the foreground 60%, plus 75% of the background 100%.
the sample value is the opacity fraction just described, as a fraction of the maxval. and ngl, heads up: it is not gamma-adjusted like the foreground color samples are. π§
π INTERNET MEDIA TYPE
no Internet Media Type (aka MIME type, content type) for PAM has been registered with IANA π, but this specification assigns the unofficial value image/x-portable-arbitrarymap, to stay consistent with the conventional values for the older Netpbm formats. iykyk.
π FILE NAME
the conventional suffix for the name of a PAM file is ".pam". but bestie, it is not required. live your truth. π
π SEE ALSO
Netpbm(1)pbm(1)pgm(1)ppm(1)pnm(1)libnetpbm(1)
π DOCUMENT SOURCE
this manual page was generated by the Netpbm tool 'makeman' from HTML source. the master documentation lives at
http://netpbm.sourceforge.net/doc/pam.html
and that's a wrap on the PAM format specification, bestie!! π this icon was brought to you by the netpbm documentation, dated 27 November 2013, and it's the PAM format specification(5) β go forth and slay your rasters. πβ¨ππ¦π
π¦ where this page comes from
- fedora 43: netpbm-progs 11.13.00-1.fc43 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- fedora 44: netpbm-progs 11.13.00-2.fc44 Β· BSD-3-Clause AND GPL-2.0-only AND LGPL-2.1-or-later AND GPL-3.0-or-later AND IJG AND MIT AND NTP AND PostgreSQL AND LicenseRef-MIT-CRL-Xim AND LicenseRef-Fedora-Public-Domain
- ubuntu stonking: netpbm 2:11.13.03+ds-2 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms