]>
git.saurik.com Git - wxWidgets.git/blob - src/tiff/tools/tiffinfo.c
4 * Copyright (c) 1988-1997 Sam Leffler
5 * Copyright (c) 1991-1997 Silicon Graphics, Inc.
7 * Permission to use, copy, modify, distribute, and sell this software and
8 * its documentation for any purpose is hereby granted without fee, provided
9 * that (i) the above copyright notices and this permission notice appear in
10 * all copies of the software and related documentation, and (ii) the names of
11 * Sam Leffler and Silicon Graphics may not be used in any advertising or
12 * publicity relating to the software without the specific, prior written
13 * permission of Sam Leffler and Silicon Graphics.
15 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
17 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
19 * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
20 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
21 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
22 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
23 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
27 #include "tif_config.h"
43 #define streq(a,b) (strcasecmp(a,b) == 0)
45 int showdata
= 0; /* show data */
46 int rawdata
= 0; /* show raw/decoded data */
47 int showwords
= 0; /* show data as bytes/words */
48 int readdata
= 0; /* read data in file */
49 int stoponerr
= 1; /* stop on first read error */
51 static void usage(void);
52 static void tiffinfo(TIFF
*, uint16
, long);
55 main(int argc
, char* argv
[])
57 int dirnum
= -1, multiplefiles
, c
;
64 int chopstrips
= 0; /* disable strip chopping */
66 while ((c
= getopt(argc
, argv
, "f:o:cdDSjilmrsvwz0123456789")) != -1)
68 case '0': case '1': case '2': case '3':
69 case '4': case '5': case '6': case '7':
71 dirnum
= atoi(&argv
[optind
-1][1]);
80 flags
|= TIFFPRINT_COLORMAP
| TIFFPRINT_CURVES
;
82 case 'f': /* fill order */
83 if (streq(optarg
, "lsb2msb"))
84 order
= FILLORDER_LSB2MSB
;
85 else if (streq(optarg
, "msb2lsb"))
86 order
= FILLORDER_MSB2LSB
;
94 diroff
= strtoul(optarg
, NULL
, 0);
97 flags
|= TIFFPRINT_JPEGQTABLES
|
98 TIFFPRINT_JPEGACTABLES
|
99 TIFFPRINT_JPEGDCTABLES
;
105 flags
|= TIFFPRINT_STRIPS
;
119 multiplefiles
= (argc
- optind
> 1);
120 for (; optind
< argc
; optind
++) {
122 printf("%s:\n", argv
[optind
]);
123 tif
= TIFFOpen(argv
[optind
], chopstrips
? "rC" : "rc");
126 if (TIFFSetDirectory(tif
, (tdir_t
) dirnum
))
127 tiffinfo(tif
, order
, flags
);
128 } else if (diroff
!= 0) {
129 if (TIFFSetSubDirectory(tif
, diroff
))
130 tiffinfo(tif
, order
, flags
);
135 tiffinfo(tif
, order
, flags
);
136 if (TIFFGetField(tif
, TIFFTAG_EXIFIFD
,
138 if (TIFFReadEXIFDirectory(tif
, offset
))
139 tiffinfo(tif
, order
, flags
);
141 } while (TIFFReadDirectory(tif
));
150 "usage: tiffinfo [options] input...",
151 "where options are:",
153 " -i ignore read errors",
154 " -c display data for grey/color response curve or colormap",
155 " -d display raw/decoded image data",
156 " -f lsb2msb force lsb-to-msb FillOrder for input",
157 " -f msb2lsb force msb-to-lsb FillOrder for input",
158 " -j show JPEG tables",
159 " -o offset set initial directory offset",
160 " -r read/display raw image data instead of decoded data",
161 " -s display strip offsets and byte counts",
162 " -w display raw data in words rather than bytes",
163 " -z enable strip chopping",
164 " -# set initial directory (first directory is # 0)",
175 fprintf(stderr
, "%s\n\n", TIFFGetVersion());
176 for (i
= 0; stuff
[i
] != NULL
; i
++)
177 fprintf(stderr
, "%s\n", stuff
[i
]);
182 ShowStrip(tstrip_t strip
, unsigned char* pp
, uint32 nrow
, tsize_t scanline
)
186 printf("Strip %lu:\n", (unsigned long) strip
);
188 for (cc
= 0; cc
< scanline
; cc
++) {
189 printf(" %02x", *pp
++);
190 if (((cc
+1) % 24) == 0)
198 TIFFReadContigStripData(TIFF
* tif
)
201 tsize_t scanline
= TIFFScanlineSize(tif
);
203 buf
= (unsigned char *)_TIFFmalloc(TIFFStripSize(tif
));
206 uint32 rowsperstrip
= (uint32
)-1;
208 TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &h
);
209 TIFFGetField(tif
, TIFFTAG_ROWSPERSTRIP
, &rowsperstrip
);
210 for (row
= 0; row
< h
; row
+= rowsperstrip
) {
211 uint32 nrow
= (row
+rowsperstrip
> h
?
212 h
-row
: rowsperstrip
);
213 tstrip_t strip
= TIFFComputeStrip(tif
, row
, 0);
214 if (TIFFReadEncodedStrip(tif
, strip
, buf
, nrow
*scanline
) < 0) {
218 ShowStrip(strip
, buf
, nrow
, scanline
);
225 TIFFReadSeparateStripData(TIFF
* tif
)
228 tsize_t scanline
= TIFFScanlineSize(tif
);
230 buf
= (unsigned char *)_TIFFmalloc(TIFFStripSize(tif
));
233 uint32 rowsperstrip
= (uint32
)-1;
234 tsample_t s
, samplesperpixel
;
236 TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &h
);
237 TIFFGetField(tif
, TIFFTAG_ROWSPERSTRIP
, &rowsperstrip
);
238 TIFFGetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, &samplesperpixel
);
239 for (row
= 0; row
< h
; row
+= rowsperstrip
) {
240 for (s
= 0; s
< samplesperpixel
; s
++) {
241 uint32 nrow
= (row
+rowsperstrip
> h
?
242 h
-row
: rowsperstrip
);
243 tstrip_t strip
= TIFFComputeStrip(tif
, row
, s
);
244 if (TIFFReadEncodedStrip(tif
, strip
, buf
, nrow
*scanline
) < 0) {
248 ShowStrip(strip
, buf
, nrow
, scanline
);
256 ShowTile(uint32 row
, uint32 col
, tsample_t sample
,
257 unsigned char* pp
, uint32 nrow
, uint32 rowsize
)
261 printf("Tile (%lu,%lu", (unsigned long) row
, (unsigned long) col
);
262 if (sample
!= (tsample_t
) -1)
263 printf(",%u", sample
);
266 for (cc
= 0; cc
< rowsize
; cc
++) {
267 printf(" %02x", *pp
++);
268 if (((cc
+1) % 24) == 0)
276 TIFFReadContigTileData(TIFF
* tif
)
279 tsize_t rowsize
= TIFFTileRowSize(tif
);
281 buf
= (unsigned char *)_TIFFmalloc(TIFFTileSize(tif
));
286 TIFFGetField(tif
, TIFFTAG_IMAGEWIDTH
, &w
);
287 TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &h
);
288 TIFFGetField(tif
, TIFFTAG_TILEWIDTH
, &tw
);
289 TIFFGetField(tif
, TIFFTAG_TILELENGTH
, &th
);
290 for (row
= 0; row
< h
; row
+= th
) {
291 for (col
= 0; col
< w
; col
+= tw
) {
292 if (TIFFReadTile(tif
, buf
, col
, row
, 0, 0) < 0) {
296 ShowTile(row
, col
, (tsample_t
) -1, buf
, th
, rowsize
);
304 TIFFReadSeparateTileData(TIFF
* tif
)
307 tsize_t rowsize
= TIFFTileRowSize(tif
);
309 buf
= (unsigned char *)_TIFFmalloc(TIFFTileSize(tif
));
313 tsample_t s
, samplesperpixel
;
315 TIFFGetField(tif
, TIFFTAG_IMAGEWIDTH
, &w
);
316 TIFFGetField(tif
, TIFFTAG_IMAGELENGTH
, &h
);
317 TIFFGetField(tif
, TIFFTAG_TILEWIDTH
, &tw
);
318 TIFFGetField(tif
, TIFFTAG_TILELENGTH
, &th
);
319 TIFFGetField(tif
, TIFFTAG_SAMPLESPERPIXEL
, &samplesperpixel
);
320 for (row
= 0; row
< h
; row
+= th
) {
321 for (col
= 0; col
< w
; col
+= tw
) {
322 for (s
= 0; s
< samplesperpixel
; s
++) {
323 if (TIFFReadTile(tif
, buf
, col
, row
, 0, s
) < 0) {
327 ShowTile(row
, col
, s
, buf
, th
, rowsize
);
336 TIFFReadData(TIFF
* tif
)
340 TIFFGetField(tif
, TIFFTAG_PLANARCONFIG
, &config
);
341 if (TIFFIsTiled(tif
)) {
342 if (config
== PLANARCONFIG_CONTIG
)
343 TIFFReadContigTileData(tif
);
345 TIFFReadSeparateTileData(tif
);
347 if (config
== PLANARCONFIG_CONTIG
)
348 TIFFReadContigStripData(tif
);
350 TIFFReadSeparateStripData(tif
);
355 ShowRawBytes(unsigned char* pp
, uint32 n
)
359 for (i
= 0; i
< n
; i
++) {
360 printf(" %02x", *pp
++);
361 if (((i
+1) % 24) == 0)
368 ShowRawWords(uint16
* pp
, uint32 n
)
372 for (i
= 0; i
< n
; i
++) {
373 printf(" %04x", *pp
++);
374 if (((i
+1) % 15) == 0)
381 TIFFReadRawData(TIFF
* tif
, int bitrev
)
383 tstrip_t nstrips
= TIFFNumberOfStrips(tif
);
384 const char* what
= TIFFIsTiled(tif
) ? "Tile" : "Strip";
387 TIFFGetField(tif
, TIFFTAG_STRIPBYTECOUNTS
, &stripbc
);
389 uint32 bufsize
= stripbc
[0];
390 tdata_t buf
= _TIFFmalloc(bufsize
);
393 for (s
= 0; s
< nstrips
; s
++) {
394 if (stripbc
[s
] > bufsize
) {
395 buf
= _TIFFrealloc(buf
, stripbc
[s
]);
396 bufsize
= stripbc
[s
];
400 "Cannot allocate buffer to read strip %lu\n",
404 if (TIFFReadRawStrip(tif
, s
, buf
, stripbc
[s
]) < 0) {
405 fprintf(stderr
, "Error reading strip %lu\n",
409 } else if (showdata
) {
411 TIFFReverseBits(buf
, stripbc
[s
]);
412 printf("%s %lu: (bit reversed)\n ",
413 what
, (unsigned long) s
);
415 printf("%s %lu:\n ", what
,
418 ShowRawWords((uint16
*) buf
, stripbc
[s
]>>1);
420 ShowRawBytes((unsigned char*) buf
, stripbc
[s
]);
429 tiffinfo(TIFF
* tif
, uint16 order
, long flags
)
431 TIFFPrintDirectory(tif
, stdout
, flags
);
437 TIFFGetFieldDefaulted(tif
,
438 TIFFTAG_FILLORDER
, &o
);
439 TIFFReadRawData(tif
, o
!= order
);
441 TIFFReadRawData(tif
, 0);
444 TIFFSetField(tif
, TIFFTAG_FILLORDER
, order
);
449 /* vim: set ts=8 sts=8 sw=8 noet: */