summary refs log tree commit diff
path: root/pngtopam.html
blob: 0cdd811b0352163fd8a7354a9960bf2cdc2d4ce9 (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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.3//EN">
<html><head><title>Pngtopam User Manual</title></head>
<body>
<h1>pngtopam</h1>
Updated: 22 July 2008
<br>
<a href="#index">Table Of Contents</a>

<h2>NAME</h2>
pngtopam - convert a PNG image into a Netpbm image

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

<b>pngtopam</b>
[<b>-verbose</b>]
[<b>-alphapam</b> | <b>-alpha</b> | <b>-mix</b>]
[<b>-background</b>=<i>color</i>]
<br>
[<b>-gamma</b>=<i>value</i>]
[<b>-text</b>=<i>filename</i>]
[<b>-time</b>]
[<b>-byrow</b>]
[<i>pngfile</i>]

<p>Minimum unique abbreviation of option is acceptable.  You may use double
hyphens instead of single hyphen to denote options.  You may use white
space in place of the equals sign to separate an option name from its value.

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

<p>This program is part of <a href="index.html">Netpbm</a>.

<p><b>pngtopam</b> reads a PNG image (Portable Network Graphics) as
input and produces a Netpbm image as output.  The type of the output file
depends on the input file - if it's black &amp; white, <b>pngtopam</b>
creates a PBM file.  If it's grayscale, <b>pngtopam</b> creates a PGM
file.  Otherwise, it creates a PPM file.  Except that with the
<b>-alphapam</b> option, it always creates a PAM file.  That file has
tuple type GRAYSCALE_ALPHA or RGB_ALPHA depending on whether the input
has color or not.

<p>To convert in the other direction, use <b>pamtopng</b> or
<b>pnmtopng</b>.  The former is the more modern of the two and can recognize
transparency information in a PAM file, as you might generate with <b>pngtopam
-alphapam</b>.  It has existed only since June 2015.  The latter has more
features, but probably not ones that matter in the modern world.


<h2 id="options">OPTIONS</h2>

<p>In addition to the options common to all programs based on libnetpbm
(most notably <b>-quiet</b>, see <a href="index.html#commonoptions">
Common Options</a>), <b>pngtopam</b> recognizes the following
command line options:

<dl compact>
<dt><b>-verbose</b>

<dd>Display various information about the input PNG image and the
conversion process.

<p>If you want even more information about the PNG image, use
<b>pngcheck</b> (not part of Netpbm).
     
<dt><b>-alphapam</b>

<dd>Produce a single output image containing the main image (foreground)
and the transparency channel or transparency mask.  This image is in the PAM
format with tuple type of either GRAYSCALE_ALPHA (which has a depth of
2 channels) or RGB_ALPHA (which has a depth of 4 channels).

<p>You can specify only one of <b>-alphapam</b>, <b>-alpha</b>, and
<b>-mix</b>.  With none of them, <b>pngtopam</b> produces an image of
the foreground of the input image and discards transparency information.

<p>This option was new in Netpbm 10.44 (September 2008).

<dt><b>-alpha</b>

<dd>Output the transparency channel or transparency mask of the image. The
result is either a PBM file or a PGM file, depending on whether
different levels of transparency appear.

<p><b>pngtopam</b> discards the main image (the foreground).

<p>You can specify only one of <b>-alphapam</b>, <b>-alpha</b>, and
<b>-mix</b>.  With none of them, <b>pngtopam</b> produces an image of
the foreground of the input image and discards transparency information.

<dt><b>-mix</b>

<dd>Compose the image with the transparency or transparency mask against a
background.  The background color is determined by the bKGD chunk in
the PNG, except that you can override it with <b>-background</b>.
If the PNG has no bKGD chunk and you don't specify <b>-background</b>,
the background color is white.

<p>You can specify only one of <b>-alphapam</b>, <b>-alpha</b>, and
<b>-mix</b>.  With none of them, <b>pngtopam</b> produces an image of
the foreground of the input image and discards transparency information.

<dt><b>-background=</b><i>color</i>

<dd>
This option specifies the background color with which to mix the image
when you specify <b>-mix</b>.  

<p><i>color</i> is as described for the <a
href="libnetpbm_image.html#colorname">argument of the <b>pnm_parsecolor()</b>
library routine</a>.

<p>Examples:

<ul>
<li><kbd>-background=rgb:01/ff/80</kbd>
<li><kbd>-background=rgbi:1/255/128</kbd>
</ul>

<p>If you don't specify <b>-background</b>, the background color is what
is specified in the PNG image, and if the PNG doesn't specify anything,
white.

<p>You cannot specify <b>-background</b> unless you also specify
<b>-mix</b>.  Before Netpbm 10.27 (March 2005), you could specify
<b>-background</b> without <b>-mix</b> and it was just ignored.  (This
caused a usability problem).


<dt><b>-gamma=</b><i>value</i>

<dd>This option causes <b>pngtopam</b> to respect the image gamma information
in the PNG file (from the gAMA chunk).  Probably by historical accident,
<b>pngtopam</b> ignores that information by default, assuming the image uses
the same gamma transformation as a Netpbm image, so the output image has
different colors than the PNG file actually represents if the PNG doesn't
actually do that.  (However, it is rare for a PNG file to use a gamma
transformation different from what the Netpbm formats specify, or if it does,
to specify with a gAMA chuck what that is).

<p>But when you <em>do</em> specify <b>-gamma</b>, you get a rather strange
additional function, probably a historical mistake:
<b>pngtopam</b> incorporates the specified screen gamma value into the output
pixels, so that the samples in the Netpbm output deviate from the Netpbm
format specifications and are appropriate raw intensity values to send to the
display.  This function essentially just exercises the ability of the PNG
library to make gamma corrections to the pixels as it reads them from the PNG
file to produce values appropriate for sending to a certain display in certain
viewing conditions.  It's a strange function because it has nothing to do with
PNG and because in Netpbm, the normal way to make gamma corrections
appropriate for sending to a ceratin display in certain viewing conditions is
with the program <b>pngtopam</b>, applied to the normal output of
<b>pngtopam</b>.

<p>If you specify <b>-gamma</b>, but the PNG image does not specify what gamma
transformation it uses (there is no gAMA chunk), <b>pngtopam</b> assumes a
simple power transformation with an image gamma of 1.0.  That is probably not
not the actual image gamma; it is much more likely to be .45.

<p>Because the gammas of uncompensated monitors are around 2.6, which results 
in an image-gamma of 0.45, some typical situations are: 
when the image-gamma is 0.45 (use -verbose to check) and the picture is too 
light, your system is gamma-corrected, so convert with "-gamma 1.0". 
When no gAMA chunk is present or the image-gamma is 1.0, use 2.2 to make the 
picture lighter and 0.45 to make the picture darker.

<p>One oddity to be aware of when using <b>-gamma</b> on an image with
transparency: The PNG image specifies that a certain color is
transparent, i.e. every pixel in the image of that color is
transparent.  But <b>pngtopam</b> interprets this as applying to the
gamma-corrected space, and there may be less precision in that space
than in the original, which means multiple uncorrected colors map to
the same corrected color.  So imagine that the image contains 3 shades
of white (gray) and specifies that one of them is transparent.  After gamma
correction, those three shades are indistinguishable, so
<b>pngtopam</b> considers pixels of all three shades to be transparent.


<dt><b>-text=</b><i>file</i>

<dd>Writes the tEXt and zTXt chunks to a file, in a format as
described in the <b>pnmtopng</b> user manual.  These chunks contain
text comments or annotations.

<dt><b>-time</b>

<dd>Prints the tIME chunk to stderr.

<dt><b>-byrow</b>

<dd>This option can make <b>pngtopam</b> run faster or in environments
where it would otherwise fail.

<p><b>pngtopam</b> has two ways to do the conversion from PNG to PAM, using
respectively two facilities of the PNG library:

<dl>

<dt>Whole Image

<dd>Decode the entire image into memory at once, using
<b>png_read_image()</b>, then convert to PAM and output row by row.
   
<dt>Row By Row
<dd>Read, convert, and output one row at a time using <b>png_read_row()</b>.

</dl>

<p>Whole Image is generally preferable because the PNG library does more of
the work, which means it understands more of the PNG format possibilities now
and in the future.  Also, if the PNG is interlaced, <b>pngtopam</b> does
not know how to assemble the rows in the right order.

<p>Row By Row uses far less memory, which means with large images, it
can run in environments where Whole Image cannot and may also run
faster.  And because Netpbm code does more of the work, it's possible
that it can be more flexible or at least give better diagnostic
information if there's something wrong with the PNG.

<p>The Netpbm native code may do something correctly that the PNG library does
incorrectly, or vice versa.

<p>In Netpbm, we stress function over performance, so by default
<b>pngtopam</b> uses Whole Image.  You can select Row By Row with
<b>-byrow</b> if you want the speed or resource requirement improvement.

<p><b>-byrow</b> was new in Netpbm 10.54 (March 2011).


<dt><b>-orientraw</b>

<dd>A TIFF stream contains raster data which can be arranged in the
stream various ways.  Most commonly, it is arranged by rows, with the
top row first, and the pixels left to right within each row, but many
other orientations are possible.

<p>The common orientation is the same on the Netpbm formats use, so
<b>tifftopnm</b> can do its jobs quite efficiently when the TIFF raster
is oriented that way.

<p>But if the TIFF raster is oriented any other way, it can take a
considerable amount of processing for <b>tifftopnm</b> to convert it to
Netpbm format.

</dl>

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

<a href="pnmtopng.html">pamtopng</a>,
<a href="pnmtopng.html">pnmtopng</a>,
<a href="pngtopnm.html">pngtopnm</a>,
<b>ptot</b>,
<a href="pnmgamma.html">pnmgamma</a>, 
<a href="pnm.html">pnm</a>

<p>For information on the PNG format, see <a
href="http://schaik.com/png">http://schaik.com/png</a>.

<h2 id="note">NOTE</h2>

<p>A PNG image contains a lot of information that can't be represented in 
Netpbm formats.  Therefore, you lose information when you convert to 
another format with "pngtopam | pnmtoxxx".  If there is a specialized 
converter that converts directly to the other format, e.g. <b>ptot</b>
to convert from PNG to TIFF, you'll get better results using that.

<h2 id="limitations">LIMITATIONS</h2>

<p>There could be an option to include PNG comment chunks in the output
image as PNM comments instead of putting them in a separate file.

<p>The program could be much faster, with a bit of code optimizing.
As with any Netpbm program, speed always takes a back seat to quick
present and future development.

<h2 id="history">HISTORY</h2>

<p><b>pngtopam</b> was new in Netpbm 10.44, as a replacement for
<b>pngtopnm</b>.  The main improvement over <b>pngtopnm</b> was that
it could generate a PAM image with a transparency channel, whereas
with <b>pngtopnm</b>, you would have to extract the transparency
channel as a separate file, in a separate run.

<p><b>pngtopnm</b> was new in Netpbm 8.1 (March 2000), the first big
change to the package in Netpbm's renaissance.  It and <b>pnmtopng</b>
were simply copied from the <a
href="http://www.libpng.org/pub/png/apps/pnmtopng.html">
<b>pnmtopng</b> package</a> by Greg Roelofs.  Those were based on
simpler reference applications by Alexander Lehmann
&lt;alex@hal.rhein-main.de&gt; and Willem van Schaik
&lt;willem@schaik.com&gt; and distributed with their PNG library.

<p>Nearly all of the code has changed since it was copied from the
<b>pnmtopng</b> package, most of it just to improve maintainability.


<h2 id="authors">AUTHORS</h2>

Copyright (C) 1995-1997 by Alexander Lehmann and Willem van Schaik.

<hr>
<h2 id="index">Table Of Contents</h2>
<ul>
<li><a href="#synopsis">SYNOPSIS</a>
<li><a href="#description">DESCRIPTION</a>
<li><a href="#options">OPTIONS</a>
<li><a href="#seealso">SEE ALSO</a>
<li><a href="#note">NOTE</a>
<li><a href="#limitations">LIMITATIONS</a>
<li><a href="#history">HISTORY</a>
<li><a href="#authors">AUTHORS</a>
</ul>
</body>
</html>