-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathciff.c
1686 lines (1623 loc) · 76.2 KB
/
ciff.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) 2005 by Duane H. Hesser. All rights reserved. */
/* */
/* See the file LICENSE.EXIFPROBE for terms of use. */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
#ifndef lint
static char *ModuleId = "@(#) $Id: ciff.c,v 1.8 2005/07/24 17:03:18 alex Exp $";
#endif
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
/* Canon CIFF/CRW routines */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
/* The information coded here is derived from the CIFF specification */
/* found at */
/* http://xyrion.org/ciff/CIFFspecV1R04.pdf */
/* with additional information from Phil Harvey's website at: */
/* http://www.sno.phy.queensu.ca/~phil/exiftool/canon_raw.html */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
#define _POSIX_C_SOURCE 200809L /* for strdup() */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "defs.h"
#include "datadefs.h"
#include "summary.h"
#include "maker.h"
#include "misc.h"
#include "tags.h"
#include "extern.h"
#include "ciff.h"
#include "canon_extern.h"
#include "maker_extern.h"
unsigned long
process_ciff(FILE *inptr,struct fileheader *header,unsigned long fileoffset_base,
unsigned long heaplength,struct image_summary *summary_entry,
char *parent_name,int level,int indent)
{
struct ciff_header *ciffheader;
unsigned long max_offset = 0UL;
unsigned short byteorder = 0;
unsigned long heap_start = 0UL;
unsigned long offset_table_end = 0UL;
if(inptr)
{
if(header)
{
if(header->ciff_header)
{
ciffheader = header->ciff_header;
byteorder = ciffheader->byteorder;
heap_start = fileoffset_base + ciffheader->headerlength;
if(heaplength)
offset_table_end = fileoffset_base + heaplength;
else if(fseek(inptr,0L,SEEK_END) == 0)
offset_table_end = ftell(inptr);
if(ferror(inptr) == 0)
{
max_offset = process_ciff_dir(inptr,heap_start,offset_table_end,
ciffheader->subtype,parent_name,
summary_entry,byteorder,
level,indent);
if(max_offset > 0L)
max_offset += 4;
}
else
fprintf(stderr,"%s: cannot read offset table\n",Progname);
}
else
fprintf(stderr,"%s: null ciffheader to process_ciff()\n",Progname);
}
else
fprintf(stderr,"%s: null fileheader to process_ciff()\n",Progname);
}
else
fprintf(stderr,"%s: no open file pointer to read Print Image data\n",
Progname);
return(max_offset);
}
unsigned long
process_ciff_dir(FILE *inptr,unsigned long start_offset,unsigned long end_offset,
char *subtype,char *dirname,struct image_summary * summary_entry,
unsigned short byteorder,int level,int indent)
{
struct ciff_direntry *entry;
unsigned long dircount_loc;
unsigned long max_dir_offset = 0L;
unsigned long entry_offset,entry_offset_start;
unsigned long next_entry_offset,dir_offset;
unsigned short num_entries;
char *tablename = CNULL;
int i;
int chpr = 0;
dircount_loc = read_ulong(inptr,byteorder,end_offset - 4) + start_offset;
num_entries = read_ushort(inptr,byteorder,dircount_loc);
entry_offset = entry_offset_start = dircount_loc + 2;
entry = NULL;
max_dir_offset = start_offset;
/* Show where this directory is in the heap */
print_tag_address(SECTION|ENTRY,start_offset,indent,"@");
if((PRINT_SECTION && dirname))
{
chpr += printf("<%s> HEAP, length %lu",dirname,end_offset - start_offset);
chpr = newline(chpr);
}
else
{
if((PRINT_TAGINFO))
{
/* Always want to know WHICH heap offset */
chpr += printf("%s.",dirname);
chpr += printf("%-*.*s",CIFFTAGWIDTH,CIFFTAGWIDTH,"HeapOffset");
}
if((PRINT_VALUE))
{
if(PRINT_BOTH_OFFSET)
chpr += printf(" = @%#lx=%lu",start_offset,start_offset);
else if(PRINT_HEX_OFFSET)
chpr += printf(" = @%#lx",start_offset);
else
chpr += printf(" = @%lu",start_offset);
}
chpr = newline(chpr);
}
/* Now burrow down to the bottom, recursively. This will show the */
/* lower level directories and entries first. */
for(i = 0; i < num_entries; ++i)
{
entry = read_ciff_direntry(inptr,entry,byteorder,entry_offset);
if(ferror(inptr))
{
fprintf(stderr,"%s: error reading directory entry at %lu\n",
Progname,entry_offset);
break;
}
if(entry == NULL)
{
fprintf(stderr,"%s: null entry %d\n",Progname,i);
break;
}
next_entry_offset = ftell(inptr);
dir_offset =
process_ciff_direntry(inptr,CIFF_INHEAP,byteorder,entry,start_offset,
dirname,summary_entry,level,indent);
entry_offset = next_entry_offset;
}
/* Next show the directory info; this will display higher level */
/* directories and their direct entry values as the recursive */
/* calls unwind back to the top. */
if(PRINT_SECTION)
{
if(level == 0)
{
if(subtype && (strncmp(subtype,"JPGM",4) == 0))
tablename = splice(dirname,".","ImageProperties");
else
tablename = splice(dirname," ","offset table");
print_tag_address(SECTION,dircount_loc,indent,"@");
chpr += printf("<%s> %u entries",tablename,num_entries);
}
else
{
dirname = dirname ? dirname : QSTRING;
print_tag_address(SECTION,dircount_loc,indent+MEDIUMINDENT,"@");
chpr += printf("<%s DIRECTORY>, %u entries",dirname,num_entries);
indent += MEDIUMINDENT;
}
chpr = newline(chpr);
}
entry_offset = entry_offset_start;
max_dir_offset = start_offset;
for(i = 0; i < num_entries; ++i)
{
entry = read_ciff_direntry(inptr,entry,byteorder,entry_offset);
next_entry_offset = ftell(inptr);
if((PRINT_SECTION))
{
print_tag_address(ENTRY,entry_offset,indent + MEDIUMINDENT,"@");
print_ciff_taginfo(entry,start_offset);
}
if(PRINT_VALUE)
{
print_ciff_value(inptr,entry,byteorder,start_offset,entry_offset,
dirname,summary_entry
,level,indent);
}
entry_offset = next_entry_offset;
if(entry_offset > max_dir_offset)
max_dir_offset = entry_offset;
}
/* Close off the directory; at the top, report the location of */
/* the offset table (or top level directory if JPGM) and loction */
/* where its location was found (at the end of the file). */
if(PRINT_SECTION)
{
if(level > 0)
{
print_tag_address(SECTION|ENTRY,max_dir_offset - 1,indent,"-");
dirname = dirname ? dirname : QSTRING;
chpr += printf("</%s DIRECTORY>\n",dirname);
print_tag_address(SECTION|ENTRY,end_offset - 4,indent,"-");
chpr += printf("%s DIRECTORY offset = %lu\n",dirname,dircount_loc);
print_tag_address(SECTION|ENTRY,end_offset - 1,indent-MEDIUMINDENT,"-");
chpr += printf("</%s>",dirname);
}
else
{
print_tag_address(SECTION|ENTRY,max_dir_offset - 1,indent,"-");
/* tablename is dynamically allocated */
tablename = tablename ? tablename : strdup(QSTRING);
chpr += printf("</%s>\n",tablename);
print_tag_address(SECTION|ENTRY,end_offset - 4,indent,"-");
chpr += printf("%s location = @%lu",tablename,dircount_loc);
}
}
else if(level == 0)
{
print_tag_address(SECTION|ENTRY,end_offset - 1,indent,"-");
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",dirname);
chpr += printf("OffsetTableOffset");
}
if((PRINT_VALUE))
chpr += printf(" = @%lu",dircount_loc);
}
chpr = newline(chpr);
if(entry)
free(entry);
if(tablename)
free(tablename);
return(max_dir_offset);
}
/* Print the part of a CIFF entry describing the entry tag, including */
/* it's tag number, name and type. Only the items enabled in */
/* "Print_options" are printed. */
void
print_ciff_taginfo(struct ciff_direntry *entry,unsigned long fileoffset_base)
{
char *nameoftag = NULL;
int tagwidth = CIFFTAGWIDTH;
unsigned short tag,format,location;
int chpr = 0;
if(entry && (PRINT_ENTRY))
{
tag = entry->type & CIFF_TYPEMASK;
format = entry->type & CIFF_FORMATMASK;
location = entry->type & CIFF_LOCATIONMASK;
if(PRINT_BOTH_TAGNO)
chpr += printf("<%#06x=%5u> ",tag,tag);
else if(PRINT_DEC_TAGNO)
chpr += printf("<%5u> ",tag);
else if(PRINT_HEX_TAGNO)
chpr += printf("<%#06x> ",tag);
if((PRINT_TAGNAME))
{
nameoftag = cifftagname(tag);
if(nameoftag)
{
chpr += printf("%-*.*s",tagwidth,tagwidth,nameoftag);
free(nameoftag);
}
}
if(PRINT_TYPE)
{
chpr += printf(" [%#06x ",format);
switch(format)
{
case 0x0000: chpr += printf("BYTE "); break;
case 0x0800: chpr += printf("ASCII "); break;
case 0x1000: chpr += printf("SHORT "); break;
case 0x1800: chpr += printf("LONG "); break;
case 0x2000: chpr += printf("STRUCT"); break;
case 0x2800: chpr += printf("SUBDIR"); break;
case 0x3000: chpr += printf("SUBDIR"); break;
case 0x3800:
default:
chpr += printf("UNDEFINED");
break;
}
switch(location)
{
case 0x0000: chpr += printf(" INHEAP %10lu %10lu",entry->length,entry->offset); break;
case 0x4000: chpr += printf(" INREC %10lu %10lu",entry->length,entry->offset); break;
case 0x8000: chpr += printf(" X8000 %10lu %10lu",entry->length,entry->offset); break;
case 0xc000: chpr += printf(" XC000 %10lu %10lu",entry->length,entry->offset); break;
default:
chpr += printf(" UNKNOWNLOC");
break;
}
chpr += printf("] ");
}
/* ###%%% should be done immediately before value is printed; */
/* not here */
if(PRINT_VALUE)
chpr += printf(" = ");
}
setcharsprinted(chpr);
}
/* Print the "value" portion of a directory entry. If the value is */
/* contained fully within the entry, the direntry processor is needed */
/* to decode the tag value, otherwise, just print the address in the */
/* heap where things have already been handled. */
void
print_ciff_value(FILE *inptr,struct ciff_direntry *entry, unsigned short byteorder,
unsigned long fileoffset_base,unsigned long entry_offset,
char *dirname,struct image_summary *summary_entry,
int level,int indent)
{
unsigned short location;
unsigned long max_dir_offset = 0;
int chpr = 0;
location = entry->type & CIFF_LOCATIONMASK;
if(location == CIFF_INREC)
{
/* chpr += printf("INREC"); */
max_dir_offset = process_ciff_direntry(inptr,CIFF_INREC,byteorder,entry,
entry_offset,dirname,summary_entry,level,
indent);
}
else if(PRINT_SECTION)
{
if(PRINT_BOTH_OFFSET)
chpr += printf("@%#lx=%lu",entry->offset + fileoffset_base,
entry->offset + fileoffset_base);
else if(PRINT_HEX_OFFSET)
chpr += printf("@%#lx",entry->offset + fileoffset_base);
else /* default to decimal offset if nothing is selected */
chpr += printf("@%lu",entry->offset + fileoffset_base);
if(fileoffset_base && (PRINT_ENTRY_RELOFFSET))
chpr += printf(" (%lu) ",entry->offset);
chpr = newline(chpr);
}
setcharsprinted(chpr);
}
unsigned long
canon_colorspace(FILE *inptr,unsigned short byteorder,char *tagprefix,
unsigned long offset,unsigned long dirlength,int indent)
{
unsigned long count,value;
unsigned long end_offset;
int i;
int chpr = 0;
if(PRINT_SECTION)
{
chpr += printf(", length %lu",dirlength);
chpr = newline(chpr);
}
end_offset = offset + dirlength;
count = (dirlength / sizeof(unsigned short));
/* There should be just one (no idea why they didn't do it */
/* INRECORD), and there is no 2-byte count */
for(i = 0; i < count; ++i)
{
value = read_ushort(inptr,byteorder,offset);
print_tag_address(ENTRY,offset,indent,"@");
if((PRINT_TAGINFO))
{
if(tagprefix && (PRINT_LONGNAMES))
chpr = printf("%s.",tagprefix);
chpr = printf("%-*.*s",CIFFTAGWIDTH,CIFFTAGWIDTH,"type");
}
if((PRINT_VALUE))
{
chpr += printf(" = %lu ",value);
if(value == 1)
chpr += printf(" = \"real-world\"");
else if(value == 2)
chpr += printf(" = \"document\"");
else if(value == 0xfff)
chpr += printf(" = \"uncalibrated\"");
else
chpr += printf(" = \"undefined\"");
}
chpr = newline(chpr);
offset += 2;
}
setcharsprinted(chpr);
return(end_offset);
}
/* Decode the "capture time"; print in the Exif "DateTimeOriginal" */
/* format. */
unsigned long
canon_ct_to_datetime(FILE *inptr,unsigned short byteorder,char *tagname,unsigned long offset,
unsigned long dirlength,int indent)
{
unsigned long end_offset = 0UL;
unsigned long count;
unsigned long timezone;
unsigned long zoneinfo;
struct tm *ts_time;
long timestamp;
int chpr = 0;
if(PRINT_SECTION)
{
chpr += printf(", length %lu",dirlength);
chpr = newline(chpr);
}
count = dirlength / sizeof(unsigned long);
end_offset = offset + dirlength;
print_tag_address(ENTRY,offset,indent+MEDIUMINDENT,"@");
tagname = tagname ? tagname : QSTRING;
if(PRINT_TAGNAME)
chpr += printf("%s",tagname);
if(PRINT_VALUE)
{
chpr += printf(" = ");
print_ulong(inptr,count,byteorder,offset);
}
timestamp = read_ulong(inptr,byteorder,offset);
timezone = read_ulong(inptr,byteorder,HERE);
zoneinfo = read_ulong(inptr,byteorder,HERE);
if(PRINT_VALUE)
{
ts_time = gmtime(×tamp);
chpr += printf(" = %02d:%02d:%02d %02d:%02d:%02d GMT",ts_time->tm_year+1900,ts_time->tm_mon+1,
ts_time->tm_mday,ts_time->tm_hour,ts_time->tm_min,ts_time->tm_sec);
if((zoneinfo & 0x80000000) && timezone)
chpr += printf(" + %lu",timezone);
}
chpr = newline(chpr);
return(end_offset);
}
/* Print a "value" from a CIFF structure entry, according to the CIFF */
/* type recorded in the entry. Print in hex or decimal (or both) */
/* according to the global Print_options variable. */
/* This is generally undefined data, usually with unknown tagname or */
/* data interpretation. It may be large, so line-by-line output is */
/* avoided in favor of the abbreviated 'print_TYPE()' routines, and */
/* an opportunity is provided to hex/ascii dump the section . */
unsigned long
print_ciffinheapdata(FILE *inptr,unsigned short byteorder,char *dirname,
char *tagname,unsigned long offset,unsigned long dirlength,
unsigned short data_format,int indent)
{
unsigned long end_offset = 0UL;
unsigned long dumplength;
unsigned short count;
int chpr = 0;
if(inptr)
{
end_offset = offset + dirlength;
switch(data_format)
{
case 0x0000: count = dirlength; break;
case 0x0800: count = dirlength; break;
case 0x1000: count = dirlength/2; break;
case 0x1800: count = dirlength/4; break;
default: count = dirlength; break; /* handle as bytes? */
}
dirname = dirname ? dirname : QSTRING;
tagname = tagname ? tagname : QSTRING;
if((PRINT_SECTION))
{
print_tag_address(SECTION|ENTRY,offset, indent,"@");
chpr += printf("<%s.%s> data, %u entries, length %lu",dirname,tagname,count,dirlength);
chpr = newline(chpr);
}
if((PRINT_TAGINFO))
{
print_tag_address(ENTRY,offset,indent+MEDIUMINDENT,"@");
if((PRINT_LONGNAMES))
chpr += printf("%s.",dirname);
chpr += printf("%-*.*s",CIFFTAGWIDTH,CIFFTAGWIDTH,tagname);
}
if(PRINT_VALUE)
{
chpr += printf(" = ");
switch(data_format)
{
case 0x1000: /* DC_USHORT */
print_ushort(inptr,count,byteorder,offset);
break;
case 0x1800: /* DC_UINT32: */
print_ulong(inptr,count,byteorder,offset);
break;
case 0x0800: /* DC_ASCII: */
print_ascii(inptr,count,offset);
break;
case 0x0000: /* DC_BYTE: */
print_ubytes(inptr,count,offset);
break;
default:
chpr += printf("(data format %#x)",data_format);
break;
}
if(Max_undefined > 0L)
{
if((Max_undefined == DUMPALL) ||
(Max_undefined > dirlength))
dumplength = dirlength;
else
dumplength = Max_undefined;
chpr = newline(chpr);
hexdump(inptr,offset,dirlength,dumplength,16,indent+MEDIUMINDENT,
MEDIUMINDENT);
chpr = newline(chpr);
}
}
if(PRINT_SECTION)
{
chpr = newline(chpr);
print_tag_address(SECTION|ENTRY,end_offset - 1, indent,"-");
dirname = dirname ? dirname : QSTRING;
chpr += printf("</%s.%s>",dirname,tagname);
}
setcharsprinted(chpr);
}
return(end_offset);
}
/* Print a "value" from a CIFF directory entry when the value is */
/* contained within the record, rather than INHEAP. The data is */
/* printed according to the CIFF type recorded in the entry, in hex */
/* or decimal (or both) according to the global Print_options */
/* variable. */
/* This is generally undefined data, usually with unknown tagname or */
/* data interpretation. */
unsigned long
print_ciffinrecdata(FILE *inptr,unsigned short byteorder,char *tagname,
unsigned long offset,unsigned long dirlength,
unsigned short data_format,int indent)
{
unsigned long end_offset = 0UL;
unsigned short count;
int chpr = 0;
if(inptr)
{
end_offset = offset + dirlength;
if((PRINT_VALUE))
{
count = dirlength;
chpr = count;
switch(data_format)
{
case 0x1000: /* DC_USHORT */
print_ushort(inptr,count/2,byteorder,offset);
break;
case 0x1800: /* DC_UINT32: */
print_ulong(inptr,count/4,byteorder,offset);
break;
case 0x0800: /* DC_ASCII: */
print_ascii(inptr,count,offset);
break;
case 0x0000: /* DC_BYTE: */
print_ubytes(inptr,count,offset);
break;
default:
chpr += printf("(data format %#x)",data_format);
break;
}
setcharsprinted(chpr);
}
}
return(end_offset);
}
unsigned long
process_ciff_direntry(FILE *inptr,unsigned short location,unsigned short byteorder,
struct ciff_direntry *entry, unsigned long fileoffset_base,
char *dirname,struct image_summary *summary_entry,int level,
int indent)
{
unsigned long max_offset = 0;
unsigned long endofdir;
unsigned short tag,marker,shvalue;
char *nameoftag = NULL;
char *fullnameoftag = NULL;
char *tagname,*makename;
int entrywidth = CIFFTAGWIDTH;
int status = 0;
int chpr = 0;
int parindent = 0;
int make,model,tagwidth;
int makelen;
float fvalue;
if(entry)
{
if((entry->type & CIFF_LOCATIONMASK) == location)
{
chpr = 0;
max_offset = fileoffset_base;
/* ###%%%
if((entry->type & CIFF_LOCATIONMASK) == CIFF_INHEAP)
chpr += printf("INHEAP");
*/
tag = entry->type & CIFF_TYPEMASK;
nameoftag = cifftagname(tag);
fullnameoftag = splice(dirname,".",nameoftag);
if(PRINT_LONGNAMES)
{
tagname = fullnameoftag;
if(dirname)
entrywidth += strlen(dirname) + 1;
}
else
tagname = nameoftag;
switch(tag)
{
case CIFFTAG_COLORINFO2: /* fall through */
case CIFFTAG_COLORINFO1: /* INHEAPDATA */
if((PRINT_SECTION))
indent += MEDIUMINDENT;
max_offset = print_ciffinheapdata(inptr,byteorder,dirname,
nameoftag,entry->offset + fileoffset_base,entry->length,
entry->type&CIFF_FORMATMASK,indent/* +MEDIUMINDENT*/);
break;
case CIFFTAG_ROMOPERATIONMODE: /* ASCII INREC */
if(!(PRINT_SECTION) && (PRINT_TAGINFO))
{
print_tag_address(ENTRY,fileoffset_base + 2,indent+MEDIUMINDENT,"@");
chpr = printf("%-*.*s",entrywidth,entrywidth,tagname);
}
if(PRINT_VALUE)
{
print_ascii(inptr,8,fileoffset_base + 2);
max_offset = fileoffset_base + 2 + 8;
}
break;
case CIFFTAG_RAWMAKEMODEL: /* ###%%% ASCII SPECIAL */
print_tag_address(ENTRY,entry->offset + fileoffset_base,indent+MEDIUMINDENT,
"@");
makename = (char *)read_bytes(inptr, entry->length,
entry->offset + fileoffset_base);
max_offset = ftell(inptr);
Make_name = strdup(makename);
makelen = strlen(makename);
Model_name = strdup(makename + makelen + 1);
dirname = dirname ? dirname : QSTRING;
if((LIST_MODE))
{
/* Make pseudo-tags and separate Make and */
/* Model */
if(PRINT_TAGNAME)
chpr += printf("%s.%-*.*s",dirname,CIFFTAGWIDTH,CIFFTAGWIDTH,"Make");
if(PRINT_VALUE)
{
chpr += printf(" = \"%s\"",Make_name);
if(Use_Make_name)
chpr += printf(" (Using: Make=%s)",Use_Make_name);
}
chpr = newline(chpr);
print_tag_address(ENTRY,entry->offset + fileoffset_base + strlen(Make_name) + 1,
indent+MEDIUMINDENT,"@");
if(PRINT_TAGNAME)
chpr += printf("%s.%-*.*s",dirname,CIFFTAGWIDTH,CIFFTAGWIDTH,"Model");
if(PRINT_VALUE)
{
chpr += printf(" = \"%s\"",Model_name);
if(Use_Make_name)
chpr += printf(" (Using: Model=%s)",Use_Model_name);
}
}
else
{
if(PRINT_TAGNAME)
{
if((PRINT_SECTION))
chpr += printf("%s.%-*.*s",dirname,CIFFTAGWIDTH,CIFFTAGWIDTH,nameoftag);
else
chpr += printf("%-*.*s",CIFFTAGWIDTH,CIFFTAGWIDTH,nameoftag);
}
if(PRINT_VALUE)
{
chpr += printf(" = ");
if((PRINT_ASCII_IGNORE_LENGTH))
chpr += printf("%s\\0%s",Make_name,Model_name);
else
print_ascii(inptr,entry->length,entry->offset + fileoffset_base);
if(Use_Make_name)
chpr += printf(" Using: Make=%s",Use_Make_name);
if(Use_Model_name)
chpr += printf(" Using: Model=%s",Use_Model_name);
}
}
break;
case CIFFTAG_FILEDESCRIPTION: /* ASCII INHEAP */
case CIFFTAG_FIRMWAREVERSION: /* ASCII INHEAP */
case CIFFTAG_OWNERNAME: /* ASCII INHEAP */
case CIFFTAG_IMAGETYPE: /* ASCII INHEAP */
case CIFFTAG_ORIGINALFILENAME: /* ASCII INHEAP */
case CIFFTAG_THUMBNAILFILENAME: /* ASCII INHEAP */
print_tag_address(ENTRY,entry->offset + fileoffset_base,indent+MEDIUMINDENT,"@");
if((PRINT_TAGINFO))
chpr = printf("%-*.*s",entrywidth,entrywidth,tagname);
if(PRINT_VALUE)
{
chpr += printf(" = ");
print_ascii(inptr,entry->length,entry->offset + fileoffset_base);
max_offset = ftell(inptr);
}
break;
case CIFFTAG_BASEISO: /* INREC */
if(!(PRINT_SECTION) && (PRINT_TAGINFO))
{
print_tag_address(ENTRY,fileoffset_base + 2,indent+MEDIUMINDENT,"@");
chpr = printf("%-*.*s",entrywidth,entrywidth,tagname);
}
if(PRINT_VALUE)
chpr += printf("%lu",entry->length);
max_offset = ftell(inptr);
break;
case CIFFTAG_FOCALLENGTH: /* INREC */
/* length mm, xy size in .001 inch ###%%% ??? */
if((PRINT_VALUE) && (PRINT_SECTION))
{
indent += 19;
chpr = printf("{");
chpr = newline(chpr);
parindent = charsprinted() - LARGEINDENT;
indent += MEDIUMINDENT;
}
if(PRINT_ENTRY)
{
entrywidth = strlen("TargetCompressionRatio");
print_tag_address(ENTRY,fileoffset_base + 2,indent + MEDIUMINDENT,"@");
parindent = charsprinted() - LARGEINDENT;
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,"Undefined");
}
if((PRINT_VALUE))
{
shvalue = read_ushort(inptr,byteorder,fileoffset_base + 2);
printf(" = %u",shvalue);
chpr = newline(chpr);
}
print_tag_address(ENTRY,fileoffset_base + 4,indent + MEDIUMINDENT,"@");
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,
"FocalLength");
}
if((PRINT_VALUE))
{
shvalue = read_ushort(inptr,byteorder,fileoffset_base + 4);
chpr += printf(" = %u mm",shvalue);
chpr = newline(chpr);
}
print_tag_address(ENTRY,fileoffset_base + 6,indent + MEDIUMINDENT,"@");
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,
"FocalPlaneXDim");
}
if((PRINT_VALUE))
{
shvalue = read_ushort(inptr,byteorder,fileoffset_base + 6);
chpr += printf(" = %u inches/1000",shvalue);
chpr = newline(chpr);
}
print_tag_address(ENTRY,fileoffset_base + 8,indent + MEDIUMINDENT,"@");
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,
"FocalPlaneYDim");
}
if((PRINT_VALUE))
{
shvalue = read_ushort(inptr,byteorder,fileoffset_base + 8);
chpr += printf(" = %u inches/1000",shvalue);
if(PRINT_SECTION)
{
chpr = newline(chpr);
print_tag_address(ENTRY,fileoffset_base + 9,0,"@");
parindent -= charsprinted();
putindent(parindent);
chpr = printf("}");
indent -= MEDIUMINDENT;
}
}
}
break;
case CIFFTAG_SHOTINFO: /* INHEAP subroutine */
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,(entry->length/sizeof(short)) - 1);
indent += MEDIUMINDENT;
}
max_offset = canon_shotinfo(inptr,byteorder,tagname,
entry->offset + fileoffset_base,
entry->length,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_CAMERASETTINGS: /* INHEAP subroutine */
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,
(entry->length/sizeof(short)) - 1);
indent += MEDIUMINDENT;
}
max_offset = canon_camera_settings(inptr,byteorder,
tagname,entry->offset + fileoffset_base,
entry->length,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_SENSORINFO: /* INHEAP subroutine */
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,(entry->length/sizeof(short)) - 1);
indent += MEDIUMINDENT;
}
max_offset = canon_sensorinfo(inptr,byteorder,tagname,entry->offset + fileoffset_base,
entry->length,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_CUSTOMFUNCTIONS: /* INHEAP subroutine */
if(Use_Make_name)
make = maker_number(Use_Make_name);
else
make = maker_number(Make_name);
if(Use_Model_name)
model = model_number(make,Use_Model_name,NULLSTRING);
else
model = model_number(make,Model_name,NULLSTRING);
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,
(entry->length/sizeof(short)) - 1);
indent += MEDIUMINDENT;
}
max_offset = canon_customfunctions(inptr,byteorder,
tagname,entry->offset + fileoffset_base,
entry->length,model,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_PICTUREINFO: /* INHEAP subroutine */
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,(entry->length/sizeof(short)) - 1);
indent += MEDIUMINDENT;
}
max_offset = canon_pictureinfo(inptr,byteorder,
tagname,entry->offset + fileoffset_base,
entry->length,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_WHITEBALANCETABLE: /* INHEAP subroutine */
if((PRINT_SECTION))
{
PUSHCOLOR(MAKER_COLOR);
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base,
indent+MEDIUMINDENT,"@");
chpr += printf("<%s> data, %lu entries",fullnameoftag,
(entry->length - sizeof(unsigned short))/sizeof(float));
indent += MEDIUMINDENT;
}
max_offset = canon_whitebalancetable(inptr,byteorder,tagname,
entry->offset + fileoffset_base,entry->length,indent+MEDIUMINDENT);
if((PRINT_SECTION))
{
indent -= MEDIUMINDENT;
print_tag_address(SECTION|ENTRY,entry->offset + fileoffset_base + entry->length - 1,
indent+MEDIUMINDENT,"-");
chpr += printf("</%s>",fullnameoftag);
POPCOLOR();
}
break;
case CIFFTAG_IMAGESPEC: /* INREC */
if((PRINT_VALUE) && (PRINT_SECTION))
{
indent += 19;
chpr = printf("{");
chpr = newline(chpr);
parindent = charsprinted();
}
if(PRINT_ENTRY)
{
entrywidth = strlen("TargetCompressionRatio");
dirname = dirname ? dirname : QSTRING;
print_tag_address(ENTRY,fileoffset_base + 2,indent + LARGEINDENT,"@");
parindent = charsprinted() - LARGEINDENT;
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,"FileFormat");
}
if((PRINT_VALUE))
{
chpr += printf(" = ");
switch(entry->length)
{
case 0x10000: chpr += printf("JPEG quantized\n"); break;
case 0x10002: chpr += printf("JPEG non-quantized\n"); break;
case 0x10003: chpr += printf("JPEG nq picture/q text\n"); break;
case 0x20001: chpr += printf("CRW\n"); break;
default: chpr += printf("unknown\n"); break;
}
}
print_tag_address(ENTRY,fileoffset_base + 6,indent + LARGEINDENT,"@");
if((PRINT_TAGINFO))
{
if((PRINT_LONGNAMES))
chpr += printf("%s.",fullnameoftag);
chpr += printf("%-*.*s",entrywidth,entrywidth,"TargetCompressionRatio");
}