Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_shared.cpp

raw
1 /*****************************************************************************/
2 // Copyright 2006-2023 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE: Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8
9 #include "dng_shared.h"
10
11 #include "dng_camera_profile.h"
12 #include "dng_exceptions.h"
13 #include "dng_gain_map.h"
14 #include "dng_globals.h"
15 #include "dng_host.h"
16 #include "dng_memory.h"
17 #include "dng_parse_utils.h"
18 #include "dng_sdk_limits.h"
19 #include "dng_tag_codes.h"
20 #include "dng_tag_types.h"
21 #include "dng_tag_values.h"
22 #include "dng_temperature.h"
23 #include "dng_utils.h"
24
25 #include <cstdio>
26
27 /*****************************************************************************/
28
29 bool dng_camera_profile_dynamic_range::IsValid () const
30 {
31
32 if (fVersion != 1)
33 return false;
34
35 if (fDynamicRange >= 2)
36 return false;
37
38 if (IsSDR () && fHintMaxOutputValue > 1.0f)
39 return false;
40
41 return true;
42
43 }
44
45 /*****************************************************************************/
46
47 void dng_camera_profile_dynamic_range::PutStream (dng_stream &stream) const
48 {
49
50 stream.Put_uint16 (fVersion);
51
52 stream.Put_uint16 (fDynamicRange);
53
54 stream.Put_real32 (fHintMaxOutputValue);
55
56 }
57
58 /*****************************************************************************/
59
60 #if qDNGValidate
61
62 /*****************************************************************************/
63
64 void dng_camera_profile_dynamic_range::Dump () const
65 {
66
67 printf ("ProfileDynamicRange: version=%u, range=%s, hint_max=%g\n",
68 unsigned (fVersion),
69 IsHDR () ? "high" : "standard",
70 float (fHintMaxOutputValue));
71
72 }
73
74 /*****************************************************************************/
75
76 #endif // qDNGValidate
77
78 /*****************************************************************************/
79 /*****************************************************************************/
80 /*****************************************************************************/
81
82 dng_camera_profile_info::dng_camera_profile_info ()
83
84 : fBigEndian (false)
85
86 , fColorPlanes (0)
87
88 , fCalibrationIlluminant1 (lsUnknown)
89 , fCalibrationIlluminant2 (lsUnknown)
90 , fCalibrationIlluminant3 (lsUnknown)
91
92 , fColorMatrix1 ()
93 , fColorMatrix2 ()
94 , fColorMatrix3 ()
95
96 , fForwardMatrix1 ()
97 , fForwardMatrix2 ()
98 , fForwardMatrix3 ()
99
100 , fReductionMatrix1 ()
101 , fReductionMatrix2 ()
102 , fReductionMatrix3 ()
103
104 , fProfileCalibrationSignature ()
105
106 , fProfileName ()
107
108 , fProfileCopyright ()
109
110 , fEmbedPolicy (pepAllowCopying)
111
112 , fProfileHues (0)
113 , fProfileSats (0)
114 , fProfileVals (0)
115
116 , fHueSatDeltas1Offset (0)
117 , fHueSatDeltas1Count (0)
118
119 , fHueSatDeltas2Offset (0)
120 , fHueSatDeltas2Count (0)
121
122 , fHueSatDeltas3Offset (0)
123 , fHueSatDeltas3Count (0)
124
125 , fHueSatMapEncoding (encoding_Linear)
126
127 , fLookTableHues (0)
128 , fLookTableSats (0)
129 , fLookTableVals (0)
130
131 , fLookTableOffset (0)
132 , fLookTableCount (0)
133
134 , fLookTableEncoding (encoding_Linear)
135
136 , fBaselineExposureOffset (0, 100)
137
138 , fDefaultBlackRender (defaultBlackRender_Auto)
139
140 , fToneCurveOffset (0)
141 , fToneCurveCount (0)
142
143 , fToneMethod (profileToneMethod_Unspecified)
144
145 , fUniqueCameraModel ()
146
147 {
148
149 }
150
151 /*****************************************************************************/
152
153 dng_camera_profile_info::~dng_camera_profile_info ()
154 {
155
156 }
157
158 /*****************************************************************************/
159
160 DNG_ATTRIB_NO_SANITIZE("unsigned-integer-overflow")
161 bool dng_camera_profile_info::ParseTag (dng_stream &stream,
162 uint32 parentCode,
163 uint32 tagCode,
164 uint32 tagType,
165 uint32 tagCount,
166 uint64 tagOffset)
167 {
168
169 switch (tagCode)
170 {
171
172 case tcCalibrationIlluminant1:
173 {
174
175 CheckTagType (parentCode, tagCode, tagType, ttShort);
176
177 CheckTagCount (parentCode, tagCode, tagCount, 1);
178
179 fCalibrationIlluminant1 = stream.TagValue_uint32 (tagType);
180
181 #if qDNGValidate
182
183 if (gVerbose)
184 {
185
186 printf ("CalibrationIlluminant1: %s\n",
187 LookupLightSource (fCalibrationIlluminant1));
188
189 }
190
191 #endif
192
193 break;
194
195 }
196
197 case tcCalibrationIlluminant2:
198 {
199
200 CheckTagType (parentCode, tagCode, tagType, ttShort);
201
202 CheckTagCount (parentCode, tagCode, tagCount, 1);
203
204 fCalibrationIlluminant2 = stream.TagValue_uint32 (tagType);
205
206 #if qDNGValidate
207
208 if (gVerbose)
209 {
210
211 printf ("CalibrationIlluminant2: %s\n",
212 LookupLightSource (fCalibrationIlluminant2));
213
214 }
215
216 #endif
217
218 break;
219
220 }
221
222 case tcCalibrationIlluminant3:
223 {
224
225 CheckTagType (parentCode, tagCode, tagType, ttShort);
226
227 CheckTagCount (parentCode, tagCode, tagCount, 1);
228
229 fCalibrationIlluminant3 = stream.TagValue_uint32 (tagType);
230
231 #if qDNGValidate
232
233 if (gVerbose)
234 {
235
236 printf ("CalibrationIlluminant3: %s\n",
237 LookupLightSource (fCalibrationIlluminant3));
238
239 }
240
241 #endif
242
243 break;
244
245 }
246
247 case tcIlluminantData1:
248 case tcIlluminantData2:
249 case tcIlluminantData3:
250 {
251
252 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
253 {
254 return false;
255 }
256
257 if (!CheckTagCount (parentCode, tagCode, tagCount, 2, 10000))
258 {
259 return false;
260 }
261
262 dng_illuminant_data *dstPtr = &fIlluminantData1;
263
264 if (tagCode == tcIlluminantData2)
265 {
266 dstPtr = &fIlluminantData2;
267 }
268
269 else if (tagCode == tcIlluminantData3)
270 {
271 dstPtr = &fIlluminantData3;
272 }
273
274 #if qDNGValidate
275 const char *tagName = LookupTagCode (parentCode, tagCode);
276 #else
277 const char *tagName = "";
278 #endif
279
280 dstPtr->Get (stream,
281 tagCount,
282 tagName);
283
284 break;
285
286 }
287
288 case tcColorMatrix1:
289 {
290
291 CheckTagType (parentCode, tagCode, tagType, ttSRational);
292
293 if (fColorPlanes == 0)
294 {
295
296 fColorPlanes = Pin_uint32 (0, tagCount / 3, kMaxColorPlanes);
297
298 }
299
300 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
301 return false;
302
303 if (!ParseMatrixTag (stream,
304 parentCode,
305 tagCode,
306 tagType,
307 tagCount,
308 fColorPlanes,
309 3,
310 fColorMatrix1))
311 return false;
312
313 #if qDNGValidate
314
315 if (gVerbose)
316 {
317
318 printf ("ColorMatrix1:\n");
319
320 DumpMatrix (fColorMatrix1);
321
322 }
323
324 #endif
325
326 break;
327
328 }
329
330 case tcColorMatrix2:
331 {
332
333 CheckTagType (parentCode, tagCode, tagType, ttSRational);
334
335 // Kludge - Hasselblad FFF files are very DNG-like, but sometimes
336 // only have a ColorMatrix2 tag and no ColorMatrix1 tag.
337
338 bool hasselbladHack = (fColorPlanes == 0);
339
340 if (hasselbladHack)
341 {
342
343 fColorPlanes = Pin_uint32 (0, tagCount / 3, kMaxColorPlanes);
344
345 #if qDNGValidate
346
347 ReportWarning ("ColorMatrix2 without ColorMatrix1");
348
349 #endif
350
351 }
352
353 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
354 return false;
355
356 if (!ParseMatrixTag (stream,
357 parentCode,
358 tagCode,
359 tagType,
360 tagCount,
361 fColorPlanes,
362 3,
363 fColorMatrix2))
364 return false;
365
366 #if qDNGValidate
367
368 if (gVerbose)
369 {
370
371 printf ("ColorMatrix2:\n");
372
373 DumpMatrix (fColorMatrix2);
374
375 }
376
377 #endif
378
379 if (hasselbladHack)
380 {
381
382 fColorMatrix1 = fColorMatrix2;
383
384 fColorMatrix2 = dng_matrix ();
385
386 }
387
388 break;
389
390 }
391
392 case tcColorMatrix3:
393 {
394
395 CheckTagType (parentCode, tagCode, tagType, ttSRational);
396
397 if (fColorPlanes == 0)
398 {
399
400 fColorPlanes = Pin_uint32 (0, tagCount / 3, kMaxColorPlanes);
401
402 }
403
404 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
405 return false;
406
407 if (!ParseMatrixTag (stream,
408 parentCode,
409 tagCode,
410 tagType,
411 tagCount,
412 fColorPlanes,
413 3,
414 fColorMatrix3))
415 return false;
416
417 #if qDNGValidate
418
419 if (gVerbose)
420 {
421
422 printf ("ColorMatrix3:\n");
423
424 DumpMatrix (fColorMatrix3);
425
426 }
427
428 #endif
429
430 break;
431
432 }
433
434 case tcForwardMatrix1:
435 {
436
437 CheckTagType (parentCode, tagCode, tagType, ttSRational);
438
439 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
440 return false;
441
442 if (!ParseMatrixTag (stream,
443 parentCode,
444 tagCode,
445 tagType,
446 tagCount,
447 3,
448 fColorPlanes,
449 fForwardMatrix1))
450 return false;
451
452 #if qDNGValidate
453
454 if (gVerbose)
455 {
456
457 printf ("ForwardMatrix1:\n");
458
459 DumpMatrix (fForwardMatrix1);
460
461 }
462
463 #endif
464
465 break;
466
467 }
468
469 case tcForwardMatrix2:
470 {
471
472 CheckTagType (parentCode, tagCode, tagType, ttSRational);
473
474 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
475 return false;
476
477 if (!ParseMatrixTag (stream,
478 parentCode,
479 tagCode,
480 tagType,
481 tagCount,
482 3,
483 fColorPlanes,
484 fForwardMatrix2))
485 return false;
486
487 #if qDNGValidate
488
489 if (gVerbose)
490 {
491
492 printf ("ForwardMatrix2:\n");
493
494 DumpMatrix (fForwardMatrix2);
495
496 }
497
498 #endif
499
500 break;
501
502 }
503
504 case tcForwardMatrix3:
505 {
506
507 CheckTagType (parentCode, tagCode, tagType, ttSRational);
508
509 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
510 return false;
511
512 if (!ParseMatrixTag (stream,
513 parentCode,
514 tagCode,
515 tagType,
516 tagCount,
517 3,
518 fColorPlanes,
519 fForwardMatrix3))
520 return false;
521
522 #if qDNGValidate
523
524 if (gVerbose)
525 {
526
527 printf ("ForwardMatrix3:\n");
528
529 DumpMatrix (fForwardMatrix3);
530
531 }
532
533 #endif
534
535 break;
536
537 }
538
539 case tcReductionMatrix1:
540 {
541
542 CheckTagType (parentCode, tagCode, tagType, ttSRational);
543
544 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
545 return false;
546
547 if (!ParseMatrixTag (stream,
548 parentCode,
549 tagCode,
550 tagType,
551 tagCount,
552 3,
553 fColorPlanes,
554 fReductionMatrix1))
555 return false;
556
557 #if qDNGValidate
558
559 if (gVerbose)
560 {
561
562 printf ("ReductionMatrix1:\n");
563
564 DumpMatrix (fReductionMatrix1);
565
566 }
567
568 #endif
569
570 break;
571
572 }
573
574 case tcReductionMatrix2:
575 {
576
577 CheckTagType (parentCode, tagCode, tagType, ttSRational);
578
579 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
580 return false;
581
582 if (!ParseMatrixTag (stream,
583 parentCode,
584 tagCode,
585 tagType,
586 tagCount,
587 3,
588 fColorPlanes,
589 fReductionMatrix2))
590 return false;
591
592 #if qDNGValidate
593
594 if (gVerbose)
595 {
596
597 printf ("ReductionMatrix2:\n");
598
599 DumpMatrix (fReductionMatrix2);
600
601 }
602
603 #endif
604
605 break;
606
607 }
608
609 case tcReductionMatrix3:
610 {
611
612 CheckTagType (parentCode, tagCode, tagType, ttSRational);
613
614 if (!CheckColorImage (parentCode, tagCode, fColorPlanes))
615 return false;
616
617 if (!ParseMatrixTag (stream,
618 parentCode,
619 tagCode,
620 tagType,
621 tagCount,
622 3,
623 fColorPlanes,
624 fReductionMatrix3))
625 return false;
626
627 #if qDNGValidate
628
629 if (gVerbose)
630 {
631
632 printf ("ReductionMatrix3:\n");
633
634 DumpMatrix (fReductionMatrix3);
635
636 }
637
638 #endif
639
640 break;
641
642 }
643
644 case tcProfileCalibrationSignature:
645 {
646
647 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
648
649 ParseStringTag (stream,
650 parentCode,
651 tagCode,
652 tagCount,
653 fProfileCalibrationSignature,
654 false);
655
656 #if qDNGValidate
657
658 if (gVerbose)
659 {
660
661 printf ("ProfileCalibrationSignature: ");
662
663 DumpString (fProfileCalibrationSignature);
664
665 printf ("\n");
666
667 }
668
669 #endif
670
671 break;
672
673 }
674
675 case tcProfileName:
676 {
677
678 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
679
680 ParseStringTag (stream,
681 parentCode,
682 tagCode,
683 tagCount,
684 fProfileName,
685 false);
686
687 #if qDNGValidate
688
689 if (gVerbose)
690 {
691
692 printf ("ProfileName: ");
693
694 DumpString (fProfileName);
695
696 printf ("\n");
697
698 }
699
700 #endif
701
702 break;
703
704 }
705
706 case tcProfileCopyright:
707 {
708
709 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
710
711 ParseStringTag (stream,
712 parentCode,
713 tagCode,
714 tagCount,
715 fProfileCopyright,
716 false);
717
718 #if qDNGValidate
719
720 if (gVerbose)
721 {
722
723 printf ("ProfileCopyright: ");
724
725 DumpString (fProfileCopyright);
726
727 printf ("\n");
728
729 }
730
731 #endif
732
733 break;
734
735 }
736
737 case tcProfileEmbedPolicy:
738 {
739
740 CheckTagType (parentCode, tagCode, tagType, ttLong);
741
742 CheckTagCount (parentCode, tagCode, tagCount, 1);
743
744 fEmbedPolicy = stream.TagValue_uint32 (tagType);
745
746 #if qDNGValidate
747
748 if (gVerbose)
749 {
750
751 const char *policy;
752
753 switch (fEmbedPolicy)
754 {
755
756 case pepAllowCopying:
757 policy = "Allow copying";
758 break;
759
760 case pepEmbedIfUsed:
761 policy = "Embed if used";
762 break;
763
764 case pepEmbedNever:
765 policy = "Embed never";
766 break;
767
768 case pepNoRestrictions:
769 policy = "No restrictions";
770 break;
771
772 default:
773 policy = "INVALID VALUE";
774
775 }
776
777 printf ("ProfileEmbedPolicy: %s\n", policy);
778
779 }
780
781 #endif
782
783 break;
784
785 }
786
787 case tcProfileHueSatMapDims:
788 {
789
790 CheckTagType (parentCode, tagCode, tagType, ttLong);
791
792 CheckTagCount (parentCode, tagCode, tagCount, 2, 3);
793
794 fProfileHues = stream.TagValue_uint32 (tagType);
795 fProfileSats = stream.TagValue_uint32 (tagType);
796
797 if (tagCount > 2)
798 fProfileVals = stream.TagValue_uint32 (tagType);
799 else
800 fProfileVals = 1;
801
802 #if qDNGValidate
803
804 if (gVerbose)
805 {
806
807 printf ("ProfileHueSatMapDims: Hues = %u, Sats = %u, Vals = %u\n",
808 (unsigned) fProfileHues,
809 (unsigned) fProfileSats,
810 (unsigned) fProfileVals);
811
812 }
813
814 #endif
815
816 break;
817
818 }
819
820 case tcProfileHueSatMapData1:
821 {
822
823 if (!CheckTagType (parentCode, tagCode, tagType, ttFloat))
824 return false;
825
826 if (fProfileSats == 0)
827 return false;
828
829 dng_safe_uint32 hueCount (fProfileHues);
830 dng_safe_uint32 valCount (fProfileVals);
831
832 bool skipSat0 = (tagCount == (hueCount *
833 (fProfileSats - 1) *
834 (valCount * 3u)).Get ());
835
836 if (!skipSat0)
837 {
838
839 dng_safe_uint32 expected = hueCount * valCount * fProfileSats * 3u;
840
841 if (!CheckTagCount (parentCode,
842 tagCode,
843 tagCount,
844 expected.Get ()))
845 {
846 return false;
847 }
848
849 }
850
851 fBigEndian = stream.BigEndian ();
852
853 fHueSatDeltas1Offset = tagOffset;
854 fHueSatDeltas1Count = tagCount;
855
856 #if qDNGValidate
857
858 if (gVerbose)
859 {
860
861 printf ("ProfileHueSatMapData1:\n");
862
863 DumpHueSatMap (stream,
864 fProfileHues,
865 fProfileSats,
866 fProfileVals,
867 skipSat0);
868
869 }
870
871 #endif
872
873 break;
874
875 }
876
877 case tcProfileHueSatMapData2:
878 {
879
880 if (!CheckTagType (parentCode, tagCode, tagType, ttFloat))
881 return false;
882
883 if (fProfileSats == 0)
884 return false;
885
886 dng_safe_uint32 hueCount (fProfileHues);
887 dng_safe_uint32 valCount (fProfileVals);
888
889 bool skipSat0 = (tagCount == (hueCount *
890 (fProfileSats - 1) *
891 (valCount * 3u)).Get ());
892
893 if (!skipSat0)
894 {
895
896 dng_safe_uint32 expected = hueCount * valCount * fProfileSats * 3u;
897
898 if (!CheckTagCount (parentCode,
899 tagCode,
900 tagCount,
901 expected.Get ()))
902 {
903 return false;
904 }
905
906 }
907
908 fBigEndian = stream.BigEndian ();
909
910 fHueSatDeltas2Offset = tagOffset;
911 fHueSatDeltas2Count = tagCount;
912
913 #if qDNGValidate
914
915 if (gVerbose)
916 {
917
918 printf ("ProfileHueSatMapData2:\n");
919
920 DumpHueSatMap (stream,
921 fProfileHues,
922 fProfileSats,
923 fProfileVals,
924 skipSat0);
925
926 }
927
928 #endif
929
930 break;
931
932 }
933
934 case tcProfileHueSatMapData3:
935 {
936
937 if (!CheckTagType (parentCode, tagCode, tagType, ttFloat))
938 return false;
939
940 if (fProfileSats == 0)
941 return false;
942
943 dng_safe_uint32 hueCount (fProfileHues);
944 dng_safe_uint32 valCount (fProfileVals);
945
946 bool skipSat0 = (tagCount == (hueCount *
947 (fProfileSats - 1) *
948 (valCount * 3u)).Get ());
949
950 if (!skipSat0)
951 {
952
953 dng_safe_uint32 expected = hueCount * valCount * fProfileSats * 3u;
954
955 if (!CheckTagCount (parentCode,
956 tagCode,
957 tagCount,
958 expected.Get ()))
959 {
960 return false;
961 }
962
963 }
964
965 fBigEndian = stream.BigEndian ();
966
967 fHueSatDeltas3Offset = tagOffset;
968 fHueSatDeltas3Count = tagCount;
969
970 #if qDNGValidate
971
972 if (gVerbose)
973 {
974
975 printf ("ProfileHueSatMapData3:\n");
976
977 DumpHueSatMap (stream,
978 fProfileHues,
979 fProfileSats,
980 fProfileVals,
981 skipSat0);
982
983 }
984
985 #endif
986
987 break;
988
989 }
990
991 case tcProfileHueSatMapEncoding:
992 {
993
994 CheckTagType (parentCode, tagCode, tagType, ttLong);
995
996 CheckTagCount (parentCode, tagCode, tagCount, 1);
997
998 fHueSatMapEncoding = stream.TagValue_uint32 (tagType);
999
1000 #if qDNGValidate
1001
1002 if (gVerbose)
1003 {
1004
1005 const char *encoding = NULL;
1006
1007 switch (fHueSatMapEncoding)
1008 {
1009
1010 case encoding_Linear:
1011 encoding = "Linear";
1012 break;
1013
1014 case encoding_sRGB:
1015 encoding = "sRGB";
1016 break;
1017
1018 default:
1019 encoding = "INVALID VALUE";
1020
1021 }
1022
1023 printf ("ProfileHueSatMapEncoding: %s\n", encoding);
1024
1025 }
1026
1027 #endif
1028
1029 break;
1030
1031 }
1032
1033 case tcProfileLookTableDims:
1034 {
1035
1036 CheckTagType (parentCode, tagCode, tagType, ttLong);
1037
1038 CheckTagCount (parentCode, tagCode, tagCount, 2, 3);
1039
1040 fLookTableHues = stream.TagValue_uint32 (tagType);
1041 fLookTableSats = stream.TagValue_uint32 (tagType);
1042
1043 if (tagCount > 2)
1044 fLookTableVals = stream.TagValue_uint32 (tagType);
1045 else
1046 fLookTableVals = 1;
1047
1048 #if qDNGValidate
1049
1050 if (gVerbose)
1051 {
1052
1053 printf ("ProfileLookTableDims: Hues = %u, Sats = %u, Vals = %u\n",
1054 (unsigned) fLookTableHues,
1055 (unsigned) fLookTableSats,
1056 (unsigned) fLookTableVals);
1057
1058 }
1059
1060 #endif
1061
1062 break;
1063
1064 }
1065
1066 case tcProfileLookTableData:
1067 {
1068
1069 if (!CheckTagType (parentCode, tagCode, tagType, ttFloat))
1070 return false;
1071
1072 if (fLookTableSats == 0)
1073 return false;
1074
1075 dng_safe_uint32 hueCount (fLookTableHues);
1076 dng_safe_uint32 valCount (fLookTableVals);
1077
1078 bool skipSat0 = (tagCount == (hueCount *
1079 (fLookTableSats - 1) *
1080 valCount * 3u).Get ());
1081
1082 if (!skipSat0)
1083 {
1084
1085 dng_safe_uint32 expected = hueCount * valCount * fLookTableSats * 3u;
1086
1087 if (!CheckTagCount (parentCode,
1088 tagCode,
1089 tagCount,
1090 expected.Get ()))
1091 {
1092 return false;
1093 }
1094
1095 }
1096
1097 fBigEndian = stream.BigEndian ();
1098
1099 fLookTableOffset = tagOffset;
1100 fLookTableCount = tagCount;
1101
1102 #if qDNGValidate
1103
1104 if (gVerbose)
1105 {
1106
1107 printf ("ProfileLookTableData:\n");
1108
1109 DumpHueSatMap (stream,
1110 fLookTableHues,
1111 fLookTableSats,
1112 fLookTableVals,
1113 skipSat0);
1114
1115 }
1116
1117 #endif
1118
1119 break;
1120
1121 }
1122
1123 case tcProfileLookTableEncoding:
1124 {
1125
1126 CheckTagType (parentCode, tagCode, tagType, ttLong);
1127
1128 CheckTagCount (parentCode, tagCode, tagCount, 1);
1129
1130 fLookTableEncoding = stream.TagValue_uint32 (tagType);
1131
1132 #if qDNGValidate
1133
1134 if (gVerbose)
1135 {
1136
1137 const char *encoding = NULL;
1138
1139 switch (fLookTableEncoding)
1140 {
1141
1142 case encoding_Linear:
1143 encoding = "Linear";
1144 break;
1145
1146 case encoding_sRGB:
1147 encoding = "sRGB";
1148 break;
1149
1150 default:
1151 encoding = "INVALID VALUE";
1152
1153 }
1154
1155 printf ("ProfileLookTableEncoding: %s\n", encoding);
1156
1157 }
1158
1159 #endif
1160
1161 break;
1162
1163 }
1164
1165 case tcBaselineExposureOffset:
1166 {
1167
1168 CheckTagType (parentCode, tagCode, tagType, ttSRational);
1169
1170 CheckTagCount (parentCode, tagCode, tagCount, 1);
1171
1172 fBaselineExposureOffset = stream.TagValue_srational (tagType);
1173
1174 #if qDNGValidate
1175
1176 if (gVerbose)
1177 {
1178
1179 printf ("BaselineExposureOffset: %+0.2f\n",
1180 fBaselineExposureOffset.As_real64 ());
1181
1182 }
1183
1184 #endif
1185
1186 break;
1187
1188 }
1189
1190 case tcDefaultBlackRender:
1191 {
1192
1193 CheckTagType (parentCode, tagCode, tagType, ttLong);
1194
1195 CheckTagCount (parentCode, tagCode, tagCount, 1);
1196
1197 fDefaultBlackRender = stream.TagValue_uint32 (tagType);
1198
1199 #if qDNGValidate
1200
1201 if (gVerbose)
1202 {
1203
1204 const char *setting = NULL;
1205
1206 switch (fDefaultBlackRender)
1207 {
1208
1209 case defaultBlackRender_Auto:
1210 setting = "Auto";
1211 break;
1212
1213 case defaultBlackRender_None:
1214 setting = "None";
1215 break;
1216
1217 default:
1218 setting = "INVALID VALUE";
1219
1220 }
1221
1222 printf ("DefaultBlackRender: %s\n",
1223 setting);
1224
1225 }
1226
1227 #endif
1228
1229 break;
1230
1231 }
1232
1233 case tcProfileToneCurve:
1234 {
1235
1236 if (!CheckTagType (parentCode, tagCode, tagType, ttFloat))
1237 return false;
1238
1239 if (!CheckTagCount (parentCode, tagCode, tagCount, 4, tagCount))
1240 return false;
1241
1242 if ((tagCount & 1) != 0)
1243 {
1244
1245 #if qDNGValidate
1246
1247 {
1248
1249 char message [256];
1250
1251 snprintf (message,
1252 256,
1253 "%s %s has odd count (%u)",
1254 LookupParentCode (parentCode),
1255 LookupTagCode (parentCode, tagCode),
1256 (unsigned) tagCount);
1257
1258 ReportWarning (message);
1259
1260 }
1261
1262 #endif
1263
1264 return false;
1265
1266 }
1267
1268 fBigEndian = stream.BigEndian ();
1269
1270 fToneCurveOffset = tagOffset;
1271 fToneCurveCount = tagCount;
1272
1273 #if qDNGValidate
1274
1275 if (gVerbose)
1276 {
1277
1278 DumpTagValues (stream,
1279 "Coord",
1280 parentCode,
1281 tagCode,
1282 tagType,
1283 tagCount);
1284
1285
1286 }
1287
1288 #endif
1289
1290 break;
1291
1292 }
1293
1294 case tcProfileToneMethod:
1295 {
1296
1297 CheckTagType (parentCode, tagCode, tagType, ttLong);
1298
1299 CheckTagCount (parentCode, tagCode, tagCount, 1);
1300
1301 fToneMethod = stream.TagValue_uint32 (tagType);
1302
1303 #if qDNGValidate
1304
1305 if (gVerbose)
1306 {
1307
1308 const char *setting = NULL;
1309
1310 switch (fToneMethod)
1311 {
1312
1313 case profileToneMethod_Unspecified:
1314 setting = "Unspecified";
1315 break;
1316
1317 case profileToneMethod_AdobePV5:
1318 setting = "Adobe PV5";
1319 break;
1320
1321 case profileToneMethod_AdobePV6:
1322 setting = "Adobe PV6";
1323 break;
1324
1325 default:
1326 setting = "INVALID VALUE";
1327
1328 }
1329
1330 printf ("ProfileToneMethod: %s\n",
1331 setting);
1332
1333 }
1334
1335 #endif
1336
1337 break;
1338
1339 }
1340
1341 case tcUniqueCameraModel:
1342 {
1343
1344 // Note: This code is only used when parsing stand-alone
1345 // profiles. The embedded profiles are assumed to be restricted
1346 // to the model they are embedded in.
1347
1348 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1349
1350 ParseStringTag (stream,
1351 parentCode,
1352 tagCode,
1353 tagCount,
1354 fUniqueCameraModel,
1355 false);
1356
1357 bool didTrim = fUniqueCameraModel.TrimTrailingBlanks ();
1358
1359 #if qDNGValidate
1360
1361 if (didTrim)
1362 {
1363
1364 ReportWarning ("UniqueCameraModel string has trailing blanks");
1365
1366 }
1367
1368 if (gVerbose)
1369 {
1370
1371 printf ("UniqueCameraModel: ");
1372
1373 DumpString (fUniqueCameraModel);
1374
1375 printf ("\n");
1376
1377 }
1378
1379 #else
1380
1381 (void) didTrim; // Unused
1382
1383 #endif
1384
1385 break;
1386
1387 }
1388
1389 case tcProfileGainTableMap2:
1390 {
1391
1392 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
1393 return false;
1394
1395 // For Camera Profile IFD, only ProfileGainTableMap2 is permitted;
1396 // not the original ProfileGainTableMap.
1397
1398 constexpr bool useVersion2format = true;
1399
1400 dng_host host; // use default allocator
1401
1402 fProfileGainTableMap.reset
1403 (dng_gain_table_map::GetStream (host,
1404 stream,
1405 useVersion2format));
1406
1407 auto pgtm = fProfileGainTableMap;
1408
1409 #if qDNGValidate
1410
1411 if (pgtm && gVerbose)
1412 {
1413
1414 dng_md5_printer printer;
1415
1416 pgtm->AddDigest (printer);
1417
1418 auto digest = printer.Result ();
1419
1420 char str [2 * dng_fingerprint::kDNGFingerprintSize + 1];
1421
1422 digest.ToUtf8HexString (str);
1423
1424 printf ("ProfileGainTableMap2 (digest): %s\n", str);
1425
1426 }
1427
1428 #endif // qDNGValidate
1429
1430 if (stream.Position () > tagOffset + (uint64) tagCount)
1431 ThrowBadFormat ("tcProfileGainTableMap2 parse error");
1432
1433 break;
1434
1435 }
1436
1437 case tcProfileDynamicRange:
1438 {
1439
1440 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
1441 return false;
1442
1443 if (!CheckTagCount (parentCode, tagCode, tagCount, 8))
1444 return false;
1445
1446 uint16 version = stream.Get_uint16 ();
1447
1448 if (version == 1)
1449 {
1450
1451 fProfileDynamicRange.fVersion = version;
1452
1453 fProfileDynamicRange.fDynamicRange = stream.Get_uint16 ();
1454
1455 fProfileDynamicRange.fHintMaxOutputValue = stream.Get_real32 ();
1456
1457 }
1458
1459 else
1460 {
1461
1462 ThrowBadFormat ("Unsupported version in ProfileDynamicRange");
1463
1464 }
1465
1466 #if qDNGValidate
1467
1468 if (gVerbose)
1469 fProfileDynamicRange.Dump ();
1470
1471 #endif
1472
1473 break;
1474
1475 }
1476
1477 case tcProfileGroupName:
1478 {
1479
1480 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
1481
1482 ParseStringTag (stream,
1483 parentCode,
1484 tagCode,
1485 tagCount,
1486 fProfileGroupName,
1487 false);
1488
1489 #if qDNGValidate
1490
1491 if (gVerbose)
1492 {
1493
1494 printf ("ProfileGroupName: ");
1495
1496 DumpString (fProfileGroupName);
1497
1498 printf ("\n");
1499
1500 }
1501
1502 #endif // qDNGValidate
1503
1504 break;
1505
1506 }
1507
1508 case tcRGBTablesDraft:
1509 case tcRGBTables:
1510 {
1511
1512 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
1513 return false;
1514
1515 const bool isDraft = (tagCode == tcRGBTablesDraft);
1516
1517 dng_host host;
1518
1519 fMaskedRGBTables.reset (dng_masked_rgb_tables::GetStream (host,
1520 stream,
1521 isDraft));
1522
1523 #if qDNGValidate
1524
1525 if (gVerbose && fMaskedRGBTables)
1526 {
1527
1528 dng_md5_printer printer;
1529
1530 fMaskedRGBTables->AddDigest (printer);
1531
1532 const dng_fingerprint &digest = printer.Result ();
1533
1534 dng_string str = digest.ToUtf8HexString ();
1535
1536 const char *tagName = isDraft ? "RGBTablesDraft" : "RGBTables";
1537
1538 printf ("%s (digest): %s\n", tagName, str.Get ());
1539
1540 fMaskedRGBTables->Dump ();
1541
1542 }
1543
1544 #endif // qDNGValidate
1545
1546 if (stream.Position () > tagOffset + (uint64) tagCount)
1547 {
1548
1549 ThrowBadFormat ("tcRGBTables parse error");
1550
1551 }
1552
1553 break;
1554
1555 }
1556
1557 default:
1558 {
1559
1560 return false;
1561
1562 }
1563
1564 }
1565
1566 return true;
1567
1568 }
1569
1570 /*****************************************************************************/
1571
1572 bool dng_camera_profile_info::ParseExtended (dng_stream &stream)
1573 {
1574
1575 try
1576 {
1577
1578 // Offsets are relative to the start of this structure, not the entire file.
1579
1580 uint64 startPosition = stream.Position ();
1581
1582 // Read header. Like a TIFF header, but with different magic number
1583 // Plus all offsets are relative to the start of the IFD, not to the
1584 // stream or file.
1585
1586 uint16 byteOrder = stream.Get_uint16 ();
1587
1588 if (byteOrder == byteOrderMM)
1589 fBigEndian = true;
1590
1591 else if (byteOrder == byteOrderII)
1592 fBigEndian = false;
1593
1594 else
1595 return false;
1596
1597 TempBigEndian setEndianness (stream, fBigEndian);
1598
1599 uint16 magicNumber = stream.Get_uint16 ();
1600
1601 if (magicNumber != magicExtendedProfile)
1602 {
1603 return false;
1604 }
1605
1606 uint32 offset = stream.Get_uint32 ();
1607
1608 stream.Skip (SafeUint32Sub (offset, 8u));
1609
1610 // Start on IFD entries.
1611
1612 uint32 ifdEntries = stream.Get_uint16 ();
1613
1614 if (ifdEntries < 1)
1615 {
1616 return false;
1617 }
1618
1619 for (uint32 tag_index = 0; tag_index < ifdEntries; tag_index++)
1620 {
1621
1622 stream.SetReadPosition (startPosition + 8 + 2 + tag_index * 12);
1623
1624 uint16 tagCode = stream.Get_uint16 ();
1625 uint32 tagType = stream.Get_uint16 ();
1626 uint32 tagCount = stream.Get_uint32 ();
1627
1628 uint64 tagOffset = stream.Position ();
1629
1630 if (SafeUint32Mult (TagTypeSize (tagType), tagCount) > 4)
1631 {
1632
1633 tagOffset = startPosition + stream.Get_uint32 ();
1634
1635 stream.SetReadPosition (tagOffset);
1636
1637 }
1638
1639 if (!ParseTag (stream,
1640 0,
1641 tagCode,
1642 tagType,
1643 tagCount,
1644 tagOffset))
1645 {
1646
1647 #if qDNGValidate
1648
1649 if (gVerbose)
1650 {
1651
1652 stream.SetReadPosition (tagOffset);
1653
1654 printf ("*");
1655
1656 DumpTagValues (stream,
1657 LookupTagType (tagType),
1658 0,
1659 tagCode,
1660 tagType,
1661 tagCount);
1662
1663 }
1664
1665 #endif
1666
1667 }
1668
1669 }
1670
1671 return true;
1672
1673 }
1674
1675 catch (...)
1676 {
1677
1678 // Eat parsing errors.
1679
1680 }
1681
1682 return false;
1683
1684 }
1685
1686 /*****************************************************************************/
1687
1688 dng_shared::dng_shared ()
1689
1690 : fExifIFD (0)
1691 , fGPSInfo (0)
1692 , fInteroperabilityIFD (0)
1693 , fKodakDCRPrivateIFD (0)
1694 , fKodakKDCPrivateIFD (0)
1695
1696 , fXMPCount (0)
1697 , fXMPOffset (0)
1698
1699 , fIPTC_NAA_Count (0)
1700 , fIPTC_NAA_Offset (0)
1701
1702 , fMakerNoteCount (0)
1703 , fMakerNoteOffset (0)
1704 , fMakerNoteSafety (0)
1705
1706 , fDNGVersion (0)
1707 , fDNGBackwardVersion (0)
1708
1709 , fUniqueCameraModel ()
1710 , fLocalizedCameraModel ()
1711
1712 , fCameraProfile ()
1713
1714 , fExtraCameraProfiles ()
1715
1716 , fCameraCalibration1 ()
1717 , fCameraCalibration2 ()
1718 , fCameraCalibration3 ()
1719
1720 , fCameraCalibrationSignature ()
1721
1722 , fAnalogBalance ()
1723
1724 , fAsShotNeutral ()
1725
1726 , fAsShotWhiteXY ()
1727
1728 , fBaselineExposure (0, 1)
1729 , fBaselineNoise (1, 1)
1730 , fBaselineSharpness (1, 1)
1731 , fLinearResponseLimit (1, 1)
1732 , fShadowScale (1, 1)
1733
1734 , fHasBaselineExposure (false)
1735 , fHasShadowScale (false)
1736
1737 , fDNGPrivateDataCount (0)
1738 , fDNGPrivateDataOffset (0)
1739
1740 , fRawImageDigest ()
1741 , fNewRawImageDigest ()
1742
1743 , fRawDataUniqueID ()
1744
1745 , fOriginalRawFileName ()
1746
1747 , fOriginalRawFileDataCount (0)
1748 , fOriginalRawFileDataOffset (0)
1749
1750 , fOriginalRawFileDigest ()
1751
1752 , fAsShotICCProfileCount (0)
1753 , fAsShotICCProfileOffset (0)
1754
1755 , fAsShotPreProfileMatrix ()
1756
1757 , fCurrentICCProfileCount (0)
1758 , fCurrentICCProfileOffset (0)
1759
1760 , fCurrentPreProfileMatrix ()
1761
1762 , fColorimetricReference (crSceneReferred)
1763
1764 , fAsShotProfileName ()
1765
1766 , fOriginalDefaultFinalSize ()
1767 , fOriginalBestQualityFinalSize ()
1768
1769 , fOriginalDefaultCropSizeH ()
1770 , fOriginalDefaultCropSizeV ()
1771
1772 , fDepthFormat (depthFormatUnknown)
1773 , fDepthNear (0, 0)
1774 , fDepthFar (0, 0)
1775 , fDepthUnits (depthUnitsUnknown)
1776 , fDepthMeasureType (depthMeasureUnknown)
1777
1778 , fBigTableDigests ()
1779 , fBigTableOffsets ()
1780 , fBigTableByteCounts ()
1781
1782 {
1783
1784 }
1785
1786 /*****************************************************************************/
1787
1788 dng_shared::~dng_shared ()
1789 {
1790
1791 }
1792
1793 /*****************************************************************************/
1794
1795 bool dng_shared::ParseTag (dng_stream &stream,
1796 dng_exif &exif,
1797 uint32 parentCode,
1798 bool /* isMainIFD */,
1799 uint32 tagCode,
1800 uint32 tagType,
1801 uint32 tagCount,
1802 uint64 tagOffset,
1803 int64 /* offsetDelta */)
1804 {
1805
1806 if (parentCode == 0)
1807 {
1808
1809 if (Parse_ifd0 (stream,
1810 exif,
1811 parentCode,
1812 tagCode,
1813 tagType,
1814 tagCount,
1815 tagOffset))
1816 {
1817
1818 return true;
1819
1820 }
1821
1822 }
1823
1824 if (parentCode == 0 ||
1825 parentCode == tcExifIFD)
1826 {
1827
1828 if (Parse_ifd0_exif (stream,
1829 exif,
1830 parentCode,
1831 tagCode,
1832 tagType,
1833 tagCount,
1834 tagOffset))
1835 {
1836
1837 return true;
1838
1839 }
1840
1841 }
1842
1843 return false;
1844
1845 }
1846
1847 /*****************************************************************************/
1848
1849 // Parses tags that should only appear in IFD 0.
1850
1851 bool dng_shared::Parse_ifd0 (dng_stream &stream,
1852 dng_exif & /* exif */,
1853 uint32 parentCode,
1854 uint32 tagCode,
1855 uint32 tagType,
1856 uint32 tagCount,
1857 uint64 tagOffset)
1858 {
1859
1860 switch (tagCode)
1861 {
1862
1863 case tcXMP:
1864 {
1865
1866 CheckTagType (parentCode, tagCode, tagType, ttByte, ttUndefined);
1867
1868 fXMPCount = tagCount;
1869 fXMPOffset = fXMPCount ? tagOffset : 0;
1870
1871 #if qDNGValidate
1872
1873 if (gVerbose)
1874 {
1875
1876 printf ("XMP: Count = %u, Offset = %u\n",
1877 (unsigned) fXMPCount,
1878 (unsigned) fXMPOffset);
1879
1880 if (fXMPCount)
1881 {
1882
1883 DumpXMP (stream, fXMPCount);
1884
1885 }
1886
1887 }
1888
1889 #endif
1890
1891 break;
1892
1893 }
1894
1895 case tcIPTC_NAA:
1896 {
1897
1898 CheckTagType (parentCode, tagCode, tagType, ttLong, ttAscii, ttUndefined);
1899
1900 fIPTC_NAA_Count = (dng_safe_uint32 (tagCount) * TagTypeSize (tagType)).Get ();
1901 fIPTC_NAA_Offset = fIPTC_NAA_Count ? tagOffset : 0;
1902
1903 #if qDNGValidate
1904
1905 if (gVerbose)
1906 {
1907
1908 printf ("IPTC/NAA: Count = %u, Offset = %llu\n",
1909 (unsigned) fIPTC_NAA_Count,
1910 (unsigned long long) fIPTC_NAA_Offset);
1911
1912 if (fIPTC_NAA_Count)
1913 {
1914
1915 DumpHexAscii (stream, fIPTC_NAA_Count);
1916
1917 }
1918
1919 // Compute and output the digest.
1920
1921 dng_memory_data buffer (fIPTC_NAA_Count);
1922
1923 stream.SetReadPosition (fIPTC_NAA_Offset);
1924
1925 stream.Get (buffer.Buffer (), fIPTC_NAA_Count);
1926
1927 const uint8 *data = buffer.Buffer_uint8 ();
1928
1929 uint32 count = fIPTC_NAA_Count;
1930
1931 // Method 1: Counting all bytes (this is correct).
1932
1933 {
1934
1935 dng_md5_printer printer;
1936
1937 printer.Process (data, count);
1938
1939 printf ("IPTCDigest: ");
1940
1941 DumpFingerprint (printer.Result ());
1942
1943 printf ("\n");
1944
1945 }
1946
1947 // Method 2: Ignoring zero padding.
1948
1949 {
1950
1951 uint32 removed = 0;
1952
1953 while ((removed < 3) && (count > 0) && (data [count - 1] == 0))
1954 {
1955 removed++;
1956 count--;
1957 }
1958
1959 if (removed != 0)
1960 {
1961
1962 dng_md5_printer printer;
1963
1964 printer.Process (data, count);
1965
1966 printf ("IPTCDigest (ignoring zero padding): ");
1967
1968 DumpFingerprint (printer.Result ());
1969
1970 printf ("\n");
1971
1972 }
1973
1974 }
1975
1976 }
1977
1978 #endif
1979
1980 break;
1981
1982 }
1983
1984 case tcExifIFD:
1985 {
1986
1987 CheckTagType (parentCode, tagCode, tagType, ttLong, ttIFD, ttLong8, ttIFD8);
1988
1989 CheckTagCount (parentCode, tagCode, tagCount, 1);
1990
1991 fExifIFD = stream.TagValue_uint64 (tagType);
1992
1993 #if qDNGValidate
1994
1995 if (gVerbose)
1996 {
1997 printf ("ExifIFD: %llu\n", (unsigned long long) fExifIFD);
1998 }
1999
2000 #endif
2001
2002 break;
2003
2004 }
2005
2006 case tcGPSInfo:
2007 {
2008
2009 CheckTagType (parentCode, tagCode, tagType, ttLong, ttIFD, ttLong8, ttIFD8);
2010
2011 CheckTagCount (parentCode, tagCode, tagCount, 1);
2012
2013 fGPSInfo = stream.TagValue_uint64 (tagType);
2014
2015 #if qDNGValidate
2016
2017 if (gVerbose)
2018 {
2019 printf ("GPSInfo: %llu\n", (unsigned long long) fGPSInfo);
2020 }
2021
2022 #endif
2023
2024 break;
2025
2026 }
2027
2028 case tcKodakDCRPrivateIFD:
2029 {
2030
2031 CheckTagType (parentCode, tagCode, tagType, ttLong, ttIFD);
2032
2033 CheckTagCount (parentCode, tagCode, tagCount, 1);
2034
2035 fKodakDCRPrivateIFD = stream.TagValue_uint32 (tagType);
2036
2037 #if qDNGValidate
2038
2039 if (gVerbose)
2040 {
2041 printf ("KodakDCRPrivateIFD: %u\n", (unsigned) fKodakDCRPrivateIFD);
2042 }
2043
2044 #endif
2045
2046 break;
2047
2048 }
2049
2050 case tcKodakKDCPrivateIFD:
2051 {
2052
2053 CheckTagType (parentCode, tagCode, tagType, ttLong, ttIFD);
2054
2055 CheckTagCount (parentCode, tagCode, tagCount, 1);
2056
2057 fKodakKDCPrivateIFD = stream.TagValue_uint32 (tagType);
2058
2059 #if qDNGValidate
2060
2061 if (gVerbose)
2062 {
2063 printf ("KodakKDCPrivateIFD: %u\n", (unsigned) fKodakKDCPrivateIFD);
2064 }
2065
2066 #endif
2067
2068 break;
2069
2070 }
2071
2072 case tcDNGVersion:
2073 {
2074
2075 CheckTagType (parentCode, tagCode, tagType, ttByte);
2076
2077 CheckTagCount (parentCode, tagCode, tagCount, 4);
2078
2079 uint32 b0 = stream.Get_uint8 ();
2080 uint32 b1 = stream.Get_uint8 ();
2081 uint32 b2 = stream.Get_uint8 ();
2082 uint32 b3 = stream.Get_uint8 ();
2083
2084 fDNGVersion = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
2085
2086 #if qDNGValidate
2087
2088 if (gVerbose)
2089 {
2090 printf ("DNGVersion: %u.%u.%u.%u\n",
2091 (unsigned) b0,
2092 (unsigned) b1,
2093 (unsigned) b2,
2094 (unsigned) b3);
2095 }
2096
2097 #endif
2098
2099 break;
2100
2101 }
2102
2103 case tcDNGBackwardVersion:
2104 {
2105
2106 CheckTagType (parentCode, tagCode, tagType, ttByte);
2107
2108 CheckTagCount (parentCode, tagCode, tagCount, 4);
2109
2110 uint32 b0 = stream.Get_uint8 ();
2111 uint32 b1 = stream.Get_uint8 ();
2112 uint32 b2 = stream.Get_uint8 ();
2113 uint32 b3 = stream.Get_uint8 ();
2114
2115 fDNGBackwardVersion = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
2116
2117 #if qDNGValidate
2118
2119 if (gVerbose)
2120 {
2121 printf ("DNGBackwardVersion: %u.%u.%u.%u\n",
2122 (unsigned) b0,
2123 (unsigned) b1,
2124 (unsigned) b2,
2125 (unsigned) b3);
2126 }
2127
2128 #endif
2129
2130 break;
2131
2132 }
2133
2134 case tcUniqueCameraModel:
2135 {
2136
2137 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2138
2139 ParseStringTag (stream,
2140 parentCode,
2141 tagCode,
2142 tagCount,
2143 fUniqueCameraModel,
2144 false);
2145
2146 bool didTrim = fUniqueCameraModel.TrimTrailingBlanks ();
2147
2148 #if qDNGValidate
2149
2150 if (didTrim)
2151 {
2152
2153 ReportWarning ("UniqueCameraModel string has trailing blanks");
2154
2155 }
2156
2157 if (gVerbose)
2158 {
2159
2160 printf ("UniqueCameraModel: ");
2161
2162 DumpString (fUniqueCameraModel);
2163
2164 printf ("\n");
2165
2166 }
2167
2168 #else
2169
2170 (void) didTrim; // Unused
2171
2172 #endif
2173
2174 break;
2175
2176 }
2177
2178 case tcLocalizedCameraModel:
2179 {
2180
2181 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
2182
2183 ParseStringTag (stream,
2184 parentCode,
2185 tagCode,
2186 tagCount,
2187 fLocalizedCameraModel,
2188 false);
2189
2190 bool didTrim = fLocalizedCameraModel.TrimTrailingBlanks ();
2191
2192 #if qDNGValidate
2193
2194 if (didTrim)
2195 {
2196
2197 ReportWarning ("LocalizedCameraModel string has trailing blanks");
2198
2199 }
2200
2201 if (gVerbose)
2202 {
2203
2204 printf ("LocalizedCameraModel: ");
2205
2206 DumpString (fLocalizedCameraModel);
2207
2208 printf ("\n");
2209
2210 }
2211
2212 #else
2213
2214 (void) didTrim; // Unused
2215
2216 #endif
2217
2218 break;
2219
2220 }
2221
2222 case tcCameraCalibration1:
2223 {
2224
2225 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2226
2227 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2228 return false;
2229
2230 if (!ParseMatrixTag (stream,
2231 parentCode,
2232 tagCode,
2233 tagType,
2234 tagCount,
2235 fCameraProfile.fColorPlanes,
2236 fCameraProfile.fColorPlanes,
2237 fCameraCalibration1))
2238 return false;
2239
2240 #if qDNGValidate
2241
2242 if (gVerbose)
2243 {
2244
2245 printf ("CameraCalibration1:\n");
2246
2247 DumpMatrix (fCameraCalibration1);
2248
2249 }
2250
2251 #endif
2252
2253 break;
2254
2255 }
2256
2257 case tcCameraCalibration2:
2258 {
2259
2260 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2261
2262 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2263 return false;
2264
2265 if (!ParseMatrixTag (stream,
2266 parentCode,
2267 tagCode,
2268 tagType,
2269 tagCount,
2270 fCameraProfile.fColorPlanes,
2271 fCameraProfile.fColorPlanes,
2272 fCameraCalibration2))
2273 return false;
2274
2275 #if qDNGValidate
2276
2277 if (gVerbose)
2278 {
2279
2280 printf ("CameraCalibration2:\n");
2281
2282 DumpMatrix (fCameraCalibration2);
2283
2284 }
2285
2286 #endif
2287
2288 break;
2289
2290 }
2291
2292 case tcCameraCalibration3:
2293 {
2294
2295 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2296
2297 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2298 return false;
2299
2300 if (!ParseMatrixTag (stream,
2301 parentCode,
2302 tagCode,
2303 tagType,
2304 tagCount,
2305 fCameraProfile.fColorPlanes,
2306 fCameraProfile.fColorPlanes,
2307 fCameraCalibration3))
2308 return false;
2309
2310 #if qDNGValidate
2311
2312 if (gVerbose)
2313 {
2314
2315 printf ("CameraCalibration3:\n");
2316
2317 DumpMatrix (fCameraCalibration3);
2318
2319 }
2320
2321 #endif
2322
2323 break;
2324
2325 }
2326
2327 case tcCameraCalibrationSignature:
2328 {
2329
2330 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
2331
2332 ParseStringTag (stream,
2333 parentCode,
2334 tagCode,
2335 tagCount,
2336 fCameraCalibrationSignature,
2337 false);
2338
2339 #if qDNGValidate
2340
2341 if (gVerbose)
2342 {
2343
2344 printf ("CameraCalibrationSignature: ");
2345
2346 DumpString (fCameraCalibrationSignature);
2347
2348 printf ("\n");
2349
2350 }
2351
2352 #endif
2353
2354 break;
2355
2356 }
2357
2358 case tcAnalogBalance:
2359 {
2360
2361 CheckTagType (parentCode, tagCode, tagType, ttRational);
2362
2363 // Kludge - Hasselblad FFF files are very DNG-like, but sometimes
2364 // they don't have any ColorMatrix tags.
2365
2366 bool hasselbladHack = (fDNGVersion == 0 &&
2367 fCameraProfile.fColorPlanes == 0);
2368
2369 if (hasselbladHack)
2370 {
2371
2372 fCameraProfile.fColorPlanes = Pin_uint32 (0, tagCount, kMaxColorPlanes);
2373
2374 #if qDNGValidate
2375
2376 ReportWarning ("AnalogBalance without ColorMatrix1");
2377
2378 #endif
2379
2380 }
2381
2382 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2383 return false;
2384
2385 if (!ParseVectorTag (stream,
2386 parentCode,
2387 tagCode,
2388 tagType,
2389 tagCount,
2390 fCameraProfile.fColorPlanes,
2391 fAnalogBalance))
2392 return false;
2393
2394 #if qDNGValidate
2395
2396 if (gVerbose)
2397 {
2398
2399 printf ("AnalogBalance:");
2400
2401 DumpVector (fAnalogBalance);
2402
2403 }
2404
2405 #endif
2406
2407 break;
2408
2409 }
2410
2411 case tcAsShotNeutral:
2412 {
2413
2414 CheckTagType (parentCode, tagCode, tagType, ttRational);
2415
2416 // Kludge - Hasselblad FFF files are very DNG-like, but sometimes
2417 // they don't have any ColorMatrix tags.
2418
2419 bool hasselbladHack = (fDNGVersion == 0 &&
2420 fCameraProfile.fColorPlanes == 0);
2421
2422 if (hasselbladHack)
2423 {
2424
2425 fCameraProfile.fColorPlanes = Pin_uint32 (0, tagCount, kMaxColorPlanes);
2426
2427 #if qDNGValidate
2428
2429 ReportWarning ("AsShotNeutral without ColorMatrix1");
2430
2431 #endif
2432
2433 }
2434
2435 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2436 return false;
2437
2438 if (!ParseVectorTag (stream,
2439 parentCode,
2440 tagCode,
2441 tagType,
2442 tagCount,
2443 fCameraProfile.fColorPlanes,
2444 fAsShotNeutral))
2445 return false;
2446
2447 #if qDNGValidate
2448
2449 if (gVerbose)
2450 {
2451
2452 printf ("AsShotNeutral:");
2453
2454 DumpVector (fAsShotNeutral);
2455
2456 }
2457
2458 #endif
2459
2460 break;
2461
2462 }
2463
2464 case tcAsShotWhiteXY:
2465 {
2466
2467 CheckTagType (parentCode, tagCode, tagType, ttRational);
2468
2469 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2470 return false;
2471
2472 if (!CheckTagCount (parentCode, tagCode, tagCount, 2))
2473 return false;
2474
2475 fAsShotWhiteXY.x = stream.TagValue_real64 (tagType);
2476 fAsShotWhiteXY.y = stream.TagValue_real64 (tagType);
2477
2478 #if qDNGValidate
2479
2480 if (gVerbose)
2481 {
2482
2483 printf ("AsShotWhiteXY: %0.4f %0.4f\n",
2484 fAsShotWhiteXY.x,
2485 fAsShotWhiteXY.y);
2486
2487 }
2488
2489 #endif
2490
2491 break;
2492
2493 }
2494
2495 case tcBaselineExposure:
2496 {
2497
2498 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2499
2500 CheckTagCount (parentCode, tagCode, tagCount, 1);
2501
2502 fBaselineExposure = stream.TagValue_srational (tagType);
2503
2504 fHasBaselineExposure = true;
2505
2506 #if qDNGValidate
2507
2508 if (gVerbose)
2509 {
2510
2511 printf ("BaselineExposure: %+0.2f\n",
2512 fBaselineExposure.As_real64 ());
2513
2514 }
2515
2516 #endif
2517
2518 break;
2519
2520 }
2521
2522 case tcBaselineNoise:
2523 {
2524
2525 CheckTagType (parentCode, tagCode, tagType, ttRational);
2526
2527 CheckTagCount (parentCode, tagCode, tagCount, 1);
2528
2529 fBaselineNoise = stream.TagValue_urational (tagType);
2530
2531 #if qDNGValidate
2532
2533 if (gVerbose)
2534 {
2535
2536 printf ("BaselineNoise: %0.2f\n",
2537 fBaselineNoise.As_real64 ());
2538
2539 }
2540
2541 #endif
2542
2543 break;
2544
2545 }
2546
2547 case tcBaselineSharpness:
2548 {
2549
2550 CheckTagType (parentCode, tagCode, tagType, ttRational);
2551
2552 CheckTagCount (parentCode, tagCode, tagCount, 1);
2553
2554 fBaselineSharpness = stream.TagValue_urational (tagType);
2555
2556 #if qDNGValidate
2557
2558 if (gVerbose)
2559 {
2560
2561 printf ("BaselineSharpness: %0.2f\n",
2562 fBaselineSharpness.As_real64 ());
2563
2564 }
2565
2566 #endif
2567
2568 break;
2569
2570 }
2571
2572 case tcLinearResponseLimit:
2573 {
2574
2575 CheckTagType (parentCode, tagCode, tagType, ttRational);
2576
2577 CheckTagCount (parentCode, tagCode, tagCount, 1);
2578
2579 fLinearResponseLimit = stream.TagValue_urational (tagType);
2580
2581 #if qDNGValidate
2582
2583 if (gVerbose)
2584 {
2585
2586 printf ("LinearResponseLimit: %0.2f\n",
2587 fLinearResponseLimit.As_real64 ());
2588
2589 }
2590
2591 #endif
2592
2593 break;
2594
2595 }
2596
2597 case tcShadowScale:
2598 {
2599
2600 CheckTagType (parentCode, tagCode, tagType, ttRational);
2601
2602 CheckTagCount (parentCode, tagCode, tagCount, 1);
2603
2604 fShadowScale = stream.TagValue_urational (tagType);
2605
2606 fHasShadowScale = true;
2607
2608 #if qDNGValidate
2609
2610 if (gVerbose)
2611 {
2612
2613 printf ("ShadowScale: %0.4f\n",
2614 fShadowScale.As_real64 ());
2615
2616 }
2617
2618 #endif
2619
2620 break;
2621
2622 }
2623
2624 case tcDNGPrivateData:
2625 {
2626
2627 CheckTagType (parentCode, tagCode, tagType, ttByte);
2628
2629 fDNGPrivateDataCount = tagCount;
2630 fDNGPrivateDataOffset = tagOffset;
2631
2632 #if qDNGValidate
2633
2634 if (gVerbose)
2635 {
2636
2637 printf ("DNGPrivateData: Count = %u, Offset = %u\n",
2638 (unsigned) fDNGPrivateDataCount,
2639 (unsigned) fDNGPrivateDataOffset);
2640
2641 DumpHexAscii (stream, tagCount);
2642
2643 }
2644
2645 #endif
2646
2647 break;
2648
2649 }
2650
2651 case tcMakerNoteSafety:
2652 {
2653
2654 CheckTagType (parentCode, tagCode, tagType, ttShort);
2655
2656 CheckTagCount (parentCode, tagCode, tagCount, 1);
2657
2658 fMakerNoteSafety = stream.TagValue_uint32 (tagType);
2659
2660 #if qDNGValidate
2661
2662 if (gVerbose)
2663 {
2664
2665 printf ("MakerNoteSafety: %s\n",
2666 LookupMakerNoteSafety (fMakerNoteSafety));
2667
2668 }
2669
2670 #endif
2671
2672 break;
2673
2674 }
2675
2676 case tcRawImageDigest:
2677 {
2678
2679 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
2680 return false;
2681
2682 if (!CheckTagCount (parentCode, tagCode, tagCount, 16))
2683 return false;
2684
2685 stream.Get (fRawImageDigest.data, 16);
2686
2687 #if qDNGValidate
2688
2689 if (gVerbose)
2690 {
2691
2692 printf ("RawImageDigest: ");
2693
2694 DumpFingerprint (fRawImageDigest);
2695
2696 printf ("\n");
2697
2698 }
2699
2700 #endif
2701
2702 break;
2703
2704 }
2705
2706 case tcNewRawImageDigest:
2707 {
2708
2709 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
2710 return false;
2711
2712 if (!CheckTagCount (parentCode, tagCode, tagCount, 16))
2713 return false;
2714
2715 stream.Get (fNewRawImageDigest.data, 16);
2716
2717 #if qDNGValidate
2718
2719 if (gVerbose)
2720 {
2721
2722 printf ("NewRawImageDigest: ");
2723
2724 DumpFingerprint (fNewRawImageDigest);
2725
2726 printf ("\n");
2727
2728 }
2729
2730 #endif
2731
2732 break;
2733
2734 }
2735
2736 case tcRawDataUniqueID:
2737 {
2738
2739 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
2740 return false;
2741
2742 if (!CheckTagCount (parentCode, tagCode, tagCount, 16))
2743 return false;
2744
2745 stream.Get (fRawDataUniqueID.data, 16);
2746
2747 #if qDNGValidate
2748
2749 if (gVerbose)
2750 {
2751
2752 printf ("RawDataUniqueID: ");
2753
2754 DumpFingerprint (fRawDataUniqueID);
2755
2756 printf ("\n");
2757
2758 }
2759
2760 #endif
2761
2762 break;
2763
2764 }
2765
2766 case tcOriginalRawFileName:
2767 {
2768
2769 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
2770
2771 ParseStringTag (stream,
2772 parentCode,
2773 tagCode,
2774 tagCount,
2775 fOriginalRawFileName,
2776 false);
2777
2778 #if qDNGValidate
2779
2780 if (gVerbose)
2781 {
2782
2783 printf ("OriginalRawFileName: ");
2784
2785 DumpString (fOriginalRawFileName);
2786
2787 printf ("\n");
2788
2789 }
2790
2791 #endif
2792
2793 break;
2794
2795 }
2796
2797 case tcOriginalRawFileData:
2798 {
2799
2800 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2801
2802 fOriginalRawFileDataCount = tagCount;
2803 fOriginalRawFileDataOffset = tagOffset;
2804
2805 #if qDNGValidate
2806
2807 if (gVerbose)
2808 {
2809
2810 printf ("OriginalRawFileData: Count = %u, Offset = %u\n",
2811 (unsigned) fOriginalRawFileDataCount,
2812 (unsigned) fOriginalRawFileDataOffset);
2813
2814 DumpHexAscii (stream, tagCount);
2815
2816 }
2817
2818 #endif
2819
2820 break;
2821
2822 }
2823
2824 case tcOriginalRawFileDigest:
2825 {
2826
2827 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
2828 return false;
2829
2830 if (!CheckTagCount (parentCode, tagCode, tagCount, 16))
2831 return false;
2832
2833 stream.Get (fOriginalRawFileDigest.data, 16);
2834
2835 #if qDNGValidate
2836
2837 if (gVerbose)
2838 {
2839
2840 printf ("OriginalRawFileDigest: ");
2841
2842 DumpFingerprint (fOriginalRawFileDigest);
2843
2844 printf ("\n");
2845
2846 }
2847
2848 #endif
2849
2850 break;
2851
2852 }
2853
2854 case tcAsShotICCProfile:
2855 {
2856
2857 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2858
2859 fAsShotICCProfileCount = tagCount;
2860 fAsShotICCProfileOffset = tagOffset;
2861
2862 #if qDNGValidate
2863
2864 if (gVerbose)
2865 {
2866
2867 printf ("AsShotICCProfile: Count = %u, Offset = %u\n",
2868 (unsigned) fAsShotICCProfileCount,
2869 (unsigned) fAsShotICCProfileOffset);
2870
2871 DumpHexAscii (stream, tagCount);
2872
2873 }
2874
2875 #endif
2876
2877 break;
2878
2879 }
2880
2881 case tcAsShotPreProfileMatrix:
2882 {
2883
2884 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2885
2886 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2887 return false;
2888
2889 uint32 rows = fCameraProfile.fColorPlanes;
2890
2891 if (tagCount == fCameraProfile.fColorPlanes * 3)
2892 {
2893 rows = 3;
2894 }
2895
2896 if (!ParseMatrixTag (stream,
2897 parentCode,
2898 tagCode,
2899 tagType,
2900 tagCount,
2901 rows,
2902 fCameraProfile.fColorPlanes,
2903 fAsShotPreProfileMatrix))
2904 return false;
2905
2906 #if qDNGValidate
2907
2908 if (gVerbose)
2909 {
2910
2911 printf ("AsShotPreProfileMatrix:\n");
2912
2913 DumpMatrix (fAsShotPreProfileMatrix);
2914
2915 }
2916
2917 #endif
2918
2919 break;
2920
2921 }
2922
2923 case tcCurrentICCProfile:
2924 {
2925
2926 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2927
2928 fCurrentICCProfileCount = tagCount;
2929 fCurrentICCProfileOffset = tagOffset;
2930
2931 #if qDNGValidate
2932
2933 if (gVerbose)
2934 {
2935
2936 printf ("CurrentICCProfile: Count = %u, Offset = %u\n",
2937 (unsigned) fCurrentICCProfileCount,
2938 (unsigned) fCurrentICCProfileOffset);
2939
2940 DumpHexAscii (stream, tagCount);
2941
2942 }
2943
2944 #endif
2945
2946 break;
2947
2948 }
2949
2950 case tcCurrentPreProfileMatrix:
2951 {
2952
2953 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2954
2955 if (!CheckColorImage (parentCode, tagCode, fCameraProfile.fColorPlanes))
2956 return false;
2957
2958 uint32 rows = fCameraProfile.fColorPlanes;
2959
2960 if (tagCount == fCameraProfile.fColorPlanes * 3)
2961 {
2962 rows = 3;
2963 }
2964
2965 if (!ParseMatrixTag (stream,
2966 parentCode,
2967 tagCode,
2968 tagType,
2969 tagCount,
2970 rows,
2971 fCameraProfile.fColorPlanes,
2972 fCurrentPreProfileMatrix))
2973 return false;
2974
2975 #if qDNGValidate
2976
2977 if (gVerbose)
2978 {
2979
2980 printf ("CurrentPreProfileMatrix:\n");
2981
2982 DumpMatrix (fCurrentPreProfileMatrix);
2983
2984 }
2985
2986 #endif
2987
2988 break;
2989
2990 }
2991
2992 case tcColorimetricReference:
2993 {
2994
2995 CheckTagType (parentCode, tagCode, tagType, ttShort);
2996
2997 CheckTagCount (parentCode, tagCode, tagCount, 1);
2998
2999 fColorimetricReference = stream.TagValue_uint32 (tagType);
3000
3001 #if qDNGValidate
3002
3003 if (gVerbose)
3004 {
3005
3006 printf ("ColorimetricReference: %s\n",
3007 LookupColorimetricReference (fColorimetricReference));
3008
3009 }
3010
3011 #endif
3012
3013 break;
3014
3015 }
3016
3017 case tcExtraCameraProfiles:
3018 {
3019
3020 CheckTagType (parentCode, tagCode, tagType, ttLong, ttLong8);
3021
3022 CheckTagCount (parentCode, tagCode, tagCount, 1, tagCount);
3023
3024 #if qDNGValidate
3025
3026 if (gVerbose)
3027 {
3028
3029 printf ("ExtraCameraProfiles: %u\n", (unsigned) tagCount);
3030
3031 }
3032
3033 #endif
3034
3035 fExtraCameraProfiles.reserve (tagCount);
3036
3037 for (uint32 index = 0; index < tagCount; index++)
3038 {
3039
3040 #if qDNGValidate
3041
3042 if (gVerbose)
3043 {
3044
3045 printf ("\nExtraCameraProfile [%u]:\n\n", (unsigned) index);
3046
3047 }
3048
3049 #endif
3050
3051 uint64 profileOffset = stream.TagValue_uint64 (tagType);
3052
3053 uint64 savePosition = stream.Position ();
3054
3055 dng_camera_profile_info profileInfo;
3056
3057 stream.SetReadPosition (profileOffset);
3058
3059 if (profileInfo.ParseExtended (stream))
3060 {
3061
3062 fExtraCameraProfiles.push_back (profileInfo);
3063
3064 }
3065
3066 else
3067 {
3068
3069 #if qDNGValidate
3070
3071 ReportWarning ("Unable to parse extra camera profile");
3072
3073 #endif
3074
3075 }
3076
3077 stream.SetReadPosition (savePosition);
3078
3079 }
3080
3081 #if qDNGValidate
3082
3083 if (gVerbose)
3084 {
3085
3086 printf ("\nDone with ExtraCameraProfiles\n\n");
3087
3088 }
3089
3090 #endif
3091
3092 break;
3093
3094 }
3095
3096 case tcAsShotProfileName:
3097 {
3098
3099 CheckTagType (parentCode, tagCode, tagType, ttAscii, ttByte);
3100
3101 ParseStringTag (stream,
3102 parentCode,
3103 tagCode,
3104 tagCount,
3105 fAsShotProfileName,
3106 false);
3107
3108 #if qDNGValidate
3109
3110 if (gVerbose)
3111 {
3112
3113 printf ("AsShotProfileName: ");
3114
3115 DumpString (fAsShotProfileName);
3116
3117 printf ("\n");
3118
3119 }
3120
3121 #endif
3122
3123 break;
3124
3125 }
3126
3127 case tcOriginalDefaultFinalSize:
3128 {
3129
3130 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
3131
3132 if (!CheckTagCount (parentCode, tagCode, tagCount, 2))
3133 return false;
3134
3135 fOriginalDefaultFinalSize.h = stream.TagValue_int32 (tagType);
3136 fOriginalDefaultFinalSize.v = stream.TagValue_int32 (tagType);
3137
3138 #if qDNGValidate
3139
3140 if (gVerbose)
3141 {
3142
3143 printf ("OriginalDefaultFinalSize: H = %d V = %d\n",
3144 (int) fOriginalDefaultFinalSize.h,
3145 (int) fOriginalDefaultFinalSize.v);
3146
3147 }
3148
3149 #endif
3150
3151 break;
3152
3153 }
3154
3155 case tcOriginalBestQualityFinalSize:
3156 {
3157
3158 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
3159
3160 if (!CheckTagCount (parentCode, tagCode, tagCount, 2))
3161 return false;
3162
3163 fOriginalBestQualityFinalSize.h = stream.TagValue_int32 (tagType);
3164 fOriginalBestQualityFinalSize.v = stream.TagValue_int32 (tagType);
3165
3166 #if qDNGValidate
3167
3168 if (gVerbose)
3169 {
3170
3171 printf ("OriginalBestQualityFinalSize: H = %d V = %d\n",
3172 (int) fOriginalBestQualityFinalSize.h,
3173 (int) fOriginalBestQualityFinalSize.v);
3174
3175 }
3176
3177 #endif
3178
3179 break;
3180
3181 }
3182
3183 case tcOriginalDefaultCropSize:
3184 {
3185
3186 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong, ttRational);
3187
3188 if (!CheckTagCount (parentCode, tagCode, tagCount, 2))
3189 return false;
3190
3191 fOriginalDefaultCropSizeH = stream.TagValue_urational (tagType);
3192 fOriginalDefaultCropSizeV = stream.TagValue_urational (tagType);
3193
3194 #if qDNGValidate
3195
3196 if (gVerbose)
3197 {
3198
3199 printf ("OriginalDefaultCropSize: H = %0.2f V = %0.2f\n",
3200 fOriginalDefaultCropSizeH.As_real64 (),
3201 fOriginalDefaultCropSizeV.As_real64 ());
3202
3203 }
3204
3205 #endif
3206
3207 break;
3208
3209 }
3210
3211 case tcDepthFormat:
3212 {
3213
3214 CheckTagType (parentCode, tagCode, tagType, ttShort);
3215
3216 CheckTagCount (parentCode, tagCode, tagCount, 1);
3217
3218 fDepthFormat = stream.TagValue_uint32 (tagType);
3219
3220 #if qDNGValidate
3221
3222 if (gVerbose)
3223 {
3224
3225 printf ("DepthFormat: %s\n",
3226 LookupDepthFormat (fDepthFormat));
3227
3228 }
3229
3230 #endif
3231
3232 break;
3233
3234 }
3235
3236 case tcDepthNear:
3237 {
3238
3239 CheckTagType (parentCode, tagCode, tagType, ttRational);
3240
3241 CheckTagCount (parentCode, tagCode, tagCount, 1);
3242
3243 fDepthNear = stream.TagValue_urational (tagType);
3244
3245 #if qDNGValidate
3246
3247 if (gVerbose)
3248 {
3249
3250 printf ("DepthNear: ");
3251
3252 if (fDepthNear == dng_urational (0, 0))
3253 {
3254 printf ("Unknown");
3255 }
3256 else if (fDepthNear.d == 0)
3257 {
3258 printf ("Infinity");
3259 }
3260 else
3261 {
3262 printf ("%0.2f", fDepthNear.As_real64 ());
3263 }
3264
3265 printf ("\n");
3266
3267 }
3268
3269 #endif
3270
3271 break;
3272
3273 }
3274
3275 case tcDepthFar:
3276 {
3277
3278 CheckTagType (parentCode, tagCode, tagType, ttRational);
3279
3280 CheckTagCount (parentCode, tagCode, tagCount, 1);
3281
3282 fDepthFar = stream.TagValue_urational (tagType);
3283
3284 #if qDNGValidate
3285
3286 if (gVerbose)
3287 {
3288
3289 printf ("DepthFar: ");
3290
3291 if (fDepthFar == dng_urational (0, 0))
3292 {
3293 printf ("Unknown");
3294 }
3295 else if (fDepthFar.d == 0)
3296 {
3297 printf ("Infinity");
3298 }
3299 else
3300 {
3301 printf ("%0.2f", fDepthFar.As_real64 ());
3302 }
3303
3304 printf ("\n");
3305
3306 }
3307
3308 #endif
3309
3310 break;
3311
3312 }
3313
3314 case tcDepthUnits:
3315 {
3316
3317 CheckTagType (parentCode, tagCode, tagType, ttShort);
3318
3319 CheckTagCount (parentCode, tagCode, tagCount, 1);
3320
3321 fDepthUnits = stream.TagValue_uint32 (tagType);
3322
3323 #if qDNGValidate
3324
3325 if (gVerbose)
3326 {
3327
3328 printf ("DepthUnits: %s\n",
3329 LookupDepthUnits (fDepthUnits));
3330
3331 }
3332
3333 #endif
3334
3335 break;
3336
3337 }
3338
3339 case tcDepthMeasureType:
3340 {
3341
3342 CheckTagType (parentCode, tagCode, tagType, ttShort);
3343
3344 CheckTagCount (parentCode, tagCode, tagCount, 1);
3345
3346 fDepthMeasureType = stream.TagValue_uint32 (tagType);
3347
3348 #if qDNGValidate
3349
3350 if (gVerbose)
3351 {
3352
3353 printf ("DepthMeasureType: %s\n",
3354 LookupDepthMeasureType (fDepthMeasureType));
3355
3356 }
3357
3358 #endif
3359
3360 break;
3361
3362 }
3363
3364 case tcBigTableDigests:
3365 {
3366
3367 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
3368 return false;
3369
3370 if (!CheckTagCount (parentCode, tagCode, tagCount, 16, 0xFFFFFFF0))
3371 return false;
3372
3373 uint32 count = tagCount >> 4;
3374
3375 fBigTableDigests.clear ();
3376 fBigTableDigests.reserve (count);
3377
3378 fBigTableOffsets.clear ();
3379 fBigTableOffsets.reserve (count);
3380
3381 fBigTableByteCounts.clear ();
3382 fBigTableByteCounts.reserve (count);
3383
3384 for (uint32 index = 0; index < count; index++)
3385 {
3386
3387 dng_fingerprint fingerprint;
3388
3389 stream.Get (fingerprint.data, 16);
3390
3391 fBigTableDigests.push_back (fingerprint);
3392
3393 fBigTableOffsets .push_back (0);
3394 fBigTableByteCounts.push_back (0);
3395
3396 }
3397
3398 #if qDNGValidate
3399
3400 if (gVerbose)
3401 {
3402
3403 printf ("BigTableDigests:\n");
3404
3405 for (uint32 index = 0; index < count; index++)
3406 {
3407
3408 printf ("\t[%u] = ", index);
3409
3410 DumpFingerprint (fBigTableDigests [index]);
3411
3412 printf ("\n");
3413
3414 }
3415
3416 }
3417
3418 #endif
3419
3420 break;
3421
3422 }
3423
3424 case tcBigTableOffsets:
3425 {
3426
3427 if (!CheckTagType (parentCode, tagCode, tagType, ttLong, ttLong8))
3428 return false;
3429
3430 if (!CheckTagCount (parentCode, tagCode, tagCount, (uint32) fBigTableOffsets.size ()))
3431 return false;
3432
3433 for (uint32 index = 0; index < tagCount; index++)
3434 {
3435
3436 fBigTableOffsets [index] = stream.TagValue_uint64 (tagType);
3437
3438 if (fBigTableOffsets [index] >= stream.Length ())
3439 {
3440
3441 DNG_REPORT ("Invalid big table offset");
3442
3443 fBigTableDigests .clear ();
3444 fBigTableOffsets .clear ();
3445 fBigTableByteCounts.clear ();
3446
3447 return false;
3448
3449 }
3450
3451 }
3452
3453 #if qDNGValidate
3454
3455 if (gVerbose)
3456 {
3457
3458 stream.SetReadPosition (tagOffset);
3459
3460 DumpTagValues (stream,
3461 "Offset",
3462 parentCode,
3463 tagCode,
3464 tagType,
3465 tagCount);
3466
3467 }
3468
3469 #endif
3470
3471 break;
3472
3473 }
3474
3475 case tcBigTableByteCounts:
3476 {
3477
3478 if (!CheckTagType (parentCode, tagCode, tagType, ttLong, ttLong8))
3479 return false;
3480
3481 if (!CheckTagCount (parentCode, tagCode, tagCount, (uint32) fBigTableByteCounts.size ()))
3482 return false;
3483
3484 for (uint32 index = 0; index < tagCount; index++)
3485 {
3486
3487 uint64 byteCount64 = stream.TagValue_uint64 (tagType);
3488
3489 if (byteCount64 > 0xFFFFFFFF)
3490 {
3491 continue;
3492 }
3493
3494 fBigTableByteCounts [index] = (uint32) byteCount64;
3495
3496 if (fBigTableByteCounts [index] +
3497 fBigTableOffsets [index] > stream.Length ())
3498 {
3499
3500 DNG_REPORT ("Invalid big table byte count");
3501
3502 fBigTableDigests .clear ();
3503 fBigTableOffsets .clear ();
3504 fBigTableByteCounts.clear ();
3505
3506 return false;
3507
3508 }
3509
3510 }
3511
3512 #if qDNGValidate
3513
3514 if (gVerbose)
3515 {
3516
3517 stream.SetReadPosition (tagOffset);
3518
3519 DumpTagValues (stream,
3520 "Count",
3521 parentCode,
3522 tagCode,
3523 tagType,
3524 tagCount);
3525
3526 }
3527
3528 #endif
3529
3530 break;
3531
3532 }
3533
3534 case tcBigTableGroupIndex:
3535 {
3536
3537 if (!CheckTagType (parentCode, tagCode, tagType, ttByte))
3538 return false;
3539
3540 if (!CheckTagCount (parentCode, tagCode, tagCount, 32, 0xFFFFFFF0))
3541 return false;
3542
3543 // Pairs of digests:
3544 // group_digest, dng_fingerprint, 16 bytes
3545 // instance_digest, dng_fingerprint, 16 bytes
3546 // Each pair is 32 bytes.
3547
3548 const uint32 count = tagCount >> 5;
3549
3550 fBigTableGroupIndex.clear ();
3551
3552 for (uint32 index = 0; index < count; index++)
3553 {
3554
3555 dng_fingerprint groupDigest;
3556 dng_fingerprint instanceDigest;
3557
3558 stream.Get (groupDigest .data, 16);
3559 stream.Get (instanceDigest.data, 16);
3560
3561 fBigTableGroupIndex.insert (std::make_pair (groupDigest,
3562 instanceDigest));
3563
3564 }
3565
3566 #if qDNGValidate
3567
3568 if (gVerbose)
3569 {
3570
3571 printf ("BigTableGroupIndex:\n");
3572
3573 uint32 index = 0;
3574
3575 for (const auto &entry : fBigTableGroupIndex)
3576 {
3577
3578 printf ("\t[%u] = ", index);
3579
3580 DumpFingerprint (entry.first);
3581
3582 printf (" -> ");
3583
3584 DumpFingerprint (entry.second);
3585
3586 printf ("\n");
3587
3588 index++;
3589
3590 }
3591
3592 }
3593
3594 #endif // qDNGValidate
3595
3596 break;
3597
3598 }
3599
3600 case tcImageSequenceInfo:
3601 {
3602
3603 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
3604 return false;
3605
3606 constexpr uint32 kMaxTagCount = 1024 * 1024;
3607
3608 constexpr uint32 kMinTagCount = (9 + // Sequence ID
3609 2 + // Sequence Type
3610 1 + // Frame Info
3611 4 + // Index
3612 4 + // Count
3613 1); // Final
3614
3615 if (tagCount < kMinTagCount)
3616 {
3617
3618 #if qDNGValidate
3619 ReportWarning ("ImageSequenceInfo tag too small -- skipping");
3620 #endif
3621
3622 return false;
3623
3624 }
3625
3626 if (tagCount > kMaxTagCount)
3627 {
3628
3629 #if qDNGValidate
3630 ReportWarning ("ImageSequenceInfo tag unusually large -- skipping");
3631 #endif
3632
3633 return false;
3634
3635 }
3636
3637 dng_image_sequence_info &info = fImageSequenceInfo;
3638
3639 std::vector<char> buf;
3640
3641 buf.resize (tagCount + 1);
3642
3643 char *ptr = &buf [0];
3644
3645 // Read sequence ID.
3646
3647 stream.Get_CString (ptr, tagCount);
3648
3649 info.fSequenceID.Set (ptr);
3650
3651 // Read sequence type.
3652
3653 stream.Get_CString (ptr, tagCount);
3654
3655 info.fSequenceType.Set (ptr);
3656
3657 // Read frame info.
3658
3659 stream.Get_CString (ptr, tagCount);
3660
3661 info.fFrameInfo.Set (ptr);
3662
3663 // Get index, count, and final fields.
3664
3665 TempBigEndian tempEndian (stream);
3666
3667 info.fIndex = stream.Get_uint32 ();
3668 info.fCount = stream.Get_uint32 ();
3669
3670 info.fIsFinal = stream.Get_uint8 ();
3671
3672 #if qDNGValidate
3673
3674 if (gVerbose)
3675 {
3676
3677 printf ("ImageSequenceInfo: seq_id=%s, seq_type=%s, "
3678 "frame_info=%s, index=%u, count=%u, final=%u\n",
3679 info.fSequenceID.Get (),
3680 info.fSequenceType.Get (),
3681 info.fFrameInfo.Get (),
3682 unsigned (info.fIndex),
3683 unsigned (info.fCount),
3684 unsigned (info.fIsFinal));
3685
3686
3687 }
3688
3689 #endif // qDNGValidate
3690
3691 break;
3692
3693 }
3694
3695 default:
3696 {
3697
3698 // The main camera profile tags also appear in IFD 0
3699
3700 return fCameraProfile.ParseTag (stream,
3701 parentCode,
3702 tagCode,
3703 tagType,
3704 tagCount,
3705 tagOffset);
3706
3707 }
3708
3709 }
3710
3711 return true;
3712
3713 }
3714
3715 /*****************************************************************************/
3716
3717 // Parses tags that should only appear in IFD 0 or EXIF IFD.
3718
3719 bool dng_shared::Parse_ifd0_exif (dng_stream &stream,
3720 dng_exif & /* exif */,
3721 uint32 parentCode,
3722 uint32 tagCode,
3723 uint32 tagType,
3724 uint32 tagCount,
3725 uint64 tagOffset)
3726 {
3727
3728 switch (tagCode)
3729 {
3730
3731 case tcMakerNote:
3732 {
3733
3734 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
3735
3736 fMakerNoteCount = tagCount;
3737 fMakerNoteOffset = tagOffset;
3738
3739 #if qDNGValidate
3740
3741 if (gVerbose)
3742 {
3743
3744 printf ("MakerNote: Count = %u, Offset = %u\n",
3745 (unsigned) fMakerNoteCount,
3746 (unsigned) fMakerNoteOffset);
3747
3748 DumpHexAscii (stream, tagCount);
3749
3750 }
3751
3752 #endif
3753
3754 break;
3755
3756 }
3757
3758 case tcInteroperabilityIFD:
3759 {
3760
3761 CheckTagType (parentCode, tagCode, tagType, ttLong, ttIFD);
3762
3763 CheckTagCount (parentCode, tagCode, tagCount, 1);
3764
3765 fInteroperabilityIFD = stream.TagValue_uint32 (tagType);
3766
3767 #if qDNGValidate
3768
3769 if (gVerbose)
3770 {
3771 printf ("InteroperabilityIFD: %u\n", (unsigned) fInteroperabilityIFD);
3772 }
3773
3774 #endif
3775
3776 break;
3777
3778 }
3779
3780 default:
3781 {
3782
3783 return false;
3784
3785 }
3786
3787 }
3788
3789 return true;
3790
3791 }
3792
3793 /*****************************************************************************/
3794
3795 void dng_shared::PostParse (dng_host & /* host */,
3796 dng_exif & /* exif */)
3797 {
3798
3799 // Fill in default values for DNG images.
3800
3801 if (fDNGVersion != 0)
3802 {
3803
3804 // Support for DNG versions before 1.0.0.0.
3805
3806 if (fDNGVersion < dngVersion_1_0_0_0)
3807 {
3808
3809 #if qDNGValidate
3810
3811 ReportWarning ("DNGVersion less than 1.0.0.0");
3812
3813 #endif
3814
3815 // The CalibrationIlluminant tags were added just before
3816 // DNG version 1.0.0.0, and were hardcoded before that.
3817
3818 fCameraProfile.fCalibrationIlluminant1 = lsStandardLightA;
3819 fCameraProfile.fCalibrationIlluminant2 = lsD65;
3820 fCameraProfile.fCalibrationIlluminant3 = lsD65;
3821
3822 fDNGVersion = dngVersion_1_0_0_0;
3823
3824 }
3825
3826 // Default value for DNGBackwardVersion tag.
3827
3828 if (fDNGBackwardVersion == 0)
3829 {
3830
3831 fDNGBackwardVersion = fDNGVersion & 0xFFFF0000;
3832
3833 }
3834
3835 // Check DNGBackwardVersion value.
3836
3837 if (fDNGBackwardVersion < dngVersion_1_0_0_0)
3838 {
3839
3840 #if qDNGValidate
3841
3842 ReportWarning ("DNGBackwardVersion less than 1.0.0.0");
3843
3844 #endif
3845
3846 fDNGBackwardVersion = dngVersion_1_0_0_0;
3847
3848 }
3849
3850 if (fDNGBackwardVersion > fDNGVersion)
3851 {
3852
3853 #if qDNGValidate
3854
3855 ReportWarning ("DNGBackwardVersion > DNGVersion");
3856
3857 #endif
3858
3859 fDNGBackwardVersion = fDNGVersion;
3860
3861 }
3862
3863 // Check UniqueCameraModel.
3864
3865 if (fUniqueCameraModel.IsEmpty ())
3866 {
3867
3868 #if qDNGValidate
3869
3870 ReportWarning ("Missing or invalid UniqueCameraModel");
3871
3872 #endif
3873
3874 fUniqueCameraModel.Set ("Digital Negative");
3875
3876 }
3877
3878 // If we don't know the color depth yet, it must be a monochrome DNG.
3879
3880 if (fCameraProfile.fColorPlanes == 0)
3881 {
3882
3883 fCameraProfile.fColorPlanes = 1;
3884
3885 }
3886
3887 if ((fCameraProfile.fCalibrationIlluminant3 != lsUnknown) &&
3888 fCameraProfile.fColorMatrix3.IsEmpty ())
3889 {
3890
3891 #if qDNGValidate
3892
3893 ReportWarning ("Ignoring CalibrationIlluminant3 because "
3894 "ColorMatrix3 invalid or missing");
3895
3896 #endif
3897
3898 fCameraProfile.fCalibrationIlluminant3 = lsUnknown;
3899
3900 }
3901
3902 if (fCameraProfile.fCalibrationIlluminant3 == lsUnknown)
3903 {
3904
3905 if (fCameraProfile.fColorMatrix3.NotEmpty ())
3906 {
3907
3908 #if qDNGValidate
3909
3910 ReportWarning ("Ignoring ColorMatrix3 because "
3911 "CalibrationIlluminant3 is unknown/missing");
3912
3913 #endif
3914
3915 fCameraProfile.fColorMatrix3.Clear ();
3916
3917 }
3918
3919 if (fCameraProfile.fForwardMatrix3.NotEmpty ())
3920 {
3921
3922 #if qDNGValidate
3923
3924 ReportWarning ("Ignoring ForwardMatrix3 because "
3925 "CalibrationIlluminant3 is unknown/missing");
3926
3927 #endif
3928
3929 fCameraProfile.fForwardMatrix3.Clear ();
3930
3931 }
3932
3933 if (fCameraProfile.fReductionMatrix3.NotEmpty ())
3934 {
3935
3936 #if qDNGValidate
3937
3938 ReportWarning ("Ignoring ReductionMatrix3 because "
3939 "CalibrationIlluminant3 is unknown/missing");
3940
3941 #endif
3942
3943 fCameraProfile.fReductionMatrix3.Clear ();
3944
3945 }
3946
3947 if (fCameraProfile.fHueSatDeltas3Offset != 0 ||
3948 fCameraProfile.fHueSatDeltas3Count != 0)
3949 {
3950
3951 #if qDNGValidate
3952
3953 ReportWarning ("Ignoring ProfileHueSatMapData3 because "
3954 "CalibrationIlluminant3 is unknown/missing");
3955
3956 #endif
3957
3958 fCameraProfile.fHueSatDeltas3Offset = 0;
3959 fCameraProfile.fHueSatDeltas3Count = 0;
3960
3961 }
3962
3963 }
3964
3965 // Check color info.
3966
3967 if (fCameraProfile.fColorPlanes > 1)
3968 {
3969
3970 // Check illuminant pair. This is for the dual-illuminant model.
3971
3972 // More detailed checks for triple-illuminant profiles are done in
3973 // dng_camera_profile::IsValid.
3974
3975 if (fCameraProfile.fColorMatrix2.NotEmpty ())
3976 {
3977
3978 // Are illuminants 1 and 2 the same? Start by assuming not.
3979
3980 bool sameLight = false;
3981
3982 if (fCameraProfile.fCalibrationIlluminant1 == fCameraProfile.fCalibrationIlluminant2)
3983 {
3984
3985 // Lights 1 and 2 have the same tag code. If they are
3986 // something besides lsOther, then they're the same light.
3987
3988 if (fCameraProfile.fCalibrationIlluminant1 != lsOther)
3989 {
3990
3991 sameLight = true;
3992
3993 }
3994
3995 // Both are lsOther, so check the custom data fields for
3996 // the same white point.
3997
3998 else
3999 {
4000
4001 dng_xy_coord white1 = fCameraProfile.fIlluminantData1.WhiteXY ();
4002 dng_xy_coord white2 = fCameraProfile.fIlluminantData2.WhiteXY ();
4003
4004 sameLight = (white1 == white2);
4005
4006 }
4007
4008 }
4009
4010 if (fCameraProfile.fCalibrationIlluminant1 == lsUnknown ||
4011 fCameraProfile.fCalibrationIlluminant2 == lsUnknown ||
4012 sameLight)
4013 {
4014
4015 #if qDNGValidate
4016
4017 ReportWarning ("Invalid CalibrationIlluminant pair");
4018
4019 #endif
4020
4021 fCameraProfile.fColorMatrix2 = dng_matrix ();
4022
4023 }
4024
4025 }
4026
4027 // If the colorimetric reference is the ICC profile PCS, then the
4028 // data must already be white balanced. The "AsShotWhiteXY" is
4029 // required to be the ICC Profile PCS white point.
4030
4031 if (fColorimetricReference == crICCProfilePCS ||
4032 fColorimetricReference == crOutputReferredHDR)
4033 {
4034
4035 if (fAsShotNeutral.NotEmpty ())
4036 {
4037
4038 #if qDNGValidate
4039
4040 ReportWarning ("AsShotNeutral not allowed for this "
4041 "ColorimetricReference value");
4042
4043 #endif
4044
4045 fAsShotNeutral.Clear ();
4046
4047 }
4048
4049 dng_xy_coord pcs = PCStoXY ();
4050
4051 #if qDNGValidate
4052
4053 if (fAsShotWhiteXY.IsValid ())
4054 {
4055
4056 if (Abs_real64 (fAsShotWhiteXY.x - pcs.x) > 0.01 ||
4057 Abs_real64 (fAsShotWhiteXY.y - pcs.y) > 0.01)
4058 {
4059
4060 ReportWarning ("AsShotWhiteXY does not match the ICC Profile PCS");
4061
4062 }
4063
4064 }
4065
4066 #endif
4067
4068 fAsShotWhiteXY = pcs;
4069
4070 }
4071
4072 else
4073 {
4074
4075 // Warn if both AsShotNeutral and AsShotWhiteXY are specified.
4076
4077 if (fAsShotNeutral.NotEmpty () && fAsShotWhiteXY.IsValid ())
4078 {
4079
4080 #if qDNGValidate
4081
4082 ReportWarning ("Both AsShotNeutral and AsShotWhiteXY included");
4083
4084 #endif
4085
4086 fAsShotWhiteXY = dng_xy_coord ();
4087
4088 }
4089
4090 // Warn if neither AsShotNeutral nor AsShotWhiteXY are specified.
4091
4092 #if qDNGValidate
4093
4094 if (fAsShotNeutral.IsEmpty () && !fAsShotWhiteXY.IsValid ())
4095 {
4096
4097 ReportWarning ("Neither AsShotNeutral nor AsShotWhiteXY included",
4098 "legal but not recommended");
4099
4100 }
4101
4102 #endif
4103
4104 }
4105
4106 // Default values of calibration signatures are required for legacy
4107 // compatibility.
4108
4109 if (fCameraProfile.fCalibrationIlluminant1 == lsStandardLightA &&
4110 fCameraProfile.fCalibrationIlluminant2 == lsD65 &&
4111 fCameraProfile.fCalibrationIlluminant3 == lsUnknown &&
4112 fCameraCalibration1.Rows () == fCameraProfile.fColorPlanes &&
4113 fCameraCalibration1.Cols () == fCameraProfile.fColorPlanes &&
4114 fCameraCalibration2.Rows () == fCameraProfile.fColorPlanes &&
4115 fCameraCalibration2.Cols () == fCameraProfile.fColorPlanes &&
4116 fCameraCalibration3.IsEmpty () &&
4117 fCameraCalibrationSignature.IsEmpty () &&
4118 fCameraProfile.fProfileCalibrationSignature.IsEmpty () )
4119 {
4120
4121 fCameraCalibrationSignature.Set (kAdobeCalibrationSignature);
4122
4123 fCameraProfile.fProfileCalibrationSignature.Set (kAdobeCalibrationSignature);
4124
4125 }
4126
4127 }
4128
4129 // Check BaselineNoise.
4130
4131 if (fBaselineNoise.As_real64 () <= 0.0)
4132 {
4133
4134 #if qDNGValidate
4135
4136 ReportWarning ("Invalid BaselineNoise");
4137
4138 #endif
4139
4140 fBaselineNoise = dng_urational (1, 1);
4141
4142 }
4143
4144 // Check BaselineSharpness.
4145
4146 if (fBaselineSharpness.As_real64 () <= 0.0)
4147 {
4148
4149 #if qDNGValidate
4150
4151 ReportWarning ("Invalid BaselineSharpness");
4152
4153 #endif
4154
4155 fBaselineSharpness = dng_urational (1, 1);
4156
4157 }
4158
4159 // Check LinearResponseLimit.
4160
4161 if (fLinearResponseLimit.As_real64 () < 0.5 ||
4162 fLinearResponseLimit.As_real64 () > 1.0)
4163 {
4164
4165 #if qDNGValidate
4166
4167 ReportWarning ("Invalid LinearResponseLimit");
4168
4169 #endif
4170
4171 fLinearResponseLimit = dng_urational (1, 1);
4172
4173 }
4174
4175 // Check ShadowScale.
4176
4177 if (fShadowScale.As_real64 () <= 0.0)
4178 {
4179
4180 #if qDNGValidate
4181
4182 ReportWarning ("Invalid ShadowScale");
4183
4184 #endif
4185
4186 fShadowScale = dng_urational (1, 1);
4187
4188 }
4189
4190 }
4191
4192 }
4193
4194 /*****************************************************************************/
4195
4196 bool dng_shared::IsValidDNG ()
4197 {
4198
4199 // Check DNGVersion value.
4200
4201 if (fDNGVersion < dngVersion_1_0_0_0)
4202 {
4203
4204 #if qDNGValidate
4205
4206 if (fDNGVersion != dngVersion_None)
4207 {
4208
4209 ReportError ("Invalid DNGVersion");
4210
4211 }
4212
4213 #if qDNGValidateTarget
4214
4215 else
4216 {
4217
4218 ReportError ("Missing DNGVersion");
4219
4220 }
4221
4222 #endif
4223
4224 #endif
4225
4226 return false;
4227
4228 }
4229
4230 // Check DNGBackwardVersion value.
4231
4232 if (fDNGBackwardVersion > dngVersion_Current)
4233 {
4234
4235 #if qDNGValidate
4236
4237 ReportError ("DNGBackwardVersion (or DNGVersion) is too high");
4238
4239 #endif
4240
4241 ThrowUnsupportedDNG ();
4242
4243 }
4244
4245 // Check color transform info.
4246
4247 if (fCameraProfile.fColorPlanes > 1)
4248 {
4249
4250 // CameraCalibration1 is optional, but it must be valid if present.
4251
4252 if (fCameraCalibration1.Cols () != 0 ||
4253 fCameraCalibration1.Rows () != 0)
4254 {
4255
4256 if (fCameraCalibration1.Cols () != fCameraProfile.fColorPlanes ||
4257 fCameraCalibration1.Rows () != fCameraProfile.fColorPlanes)
4258 {
4259
4260 #if qDNGValidate
4261
4262 ReportError ("CameraCalibration1 is wrong size");
4263
4264 #endif
4265
4266 return false;
4267
4268 }
4269
4270 // Make sure it is invertable.
4271
4272 try
4273 {
4274
4275 (void) Invert (fCameraCalibration1);
4276
4277 }
4278
4279 catch (...)
4280 {
4281
4282 #if qDNGValidate
4283
4284 ReportError ("CameraCalibration1 is not invertable");
4285
4286 #endif
4287
4288 return false;
4289
4290 }
4291
4292 }
4293
4294 // CameraCalibration2 is optional, but it must be valid if present.
4295
4296 if (fCameraCalibration2.Cols () != 0 ||
4297 fCameraCalibration2.Rows () != 0)
4298 {
4299
4300 if (fCameraCalibration2.Cols () != fCameraProfile.fColorPlanes ||
4301 fCameraCalibration2.Rows () != fCameraProfile.fColorPlanes)
4302 {
4303
4304 #if qDNGValidate
4305
4306 ReportError ("CameraCalibration2 is wrong size");
4307
4308 #endif
4309
4310 return false;
4311
4312 }
4313
4314 // Make sure it is invertable.
4315
4316 try
4317 {
4318
4319 (void) Invert (fCameraCalibration2);
4320
4321 }
4322
4323 catch (...)
4324 {
4325
4326 #if qDNGValidate
4327
4328 ReportError ("CameraCalibration2 is not invertable");
4329
4330 #endif
4331
4332 return false;
4333
4334 }
4335
4336 }
4337
4338 // CameraCalibration3 is optional, but it must be valid if present.
4339
4340 if (fCameraCalibration3.Cols () != 0 ||
4341 fCameraCalibration3.Rows () != 0)
4342 {
4343
4344 if (fCameraCalibration3.Cols () != fCameraProfile.fColorPlanes ||
4345 fCameraCalibration3.Rows () != fCameraProfile.fColorPlanes)
4346 {
4347
4348 #if qDNGValidate
4349
4350 ReportError ("CameraCalibration3 is wrong size");
4351
4352 #endif
4353
4354 return false;
4355
4356 }
4357
4358 // Make sure it is invertable.
4359
4360 try
4361 {
4362
4363 (void) Invert (fCameraCalibration3);
4364
4365 }
4366
4367 catch (...)
4368 {
4369
4370 #if qDNGValidate
4371
4372 ReportError ("CameraCalibration3 is not invertable");
4373
4374 #endif
4375
4376 return false;
4377
4378 }
4379
4380 }
4381
4382 // Check analog balance
4383
4384 dng_matrix analogBalance;
4385
4386 if (fAnalogBalance.NotEmpty ())
4387 {
4388
4389 analogBalance = fAnalogBalance.AsDiagonal ();
4390
4391 try
4392 {
4393
4394 (void) Invert (analogBalance);
4395
4396 }
4397
4398 catch (...)
4399 {
4400
4401 #if qDNGValidate
4402
4403 ReportError ("AnalogBalance is not invertable");
4404
4405 #endif
4406
4407 return false;
4408
4409 }
4410
4411 }
4412
4413 }
4414
4415 return true;
4416
4417 }
4418
4419 /*****************************************************************************/