nicer way to avoid reading data for non-image directories

This commit is contained in:
Frank Warmerdam 2012-06-06 06:05:29 +00:00
parent 7e632eb41c
commit b246f148ff

View File

@ -1,4 +1,4 @@
/* $Id: tiffinfo.c,v 1.20 2012-06-01 23:22:54 fwarmerdam Exp $ */ /* $Id: tiffinfo.c,v 1.21 2012-06-06 06:05:29 fwarmerdam Exp $ */
/* /*
* Copyright (c) 1988-1997 Sam Leffler * Copyright (c) 1988-1997 Sam Leffler
@ -53,7 +53,7 @@ static int readdata = 0; /* read data in file */
static int stoponerr = 1; /* stop on first read error */ static int stoponerr = 1; /* stop on first read error */
static void usage(void); static void usage(void);
static void tiffinfo(TIFF*, uint16, long); static void tiffinfo(TIFF*, uint16, long, int);
static void static void
PrivateErrorHandler(const char* module, const char* fmt, va_list ap) PrivateErrorHandler(const char* module, const char* fmt, va_list ap)
@ -139,22 +139,19 @@ main(int argc, char* argv[])
if (tif != NULL) { if (tif != NULL) {
if (dirnum != -1) { if (dirnum != -1) {
if (TIFFSetDirectory(tif, (tdir_t) dirnum)) if (TIFFSetDirectory(tif, (tdir_t) dirnum))
tiffinfo(tif, order, flags); tiffinfo(tif, order, flags, 1);
} else if (diroff != 0) { } else if (diroff != 0) {
if (TIFFSetSubDirectory(tif, diroff)) if (TIFFSetSubDirectory(tif, diroff))
tiffinfo(tif, order, flags); tiffinfo(tif, order, flags, 1);
} else { } else {
do { do {
toff_t offset; toff_t offset;
tiffinfo(tif, order, flags); tiffinfo(tif, order, flags, 1);
if (TIFFGetField(tif, TIFFTAG_EXIFIFD, if (TIFFGetField(tif, TIFFTAG_EXIFIFD,
&offset)) { &offset)) {
if (TIFFReadEXIFDirectory(tif, offset)) { if (TIFFReadEXIFDirectory(tif, offset)) {
int old_readdata = readdata; tiffinfo(tif, order, flags, 0);
readdata = 0;
tiffinfo(tif, order, flags);
readdata = old_readdata;
} }
} }
} while (TIFFReadDirectory(tif)); } while (TIFFReadDirectory(tif));
@ -445,10 +442,10 @@ TIFFReadRawData(TIFF* tif, int bitrev)
} }
static void static void
tiffinfo(TIFF* tif, uint16 order, long flags) tiffinfo(TIFF* tif, uint16 order, long flags, int is_image)
{ {
TIFFPrintDirectory(tif, stdout, flags); TIFFPrintDirectory(tif, stdout, flags);
if (!readdata) if (!readdata || !is_image)
return; return;
if (rawdata) { if (rawdata) {
if (order) { if (order) {