summary refs log tree commit diff
path: root/tifftopnm.html
blob: af540dfc0453e0a7b2d373d176a3db5f4257cb9f (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>Tifftopnm User Manual</title></head>
<body>
<h1>tifftopnm</h1>
Updated: 02 January 2015
<br>
<a href="#index">Table Of Contents</a>

<h2>NAME</h2>

tifftopnm - convert a TIFF file into a PNM image

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

<b>tifftopnm</b>

[<b>-alphaout=</b>{<i>alpha-filename</i>,<b>-</b>}]
[<b>-headerdump</b>]
[<b>-verbose</b>]
<br>
[<b>-respectfillorder</b>]
[<b>-byrow</b>]
[<b>-orientraw</b>]
[<i>tiff-filename</i>]


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

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

<p><b>tifftopnm</b> reads a TIFF file as input and produces a PNM image as
output.  The type of the output file depends on the input file - if it's black
and white, <b>tifftopnm</b> generates a PBM image; if it's grayscale, it
generates a PGM image; otherwise, the output is PPM.  The program tells you
which type it is writing.

<p>If the TIFF file contains multiple images (multiple
"directories"), <b>tifftopnm</b> generates a multi-image PNM
output stream.  Before Netpbm 10.27 (March 2005), however, it would
just ignore all but the first input image.

<p>The <i>tiff-filename</i> argument names the file that contains the Tiff
image.  If you specify "-" or don't specify this
argument, <b>tifftopnm</b> uses Standard Input.

<p>In either case, before Netpbm 10.70 (March 2015), the file must be
seekable.  That means no pipe, but any regular file is fine.  In current
Netpbm, the file need not be seekable, but if it isn't, <b>tifftopnm</b>
creates a temporary regular file containing the entire image, so you must have
resources for that (and it may defeat your reason for using a pipe).

<h3 id="library">TIFF Capability</h3>

<p><b>pamtotiff</b> uses the Libtiff.org TIFF library (or whatever
equivalent you provide) to interpret the TIFF input.  So the set of files
it is able to interpret is determined mostly by that library.

<p>This program cannot read every possible TIFF file -- there are
myriad variations of the TIFF format.  However, it does understand
monochrome and gray scale, RGB, RGBA (red/green/blue with transparency
channel), CMYK (Cyan-Magenta-Yellow-Black ink color separation), and
color palette TIFF files.  An RGB file can have either single plane
(interleaved) color or multiple plane format.  The program reads 1-8
and 16 bit-per-sample input, the latter in either bigendian or
littlendian encoding.  Tiff directory information may also be either
bigendian or littlendian.

<p>There are many TIFF formats that <b>tifftopnm</b> can read only if
the image is small enough to fit in memory.  <b>tifftopnm</b> uses the
TIFF library's TIFFRGBAImageGet() function to process the TIFF image
if it can get enough memory for TIFFRGBAImageGet() to store the whole
image in memory at once (that's what TIFFRGBAImageGet() does).  If
not, <b>tifftopnm</b> uses a more primitive row-by-row conversion
strategy using the raw data returned by TIFFReadScanLine() and native
intelligence.  That native intelligence does not know as many formats
as TIFFRGBAImageGet() does.  And certain compressed formats simply
cannot be read with TIFFReadScanLine().

<p>Before Netpbm 10.11 (October 2002), <b>tifftopnm</b> never used
TIFFRGBAImageGet(), so it could not interpret many of the formats it
can interpret today.

<p>There is no fundamental reason that this program could not read
other kinds of TIFF files even when they don't fit in memory all at
once.  The existing limitations are mainly because no one has asked
for more.

<h3 id="output">Output Image</h3>

<p>The PNM output has the same maxval as the Tiff input, except that
if the Tiff input is colormapped (which implies a maxval of 65535) the
PNM output has a maxval of 255.  Though this may result in lost
information, such input images hardly ever actually have more color
resolution than a maxval of 255 provides and people often cannot deal
with PNM files that have maxval &gt; 255.  By contrast, a
non-colormapped Tiff image that doesn't need a maxval &gt; 255 doesn't
<em>have</em> a maxval &gt; 255, so when <b>tifftopnm</b> sees a
non-colormapped maxval &gt; 255, it takes it seriously and produces a
matching output maxval.

<p>Another exception is where the TIFF maxval is greater than 65535,
which is the maximum allowed by the Netpbm formats.  In that case,
<b>tifftopnm</b> uses a maxval of 65535, and you lose some information
in the conversion.

<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>tifftopnm</b> recognizes the following
command line options:

<p>You may abbreviate any option to its shortest unique prefix.  You may use
two hyphens instead of one in options.  You may separate an option and
its value either by an equals sign or white space.

<dl compact>
<dt><b>-alphaout=</b><i>alpha-filename</i>

<dd><b>tifftopnm </b>creates a PGM file containing the alpha channel
values in the input image.  If the input image doesn't contain a
transparency channel, the <i>alpha-filename</i> file contains all zero
(transparent) transparency values.  If you don't specify <b>-alphaout</b>,

<b>tifftopnm</b> does not generate a transparency file, and if the input
image has an transparency channel, <b>tifftopnm</b> simply discards it.

<p>If you specify <b>-</b> as the filename, <b>tifftopnm</b>
writes the transparency output to Standard Output and discards the image.

<p>See <b><a href="pamcomp.html">pamcomp</a></b> for one way to use
the transparency output file.

<dt><b>-respectfillorder</b>

<dd>By default, <b>tifftopnm </b> ignores the "fillorder"
tag in the TIFF input, which means it may incorrectly interpret the
image.  To make it follow the spec, use this option.  For a lengthy
but engaging discussion of why <b>tifftopnm</b> works this way and how
to use the <b>-respectfillorder</b> option, see the note on fillorder
below.  

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

<dd>This option can make <b>tifftopnm</b> run faster.

<p><b>tifftopnm</b> has two ways to do the conversion from Tiff to PNM, using
respectively two facilities of the TIFF library:

<dl>

<dt>Whole Image

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

</dl>

<p>Whole Image is preferable because the Tiff library does more of the
work, which means it understands more of the Tiff format possibilities
now and in the future.  Also, some compressed TIFF formats don't allow
you to extract an individual row.

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

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

<p>In Netpbm, we stress function over performance, so by default we
try Whole Image first, and if we can't get enough memory for the
decoded image or <b>TIFFRGBAImageGet()</b> fails, we fall back to Row By Row.
But if you specify the <b>-byrow</b> option, <b>tifftopnm</b> will not
attempt Whole Image.  If Row By Row does not work, it simply fails.

<p>See <a href="#cmyk">Color Separation (CMYK) TIFFs</a> for a
description of one way Row By Row makes a significant difference in
your results.

<p>Whole Image costs you precision when your TIFF image uses more than
8 bits per sample.  <b>TIFFRGBAImageGet()</b> converts the samples to 8 bits.
<b>tifftopnm</b> then scales them back to maxval 65535, but the lower
8 bits of information is gone.

<p>In many versions of the TIFF library, <b>TIFFRGBAImageGet()</b> does not
correctly interpret TIFF files in which the raster orientation is
column-major (i.e. a row of the raster is a column of the image).
With such a TIFF library and file, you must use <b>-byrow</b> to get
correct output.

<p>Before Netpbm 10.11 (October 2002), <b>tifftopnm</b> always did Row
By Row.  Netpbm 10.12 always tried Whole Image first.  <b>-byrow</b>
came in with Netpbm 10.13 (January 2003).

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

<p><b>-orientraw</b> says to produce an output image that represents the raw
raster in the TIFF stream rather than the image the TIFF stream is supposed to
represent.  In the output, the top left corner corresponds to the start of the
TIFF raster, the next pixel to the right is the next pixel in the TIFF raster,
etc.  <b>tifftopnm</b> can do this easily, but you don't get the right image
out.  You can use <b>pamflip</b> to turn the output into the image the TIFF
stream represents (but if you do that, you pretty much lose the benefit of
<b>-orientraw</b>).

<p>With this option, <b>tifftopnm</b> always uses the Row By Row method
(see <b>-byrow</b>).

<p>This option was new in Netpbm 10.42 (March 2008).  Before that,
<b>tifftopnm</b> generally produces arbitrary results with TIFF images
that have an orientation other than the common one.

<dt><b>-verbose</b>

<dd>Print extra messages to Standard Error about the conversion.

<dt><b>-headerdump</b>

<dd>Dump TIFF file information to stderr.  This information may be useful 
in debugging TIFF file conversion problems.  

</dl>

<h2 id="notes">NOTES</h2>

<h3 id="fillorder">Fillorder</h3>

<p>
There is a piece of information in the header of a TIFF image called
"fillorder." The TIFF specification quite clearly states
that this value tells the order in which bits are arranged in a byte
in the description of the image's pixels.  There are two options,
assuming that the image has a format where more than one pixel can be
represented by a single byte: 1) the byte is filled from most
significant bit to least significant bit going left to right in the
image; and 2) the opposite.
<p>
However, there is confusion in the world as to the meaning of
fillorder.  Evidence shows that some people believe it has to do with
byte order when a single value is represented by two bytes.
<p>
These people cause TIFF images to be created that, while they use a 
MSB-to-LSB fillorder, have a fillorder tag that says they used LSB-to-MSB.
A program that properly interprets a TIFF image will not end up with the
image that the author intended in this case.
<p>
For a long time, <b>tifftopnm</b> did not understand fillorder itself
and assumed the fillorder was MSB-to-LSB regardless of the fillorder
tag in the TIFF header.  And as far as I know, there is no legitimate
reason to use a fillorder other than MSB-to-LSB.  So users of
<b>tifftopnm</b> were happily using those TIFF images that had
incorrect fillorder tags.
<p>
So that those users can continue to be happy, <b>tifftopnm</b> today
continues to ignore the fillorder tag unless you tell it not to.  (It
does, however, warn you when the fillorder tag does not say MSB-to-LSB
that the tag is being ignored).
<p>
If for some reason you have a TIFF image that actually has LSB-to-MSB
fillorder, and its fillorder tag correctly indicates that, you must
use the <b>-respectfillorder</b> option on <b>tifftopnm</b> to get
proper results.
<p>
Examples of incorrect TIFF images are at <a
href="ftp://weather.noaa.gov.">ftp://weather.noaa.gov.</a> They are
apparently created by a program called <b>faxtotiff</b>.

<p>
This note was written on January 1, 2002.


<h3 id="cmyk">Color Separation (CMYK) TIFFs</h3>

<p>Some TIFF images contain color information in CMYK form, whereas PNM
images use RGB.  There are various formulas for converting between these
two forms, and <b>tifftopnm</b> can use either of two.

<p>The TIFF library (Version 3.5.4 from libtiff.org) uses
Y=(1-K)*(1-B) (similar for R and G) in its TIFFRGBAImageGet() service.
When <b>tifftopnm</b> works in Whole Image mode, it uses that service,
so that's the conversion you get.

<p>But when <b>tifftopnm</b> runs in Row By Row mode, it does not use
TIFFRGBAImageGet(), and you get what appears to be more useful:
Y=1-(B+K).  This is the inverse of what <b>pnmtotiffcmyk</b> does.

<p>See the <b>-byrow</b> option for more information on Whole Image versus
Row By Row mode.

<p>Before Netpbm 10.21 (March 2004), <b>tifftopnm</b> used the
Y=(1-K)*(1-B) formula always.


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

<b><a href="pnmtotiff.html">pnmtotiff</a></b>,
<b><a href="pnmtotiffcmyk.html">pnmtotiffcmyk</a></b>,
<b><a href="pamcomp.html">pamcomp</a></b>,
<b><a href="pnm.html">pnm</a></b>

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

<p>Derived by Jef Poskanzer from tif2ras.c, which is Copyright (c)
1990 by Sun Microsystems, Inc.  Author: Patrick J. Naughton (<a
href="mailto:naughton@wind.sun.com">naughton@wind.sun.com</a>).

<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="#library">TIFF Capability</a>
  <li><a href="#output">Output Image</a>
  </ul>
<li><a href="#options">OPTIONS</a>
<li><a href="#notes">NOTES</a>
  <ul>
  <li><a href="#fillorder">Fillorder</a>
  <li><a href="#cmyk">Color Separation (CMYK) TIFFs</a>
  </ul>
<li><a href="#seealso">SEE ALSO</a>
<li><a href="#author">AUTHOR</a>
</ul>
</body>
</html>