Skip to content

Commit fa99e8c

Browse files
SuLausrouault
authored andcommitted
tiffinfo: Updated to parse through SubIFDs and show their tags.
1 parent 47e61f6 commit fa99e8c

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
lines changed

test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,7 @@ add_reader_test(tiffdump "" "images/miniswhite-1c-1b.tiff")
372372
# tiffinfo
373373
add_reader_test(tiffinfo "-c -D -d -j -s" "images/custom_dir_EXIF_GPS.tiff")
374374
add_reader_test(tiffinfo "-c -D -d -j -s" "images/minisblack-1c-16b.tiff")
375+
add_reader_test(tiffinfo " " "images/tiff_with_subifd_chain.tif")
375376

376377
# tiffcp split/join
377378
foreach(image ${UNCOMPRESSEDIMAGES})

test/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ IMAGES_EXTRA_DIST = \
209209
images/miniswhite-1c-1b.g3 \
210210
images/test_float64_predictor2_le_lzw.tif \
211211
images/test_float64_predictor2_be_lzw.tif \
212+
images/tiff_with_subifd_chain.tif \
212213
$(PNMIMAGES) \
213214
$(TIFFIMAGES)
214215

test/common.sh

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ IMG_MINISWHITE_1C_1B_PBM=${IMAGES}/miniswhite-1c-1b.pbm
4848
IMG_MINISBLACK_1C_8B_PGM=${IMAGES}/minisblack-1c-8b.pgm
4949
IMG_RGB_3C_16B_PPM=${IMAGES}/rgb-3c-16b.ppm
5050
IMG_RGB_3C_8B_PPM=${IMAGES}/rgb-3c-8b.ppm
51+
IMG_TIFF_WITH_SUBIFD_CHAIN=${IMAGES}/tiff_with_subifd_chain.tif
5152

5253
# All uncompressed image files
5354
IMG_UNCOMPRESSED="${IMG_MINISBLACK_1C_16B} ${IMG_MINISBLACK_1C_8B} ${IMG_MINISWHITE_1C_1B} ${IMG_PALETTE_1C_1B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_4B} ${IMG_PALETTE_1C_8B} ${IMG_RGB_3C_8B} ${IMG_RGB_3C_16B}"
19 KB
Binary file not shown.

test/tiffinfo.sh

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
#
55
. ${srcdir:-.}/common.sh
66
f_test_reader "${TIFFINFO} -c -D -d -j -s " "${IMG_MINISBLACK_1C_16B}"
7+
f_test_reader "${TIFFINFO} " "${IMG_TIFF_WITH_SUBIFD_CHAIN}"

tools/tiffinfo.c

+34-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ main(int argc, char* argv[])
151151
multiplefiles = (argc - optind > 1);
152152
for (; optind < argc; optind++) {
153153
if (multiplefiles)
154-
printf("%s:\n", argv[optind]);
154+
printf("File %s:\n", argv[optind]);
155155
tif = TIFFOpen(argv[optind], chopstrips ? "rC" : "rc");
156156
if (tif != NULL) {
157157
if (dirnum != -1) {
@@ -168,6 +168,7 @@ main(int argc, char* argv[])
168168
tiffinfo(tif, order, flags, 1);
169169
if (TIFFGetField(tif, TIFFTAG_EXIFIFD,
170170
&offset)) {
171+
printf("--- EXIF directory within directory %d \n", curdir);
171172
if (TIFFReadEXIFDirectory(tif, offset)) {
172173
tiffinfo(tif, order, flags, 0);
173174
/*-- Go back to previous directory, (directory is reloaded from file!) */
@@ -176,11 +177,43 @@ main(int argc, char* argv[])
176177
}
177178
if (TIFFGetField(tif, TIFFTAG_GPSIFD,
178179
&offset)) {
180+
printf("--- GPS directory within directory %d \n", curdir);
179181
if (TIFFReadGPSDirectory(tif, offset)) {
180182
tiffinfo(tif, order, flags, 0);
181183
TIFFSetDirectory(tif, curdir);
182184
}
183185
}
186+
/*-- Check for SubIFDs --*/
187+
uint16_t nCount;
188+
void *vPtr;
189+
uint64_t *subIFDoffsets = NULL;
190+
if (TIFFGetField(tif, TIFFTAG_SUBIFD, &nCount, &vPtr)) {
191+
if (nCount > 0) {
192+
subIFDoffsets = malloc(nCount * sizeof(uint64_t));
193+
if (subIFDoffsets != NULL) {
194+
memcpy(subIFDoffsets, vPtr, nCount * sizeof(subIFDoffsets[0]));
195+
printf("--- SubIFD image descriptor tag within TIFF directory %d with array of %d SubIFD chains ---\n", curdir, nCount);
196+
for (int i = 0; i < nCount; i++) {
197+
offset = subIFDoffsets[i];
198+
int s = 0;
199+
if (TIFFSetSubDirectory(tif, offset)) {
200+
/* print info and check for SubIFD chain */
201+
do {
202+
printf("--- SubIFD %d of chain %d at offset 0x%"PRIx64" (%"PRIu64"):\n", s, i, offset, offset);
203+
tiffinfo(tif, order, flags, 0);
204+
s++;
205+
} while (TIFFReadDirectory(tif));
206+
}
207+
}
208+
TIFFSetDirectory(tif, curdir);
209+
free(subIFDoffsets);
210+
subIFDoffsets = NULL;
211+
} else {
212+
fprintf(stderr, "Error: Could not allocate memory for SubIFDs list. SubIFDs not parsed.\n");
213+
}
214+
}
215+
}
216+
printf("\n");
184217
} while (TIFFReadDirectory(tif));
185218
}
186219
TIFFClose(tif);

0 commit comments

Comments
 (0)