summary refs log tree commit diff
path: root/libpnm.html
blob: e370389a8ec0b4bae3c8dc0ced36590220efd3d3 (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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html>
<head>
<title>User manual for old pnm functions</title>
<meta name="manual_section" content="3">
</head>
<body>
<h1>pnm Functions</h1>
Updated: 08 September 2007
<br>
<a href="#index">Table Of Contents</a>
<h2>NAME</h2>
libpnm - libnetpbm functions to read and write PNM image files

<h2 id="synopsis">SYNOPSIS</h2>

<b>#include &lt;netpbm/pnm.h&gt;</b>

<p>
<b>void pnm_init(</b>
<b>int *</b><i>argcP</i><b>,</b>
<b>char *</b><i>argv</i><b>[]</b>
<b>);</b>

<p>
<b>xel ** pnm_allocarray(</b>
<b>int </b><i>cols</i><b>,</b>
<b>int </b><i>rows</i><b>);</b>

<p>
<b>xel * pnm_allocrow(</b>
<b>int </b><i>cols</i><b>);</b>

<p>
<b>void pnm_freearray(</b>
<b>xel **</b><i>xels</i><b>,</b>
<b>int </b><i>rows</i><b>);</b>

<p>
<b>void pnm_freerow(</b>
<b>xel *</b><i>xelrow</i><b>);</b>

<p>
<b>void pnm_readpnminit( </b>
<b>FILE *</b><i>fp</i><b>,</b>
<b>int *</b><i>colsP</i><b>,</b>
<b>int *</b><i>rowsP</i><b>,</b>
<b>xelval *</b><i>maxvalP</i><b>,</b>
<b>int *</b><i>formatP</i><b> );</b>

<p>
<b>void pnm_readpnmrow( </b>
<b>FILE *</b><i>fp</i><b>,</b>
<b>xel *</b><i>xelrow</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>

<br>

<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b> );</b>

<p>
<b>xel ** pnm_readpnm( </b>
<b>FILE *</b><i>fp</i><b>,</b>
<b>int *</b><i>colsP</i><b>,</b>
<b>int *</b><i>rowsP</i><b>,</b>

<br>

<b>xelval *</b><i>maxvalP</i><b>, int</b><i>*</i><b> formatP </b><i>);</i>

<p>
<b>void pnm_writepnminit( </b>
<b>FILE *  fp , </b>
<b>int </b><i>cols</i><b>,</b>
<b>int </b><i>rows</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>,</b>
<b>int </b><i>forceplain</i><b>);</b>

<p>
<b>void pnm_writepnmrow( </b>
<b>FILE *</b><i>fp</i><b>,</b>
<b>xel *</b><i>xelrow</i><b>,</b>
<b>int cols</b><i>,</i>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>,</b>
<b>int </b><i>forceplain</i><b> );</b>

<p>
<b>void pnm_writepnm( </b>
<b>FILE *</b><i>fp</i><b>,</b>
<b>xel ** </b><i>xels</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>
<b>int </b><i>rows</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>,</b>
<b>int </b><i>forceplain</i><b> );</b>

<p>
<b>void pnm_nextimage(</b><b>FILE *</b> <i>file</i><b>,</b>
  <b>int * const</b> <i>eofP</i><b>);</b>

<p>
<b>void pnm_check(</b>
<b>FILE * </b><i>file</i><b>,</b>
<b>const enum pm_check_type </b><i>check_type</i><b>,</b>
<b>const int </b><i>format</i><b>,</b>
<b>const int </b><i>cols</i><b>,</b>
<b>const int </b><i>rows</i><b>,</b>
<b>const xelval </b><i>maxval</i><b>,</b>
<b>enum pm_check_code *</b><i>retvalP</i><b>);</b>

<p>
<b>void pnm_promoteformatrow( </b>
<b>xel *</b><i>xelrow</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>,</b>
<b>xelval </b><i>newmaxval</i><b>,</b>
<b>int </b><i>newformat</i><b>);</b>

<p>
<b>void pnm_promoteformat( </b>
<b>xel **</b><i>xels</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>,</b>
<b>xelval </b><i>newmaxval</i><b>,</b>
<b>int </b><i>newformat</i><b>);</b>

<p>
<b>xel pnm_whitexel( </b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>);</b>

<p>
<b>xel pnm_blackxel( </b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>);</b>

<p>
<b>void pnm_invertxel( </b>
<b>xel *</b><i>x</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>);</b>

<p>
<b>xel pnm_backgroundxelrow( </b>
<b>xel *</b><i>xelrow</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>);</b>

<p>
<b>xel pnm_backgroundxel( </b>
<b>xel **</b><i>xels</i><b>,</b>
<b>int </b><i>cols</i><b>,</b>
<b>int </b><i>rows</i><b>,</b>
<b>xelval </b><i>maxval</i><b>,</b>
<b>int </b><i>format</i><b>);</b>
<p><b>typedef ... xelval;</b>
<p><b>typedef ... xel;</b>

<p>
<b>#define </b>
<b>PNM_ASSIGN1(</b><i>x</i><b>,</b><i>v</i><b>)</b>
<b>...</b>

<p>
<b>#define </b>
<b>PNM_GET1(</b><i>x</i><b>)</b>
<b>...</b>

<p>
<b>#define </b>
<b>PNM_EQUAL(</b><i>x</i><b>,</b><i>y</i><b>)</b>
<b>...</b>

<p>
<b>#define </b>
<b>PNM_FORMAT_TYPE(</b><i>format</i><b>)</b>
<b>...</b>

<h2 id="description">DESCRIPTION</h2>

<p>These library functions are part of <a href="index.html">Netpbm</a>.


<h3 id="types">TYPES AND CONSTANTS</h3>

<p>Each <b>xel</b> contains three <b>xelval</b>s, each of which should
contain only the values between <b>0</b> and <b>PNM_MAXMAXVAL</b>,
inclusive. 

<h3 id="xel">XEL MANIPULATIONS</h3>

<p>The <b>PNM_GET1</b> macro extracts a single value from an xel, when
ou know it's from a PBM or PGM file.  When it's from a PPM file, use
<b>PPM_GETR()</b>, <b>PPM_GETG()</b>, and <b>PPM_GETB()</b>.

<p>The <b>PNM_ASSIGN1</b> macro assigns a single value to an xel, when
you know it's from a PBM or PGM file.  When it's from a PPM file, use
<b>PPM_ASSIGN</b>.

The <b>PNM_EQUAL</b> macro checks two xels for equality.  The
<b>PNM_FORMAT_TYPE</b> macro computes a
format type code from a format code.  The format types are PBM, PGM,
PPM, and PAM.  But note that PBM, PGM, and PPM each are two different
formats: a plain one and a raw one.  So there are four format types,
but seven formats.  <b>PNM_FORMAT_TYPE</b> does not work on the PAM
format code.

<b>pnm_whitexel()</b> and <b>pnm_blackxel()</b> return a white or
black xel, respectively, for the given <i>maxval</i> and
<i>format</i>.

<p><b>pnm_invertxel()</b> inverts an xel.

<h3 id="initialization">INITIALIZATION</h3>

<p><b>pnm_init()</b> is obsolete (at least since Netpbm 9.25 (March 2002)).
Use <a href="libpm.html#initialization"><b>pm_proginit()</b></a> instead.

<p><b>pnm_init()</b> is identical to <b>pm_proginit</b>.

<h3 id="memorymanagement">MEMORY MANAGEMENT</h3>

<p><b>pnm_allocarray()</b> allocates space for an array of xels.
<b>pnm_freearray()</b> frees an array space allocated by
<b>pnm_allocarray()</b> or <b>pnm_readpnm()</b>.

<p><b>pnm_allocrow()</b> allocates space for a row of a PNM image.
<b>pnm_freerow()</b> frees it.


<h3 id="reading">READING PNM FILES</h3>

<p><b>pnm_readpnminit()</b> is similar to <b>pnm_readpaminit()</b>,
but reads only PNM images and has a different parameter list.

<p><b>pnm_readpnmrow()</b> is similar to <b>pnm_readpamrow()</b>
but only works on PNM images and has a different parameter list and returns
the row as an array of xels instead of tuples.

<p><b>pnm_readpnm()</b> is similar to <b>pnm_readpam()</b> except that
it reads only PNM images and uses a different parameter list and
returns an array of rows such that <b>pnm_readpnmrow()</b> would
return rather than such that <b>pnm_readpamrow()</b> would return.


<h3 id="writing">WRITING FILES</h3>

<p><b>pnm_writepnminit()</b> is similar to <b>pnm_writepaminit()</b>
except that it can write only a PNM header and has a different
parameter list.

<p><i>forceplain</i> is a binary value.  True (nonzero) means to write
the image in the plain (ASCII) version of the selected format.  False
(zero) means to write it in the raw (binary) version of the selected
format.  See <a href="pnm.html">PNM format specification</a>.

<p><b>pnm_writepnmrow()</b> is similar to <b>pnm_writepamrow()</b>
except that it works only on PNM images and has a different parameter
list and takes an array of xels instead of an array of tuples.  See
the description of <i>forceplain </i> above.

<p><b>pnm_writepnm()</b> is similar to <b>pnm_writepam()</b> except
that it works only on PNM image, has a different parameter list, and
takes an array of rows of xels instead of an array of rows of tuples.
See the description of <i>forceplain</i> above.


<h3 id="promotion">FORMAT PROMOTION</h3>

<b>pnm_promoteformatrow()</b> promotes a row of xels from one maxval
and format to a new set.  Use this when you are combining multiple
anymaps of different types - just take the maximum of the maxvals and
the maximum of the formats, and promote them all to that.

<p><b>pnm_promoteformat()</b> promotes an entire anymap.

<h3 id="miscellaneous">MISCELLANEOUS</h3>

<p><b>pnm_nextimage()</b> positions a PNM input file to the next image
in it (so that a subsequent <b>pnm_readpnminit()</b> reads its
header).

<p><b>pnm_nextimage()</b> is analogous to <b>pbm_nextimage()</b>, but
works on PPM, PGM, and PBM files.

<p> <b>pnm_check()</b> is similar to <b>pnm_checkpam()</b> except it
works only on PNM images.

<p><b>pnm_check()</b> is identical to <b>ppm_check()</b>.

<p><b>pnm_backgroundxelrow()</b> figures out an appropriate background
xel based on the row of xels <i>xelrow</i>, which is <i>cols</i> xels
wide, has maxval <i>maxval</i>, and represents an image with format
<i>format</i>.

<p>This estimate works best when the row is the top or bottom row of
the image.

<p><b>pnm_backgroundxel()</b> does the same thing as
<b>pnm_backgroundxelrow()</b>, except based on an entire image instead
of just one row.  This tends to do a slightly better job than
<b>pnmbackgroundxelrow()</b>.

<h2 id="seealso">SEE ALSO</h2>

<b><a href="libnetpbm.html">Libnetpbm</a></b>,
<b><a href="libnetpbm_ug.html">Libnetpbm User's Guide</a></b>,
<b><a href="libnetpbm_dir.html">Libnetpbm Directory</a></b>,
<b><a href="pbm.html">pbm</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="libpbm.html">libpbm</a></b>,
<b><a href="libpgm.html">libpgm</a></b>,
<b><a href="libppm.html">libppm</a></b>

<h2 id="author">AUTHOR</h2>

Copyright (C) 1989, 1991 by Tony Hansen and Jef Poskanzer.

<hr>
<h2 id="index">Table Of Contents</h2>
<ul>
  <li><a href="#synopsis">SYNOPSIS</a>
  <li><a href="#description">DESCRIPTION</a>
  <ul>
    <li><a href="#types">TYPES AND CONSTANTS</a>
    <li><a href="#xel">XEL MANIPULATIONS</a>
    <li><a href="#initialization">INITIALIZATION</a>
    <li><a href="#memorymanagement">MEMORY MANAGEMENT</a>
    <li><a href="#reading">READING PNM FILES</a>
    <li><a href="#writing">WRITING FILES</a>
    <li><a href="#promotion">FORMAT PROMOTION</a>
    <li><a href="#miscellaneous">MISCELLANEOUS</a>
    </ul>
  <li><a href="#seealso">SEE ALSO</a>
  <li><a href="#author">AUTHOR</a>
  </ul>
</body>
</html>