@@ -151,7 +151,7 @@ main(int argc, char* argv[])
151
151
multiplefiles = (argc - optind > 1 );
152
152
for (; optind < argc ; optind ++ ) {
153
153
if (multiplefiles )
154
- printf ("%s:\n" , argv [optind ]);
154
+ printf ("File %s:\n" , argv [optind ]);
155
155
tif = TIFFOpen (argv [optind ], chopstrips ? "rC" : "rc" );
156
156
if (tif != NULL ) {
157
157
if (dirnum != -1 ) {
@@ -168,6 +168,7 @@ main(int argc, char* argv[])
168
168
tiffinfo (tif , order , flags , 1 );
169
169
if (TIFFGetField (tif , TIFFTAG_EXIFIFD ,
170
170
& offset )) {
171
+ printf ("--- EXIF directory within directory %d \n" , curdir );
171
172
if (TIFFReadEXIFDirectory (tif , offset )) {
172
173
tiffinfo (tif , order , flags , 0 );
173
174
/*-- Go back to previous directory, (directory is reloaded from file!) */
@@ -176,11 +177,43 @@ main(int argc, char* argv[])
176
177
}
177
178
if (TIFFGetField (tif , TIFFTAG_GPSIFD ,
178
179
& offset )) {
180
+ printf ("--- GPS directory within directory %d \n" , curdir );
179
181
if (TIFFReadGPSDirectory (tif , offset )) {
180
182
tiffinfo (tif , order , flags , 0 );
181
183
TIFFSetDirectory (tif , curdir );
182
184
}
183
185
}
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" );
184
217
} while (TIFFReadDirectory (tif ));
185
218
}
186
219
TIFFClose (tif );
0 commit comments