1The PBM Format(5)             File Formats Manual            The PBM Format(5)
2
3
4

NAME

6       pbm - Netpbm bi-level image format
7
8

DESCRIPTION

10       This program is part of Netpbm(1).
11
12       The  PBM  format is a lowest common denominator monochrome file format.
13       It serves as the common language of a large family of bitmap image con‐
14       version  filters.  Because the format pays no heed to efficiency, it is
15       simple and general enough that one can easily develop programs to  con‐
16       vert to and from just about any other graphics format, or to manipulate
17       the image.
18
19       The name "PBM" is an acronym derived from "Portable Bit Map."
20
21       This is not a format that one would normally use to store a file or  to
22       transmit  it to someone -- it's too expensive and not expressive enough
23       for that.  It's just an intermediary format.  In it's  purest  use,  it
24       lives only in a pipe between two other programs.
25
26       The format definition is as follows.
27
28       A  PBM file consists of a sequence of one or more PBM images. There are
29       no data, delimiters, or padding before, after, or between images.
30
31       Each PBM image consists of the following:
32
33
34
35
36       ·      A 'magic number' for identifying the file type.  A  pbm  image's
37              magic number is the two characters 'P4'.
38
39
40       ·      Whitespace (blanks, TABs, CRs, LFs).
41
42
43       ·      The  width in pixels of the image, formatted as ASCII characters
44              in decimal.
45
46
47       ·      Whitespace.
48
49
50       ·      The height in pixels of the image, again in ASCII decimal.
51
52
53       ·      A single whitespace character (usually a newline).
54
55
56       ·      A raster of Height rows, in order from top to bottom.  Each  row
57              is  Width bits, packed 8 to a byte, with don't care bits to fill
58              out the last byte in the row.  Each bit represents a pixel: 1 is
59              black,  0  is  white.  The order of the pixels is left to right.
60              The order of their storage within each file byte is most signif‐
61              icant bit to least significant bit.  The order of the file bytes
62              is from the beginning of the file toward the end of the file.
63
64              A row of an image is horizontal.  A  column  is  vertical.   The
65              pixels in the image are square and contiguous.
66
67
68       ·      Before  the  whitespace  character that delimits the raster, any
69              characters from a '#' through the next carriage return  or  new‐
70              line  character, is a comment and is ignored.  Note that this is
71              rather unconventional, because a comment can actually be in  the
72              middle  of what you might consider a token.  Note also that this
73              means if you have a comment right before the raster, the newline
74              at  the  end  of  the  comment  is not sufficient to delimit the
75              raster.
76
77
78
79       There is actually another version of the PBM format, even more simplis‐
80       tic, more lavishly wasteful of space than PBM, called Plain PBM.  Plain
81       PBM actually came first, but even its inventor couldn't stand its reck‐
82       lessly  squanderous use of resources after a while and switched to what
83       we now know as the regular PBM format.  But Plain PBM is  so  redundant
84       --  so  overstated -- that it's virtually impossible to break.  You can
85       send it through the most liberal mail system (which  was  the  original
86       purpose  of the PBM format) and it will arrive still readable.  You can
87       flip a dozen random bits and easily piece back  together  the  original
88       image.   And  we hardly need to define the format here, because you can
89       decode it by inspection.
90
91       Netpbm programs generate  Raw  PBM  format  instead  of  Plain  PBM  by
92       default,  but  the  common  option  ⟨index.html#commonoptions⟩   -plain
93       chooses Plain PBM.
94
95       The difference is:
96
97
98       -      There is exactly one image in a file.
99
100       -      The 'magic number' is 'P1' instead of 'P4'.
101
102       -      Each pixel in the raster is represented  by  a  byte  containing
103              ASCII  '1'  or  '0',  representing black and white respectively.
104              There are no fill bits at the end of a row.
105
106       -      White space in the raster section is ignored.
107
108       -      You can put any junk you want after the  raster,  if  it  starts
109              with a white space character.
110
111       -      No line should be longer than 70 characters.
112
113
114       Here is an example of a small image in the plain PBM format.
115       P1
116       # feep.pbm
117       24 7
118       0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
119       0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 1 1 1 0
120       0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 1 0
121       0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 1 0
122       0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0
123       0 1 0 0 0 0 0 1 1 1 1 0 0 1 1 1 1 0 0 1 0 0 0 0
124       0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
125
126       There is a newline character at the end of each of these lines.
127
128       You  can  generate  the  Plain  PBM  format from the regular PBM format
129       (first image in the file only) with the pnmtoplainpnm program.
130
131       Programs that read this  format  should  be  as  lenient  as  possible,
132       accepting anything that looks remotely like a bitmap.
133
134       All  characters  referred  to  herein  are encoded in ASCII.  'newline'
135       refers the the character known in ASCII as Line Feed or LF.   A  'white
136       space'  character  is space, CR, LF, TAB, VT, or FF (I.e. what the ANSI
137       standard C isspace() function calls white space).
138
139

COMPATIBILITY

141       Before July 2000, there could be at most one image in a PBM file.  As a
142       result,  most  tools  to  process PBM files ignore (and don't read) any
143       data after the first image.
144
145

SEE ALSO

147       libnetpbm(1), pnm(1), pgm(1), ppm(1), pam(1), programsthatprocessPBM(1)
148
149
150
151netpbm documentation           22 September 2006             The PBM Format(5)
Impressum