summary refs log tree commit diff
path: root/pbm.html
blob: df357575cdc625b0a3be68893859ba00f29b5012 (plain) (blame)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html>
<head>
<title>The PBM Format</title>
<meta name="manual_section" content="5">
</head>
<body>
<h1>pbm</h1>
Updated: 27 November 2013
<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.

<h2 id="layout">THE LAYOUT</h2>

<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:

<ul>

<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.

</ul>

<p>All characters referred to herein are encoded in ASCII.
"newline" refers to 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).


<h3 id="plainpbm">Plain PBM</h3>
<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:
<ul>
<li>
There is exactly one image in a file.
<li>
The "magic number" is "P1" instead of "P4".
<li>
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.
<li>
White space in the raster section is ignored.
<li>
You can put any junk you want after the raster, if it starts with a 
white space character.
<li>
No line should be longer than 70 characters.
</ul>

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.


<h2 id="internetmediatype">INTERNET MEDIA TYPE</h2>

<p>No Internet Media Type (aka MIME type, content type) for PBM has been
registered with IANA, but the value <code>image/x-portable-bitmap</code>
is conventional.

<p>Note that the PNM Internet Media Type <code>image/x-portable-anymap</code>
also applies.


<h2 id="filename">FILE NAME</h2>

<p>There are no requirements on the name of a PBM file, but the convention is
to use the suffix ".pbm".  "pnm" is also conventional, for
cases where distinguishing between the particular subformats of PNM is not
convenient.


<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="#layout">THE LAYOUT</a>
<ul>
  <li><a href="#plainpbm">Plain PBM</a>
    </ul>
<li><a href="#internetmediatype">INTERNET MEDIA TYPE</a>
<li><a href="#filename">FILE NAME</a>
<li><a href="#compatibility">COMPATIBILITY</a>
<li><a href="#seealso">SEE ALSO</a>
</ul>
</body>
</html>