1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>The PBM Format</TITLE>
<META NAME="manual_section" CONTENT="5">
</HEAD>
<BODY>
<H1>pbm</H1>
Updated: 22 September 2006
<BR>
<A HREF="#index">Table Of Contents</A>
<H2>NAME</H2>
pbm - Netpbm bi-level image format
<H2 id="description">DESCRIPTION</H2>
<p>This program is part of <a href="index.html">Netpbm</a>.
<P>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.
<P>The name "PBM" is an acronym derived from "Portable Bit Map."
<P>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.
<P>The format definition is as follows.
<P>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.
<P>Each PBM image consists of the following:
<OL>
<LI>A "magic number" for identifying the file type.
A pbm image's magic number is the two characters "P4".
<LI>Whitespace (blanks, TABs, CRs, LFs).
<LI>The width in pixels of the image, formatted as ASCII characters in decimal.
<LI>Whitespace.
<LI>The height in pixels of the image, again in ASCII decimal.
<LI>A single whitespace character (usually a newline).
<LI>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.
<P>A row of an image is horizontal. A column is vertical. The pixels
in the image are square and contiguous.
<li>Before the whitespace character that delimits the raster, any
characters from a "#" through the next carriage return or
newline character, is a comment and is ignored. Note that this is
rather unconventional, because a comment can actually be in the middle
of what you might consider a token. Note also that this means if you
have a comment right before the raster, the newline at the end of the
comment is not sufficient to delimit the raster.
</OL>
<P>
There is actually another version of the PBM format, even 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.
<p>Netpbm programs generate Raw PBM format instead of Plain PBM by
default, but the <a href="index.html#commonoptions">common option</a>
<b>-plain</b> chooses Plain PBM.
<P>The difference is:
<DL COMPACT>
<DT>-<DD>
There is exactly one image in a file.
<DT>-<DD>
The "magic number" is "P1" instead of "P4".
<DT>-<DD>
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.
<DT>-<DD>
White space in the raster section is ignored.
<DT>-<DD>
You can put any junk you want after the raster, if it starts with a
white space character.
<DT>-<DD>
No line should be longer than 70 characters.
</DL>
<P>
Here is an example of a small image in the plain PBM format.
<PRE>
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
</PRE>
<p>There is a newline character at the end of each of these lines.
<P>You can generate the Plain PBM format from the regular PBM format
(first image in the file only) with the <B>pnmtoplainpnm</B> program.
<P>Programs that read this format should be as lenient as possible,
accepting anything that looks remotely like a bitmap.
<p>All characters referred to herein are encoded in ASCII.
"newline" refers the the character known in ASCII as Line
Feed or LF. A "white space" character is space, CR, LF,
TAB, VT, or FF (I.e. what the ANSI standard C isspace() function
calls white space).
<H2 id="compatibility">COMPATIBILITY</H2>
<P>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.
<H2 id="seealso">SEE ALSO</H2>
<B><A HREF="libnetpbm.html">libnetpbm</A></B>,
<B><A HREF="pnm.html">pnm</A></B>,
<B><A HREF="pgm.html">pgm</A></B>,
<B><A HREF="ppm.html">ppm</A></B>,
<B><A HREF="pam.html">pam</A></B>,
<B><A HREF="directory.html">programs that process PBM</A></B>
<HR>
<H2 id="index">Table Of Contents</H2>
<UL>
<LI><A HREF="#description">DESCRIPTION</A>
<LI><A HREF="#compatibility">COMPATIBILITY</A>
<LI><A HREF="#seealso">SEE ALSO</A>
</UL>
</BODY>
</HTML>
|