.TL
The PBM Format
.SH 1
pbm
.LP
Updated: 22 September 2006
.br
Table Of Contents
.SH 2
NAME
.LP
pbm - Netpbm bi-level image format
.SH 2
DESCRIPTION
.LP
.LP
This program is part of Netpbm.
.LP
The PBM format is a lowest common denominator monochrome file format.
It serves as the common language of a large
family of bitmap image conversion filters. Because the format pays no heed
to efficiency, it is simple and general enough that one can easily
develop programs to convert to and from just about any other graphics
format, or to manipulate the image.
.LP
The name "PBM" is an acronym derived from "Portable Bit Map."
.LP
This is not a format that one would normally use to store a file
or to transmit it to someone -- it's too expensive and not expressive
enough for that. It's just an intermediary format. In it's purest
use, it lives only in a pipe between two other programs.
.LP
The format definition is as follows.
.LP
A PBM file consists of a sequence of one or more PBM images. There are
no data, delimiters, or padding before, after, or between images.
.LP
Each PBM image consists of the following:
.IP 1
A "magic number" for identifying the file type.
A pbm image's magic number is the two characters "P4".
.IP 2
Whitespace (blanks, TABs, CRs, LFs).
.IP 3
The width in pixels of the image, formatted as ASCII characters in decimal.
.IP 4
Whitespace.
.IP 5
The height in pixels of the image, again in ASCII decimal.
.IP 6
Newline or other single whitespace character.
.IP 7
A raster of Height rows, in order from top to bottom. Each row is
Width bits, packed 8 to a byte, with don't care bits to fill out the
last byte in the row. Each bit represents a pixel: 1 is black, 0 is
white. The order of the pixels is left to right. The order of their
storage within each file byte is most significant bit to least
significant bit. The order of the file bytes is from the beginning of
the file toward the end of the file.
.LP
A row of an image is horizontal. A column is vertical. The pixels
in the image are square and contiguous.
.IP 8
Characters from a "#" to the next end-of-line, before
the width/height line, are comments and are ignored.
.LP
.LP
There is actually another version of the PBM format, even more more
simplistic, more lavishly wasteful of space than PBM, called Plain
PBM. Plain PBM actually came first, but even its inventor couldn't
stand its recklessly squanderous use of resources after a while and
switched to what we now know as the regular PBM format. But Plain PBM
is so redundant -- so overstated -- that it's virtually impossible to
break. You can send it through the most liberal mail system (which
was the original purpose of the PBM format) and it will arrive still
readable. You can flip a dozen random bits and easily piece back
together the original image. And we hardly need to define the format
here, because you can decode it by inspection.
.LP
Netpbm programs generate Raw PBM format instead of Plain PBM by
default, but the common option
\fB-plain\fR chooses Plain PBM.
.LP
The difference is:
.RS
.IP "-"
There is exactly one image in a file.
.IP "-"
The "magic number" is "P1" instead of "P4".
.IP "-"
Each pixel in the raster is represented by a byte containing ASCII '1' or '0',
representing black and white respectively. There are no fill bits at the
end of a row.
.IP "-"
White space in the raster section is ignored.
.IP "-"
You can put any junk you want after the raster, if it starts with a
white space character.
.IP "-"
No line should be longer than 70 characters.
.RE
.LP
Here is an example of a small image in the plain PBM format.
.DS L
P1
# feep.pbm
24 7
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 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 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 1 1 1 0 0 1 1 1 1 0 0 1 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
.DE
.LP
There is a newline character at the end of each of these lines.
.LP
You can generate the Plain PBM format from the regular PBM format
(first image in the file only) with the \fBpnmtoplainpnm\fR program.
.LP
Programs that read this format should be as lenient as possible,
accepting anything that looks remotely like a bitmap.
.SH 2
COMPATIBILITY
.LP
.LP
Before July 2000, there could be at most one image in a PBM file. As
a result, most tools to process PBM files ignore (and don't read) any
data after the first image.
.SH 2
SEE ALSO
.LP
\fBlibnetpbm\fR,
\fBpnm\fR,
\fBpgm\fR,
\fBppm\fR,
\fBpam\fR,
\fBprograms that process PBM\fR
.br
\l'5i'
.SH 2
Table Of Contents
.LP
.IP \(bu
DESCRIPTION
.IP \(bu
COMPATIBILITY
.IP \(bu
SEE ALSO
.LP
|