-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprint.c
3268 lines (3088 loc) · 108 KB
/
print.c
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
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
/* EXIFPROBE - TIFF/JPEG/EXIF image file probe */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
/* Copyright (C) 2002,2005 by Duane H. Hesser. All rights reserved. */
/* */
/* See the file LICENSE.EXIFPROBE for terms of use. */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
#ifndef lint
static char *ModuleId = "@(#) $Id: print.c,v 1.51 2005/07/24 17:16:59 alex Exp $";
#endif
/* This file contains the primary "print" routines for TIFF/EXIF */
/* data, file offsets, etc. */
#define _DEFAULT_SOURCE /* for isacii() */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "defs.h"
#include "datadefs.h"
#include "summary.h"
#include "misc.h"
#include "tags.h"
#include "extern.h"
#include "maker_extern.h"
#include "ciff_extern.h"
#include "jp2_extern.h"
#include "mrw_extern.h"
/* Print the "header" information from the beginning of a file which */
/* identifies the image type and/or image characteristics. Return 0 */
/* if all goes well, -1 if no header is passed or the header magic */
/* number is invlid. */
int
print_header(struct fileheader *header,unsigned long section_id)
{
int status = -1;
int chpr = 0;
if(header)
{
switch(header->probe_magic)
{
case JPEG_SOI:
if(Print_options & section_id)
chpr += printf("JPEG SOI %#06x",header->file_marker);
status = 0;
chpr = newline(chpr);
break;
case ORF1_MAGIC:
status = print_tiff_header(ORF1_MAGIC,header->file_marker,section_id);
/* no newline */
break;
case ORF2_MAGIC:
status = print_tiff_header(ORF2_MAGIC,header->file_marker,section_id);
/* no newline */
break;
case RW2_MAGIC:
status = print_tiff_header(RW2_MAGIC,header->file_marker,section_id);
/* no newline */
break;
case TIFF_MAGIC:
status = print_tiff_header(TIFF_MAGIC,header->file_marker,section_id);
/* no newline */
break;
case PROBE_CIFFMAGIC:
status = print_ciff_header(header,section_id);
chpr = newline(chpr);
break;
case PROBE_JP2MAGIC:
status = print_jp2_header(header,section_id);
chpr = newline(chpr);
break;
case PROBE_MRWMAGIC:
status = print_mrw_header(header,section_id);
chpr = newline(chpr);
break;
case PROBE_RAFMAGIC:
chpr = printf("FUJIFILMCCD-RAW ");
chpr = newline(chpr);
break;
default:
if(Print_options & section_id)
chpr += printf("UNKNOWN HEADER MAGIC %#06lx",header->probe_magic);
chpr = newline(chpr);
break;
}
}
else
fprintf(stderr,"%s: null fileheader to print_header()\n",Progname);
return(status);
}
/* Print TIFF header information if options permit. Return 0 if */
/* information is valid to print or does not need to be printed for */
/* the identified section id. Return -1 if the magic number or */
/* byteorder are invalid. */
int
print_tiff_header(unsigned short magic,unsigned short byteorder,unsigned long section_id)
{
char *name = CNULL;
int status = -1;
int chpr = 0;
if(Print_options & section_id)
{
switch(magic)
{
case TIFF_MAGIC: name = "TIFF"; break;
case ORF1_MAGIC: name = "ORF1"; break;
case ORF2_MAGIC: name = "ORF2"; break;
case RW2_MAGIC: name = "RW2"; break;
default: break;
}
if(name)
{
chpr += printf("%s",name);
switch(byteorder)
{
case TIFF_INTEL:
case TIFF_MOTOROLA:
print_byteorder(byteorder,1);
print_magic((unsigned long)magic,2);
status = 0;
break;
default:
chpr += printf("INVALID %s BYTEORDER ",name);
print_byteorder(byteorder,1);
print_magic((unsigned long)magic,2);
break;
}
}
else
{
chpr += printf("INVALID TIFF IDENTIFIER, byteorder ");
print_byteorder(byteorder,1);
print_magic((unsigned long)magic,2);
}
}
else
status = 0;
setcharsprinted(chpr);
return(status);
}
/* Print the file type as indicated by the "header" information at */
/* the start of the file. */
int
print_filetype(unsigned long magic,unsigned short marker)
{
int status = -1;
int chpr = 0;
switch(magic)
{
case JPEG_SOI:
chpr += printf("JPEG");
status = 0;
break;
case ORF1_MAGIC:
chpr += printf("ORF1");
switch(marker)
{
case TIFF_INTEL:
chpr += printf(":II");
break;
case TIFF_MOTOROLA:
chpr += printf(":MM");
break;
default:
break;
}
status = 0;
break;
case ORF2_MAGIC:
chpr += printf("ORF2");
switch(marker)
{
case TIFF_INTEL:
chpr += printf(":II");
break;
case TIFF_MOTOROLA:
chpr += printf(":MM");
break;
default:
break;
}
status = 0;
break;
case RW2_MAGIC:
chpr += printf("RW2");
switch(marker)
{
case TIFF_INTEL:
chpr += printf(":II");
break;
case TIFF_MOTOROLA:
chpr += printf(":MM");
break;
default:
break;
}
status = 0;
break;
case TIFF_MAGIC:
chpr += printf("TIFF");
switch(marker)
{
case TIFF_INTEL:
chpr += printf(":II");
break;
case TIFF_MOTOROLA:
chpr += printf(":MM");
break;
default:
break;
}
status = 0;
break;
case PROBE_CIFFMAGIC:
chpr += printf("CIFF");
switch(marker)
{
case TIFF_INTEL:
chpr += printf(":II");
break;
case TIFF_MOTOROLA:
chpr += printf(":MM");
break;
default:
break;
}
status = 0;
break;
case PROBE_JP2MAGIC:
chpr += printf("JP2");
status = 0;
break;
case PROBE_MRWMAGIC:
chpr += printf("MRW");
status = 0;
break;
case PROBE_RAFMAGIC:
chpr += printf("RAF");
status = 0;
break;
case PROBE_X3FMAGIC:
chpr += printf("X3F");
status = 0;
break;
default:
chpr += printf("UNKNOWN");
break;
}
setcharsprinted(chpr);
return(status);
}
/* Print an address in the file (offset from beginning of file), in */
/* hex, decimal, or both, offset from left margin by 'indent' spaces. */
/* "Addresses" are usually prefixed by an "@", but may be prefixed by */
/* a string passed as argument (this is normally used to pass a '-' */
/* prefix to mark the end of a segment, or something to flag an */
/* out-of-order segment). */
/* If this routine is called with all PRINT_ADDRESS bits off, it */
/* produces only the indent. */
void
print_tag_address(unsigned long section_id,unsigned long address,int indent,char *prefix)
{
int chpr = 0;
if(Print_options & section_id)
{
print_filename();
if(PRINT_INDENT_BEFORE_ADDRESS)
putindent(indent);
if(!prefix)
prefix = "@";
if(address == HERE)
{
/* special case; bland address field */
if(PRINT_BOTH_ADDRESS)
chpr += printf("%*s: ",(ADDRWIDTH * 2) + 3,prefix);
else if(PRINT_HEX_ADDRESS)
chpr += printf("%*s: ",ADDRWIDTH + 1,prefix);
else if(PRINT_DEC_ADDRESS)
chpr += printf("%*s: ",ADDRWIDTH,prefix);
}
else
{
if(PRINT_BOTH_ADDRESS)
chpr += printf("%s%#0*lx=%-*lu: ",prefix,ADDRWIDTH+1,address,ADDRWIDTH,address);
else if(PRINT_HEX_ADDRESS)
chpr += printf("%s%#0*lx: ",prefix,ADDRWIDTH+1,address);
else if(PRINT_DEC_ADDRESS)
chpr += printf("%s%-*lu: ",prefix,ADDRWIDTH,address);
}
if(PRINT_INDENT_AFTER_ADDRESS)
putindent(indent);
setcharsprinted(chpr);
}
}
/* Print the option-selected items in a TIFF IFD entry, including the */
/* tag number, tag name, tag type, and offset or value. If the */
/* "value" doesn't fit in 4 bytes, print_offset_value() will be */
/* called and may defer printing to be handled later (by the caller's */
/* second pass) or may print the offset, preceded by an '@' sign if */
/* appropriate. If the value does fit in the 4 bytes provided in the */
/* entry, print it according to its TIFF type, intercepting tags */
/* which require special handling of value. */
unsigned long
print_entry(FILE *inptr,unsigned short byteorder,struct ifd_entry *entry_ptr,
unsigned long fileoffset_base,struct image_summary *summary_entry,
char *parent_name,int ifdtype,int ifdnum,int subifdnum,int indent)
{
int value_is_offset = 0;
unsigned long endoffset = 0UL;
int chpr = 0;
value_is_offset = is_offset(entry_ptr);
if((PRINT_ENTRY))
{
print_taginfo(entry_ptr,parent_name,indent,ifdtype,ifdnum,subifdnum);
if((entry_ptr->value_type == 0) || (entry_ptr->value_type > DOUBLE) ||
ferror(inptr) || feof(inptr))
{
clearerr(inptr);
printred("# INVALID ENTRY");
endoffset = ftell(inptr);
}
else if(entry_ptr->count == 0)
{
if(PRINT_VALUE)
chpr += printf(" EMPTY (value=%#lx)",entry_ptr->value);
endoffset = ftell(inptr);
}
else if(value_is_offset)
{
/* Offsets read from the file are printed relative to the */
/* beginning of the file (with fileoffset_base added) so */
/* that the values, printed later, will be easy to find. */
if(PRINT_BOTH_OFFSET)
chpr += printf("@%#lx=%lu",entry_ptr->value + fileoffset_base,
entry_ptr->value + fileoffset_base);
else if(PRINT_HEX_OFFSET)
chpr += printf("@%#lx",entry_ptr->value + fileoffset_base);
else if(PRINT_DEC_OFFSET)
chpr += printf("@%lu",entry_ptr->value + fileoffset_base);
if(fileoffset_base && (PRINT_ENTRY_RELOFFSET))
chpr += printf(" (%lu) ",entry_ptr->value);
/* Print "inline" in REPORT & LIST modes */
if(!(PRINT_VALUE_AT_OFFSET))
{
setcharsprinted(chpr);
chpr = 0;
endoffset = print_offset_value(inptr,byteorder,entry_ptr,
fileoffset_base,parent_name,
ifdtype,indent,0);
}
}
else if(PRINT_VALUE)
{
/* Intercept some EXIF values which print_value() would */
/* not handle properly, possibly because they are ascii */
/* items tagged as UNDEFINED. A few items given as LONG */
/* type are actually offsets, and are printed as such */
/* here, with fileoffset_base added. */
switch(entry_ptr->tag)
{
case EXIFTAG_ExifVersion:
case EXIFTAG_FlashPixVersion:
case INTEROPTAG_Version:
case INTEROPTAG_Index:
/* ASCII */
/* ###%%% show_string()? */
chpr += printf("%s\'%s\'",PREFIX,(char *)&entry_ptr->value);
break;
case EXIFTAG_ExifIFDPointer:
case EXIFTAG_GPSInfoIFDPointer:
case EXIFTAG_Interoperability:
case TIFFTAG_JPEGInterchangeFormat:
/* OFFSETS */
if(PRINT_BOTH_OFFSET)
{
chpr += printf("@%#lx=%lu",entry_ptr->value + fileoffset_base,
entry_ptr->value + fileoffset_base);
}
else if(PRINT_HEX_OFFSET)
chpr += printf("@%#lx",entry_ptr->value + fileoffset_base);
else if((PRINT_DEC_OFFSET) || is_a_long_offset(entry_ptr))
chpr += printf("@%lu",entry_ptr->value + fileoffset_base);
if(fileoffset_base && (PRINT_ENTRY_RELOFFSET))
chpr += printf(" (%lu)",entry_ptr->value);
break;
default:
/* VALUES */
if(entry_ptr->tag == TIFFTAG_StripOffsets)
print_value(entry_ptr,"@");
else
print_value(entry_ptr,PREFIX);
/* This one is worth flagging... */
if((entry_ptr->tag == TIFFTAG_StripOffsets) &&
(entry_ptr->value == 0))
{
printred(" (BAD START OFFSET)");
}
interpret_value(entry_ptr,summary_entry);
break;
}
}
chpr = newline(chpr);
}
return(endoffset);
}
/* Some items are marked as LONG, but are intended to be interpreted */
/* as offsets. */
int
is_a_long_offset(struct ifd_entry *entry_ptr)
{
int is_an_offset = 0;
if(entry_ptr)
{
switch(entry_ptr->tag)
{
case EXIFTAG_ExifIFDPointer:
case EXIFTAG_GPSInfoIFDPointer:
case EXIFTAG_Interoperability:
case TIFFTAG_JPEGInterchangeFormat:
++is_an_offset;
break;
default:
break;
}
}
return(is_an_offset);
}
/* Repeat the tag identifier for values printed at an offset. This is */
/* called only when printing offset values at the offset (rather than */
/* "inline"), and repeats only one of the identifiers (preferably */
/* tagname). */
void
print_tagid(struct ifd_entry *entry_ptr,int indent,int ifdtype)
{
char *nameoftag;
int chpr = 0;
if(entry_ptr && (PRINT_ENTRY))
{
if(PRINT_TAGNAME || !(PRINT_TAGNO))
{
switch(ifdtype)
{
case GPS_IFD:
nameoftag = gps_tagname(entry_ptr->tag);
break;
case INTEROP_IFD:
nameoftag = interop_tagname(entry_ptr->tag);
break;
case EXIF_IFD:
case TIFF_IFD:
case TIFF_SUBIFD:
default:
nameoftag = tagname(entry_ptr->tag);
break;
}
chpr += printf("%-*.*s",TAGWIDTH,TAGWIDTH,nameoftag);
}
else if(PRINT_HEX_TAGNO)
chpr += printf("<%#06x>",entry_ptr->tag & 0xffff);
else if(PRINT_DEC_TAGNO)
chpr += printf("<%5u>",entry_ptr->tag & 0xffff);
}
setcharsprinted(chpr);
}
/* Print the part of an IFD entry describing the entry tag, including */
/* it's tag number, name and type. Only the items enabled in */
/* "Print_options" are printed. */
/* When the LONGNAMES option bit is set prefix the tag name with a */
/* section identifier (parent_name). */
void
print_taginfo(struct ifd_entry *entry_ptr,char *parent_name,
int indent,int ifdtype,int ifdnum,int subifdnum)
{
char *nameoftag;
char *nameof_value_type;
int tagwidth = TAGWIDTH;
int chpr = 0;
if(entry_ptr && (PRINT_ENTRY))
{
if(PRINT_BOTH_TAGNO)
chpr += printf("<%#06x=%5u> ",entry_ptr->tag & 0xffff,entry_ptr->tag & 0xffff);
else if(PRINT_DEC_TAGNO)
chpr += printf("<%5u> ",entry_ptr->tag & 0xffff);
else if(PRINT_HEX_TAGNO)
chpr += printf("<%#06x> ",entry_ptr->tag & 0xffff);
if((PRINT_TAGNAME))
{
switch(ifdtype)
{
case GPS_IFD:
nameoftag = gps_tagname(entry_ptr->tag);
break;
case INTEROP_IFD:
nameoftag = interop_tagname(entry_ptr->tag);
break;
case EXIF_IFD:
case TIFF_IFD:
case TIFF_SUBIFD:
nameoftag = tagname(entry_ptr->tag);
break;
default:
nameoftag = tagname(entry_ptr->tag);
break;
}
if((PRINT_LONGNAMES))
printf("%s.",parent_name);
chpr += printf("%-*.*s",tagwidth,tagwidth,nameoftag ? nameoftag : "NULL");
}
if(PRINT_TYPE)
{
nameof_value_type = value_type_name(entry_ptr->value_type);
chpr += printf(" [%-2u=%-9.9s %5lu] ",entry_ptr->value_type,
nameof_value_type,entry_ptr->count);
}
if(PRINT_VALUE)
chpr += printf(" = ");
}
setcharsprinted(chpr);
}
/* Print a "value" from an ifd structure entry, according to the TIFF */
/* type recorded in the entry. Print in hex or decimal (or both) */
/* according to the global Print_options variable. */
void
print_value(struct ifd_entry *entry_ptr,char *prefix)
{
unsigned long byte;
unsigned short ushort_val;
unsigned long i;
int chpr = 0;
if(entry_ptr && (PRINT_VALUE))
{
if(prefix)
chpr += printf("%s",prefix);
switch(entry_ptr->value_type)
{
case SBYTE:
byte = entry_ptr->value;
for(i = 0; i < entry_ptr->count; ++i)
{
if(PRINT_BOTH_VALUE)
chpr += printf("%#x=%d",(unsigned int)((char)byte & 0xff),
(int)((char)byte & 0xff));
else if(PRINT_HEX_VALUE)
chpr += printf("%#x",(unsigned int)((char)byte & 0xff));
else if(PRINT_DEC_VALUE)
chpr += printf("%d",(int)((char)byte & 0xff));
byte >>= 8;
}
break;
case SHORT:
ushort_val = entry_ptr->value ;
if(PRINT_BOTH_VALUE)
chpr += printf("%#x=%u",ushort_val,ushort_val);
else if(PRINT_HEX_VALUE)
chpr += printf("%#x",ushort_val);
else if(PRINT_DEC_VALUE)
chpr += printf("%u",ushort_val);
if(entry_ptr->count > 1)
{
(void)putchar(','); ++chpr;
ushort_val = (entry_ptr->value & 0xffff0000) >> 16;
if(PRINT_BOTH_VALUE)
chpr += printf("%#x=%u",ushort_val,ushort_val);
else if(PRINT_HEX_VALUE)
chpr += printf("%#x",ushort_val);
else if(PRINT_DEC_VALUE)
chpr += printf("%u",ushort_val);
}
break;
case SSHORT:
ushort_val = entry_ptr->value & 0xffff;
if(PRINT_BOTH_VALUE)
chpr += printf("%#x=%d",(unsigned int)ushort_val,
(int)ushort_val);
else if(PRINT_HEX_VALUE)
chpr += printf("%#x",(unsigned int)ushort_val);
else if(PRINT_DEC_VALUE)
chpr += printf("%d",(int)ushort_val);
if(entry_ptr->count > 1)
{
(void)putchar(',');
ushort_val = (entry_ptr->value & 0xffff0000) >> 16;
if(PRINT_BOTH_VALUE)
chpr += printf("%#x=%d",(unsigned int)ushort_val,
(int)ushort_val);
else if(PRINT_HEX_VALUE)
chpr += printf("%#x",(unsigned int)ushort_val);
else if(PRINT_DEC_VALUE)
chpr += printf("%d",(int)ushort_val);
}
break;
case LONG:
if(PRINT_BOTH_VALUE)
chpr += printf("0x%08lx=%lu",entry_ptr->value,
entry_ptr->value);
else if(PRINT_HEX_VALUE)
chpr += printf("0x%08lx",entry_ptr->value);
else if(PRINT_DEC_VALUE)
chpr += printf("%lu",entry_ptr->value);
break;
case SLONG:
if(PRINT_BOTH_VALUE)
chpr += printf("%#lx=%ld",(unsigned long)entry_ptr->value,
(long)entry_ptr->value);
else if(PRINT_HEX_VALUE)
chpr += printf("%#lx",(unsigned long)entry_ptr->value);
else if(PRINT_DEC_VALUE)
chpr += printf("%ld",(long)entry_ptr->value);
break;
case ASCII:
byte = entry_ptr->value;
if(entry_ptr->count <= 4)
{
chpr += printf("\'");
for(i = 0; i < entry_ptr->count; ++i)
{
if(isprint(byte & 0xff))
(void)putchar(byte & 0xff);
else
chpr += printf("\\%03ld",byte & 0xff);
byte >>= 8;
++chpr;
}
chpr += printf("\'");
}
break;
case FLOAT:
chpr += printf("%g",(float)entry_ptr->value);
break;
case DOUBLE: /* double is not possible in a direct ifd entry */
chpr += printf("# DOUBLE TYPE IS INVALID HERE");
break;
case UNDEFINED: /* fall through; handle these as BYTE */
case BYTE:
default:
byte = entry_ptr->value;
for(i = 0; i < entry_ptr->count; ++i)
{
if(i)
(void)putchar(',');
if(PRINT_BOTH_VALUE)
chpr += printf("%#lx=%lu",byte & 0xff,byte & 0xff);
else if(PRINT_HEX_VALUE)
chpr += printf("%#lx",byte & 0xff);
else if(PRINT_DEC_VALUE)
chpr += printf("%lu",byte & 0xff);
byte >>= 8;
}
/* UNDEFINED stuff may be ascii */
byte = entry_ptr->value;
if((entry_ptr->value_type == UNDEFINED) &&
(entry_ptr->count == 4) &&
isprint(byte & 0xff))
{
chpr += printf(" = \'");
for(i = 0; i < entry_ptr->count; ++i)
{
if(isprint(byte & 0xff))
(void)putchar(byte & 0xff);
else
(void)putchar('.');
byte >>= 8;
++chpr;
}
(void)putchar('\'');
++chpr;
}
break;
}
}
setcharsprinted(chpr);
}
/* Goto the offset given by an IFD entry whose value couldn't be */
/* squeezed into the 4 bytes of the entry itself, and read the value */
/* found at that offset, printing according to the TIFF type found in */
/* the entry. UNDEFINED entry types must/may be special-cased, else */
/* their presence and size will be noted and the data skipped or */
/* hexdumped. */
/* Returns the file pointer offset at the end of processing, which */
/* may be 0 if the seek or read fails, or if the entry does not have */
/* offset data, or the data is outside the current IFD (e.g. */
/* JPEGTables). */
unsigned long
print_offset_value(FILE *inptr,unsigned short byteorder,
struct ifd_entry *entry_ptr,unsigned long fileoffset_base,
char *parent_name,int ifdtype,int indent,
int at_offset)
{
unsigned long endoffset = 0L;
unsigned long value_offset,dumplength,total;
char *nameoftag,*data;
int chpr = 0;
if(inptr && entry_ptr)
{
value_offset = fileoffset_base + entry_ptr->value;
endoffset = value_offset +
(value_type_size(entry_ptr->value_type) * entry_ptr->count);
if(PRINT_VALUE)
{
if((at_offset && (PRINT_VALUE_AT_OFFSET)) ||
((PRINT_OFFSET) && (entry_ptr->value_type != UNDEFINED)))
chpr += printf(" = ");
switch(entry_ptr->value_type)
{
case UNDEFINED:
if(!at_offset && (PRINT_VALUE))
{
if(!(PRINT_OFFSET))
chpr += printf("@%lu:%lu",value_offset,entry_ptr->count);
else
chpr += printf(":%lu", entry_ptr->count);
}
switch(entry_ptr->tag)
{
case EXIFTAG_CFAPattern:
if(!at_offset && (PRINT_VALUE))
chpr += printf(" = ");
nameoftag = tagname(entry_ptr->tag);
setcharsprinted(chpr);
chpr = 0;
print_cfapattern(inptr,entry_ptr->count,
byteorder,value_offset,
parent_name,nameoftag);
break;
case EXIFTAG_UserComment:
if(!at_offset && (PRINT_VALUE))
chpr += printf(" = ");
setcharsprinted(chpr);
chpr = 0;
print_user_comment(inptr,entry_ptr->count,
value_offset,byteorder);
break;
case TIFFTAG_META_0xc353:
/* This should probably be handled */
/* through the 'private IFD' mechanism, */
/* but do it here for now. */
if(!at_offset && (PRINT_VALUE))
chpr += printf(" = ");
/* The first 8 bytes should say "UNICODE" */
if((data = (char *)read_bytes(inptr,8UL,value_offset)) && (strncmp(data,"UNICODE",8) == 0))
{
if(!(LIST_MODE))
chpr += printf("UNICODE: ");
setcharsprinted(chpr);
chpr = 0;
print_unicode(inptr,entry_ptr->count - 8,HERE,byteorder);
}
else
{
chpr = newline(chpr);
dumplength = entry_ptr->count;
hexdump(inptr,value_offset,dumplength,dumplength,16,0,SUBINDENT);
}
break;
case TIFFTAG_PrintIM:
case EXIFTAG_MakerNote:
case TIFFTAG_JPEGTables:
break;
/* TIFFEP_CFAPATTERN is not quite the same as */
/* EXIF_CFAPattern: it will be handled in */
/* interpret.c */
case TIFFEPTAG_CFAPattern:
case TIFFEPTAG_SpatialFrequencyResponse:
case EXIFTAG_SpatialFrequencyResponse:
case EXIFTAG_SpectralSensitivity:
case EXIFTAG_OECF:
/* fall through, until some routines are */
/* written for these. */
default:
/* Could make a pseudo-tag for 'count' in */
/* LIST mode... */
if(at_offset)
{
if(Max_undefined == 0L)
chpr += printf(" (not dumped, use -U)");
else
{
/* Even in LIST mode */
if((Max_undefined == DUMPALL) ||
(Max_undefined > entry_ptr->count))
dumplength = entry_ptr->count;
else
dumplength = Max_undefined;
chpr = newline(1);
hexdump(inptr,value_offset,entry_ptr->count,
dumplength,12,indent,SUBINDENT);
}
}
/* make certain we're at the end */
fseek(inptr,(long)(value_offset + entry_ptr->count),SEEK_SET);
break;
}
if(!at_offset && (PRINT_VALUE))
chpr += printf(" # UNDEFINED");
break;
case BYTE:
if(entry_ptr->tag == DNGTAG_OriginalRawFileName)
print_ascii(inptr,entry_ptr->count,value_offset);
else
print_ubytes(inptr,entry_ptr->count,value_offset);
break;
case SBYTE:
print_sbytes(inptr,entry_ptr->count,value_offset);
break;
case ASCII:
print_ascii(inptr,entry_ptr->count,value_offset);
if(Debug & NOTE_DEBUG)
{
if(entry_ptr->tag == TIFFTAG_Make)
chpr += printf(" [%d]",maker_number(Make_name));
else if(entry_ptr->tag == TIFFTAG_Model)
chpr += printf(" [%d]",model_number(maker_number(Make_name),
Model_name,CNULL));
}
break;
case SHORT:
if(entry_ptr->tag == TIFFTAG_StripOffsets)
chpr += printf("@");
print_ushort(inptr,entry_ptr->count,byteorder,value_offset);
if(entry_ptr->tag == TIFFTAG_StripByteCounts)
{
total = sum_strip_bytecounts(inptr,byteorder,
entry_ptr->value + fileoffset_base,
entry_ptr->count,entry_ptr->value_type);
chpr += printf(" = %lu",total);
}
break;
case SSHORT:
print_sshort(inptr,entry_ptr->count,byteorder,value_offset);
break;
case LONG:
if(entry_ptr->tag == TIFFTAG_StripOffsets)
chpr += printf("@");
print_ulong(inptr,entry_ptr->count,byteorder,value_offset);
if(entry_ptr->tag == TIFFTAG_StripByteCounts)
{
total = sum_strip_bytecounts(inptr,byteorder,
entry_ptr->value + fileoffset_base,
entry_ptr->count,entry_ptr->value_type);
chpr += printf(" = %lu",total);
}
break;
case SLONG:
print_slong(inptr,entry_ptr->count,byteorder,value_offset);
break;
case RATIONAL:
print_urational(inptr,entry_ptr->count,byteorder,value_offset);
break;
case SRATIONAL:
print_srational(inptr,entry_ptr->count,byteorder,value_offset);
break;
case FLOAT:
print_float(inptr,entry_ptr->count,byteorder,value_offset);
break;
case DOUBLE:
print_double(inptr,entry_ptr->count,byteorder,value_offset);
break;
default:
chpr += printf(" INVALID TYPE %#x",entry_ptr->value_type);
break;
}
setcharsprinted(chpr);
chpr = 0;
interpret_offset_value(inptr,entry_ptr,byteorder,fileoffset_base);
chpr = newline(chpr);
}
}
else
{
chpr += printf(" invalid call to print_offset_value() ");
if(inptr == (FILE *)0)
chpr += printf(" - no input file pointer ");
if(entry_ptr == (struct ifd_entry *)0)
chpr += printf(" - null entry pointer");
chpr = newline(chpr);
}
return(endoffset);
}
/* Read 'count' unsigned bytes starting at 'offset' and print their */
/* values in hex. If there are a lot, just print the first few, an */
/* elipsis to admit that something is left out, then print the count */
/* and the last value and its offset. */
void
print_ubytes(FILE *inptr,unsigned long count,unsigned long offset)
{
int i,j;
unsigned short byte;
int chpr = 0;
if(count)
{
byte = read_ubyte(inptr,offset);
if(feof(inptr) || ferror(inptr))
{
clearerr(inptr);
setcharsprinted(chpr);
return;
}
chpr += printf("%02x",(unsigned int)byte & 0xff);
}
if(PRINT_MULTIVAL_ALL)
{
for(i = 1; i < count; ++i,offset += 2L)
{
byte = read_ubyte(inptr,HERE);
if(feof(inptr) || ferror(inptr))
{
clearerr(inptr);
setcharsprinted(chpr);
return;
}
chpr += printf(",%02x",(unsigned int)byte & 0xff);
}
}
else
{
#define MAX 10UL
j = count > MAX + 2 ? MAX : count;
for(i = 1; i < j; ++i)
{
byte = read_ubyte(inptr,HERE);
if(feof(inptr) || ferror(inptr))
{
clearerr(inptr);
setcharsprinted(chpr);
return;
}
chpr += printf(",%02x",(unsigned int)byte & 0xff);
}
if((count > j) && (ferror(inptr) == 0))
{
chpr += printf(" ... ");
offset += (unsigned long)(count - 1);
byte = read_ubyte(inptr,offset);
if(feof(inptr) || ferror(inptr))
{
clearerr(inptr);
setcharsprinted(chpr);
return;
}
chpr += printf(",%02x (%lu)",(unsigned int)byte & 0xff,count);
if(PRINT_ADDRESS)
chpr += printf(" -> @%lu",offset);
}
#undef MAX
}
}
/* Read 'count' signed bytes starting at 'offset' and print their */
/* values in decimale. If there are a lot, just print the first few, */
/* an elipsis to admit that something is left out, then print the */
/* last value and its offset. */