Debian Codegraph @

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

raw
1 /*****************************************************************************/
2 // Copyright 2006-2019 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_flags.h"
10
11 /*****************************************************************************/
12
13 #if qDNGUseXMP
14
15 /*****************************************************************************/
16
17 #include "dng_assertions.h"
18 #include "dng_date_time.h"
19 #include "dng_exceptions.h"
20 #include "dng_exif.h"
21 #include "dng_image_writer.h"
22 #include "dng_iptc.h"
23 #include "dng_negative.h"
24 #include "dng_string.h"
25 #include "dng_string_list.h"
26 #include "dng_utils.h"
27 #include "dng_xmp.h"
28 #include "dng_xmp_sdk.h"
29
30 /*****************************************************************************/
31
32 dng_xmp::dng_xmp (dng_memory_allocator &allocator)
33
34 : fAllocator (allocator)
35
36 , fSDK (NULL)
37
38 {
39
40 fSDK = new dng_xmp_sdk ();
41
42 if (!fSDK)
43 {
44 ThrowMemoryFull ();
45 }
46
47 }
48
49 /*****************************************************************************/
50
51 dng_xmp::dng_xmp (const dng_xmp &xmp)
52
53 : fAllocator (xmp.fAllocator)
54
55 , fSDK (NULL)
56
57 {
58
59 fSDK = new dng_xmp_sdk (*xmp.fSDK);
60
61 if (!fSDK)
62 {
63 ThrowMemoryFull ();
64 }
65
66 }
67
68 /*****************************************************************************/
69
70 dng_xmp::~dng_xmp ()
71 {
72
73 if (fSDK)
74 {
75
76 delete fSDK;
77
78 }
79
80 }
81
82 /*****************************************************************************/
83
84 dng_xmp * dng_xmp::Clone () const
85 {
86
87 dng_xmp *result = new dng_xmp (*this);
88
89 if (!result)
90 {
91 ThrowMemoryFull ();
92 }
93
94 return result;
95
96 }
97
98 /*****************************************************************************/
99
100 void dng_xmp::TrimDecimal (char *s)
101 {
102
103 uint32 len = (uint32) strlen (s);
104
105 while (len > 0)
106 {
107
108 if (s [len - 1] == '0')
109 s [--len] = 0;
110
111 else
112 break;
113
114 }
115
116 if (len > 0)
117 {
118
119 if (s [len - 1] == '.')
120 s [--len] = 0;
121
122 }
123
124 }
125
126 /*****************************************************************************/
127
128 dng_string dng_xmp::EncodeFingerprint (const dng_fingerprint &f,
129 bool allowInvalid)
130 {
131
132 dng_string result;
133
134 if (f.IsValid () || allowInvalid)
135 {
136
137 char s [dng_fingerprint::kDNGFingerprintSize * 2 + 1];
138
139 f.ToUtf8HexString (s);
140
141 result.Set (s);
142
143 }
144
145 return result;
146
147 }
148
149 /*****************************************************************************/
150
151 dng_fingerprint dng_xmp::DecodeFingerprint (const dng_string &s)
152 {
153
154 dng_fingerprint result;
155
156 if (s.Length () == 32)
157 result.FromUtf8HexString (s.Get ());
158
159 return result;
160
161 }
162
163 /*****************************************************************************/
164
165 dng_string dng_xmp::EncodeGPSVersion (uint32 version)
166 {
167
168 dng_string result;
169
170 if (version)
171 {
172
173 uint8 b0 = (uint8) (version >> 24);
174 uint8 b1 = (uint8) (version >> 16);
175 uint8 b2 = (uint8) (version >> 8);
176 uint8 b3 = (uint8) (version );
177
178 if (b0 <= 9 && b1 <= 9 && b2 <= 9 && b3 <= 9)
179 {
180
181 char s [32];
182
183 snprintf (s,
184 32,
185 "%u.%u.%u.%u",
186 (unsigned) b0,
187 (unsigned) b1,
188 (unsigned) b2,
189 (unsigned) b3);
190
191 result.Set (s);
192
193 }
194
195 }
196
197 return result;
198
199 }
200
201 /*****************************************************************************/
202
203 uint32 dng_xmp::DecodeGPSVersion (const dng_string &s)
204 {
205
206 uint32 result = 0;
207
208 if (s.Length () == 7)
209 {
210
211 unsigned b0 = 0;
212 unsigned b1 = 0;
213 unsigned b2 = 0;
214 unsigned b3 = 0;
215
216 if (sscanf (s.Get (),
217 "%u.%u.%u.%u",
218 &b0,
219 &b1,
220 &b2,
221 &b3) == 4)
222 {
223
224 result = (b0 << 24) |
225 (b1 << 16) |
226 (b2 << 8) |
227 (b3 );
228
229 }
230
231 }
232
233 return result;
234
235 }
236
237 /*****************************************************************************/
238
239 dng_string dng_xmp::EncodeGPSCoordinate (const dng_string &ref,
240 const dng_urational *coord)
241 {
242
243 dng_string result;
244
245 if (ref.Length () == 1 && coord [0].IsValid () &&
246 coord [1].IsValid ())
247 {
248
249 char refChar = ForceUppercase (ref.Get () [0]);
250
251 if (refChar == 'N' ||
252 refChar == 'S' ||
253 refChar == 'E' ||
254 refChar == 'W')
255 {
256
257 char s [256];
258
259 // Use the seconds case if all three values are
260 // integers.
261
262 if (coord [0].d == 1 &&
263 coord [1].d == 1 &&
264 coord [2].d == 1)
265 {
266
267 snprintf (s,
268 256,
269 "%u,%u,%u%c",
270 (unsigned) coord [0].n,
271 (unsigned) coord [1].n,
272 (unsigned) coord [2].n,
273 refChar);
274
275 }
276
277 // Else we need to use the fractional minutes case.
278
279 else
280 {
281
282 // Find value minutes.
283
284 real64 x = coord [0].As_real64 () * 60.0 +
285 coord [1].As_real64 () +
286 coord [2].As_real64 () * (1.0 / 60.0);
287
288 // Round to fractional seven decimal places.
289
290 uint64 y = (uint64) Round_int64 (x * 10000000.0);
291
292 // Split into degrees and minutes.
293
294 uint32 d = (uint32) (y / (60 * 10000000));
295 uint32 m = (uint32) (y % (60 * 10000000));
296
297 char min [32];
298
299 snprintf (min, 32, "%.7f", m * (1.0 / 10000000.0));
300
301 TrimDecimal (min);
302
303 snprintf (s,
304 256,
305 "%u,%s%c",
306 (unsigned) d,
307 min,
308 refChar);
309
310 }
311
312 result.Set (s);
313
314 }
315
316 }
317
318 return result;
319
320 }
321
322 /*****************************************************************************/
323
324 void dng_xmp::DecodeGPSCoordinate (const dng_string &s,
325 dng_string &ref,
326 dng_urational *coord)
327 {
328
329 ref.Clear ();
330
331 coord [0].Clear ();
332 coord [1].Clear ();
333 coord [2].Clear ();
334
335 if (s.Length () > 1)
336 {
337
338 char refChar = ForceUppercase (s.Get () [s.Length () - 1]);
339
340 if (refChar == 'N' ||
341 refChar == 'S' ||
342 refChar == 'E' ||
343 refChar == 'W')
344 {
345
346 dng_string ss (s);
347
348 ss.Truncate (ss.Length () - 1);
349
350 ss.NormalizeAsCommaSeparatedNumbers ();
351
352 int degrees = 0;
353
354 real64 minutes = 0.0;
355 real64 seconds = 0.0;
356
357 int count = sscanf (ss.Get (),
358 "%d,%lf,%lf",
359 &degrees,
360 &minutes,
361 &seconds);
362
363 if (count < 1)
364 {
365 return;
366 }
367
368 // The degree, minute, second values should always be positive.
369
370 if (degrees < 0 || minutes < 0 || seconds < 0)
371 {
372 return;
373 }
374
375 coord [0] = dng_urational ((uint32) degrees, 1);
376
377 if (count <= 2)
378 {
379 coord [1].Set_real64 (minutes, 10000000);
380 coord [2] = dng_urational (0, 1);
381 }
382 else
383 {
384 coord [1].Set_real64 (minutes, 1);
385 coord [2].Set_real64 (seconds, 100000);
386 }
387
388 char r [2];
389
390 r [0] = refChar;
391 r [1] = 0;
392
393 ref.Set (r);
394
395 }
396
397 }
398
399 }
400
401 /*****************************************************************************/
402
403 dng_string dng_xmp::EncodeGPSDateTime (const dng_string &dateStamp,
404 const dng_urational *timeStamp)
405 {
406
407 dng_string result;
408
409 if (timeStamp [0].IsValid () &&
410 timeStamp [1].IsValid () &&
411 timeStamp [2].IsValid ())
412 {
413
414 char s [256];
415
416 char sec [32];
417
418 snprintf (sec,
419 32,
420 "%09.6f",
421 timeStamp [2].As_real64 ());
422
423 TrimDecimal (sec);
424
425 int year = 0;
426 int month = 0;
427 int day = 0;
428
429 if (dateStamp.NotEmpty ())
430 {
431
432 sscanf (dateStamp.Get (),
433 "%d:%d:%d",
434 &year,
435 &month,
436 &day);
437
438 }
439
440 if (year >= 1 && year <= 9999 &&
441 month >= 1 && month <= 12 &&
442 day >= 1 && day <= 31)
443 {
444
445 snprintf (s,
446 256,
447 "%04d-%02d-%02dT%02u:%02u:%sZ",
448 year,
449 month,
450 day,
451 (unsigned) Round_uint32 (timeStamp [0].As_real64 ()),
452 (unsigned) Round_uint32 (timeStamp [1].As_real64 ()),
453 sec);
454
455 }
456
457 else
458 {
459
460 snprintf (s,
461 256,
462 "%02u:%02u:%sZ",
463 (unsigned) Round_uint32 (timeStamp [0].As_real64 ()),
464 (unsigned) Round_uint32 (timeStamp [1].As_real64 ()),
465 sec);
466
467 }
468
469 result.Set (s);
470
471 }
472
473 return result;
474
475 }
476
477 /*****************************************************************************/
478
479 void dng_xmp::DecodeGPSDateTime (const dng_string &s,
480 dng_string &dateStamp,
481 dng_urational *timeStamp)
482 {
483
484 dateStamp.Clear ();
485
486 timeStamp [0].Clear ();
487 timeStamp [1].Clear ();
488 timeStamp [2].Clear ();
489
490 if (s.NotEmpty ())
491 {
492
493 unsigned year = 0;
494 unsigned month = 0;
495 unsigned day = 0;
496 unsigned hour = 0;
497 unsigned minute = 0;
498
499 double second = 0.0;
500
501 if (sscanf (s.Get (),
502 "%u-%u-%uT%u:%u:%lf",
503 &year,
504 &month,
505 &day,
506 &hour,
507 &minute,
508 &second) == 6)
509 {
510
511 if (year >= 1 && year <= 9999 &&
512 month >= 1 && month <= 12 &&
513 day >= 1 && day <= 31 )
514 {
515
516 char ss [64];
517
518 snprintf (ss,
519 64,
520 "%04u:%02u:%02u",
521 year,
522 month,
523 day);
524
525 dateStamp.Set (ss);
526
527 }
528
529 }
530
531 else if (sscanf (s.Get (),
532 "%u:%u:%lf",
533 &hour,
534 &minute,
535 &second) != 3)
536 {
537
538 return;
539
540 }
541
542 timeStamp [0] = dng_urational ((uint32) hour , 1);
543 timeStamp [1] = dng_urational ((uint32) minute, 1);
544
545 timeStamp [2].Set_real64 (second, 1000);
546
547 }
548
549 }
550
551 /*****************************************************************************/
552
553 void dng_xmp::Parse (dng_host &host,
554 const void *buffer,
555 uint32 count)
556 {
557
558 fSDK->Parse (host,
559 (const char *) buffer,
560 count);
561
562 }
563
564 /*****************************************************************************/
565
566 dng_memory_block * dng_xmp::Serialize (bool asPacket,
567 uint32 targetBytes,
568 uint32 padBytes,
569 bool forJPEG,
570 bool compact) const
571 {
572
573 return fSDK->Serialize (fAllocator,
574 asPacket,
575 targetBytes,
576 padBytes,
577 forJPEG,
578 compact);
579
580 }
581
582 /*****************************************************************************/
583
584 void dng_xmp::PackageForJPEG (AutoPtr<dng_memory_block> &stdBlock,
585 AutoPtr<dng_memory_block> &extBlock,
586 dng_string &extDigest) const
587 {
588
589 fSDK->PackageForJPEG (fAllocator,
590 stdBlock,
591 extBlock,
592 extDigest);
593
594 }
595
596 /*****************************************************************************/
597
598 void dng_xmp::MergeFromJPEG (const dng_xmp &xmp)
599 {
600
601 fSDK->MergeFromJPEG (xmp.fSDK);
602
603 }
604
605 /*****************************************************************************/
606
607 bool dng_xmp::HasMeta () const
608 {
609
610 return fSDK->HasMeta ();
611
612 }
613
614 /*****************************************************************************/
615
616 void * dng_xmp::GetPrivateMeta ()
617 {
618
619 return fSDK->GetPrivateMeta ();
620
621 }
622
623 /*****************************************************************************/
624
625 bool dng_xmp::Exists (const char *ns,
626 const char *path) const
627 {
628
629 return fSDK->Exists (ns, path);
630
631 }
632
633 /*****************************************************************************/
634
635 bool dng_xmp::HasNameSpace (const char *ns) const
636 {
637
638 return fSDK->HasNameSpace (ns);
639
640 }
641
642 /*****************************************************************************/
643
644 bool dng_xmp::IteratePaths (IteratePathsCallback *callback,
645 void *callbackData,
646 const char *ns,
647 const char *path,
648 bool justChildren) const
649 {
650
651 return fSDK->IteratePaths (callback, callbackData, ns, path, justChildren);
652
653 }
654
655 /*****************************************************************************/
656
657 void dng_xmp::DuplicateSubtree (const dng_xmp &source,
658 const char *sourceNS,
659 const char *sourceRoot,
660 const char *destNS,
661 const char *destRoot)
662 {
663
664 if (source.Exists (sourceNS,
665 sourceRoot))
666 {
667
668 fSDK->DuplicateSubtree (*source.fSDK,
669 sourceNS,
670 sourceRoot,
671 destNS,
672 destRoot);
673
674 }
675
676 }
677
678 /*****************************************************************************/
679
680 static bool DuplicateNameSpaceCallback (const char *ns,
681 const char *path,
682 void *callbackData)
683 {
684
685 if (path == NULL || path [0] == 0)
686 {
687 return true;
688 }
689
690 dng_xmp *xmp = (dng_xmp *) ((void **) callbackData) [0];
691
692 const dng_xmp &source = *((const dng_xmp *) ((void **) callbackData) [1]);
693
694 if (xmp->Exists (ns, path))
695 {
696 return true;
697 }
698
699 xmp->DuplicateSubtree (source, ns, path);
700
701 return true;
702
703 }
704
705 /*****************************************************************************/
706
707 void dng_xmp::DuplicateNameSpace (const dng_xmp &source,
708 const char *ns)
709 {
710
711 void * callbackData [2];
712
713 callbackData [0] = this;
714 callbackData [1] = (void *) &source;
715
716 source.IteratePaths (DuplicateNameSpaceCallback,
717 callbackData,
718 ns,
719 NULL,
720 true);
721
722 }
723
724 /*****************************************************************************/
725
726 void dng_xmp::Remove (const char *ns,
727 const char *path)
728 {
729
730 fSDK->Remove (ns, path);
731
732 }
733
734 /*****************************************************************************/
735
736 void dng_xmp::RemoveProperties (const char *ns)
737 {
738
739 fSDK->RemoveProperties (ns);
740
741 }
742
743 /*****************************************************************************/
744
745 void dng_xmp::RemoveEmptyStringOrArray (const char *ns,
746 const char *path)
747 {
748
749 if (path == NULL || path [0] == 0)
750 {
751 return;
752 }
753
754 if (fSDK->IsEmptyString (ns, path) ||
755 fSDK->IsEmptyArray (ns, path))
756 {
757
758 Remove (ns, path);
759
760 }
761
762 }
763
764 /*****************************************************************************/
765
766 static bool RemoveEmptyStringsAndArraysCallback (const char *ns,
767 const char *path,
768 void *callbackData)
769 {
770
771 dng_xmp *xmp = (dng_xmp *) callbackData;
772
773 xmp->RemoveEmptyStringOrArray (ns, path);
774
775 return true;
776
777 }
778
779 /*****************************************************************************/
780
781 void dng_xmp::RemoveEmptyStringsAndArrays (const char *ns)
782 {
783
784 IteratePaths (RemoveEmptyStringsAndArraysCallback,
785 (void *) this,
786 ns,
787 NULL,
788 true);
789
790 }
791
792 /*****************************************************************************/
793
794 void dng_xmp::Set (const char *ns,
795 const char *path,
796 const char *text)
797 {
798
799 fSDK->Set (ns, path, text);
800
801 }
802
803 /*****************************************************************************/
804
805 bool dng_xmp::GetString (const char *ns,
806 const char *path,
807 dng_string &s) const
808 {
809
810 return fSDK->GetString (ns, path, s);
811
812 }
813
814 /*****************************************************************************/
815
816 void dng_xmp::SetString (const char *ns,
817 const char *path,
818 const dng_string &s)
819 {
820
821 fSDK->SetString (ns, path, s);
822
823 }
824
825 /*****************************************************************************/
826
827 bool dng_xmp::SyncString (const char *ns,
828 const char *path,
829 dng_string &s,
830 uint32 options)
831 {
832
833 bool isDefault = s.IsEmpty ();
834
835 // Sync 1: Force XMP to match non-XMP.
836
837 if (options & ignoreXMP)
838 {
839
840 if ((isDefault || (options & removeXMP)) && !(options & requireXMP))
841 {
842
843 Remove (ns, path);
844
845 }
846
847 else
848 {
849
850 SetString (ns, path, s);
851
852 }
853
854 return false;
855
856 }
857
858 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
859
860 if ((options & preferNonXMP) && !isDefault)
861 {
862
863 if (options & removeXMP)
864 {
865
866 Remove (ns, path);
867
868 }
869
870 else
871 {
872
873 SetString (ns, path, s);
874
875 }
876
877 return false;
878
879 }
880
881 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
882
883 if ((options & preferXMP) || isDefault)
884 {
885
886 if (GetString (ns, path, s))
887 {
888
889 if (options & removeXMP)
890 {
891
892 Remove (ns, path);
893
894 }
895
896 return true;
897
898 }
899
900 }
901
902 // Sync 4: From non-XMP to XMP.
903
904 if (options & removeXMP)
905 {
906
907 Remove (ns, path);
908
909 }
910
911 else if (!isDefault || (options & requireXMP))
912 {
913
914 SetString (ns, path, s);
915
916 }
917
918 return false;
919
920 }
921
922 /*****************************************************************************/
923
924 bool dng_xmp::GetStringList (const char *ns,
925 const char *path,
926 dng_string_list &list,
927 dng_abort_sniffer *sniffer) const
928 {
929
930 return fSDK->GetStringList (ns, path, list, sniffer);
931
932 }
933
934 /*****************************************************************************/
935
936 void dng_xmp::SetStringList (const char *ns,
937 const char *path,
938 const dng_string_list &list,
939 bool isBag)
940 {
941
942 fSDK->SetStringList (ns, path, list, isBag);
943
944 }
945
946 /*****************************************************************************/
947
948 void dng_xmp::SyncStringList (const char *ns,
949 const char *path,
950 dng_string_list &list,
951 bool isBag,
952 uint32 options)
953 {
954
955 bool isDefault = (list.Count () == 0);
956
957 // First make sure the XMP is not badly formatted, since
958 // this breaks some Photoshop logic.
959
960 ValidateStringList (ns, path);
961
962 // Sync 1: Force XMP to match non-XMP.
963
964 if (options & ignoreXMP)
965 {
966
967 if (isDefault)
968 {
969
970 Remove (ns, path);
971
972 }
973
974 else
975 {
976
977 SetStringList (ns, path, list, isBag);
978
979 }
980
981 return;
982
983 }
984
985 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
986
987 if ((options & preferNonXMP) && !isDefault)
988 {
989
990 SetStringList (ns, path, list, isBag);
991
992 return;
993
994 }
995
996 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
997
998 if ((options & preferXMP) || isDefault)
999 {
1000
1001 if (GetStringList (ns, path, list))
1002 {
1003
1004 return;
1005
1006 }
1007
1008 }
1009
1010 // Sync 4: From non-XMP to XMP.
1011
1012 if (!isDefault)
1013 {
1014
1015 SetStringList (ns, path, list, isBag);
1016
1017 }
1018
1019 }
1020
1021 /*****************************************************************************/
1022
1023 void dng_xmp::SetStructField (const char *ns,
1024 const char *path,
1025 const char *fieldNS,
1026 const char *fieldName,
1027 const dng_string &s)
1028 {
1029
1030 dng_string ss (s);
1031
1032 ss.SetLineEndings ('\n');
1033
1034 ss.StripLowASCII ();
1035
1036 fSDK->SetStructField (ns, path, fieldNS, fieldName, ss.Get ());
1037
1038 }
1039
1040 /*****************************************************************************/
1041
1042 void dng_xmp::SetStructField (const char *ns,
1043 const char *path,
1044 const char *fieldNS,
1045 const char *fieldName,
1046 const char *s)
1047 {
1048
1049 fSDK->SetStructField (ns, path, fieldNS, fieldName, s);
1050
1051 }
1052
1053 /*****************************************************************************/
1054
1055 void dng_xmp::DeleteStructField (const char *ns,
1056 const char *path,
1057 const char *fieldNS,
1058 const char *fieldName)
1059 {
1060
1061 fSDK->DeleteStructField (ns, path, fieldNS, fieldName);
1062
1063 }
1064
1065 /*****************************************************************************/
1066
1067 bool dng_xmp::GetStructField (const char *ns,
1068 const char *path,
1069 const char *fieldNS,
1070 const char *fieldName,
1071 dng_string &s) const
1072 {
1073
1074 return fSDK->GetStructField (ns, path, fieldNS, fieldName, s);
1075
1076 }
1077
1078 /*****************************************************************************/
1079
1080 void dng_xmp::SetAltLangDefault (const char *ns,
1081 const char *path,
1082 const dng_string &s)
1083 {
1084
1085 fSDK->SetAltLangDefault (ns, path, s);
1086
1087 }
1088
1089 /*****************************************************************************/
1090
1091 void dng_xmp::SetLocalString (const char *ns,
1092 const char *path,
1093 const dng_local_string &s)
1094 {
1095
1096 fSDK->SetLocalString (ns, path, s);
1097
1098 }
1099
1100 /*****************************************************************************/
1101
1102 bool dng_xmp::GetAltLangDefault (const char *ns,
1103 const char *path,
1104 dng_string &s,
1105 bool silent) const
1106 {
1107
1108 return fSDK->GetAltLangDefault (ns, path, s, silent);
1109
1110 }
1111
1112 /*****************************************************************************/
1113
1114 bool dng_xmp::GetLocalString (const char *ns,
1115 const char *path,
1116 dng_local_string &s) const
1117 {
1118
1119 return fSDK->GetLocalString (ns, path, s);
1120
1121 }
1122
1123 /*****************************************************************************/
1124
1125 bool dng_xmp::SyncAltLangDefault (const char *ns,
1126 const char *path,
1127 dng_string &s,
1128 uint32 options)
1129 {
1130
1131 bool isDefault = s.IsEmpty ();
1132
1133 // Sync 1: Force XMP to match non-XMP.
1134
1135 if (options & ignoreXMP)
1136 {
1137
1138 if (isDefault)
1139 {
1140
1141 Remove (ns, path);
1142
1143 }
1144
1145 else
1146 {
1147
1148 SetAltLangDefault (ns, path, s);
1149
1150 }
1151
1152 return false;
1153
1154 }
1155
1156 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
1157
1158 if ((options & preferNonXMP) && !isDefault)
1159 {
1160
1161 SetAltLangDefault (ns, path, s);
1162
1163 return false;
1164
1165 }
1166
1167 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
1168
1169 if ((options & preferXMP) || isDefault)
1170 {
1171
1172 if (GetAltLangDefault (ns, path, s))
1173 {
1174
1175 return true;
1176
1177 }
1178
1179 }
1180
1181 // Sync 4: From non-XMP to XMP.
1182
1183 if (!isDefault)
1184 {
1185
1186 SetAltLangDefault (ns, path, s);
1187
1188 }
1189
1190 return false;
1191
1192 }
1193
1194 /*****************************************************************************/
1195
1196 bool dng_xmp::GetBoolean (const char *ns,
1197 const char *path,
1198 bool &x) const
1199 {
1200
1201 dng_string s;
1202
1203 if (GetString (ns, path, s))
1204 {
1205
1206 if (s.Matches ("True"))
1207 {
1208
1209 x = true;
1210
1211 return true;
1212
1213 }
1214
1215 if (s.Matches ("False"))
1216 {
1217
1218 x = false;
1219
1220 return true;
1221
1222 }
1223
1224 }
1225
1226 return false;
1227
1228 }
1229
1230 /*****************************************************************************/
1231
1232 void dng_xmp::SetBoolean (const char *ns,
1233 const char *path,
1234 bool x)
1235 {
1236
1237 Set (ns, path, x ? "True" : "False");
1238
1239 }
1240
1241 /*****************************************************************************/
1242
1243 bool dng_xmp::Get_int32 (const char *ns,
1244 const char *path,
1245 int32 &x) const
1246 {
1247
1248 dng_string s;
1249
1250 if (GetString (ns, path, s))
1251 {
1252
1253 if (s.NotEmpty ())
1254 {
1255
1256 int y = 0;
1257
1258 if (sscanf (s.Get (), "%d", &y) == 1)
1259 {
1260
1261 x = y;
1262
1263 return true;
1264
1265 }
1266
1267 }
1268
1269 }
1270
1271 return false;
1272
1273 }
1274
1275 /*****************************************************************************/
1276
1277 void dng_xmp::Set_int32 (const char *ns,
1278 const char *path,
1279 int32 x,
1280 bool usePlus)
1281 {
1282
1283 char s [64];
1284
1285 if (x > 0 && usePlus)
1286 {
1287 snprintf (s, 64, "+%d", (int) x);
1288 }
1289 else
1290 {
1291 snprintf (s, 64, "%d", (int) x);
1292 }
1293
1294 Set (ns, path, s);
1295
1296 }
1297
1298 /*****************************************************************************/
1299
1300 bool dng_xmp::Get_uint32 (const char *ns,
1301 const char *path,
1302 uint32 &x) const
1303 {
1304
1305 dng_string s;
1306
1307 if (GetString (ns, path, s))
1308 {
1309
1310 if (s.NotEmpty ())
1311 {
1312
1313 unsigned y = 0;
1314
1315 if (sscanf (s.Get (), "%u", &y) == 1)
1316 {
1317
1318 x = y;
1319
1320 return true;
1321
1322 }
1323
1324 }
1325
1326 }
1327
1328 return false;
1329
1330 }
1331
1332 /*****************************************************************************/
1333
1334 void dng_xmp::Set_uint32 (const char *ns,
1335 const char *path,
1336 uint32 x)
1337 {
1338
1339 char s [64];
1340
1341 snprintf (s,
1342 64,
1343 "%u",
1344 (unsigned) x);
1345
1346 Set (ns, path, s);
1347
1348 }
1349
1350 /*****************************************************************************/
1351
1352 void dng_xmp::Sync_uint32 (const char *ns,
1353 const char *path,
1354 uint32 &x,
1355 bool isDefault,
1356 uint32 options,
1357 uint32 defaultValue)
1358 {
1359
1360 // Sync 1: Force XMP to match non-XMP.
1361
1362 if (options & ignoreXMP)
1363 {
1364
1365 if (isDefault && (options & requireXMP))
1366 {
1367
1368 Set (ns, path, "");
1369
1370 }
1371
1372 else if (isDefault || (options & removeXMP))
1373 {
1374
1375 Remove (ns, path);
1376
1377 }
1378
1379 else
1380 {
1381
1382 Set_uint32 (ns, path, x);
1383
1384 }
1385
1386 return;
1387
1388 }
1389
1390 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
1391
1392 if ((options & preferNonXMP) && !isDefault)
1393 {
1394
1395 if (options & removeXMP)
1396 {
1397
1398 Remove (ns, path);
1399
1400 }
1401
1402 else
1403 {
1404
1405 Set_uint32 (ns, path, x);
1406
1407 }
1408
1409 return;
1410
1411 }
1412
1413 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
1414
1415 if ((options & preferXMP) || isDefault)
1416 {
1417
1418 if (Exists (ns, path))
1419 {
1420
1421 if (!Get_uint32 (ns, path, x))
1422 {
1423
1424 x = defaultValue;
1425
1426 }
1427
1428 if (options & removeXMP)
1429 {
1430
1431 Remove (ns, path);
1432
1433 }
1434
1435 return;
1436
1437 }
1438
1439 }
1440
1441 // Sync 4: From non-XMP to XMP.
1442
1443 if (options & removeXMP)
1444 {
1445
1446 Remove (ns, path);
1447
1448 }
1449
1450 else if (!isDefault)
1451 {
1452
1453 Set_uint32 (ns, path, x);
1454
1455 }
1456
1457 else if (options & requireXMP)
1458 {
1459
1460 Set (ns, path, "");
1461
1462 }
1463
1464 }
1465
1466 /*****************************************************************************/
1467
1468 void dng_xmp::Sync_uint32_array (const char *ns,
1469 const char *path,
1470 uint32 *data,
1471 uint32 &count,
1472 uint32 maxCount,
1473 uint32 options)
1474 {
1475
1476 dng_string_list list;
1477
1478 for (uint32 j = 0; j < count; j++)
1479 {
1480
1481 char s [32];
1482
1483 snprintf (s, 32, "%u", (unsigned) data [j]);
1484
1485 dng_string ss;
1486
1487 ss.Set (s);
1488
1489 list.Append (ss);
1490
1491 }
1492
1493 SyncStringList (ns,
1494 path,
1495 list,
1496 false,
1497 options);
1498
1499 count = 0;
1500
1501 for (uint32 k = 0; k < maxCount; k++)
1502 {
1503
1504 data [k] = 0;
1505
1506 if (k < list.Count ())
1507 {
1508
1509 unsigned x = 0;
1510
1511 if (sscanf (list [k].Get (), "%u", &x) == 1)
1512 {
1513
1514 data [count++] = x;
1515
1516 }
1517
1518 }
1519
1520 }
1521
1522 }
1523
1524 /*****************************************************************************/
1525
1526 bool dng_xmp::Get_real64 (const char *ns,
1527 const char *path,
1528 real64 &x) const
1529 {
1530
1531 dng_string s;
1532
1533 if (GetString (ns, path, s))
1534 {
1535
1536 if (s.NotEmpty ())
1537 {
1538
1539 double y = 0;
1540
1541 if (sscanf (s.Get (), "%lf", &y) == 1)
1542 {
1543
1544 x = y;
1545
1546 return true;
1547
1548 }
1549
1550 }
1551
1552 }
1553
1554 return false;
1555
1556 }
1557
1558 /*****************************************************************************/
1559
1560 void dng_xmp::Set_real64 (const char *ns,
1561 const char *path,
1562 real64 x,
1563 uint32 places,
1564 bool trim,
1565 bool usePlus)
1566 {
1567
1568 char s [64];
1569
1570 if (x > 0.0 && usePlus)
1571 {
1572 snprintf (s, 64, "+%0.*f", (unsigned) places, (double) x);
1573 }
1574 else
1575 {
1576 snprintf (s, 64, "%0.*f", (unsigned) places, (double) x);
1577 }
1578
1579 if (trim)
1580 {
1581
1582 while (s [strlen (s) - 1] == '0')
1583 {
1584 s [strlen (s) - 1] = 0;
1585 }
1586
1587 if (s [strlen (s) - 1] == '.')
1588 {
1589 s [strlen (s) - 1] = 0;
1590 }
1591
1592 }
1593
1594 Set (ns, path, s);
1595
1596 }
1597
1598 /*****************************************************************************/
1599
1600 bool dng_xmp::Get_urational (const char *ns,
1601 const char *path,
1602 dng_urational &r) const
1603 {
1604
1605 dng_string s;
1606
1607 if (GetString (ns, path, s))
1608 {
1609
1610 if (s.NotEmpty ())
1611 {
1612
1613 unsigned n = 0;
1614 unsigned d = 0;
1615
1616 if (sscanf (s.Get (), "%u/%u", &n, &d) == 2)
1617 {
1618
1619 if (d != 0)
1620 {
1621
1622 r = dng_urational (n, d);
1623
1624 return true;
1625
1626 }
1627
1628 }
1629
1630 }
1631
1632 }
1633
1634 return false;
1635
1636 }
1637
1638 /*****************************************************************************/
1639
1640 void dng_xmp::Set_urational (const char *ns,
1641 const char *path,
1642 const dng_urational &r)
1643 {
1644
1645 char s [64];
1646
1647 snprintf (s,
1648 64,
1649 "%u/%u",
1650 (unsigned) r.n,
1651 (unsigned) r.d);
1652
1653 Set (ns, path, s);
1654
1655 }
1656
1657 /*****************************************************************************/
1658
1659 void dng_xmp::Sync_urational (const char *ns,
1660 const char *path,
1661 dng_urational &r,
1662 uint32 options)
1663 {
1664
1665 bool isDefault = r.NotValid ();
1666
1667 // Sync 1: Force XMP to match non-XMP.
1668
1669 if (options & ignoreXMP)
1670 {
1671
1672 if (isDefault && (options & requireXMP))
1673 {
1674
1675 Set (ns, path, "");
1676
1677 }
1678
1679 else if (isDefault || (options & removeXMP))
1680 {
1681
1682 Remove (ns, path);
1683
1684 }
1685
1686 else
1687 {
1688
1689 Set_urational (ns, path, r);
1690
1691 }
1692
1693 return;
1694
1695 }
1696
1697 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
1698
1699 if ((options & preferNonXMP) && !isDefault)
1700 {
1701
1702 if (options & removeXMP)
1703 {
1704
1705 Remove (ns, path);
1706
1707 }
1708
1709 else
1710 {
1711
1712 Set_urational (ns, path, r);
1713
1714 }
1715
1716 return;
1717
1718 }
1719
1720 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
1721
1722 if ((options & preferXMP) || isDefault)
1723 {
1724
1725 if (Exists (ns, path))
1726 {
1727
1728 if (!Get_urational (ns, path, r))
1729 {
1730
1731 r.Clear ();
1732
1733 }
1734
1735 if (options & removeXMP)
1736 {
1737
1738 Remove (ns, path);
1739
1740 }
1741
1742 return;
1743
1744 }
1745
1746 }
1747
1748 // Sync 4: From non-XMP to XMP.
1749
1750 if (options & removeXMP)
1751 {
1752
1753 Remove (ns, path);
1754
1755 }
1756
1757 else if (!isDefault)
1758 {
1759
1760 Set_urational (ns, path, r);
1761
1762 }
1763
1764 else if (options & requireXMP)
1765 {
1766
1767 Set (ns, path, "");
1768
1769 }
1770
1771 }
1772
1773 /*****************************************************************************/
1774
1775 bool dng_xmp::Get_srational (const char *ns,
1776 const char *path,
1777 dng_srational &r) const
1778 {
1779
1780 dng_string s;
1781
1782 if (GetString (ns, path, s))
1783 {
1784
1785 if (s.NotEmpty ())
1786 {
1787
1788 int n = 0;
1789 int d = 0;
1790
1791 if (sscanf (s.Get (), "%d/%d", &n, &d) == 2)
1792 {
1793
1794 if (d != 0)
1795 {
1796
1797 r = dng_srational (n, d);
1798
1799 return true;
1800
1801 }
1802
1803 }
1804
1805 }
1806
1807 }
1808
1809 return false;
1810
1811 }
1812
1813 /*****************************************************************************/
1814
1815 void dng_xmp::Set_srational (const char *ns,
1816 const char *path,
1817 const dng_srational &r)
1818 {
1819
1820 char s [64];
1821
1822 snprintf (s,
1823 64,
1824 "%d/%d",
1825 (int) r.n,
1826 (int) r.d);
1827
1828 Set (ns, path, s);
1829
1830 }
1831
1832 /*****************************************************************************/
1833
1834 void dng_xmp::Sync_srational (const char *ns,
1835 const char *path,
1836 dng_srational &r,
1837 uint32 options)
1838 {
1839
1840 bool isDefault = r.NotValid ();
1841
1842 // Sync 1: Force XMP to match non-XMP.
1843
1844 if (options & ignoreXMP)
1845 {
1846
1847 if (isDefault || (options & removeXMP))
1848 {
1849
1850 Remove (ns, path);
1851
1852 }
1853
1854 else
1855 {
1856
1857 Set_srational (ns, path, r);
1858
1859 }
1860
1861 return;
1862
1863 }
1864
1865 // Sync 2: From non-XMP to XMP if non-XMP is prefered.
1866
1867 if ((options & preferNonXMP) && !isDefault)
1868 {
1869
1870 if (options & removeXMP)
1871 {
1872
1873 Remove (ns, path);
1874
1875 }
1876
1877 else
1878 {
1879
1880 Set_srational (ns, path, r);
1881
1882 }
1883
1884 return;
1885
1886 }
1887
1888 // Sync 3: From XMP to non-XMP if XMP is prefered or default non-XMP.
1889
1890 if ((options & preferXMP) || isDefault)
1891 {
1892
1893 if (Get_srational (ns, path, r))
1894 {
1895
1896 if (options & removeXMP)
1897 {
1898
1899 Remove (ns, path);
1900
1901 }
1902
1903 return;
1904
1905 }
1906
1907 }
1908
1909 // Sync 4: From non-XMP to XMP.
1910
1911 if (options & removeXMP)
1912 {
1913
1914 Remove (ns, path);
1915
1916 }
1917
1918 else if (!isDefault)
1919 {
1920
1921 Set_srational (ns, path, r);
1922
1923 }
1924
1925 }
1926
1927 /*****************************************************************************/
1928
1929 bool dng_xmp::GetFingerprint (const char *ns,
1930 const char *path,
1931 dng_fingerprint &print) const
1932 {
1933
1934 dng_string s;
1935
1936 if (GetString (ns, path, s))
1937 {
1938
1939 dng_fingerprint temp = DecodeFingerprint (s);
1940
1941 if (temp.IsValid ())
1942 {
1943
1944 print = temp;
1945
1946 return true;
1947
1948 }
1949
1950 }
1951
1952 return false;
1953
1954 }
1955
1956 /******************************************************************************/
1957
1958 void dng_xmp::SetFingerprint (const char *ns,
1959 const char *tag,
1960 const dng_fingerprint &print,
1961 bool allowInvalid)
1962 {
1963
1964 dng_string s = EncodeFingerprint (print, allowInvalid);
1965
1966 if (s.IsEmpty ())
1967 {
1968
1969 Remove (ns, tag);
1970
1971 }
1972
1973 else
1974 {
1975
1976 SetString (ns, tag, s);
1977
1978 }
1979
1980 }
1981
1982 /******************************************************************************/
1983
1984 void dng_xmp::SetVersion2to4 (const char *ns,
1985 const char *path,
1986 uint32 version)
1987 {
1988
1989 char buf [32];
1990
1991 if (version & 0x000000ff)
1992 {
1993
1994 // x.x.x.x
1995
1996 snprintf (buf,
1997 32,
1998 "%u.%u.%u.%u",
1999 (unsigned) ((version >> 24) & 0xff),
2000 (unsigned) ((version >> 16) & 0xff),
2001 (unsigned) ((version >> 8) & 0xff),
2002 (unsigned) ((version ) & 0xff));
2003
2004 }
2005
2006 else if (version & 0x0000ff00)
2007 {
2008
2009 // x.x.x
2010
2011 snprintf (buf,
2012 32,
2013 "%u.%u.%u",
2014 (unsigned) ((version >> 24) & 0xff),
2015 (unsigned) ((version >> 16) & 0xff),
2016 (unsigned) ((version >> 8) & 0xff));
2017
2018 }
2019
2020 else
2021 {
2022
2023 // x.x
2024
2025 snprintf (buf,
2026 32,
2027 "%u.%u",
2028 (unsigned) ((version >> 24) & 0xff),
2029 (unsigned) ((version >> 16) & 0xff));
2030
2031 }
2032
2033 Set (ns, path, buf);
2034
2035 }
2036
2037 /******************************************************************************/
2038
2039 dng_fingerprint dng_xmp::GetIPTCDigest () const
2040 {
2041
2042 dng_fingerprint digest;
2043
2044 if (GetFingerprint (XMP_NS_PHOTOSHOP,
2045 "LegacyIPTCDigest",
2046 digest))
2047 {
2048
2049 return digest;
2050
2051 }
2052
2053 return dng_fingerprint ();
2054
2055 }
2056
2057 /******************************************************************************/
2058
2059 void dng_xmp::SetIPTCDigest (dng_fingerprint &digest)
2060 {
2061
2062 SetFingerprint (XMP_NS_PHOTOSHOP,
2063 "LegacyIPTCDigest",
2064 digest);
2065
2066 }
2067
2068 /******************************************************************************/
2069
2070 void dng_xmp::ClearIPTCDigest ()
2071 {
2072
2073 Remove (XMP_NS_PHOTOSHOP, "LegacyIPTCDigest");
2074
2075 }
2076
2077 /*****************************************************************************/
2078
2079 void dng_xmp::SyncIPTC (dng_iptc &iptc,
2080 uint32 options)
2081 {
2082
2083 SyncAltLangDefault (XMP_NS_DC,
2084 "title",
2085 iptc.fTitle,
2086 options);
2087
2088 SyncString (XMP_NS_PHOTOSHOP,
2089 "Category",
2090 iptc.fCategory,
2091 options);
2092
2093 {
2094
2095 uint32 x = 0xFFFFFFFF;
2096
2097 if (iptc.fUrgency >= 0)
2098 {
2099
2100 x = (uint32) iptc.fUrgency;
2101
2102 }
2103
2104 Sync_uint32 (XMP_NS_PHOTOSHOP,
2105 "Urgency",
2106 x,
2107 x == 0xFFFFFFFF,
2108 options);
2109
2110 if (x <= 9)
2111 {
2112
2113 iptc.fUrgency = (int32) x;
2114
2115 }
2116
2117 }
2118
2119 SyncStringList (XMP_NS_PHOTOSHOP,
2120 "SupplementalCategories",
2121 iptc.fSupplementalCategories,
2122 true,
2123 options);
2124
2125 SyncStringList (XMP_NS_PHOTOSHOP,
2126 "Keywords",
2127 iptc.fKeywords,
2128 true,
2129 options);
2130
2131 SyncString (XMP_NS_PHOTOSHOP,
2132 "Instructions",
2133 iptc.fInstructions,
2134 options);
2135
2136 {
2137
2138 dng_string s = iptc.fDateTimeCreated.Encode_ISO_8601 ();
2139
2140 if (SyncString (XMP_NS_PHOTOSHOP,
2141 "DateCreated",
2142 s,
2143 options))
2144 {
2145
2146 iptc.fDateTimeCreated.Decode_ISO_8601 (s.Get ());
2147
2148 }
2149
2150 }
2151
2152 {
2153
2154 dng_string s = iptc.fDigitalCreationDateTime.Encode_ISO_8601 ();
2155
2156 if (SyncString (XMP_NS_EXIF,
2157 "DateTimeDigitized",
2158 s,
2159 options))
2160 {
2161
2162 iptc.fDigitalCreationDateTime.Decode_ISO_8601 (s.Get ());
2163
2164 }
2165
2166 }
2167
2168 SyncStringList (XMP_NS_DC,
2169 "creator",
2170 iptc.fAuthors,
2171 false,
2172 options);
2173
2174 SyncString (XMP_NS_PHOTOSHOP,
2175 "AuthorsPosition",
2176 iptc.fAuthorsPosition,
2177 options);
2178
2179 SyncString (XMP_NS_PHOTOSHOP,
2180 "City",
2181 iptc.fCity,
2182 options);
2183
2184 SyncString (XMP_NS_PHOTOSHOP,
2185 "State",
2186 iptc.fState,
2187 options);
2188
2189 SyncString (XMP_NS_PHOTOSHOP,
2190 "Country",
2191 iptc.fCountry,
2192 options);
2193
2194 SyncString (XMP_NS_IPTC,
2195 "CountryCode",
2196 iptc.fCountryCode,
2197 options);
2198
2199 SyncString (XMP_NS_IPTC,
2200 "Location",
2201 iptc.fLocation,
2202 options);
2203
2204 SyncString (XMP_NS_PHOTOSHOP,
2205 "TransmissionReference",
2206 iptc.fTransmissionReference,
2207 options);
2208
2209 SyncString (XMP_NS_PHOTOSHOP,
2210 "Headline",
2211 iptc.fHeadline,
2212 options);
2213
2214 SyncString (XMP_NS_PHOTOSHOP,
2215 "Credit",
2216 iptc.fCredit,
2217 options);
2218
2219 SyncString (XMP_NS_PHOTOSHOP,
2220 "Source",
2221 iptc.fSource,
2222 options);
2223
2224 SyncAltLangDefault (XMP_NS_DC,
2225 "rights",
2226 iptc.fCopyrightNotice,
2227 options);
2228
2229 SyncAltLangDefault (XMP_NS_DC,
2230 "description",
2231 iptc.fDescription,
2232 options);
2233
2234 SyncString (XMP_NS_PHOTOSHOP,
2235 "CaptionWriter",
2236 iptc.fDescriptionWriter,
2237 options);
2238
2239 }
2240
2241 /*****************************************************************************/
2242
2243 void dng_xmp::IngestIPTC (dng_metadata &metadata,
2244 bool xmpIsNewer)
2245 {
2246
2247 if (metadata.IPTCLength ())
2248 {
2249
2250 // Parse the IPTC block.
2251
2252 dng_iptc iptc;
2253
2254 iptc.Parse (metadata.IPTCData (),
2255 metadata.IPTCLength (),
2256 metadata.IPTCOffset ());
2257
2258 // Compute fingerprint of IPTC data both ways, including and
2259 // excluding the padding data.
2260
2261 dng_fingerprint iptcDigest1 = metadata.IPTCDigest (true );
2262 dng_fingerprint iptcDigest2 = metadata.IPTCDigest (false);
2263
2264 // See if there is an IPTC fingerprint stored in the XMP.
2265
2266 dng_fingerprint xmpDigest = GetIPTCDigest ();
2267
2268 if (xmpDigest.IsValid ())
2269 {
2270
2271 // If they match, the XMP was already synced with this
2272 // IPTC block, and we should not resync since it might
2273 // overwrite changes in the XMP data.
2274
2275 if (iptcDigest1 == xmpDigest)
2276 {
2277
2278 return;
2279
2280 }
2281
2282 // If it matches the incorrectly computed digest, skip
2283 // the sync, but fix the digest in the XMP.
2284
2285 if (iptcDigest2 == xmpDigest)
2286 {
2287
2288 SetIPTCDigest (iptcDigest1);
2289
2290 return;
2291
2292 }
2293
2294 // Else the IPTC has changed, so force an update.
2295
2296 xmpIsNewer = false;
2297
2298 }
2299
2300 else
2301 {
2302
2303 // There is no IPTC digest. Previously we would
2304 // prefer the IPTC in this case, but the MWG suggests
2305 // that we prefer the XMP in this case.
2306
2307 xmpIsNewer = true;
2308
2309 }
2310
2311 // Remember the fingerprint of the IPTC we are syncing with.
2312
2313 SetIPTCDigest (iptcDigest1);
2314
2315 // Find the sync options.
2316
2317 uint32 options = xmpIsNewer ? preferXMP
2318 : preferNonXMP;
2319
2320 // Synchronize the fields.
2321
2322 SyncIPTC (iptc, options);
2323
2324 }
2325
2326 // After the IPTC data is moved to XMP, we don't need it anymore.
2327
2328 metadata.ClearIPTC ();
2329
2330 }
2331
2332 /*****************************************************************************/
2333
2334 void dng_xmp::RebuildIPTC (dng_metadata &metadata,
2335 dng_memory_allocator &allocator,
2336 bool padForTIFF)
2337 {
2338
2339 // If there is no XMP, then there is no IPTC.
2340
2341 if (!fSDK->HasMeta ())
2342 {
2343 return;
2344 }
2345
2346 // Extract the legacy IPTC fields from the XMP data.
2347
2348 dng_iptc iptc;
2349
2350 SyncIPTC (iptc, preferXMP);
2351
2352 // Build legacy IPTC record
2353
2354 if (iptc.NotEmpty ())
2355 {
2356
2357 AutoPtr<dng_memory_block> block (iptc.Spool (allocator,
2358 padForTIFF));
2359
2360 metadata.SetIPTC (block);
2361
2362 }
2363
2364 }
2365
2366 /*****************************************************************************/
2367
2368 void dng_xmp::SyncFlash (uint32 &flashState,
2369 uint32 &flashMask,
2370 uint32 options)
2371 {
2372
2373 bool isDefault = (flashState == 0xFFFFFFFF);
2374
2375 if ((options & ignoreXMP) || !isDefault)
2376 {
2377
2378 Remove (XMP_NS_EXIF, "Flash");
2379
2380 }
2381
2382 if (!isDefault)
2383 {
2384
2385 fSDK->SetStructField (XMP_NS_EXIF,
2386 "Flash",
2387 XMP_NS_EXIF,
2388 "Fired",
2389 (flashState & 0x1) ? "True" : "False");
2390
2391 if (((flashMask >> 1) & 3) == 3)
2392 {
2393
2394 char s [8];
2395
2396 snprintf (s, 8, "%u", (unsigned) ((flashState >> 1) & 3));
2397
2398 fSDK->SetStructField (XMP_NS_EXIF,
2399 "Flash",
2400 XMP_NS_EXIF,
2401 "Return",
2402 s);
2403
2404 }
2405
2406 if (((flashMask >> 3) & 3) == 3)
2407 {
2408
2409 char s [8];
2410
2411 snprintf (s, 8, "%u", (unsigned) ((flashState >> 3) & 3));
2412
2413 fSDK->SetStructField (XMP_NS_EXIF,
2414 "Flash",
2415 XMP_NS_EXIF,
2416 "Mode",
2417 s);
2418
2419 }
2420
2421 if ((flashMask & (1 << 5)) != 0)
2422 {
2423
2424 fSDK->SetStructField (XMP_NS_EXIF,
2425 "Flash",
2426 XMP_NS_EXIF,
2427 "Function",
2428 (flashState & (1 << 5)) ? "True" : "False");
2429
2430 }
2431
2432 if ((flashMask & (1 << 6)) != 0)
2433 {
2434
2435 fSDK->SetStructField (XMP_NS_EXIF,
2436 "Flash",
2437 XMP_NS_EXIF,
2438 "RedEyeMode",
2439 (flashState & (1 << 6)) ? "True" : "False");
2440
2441 }
2442
2443 }
2444
2445 else if (fSDK->Exists (XMP_NS_EXIF, "Flash"))
2446 {
2447
2448 dng_string s;
2449
2450 if (fSDK->GetStructField (XMP_NS_EXIF,
2451 "Flash",
2452 XMP_NS_EXIF,
2453 "Fired",
2454 s))
2455 {
2456
2457 flashState = 0;
2458 flashMask = 1;
2459
2460 if (s.Matches ("True"))
2461 {
2462 flashState |= 1;
2463 }
2464
2465 if (fSDK->GetStructField (XMP_NS_EXIF,
2466 "Flash",
2467 XMP_NS_EXIF,
2468 "Return",
2469 s))
2470 {
2471
2472 unsigned x = 0;
2473
2474 if (sscanf (s.Get (), "%u", &x) == 1 && x <= 3)
2475 {
2476
2477 flashState |= x << 1;
2478 flashMask |= 3 << 1;
2479
2480 }
2481
2482 }
2483
2484 if (fSDK->GetStructField (XMP_NS_EXIF,
2485 "Flash",
2486 XMP_NS_EXIF,
2487 "Mode",
2488 s))
2489 {
2490
2491 unsigned x = 0;
2492
2493 if (sscanf (s.Get (), "%u", &x) == 1 && x <= 3)
2494 {
2495
2496 flashState |= x << 3;
2497 flashMask |= 3 << 3;
2498
2499 }
2500
2501 }
2502
2503 if (fSDK->GetStructField (XMP_NS_EXIF,
2504 "Flash",
2505 XMP_NS_EXIF,
2506 "Function",
2507 s))
2508 {
2509
2510 flashMask |= 1 << 5;
2511
2512 if (s.Matches ("True"))
2513 {
2514 flashState |= 1 << 5;
2515 }
2516
2517 }
2518
2519 if (fSDK->GetStructField (XMP_NS_EXIF,
2520 "Flash",
2521 XMP_NS_EXIF,
2522 "RedEyeMode",
2523 s))
2524 {
2525
2526 flashMask |= 1 << 6;
2527
2528 if (s.Matches ("True"))
2529 {
2530 flashState |= 1 << 6;
2531 }
2532
2533 }
2534
2535 }
2536
2537 }
2538
2539 }
2540
2541 /*****************************************************************************/
2542
2543 void dng_xmp::GenerateDefaultLensName (dng_exif &exif)
2544 {
2545
2546 // Generate default lens name from lens info if required.
2547 // Ignore names names that end in "f/0.0" due to third party bug.
2548
2549 if ((exif.fLensName.IsEmpty () ||
2550 exif.fLensName.EndsWith ("f/0.0")) && exif.fLensInfo [0].IsValid ())
2551 {
2552
2553 char s [256];
2554
2555 real64 minFL = exif.fLensInfo [0].As_real64 ();
2556 real64 maxFL = exif.fLensInfo [1].As_real64 ();
2557
2558 // The f-stop numbers are optional.
2559
2560 if (exif.fLensInfo [2].IsValid ())
2561 {
2562
2563 real64 minFS = exif.fLensInfo [2].As_real64 ();
2564 real64 maxFS = exif.fLensInfo [3].As_real64 ();
2565
2566 if (minFL == maxFL)
2567 snprintf (s, 256, "%.1f mm f/%.1f", minFL, minFS);
2568
2569 else if (minFS == maxFS)
2570 snprintf (s, 256, "%.1f-%.1f mm f/%.1f", minFL, maxFL, minFS);
2571
2572 else
2573 snprintf (s, 256, "%.1f-%.1f mm f/%.1f-%.1f", minFL, maxFL, minFS, maxFS);
2574
2575 }
2576
2577 else
2578 {
2579
2580 if (minFL == maxFL)
2581 snprintf (s, 256, "%.1f mm", minFL);
2582
2583 else
2584 snprintf (s, 256, "%.1f-%.1f mm", minFL, maxFL);
2585
2586 }
2587
2588 exif.fLensName.Set (s);
2589
2590 SetString (XMP_NS_AUX,
2591 "Lens",
2592 exif.fLensName);
2593
2594 // Don't generate exifEX for now.
2595
2596 // SetString (XMP_NS_EXIFEX,
2597 // "LensModel",
2598 // exif.fLensName);
2599
2600 }
2601
2602 }
2603
2604 /*****************************************************************************/
2605
2606 void dng_xmp::SyncLensName (dng_exif &exif)
2607 {
2608
2609 // EXIF lens names are sometimes missing or wrong (esp. when non-OEM lenses
2610 // are used). So prefer the value from XMP.
2611
2612 // Check XMP for the lens model in the aux namespace first. If not there,
2613 // then check the exifEX namespace.
2614
2615 if (!SyncString (XMP_NS_AUX,
2616 "Lens",
2617 exif.fLensName,
2618 preferXMP))
2619 {
2620
2621 SyncString (XMP_NS_EXIFEX,
2622 "LensModel",
2623 exif.fLensName,
2624 preferXMP);
2625
2626 }
2627
2628 GenerateDefaultLensName (exif);
2629
2630 }
2631
2632 /*****************************************************************************/
2633
2634 void dng_xmp::SyncExif (dng_exif &exif,
2635 const dng_exif *originalExif,
2636 bool doingUpdateFromXMP,
2637 bool removeFromXMP)
2638 {
2639
2640 DNG_ASSERT (!doingUpdateFromXMP || originalExif,
2641 "Must have original EXIF if doingUpdateFromXMP");
2642
2643 // Default synchronization options for the read-only fields.
2644
2645 uint32 readOnly = doingUpdateFromXMP ? ignoreXMP
2646 : preferNonXMP;
2647
2648 // Option for removable fields.
2649
2650 uint32 removable = removeFromXMP ? removeXMP
2651 : 0;
2652
2653 // Make:
2654
2655 SyncString (XMP_NS_TIFF,
2656 "Make",
2657 exif.fMake,
2658 readOnly + removable);
2659
2660 // Model:
2661
2662 SyncString (XMP_NS_TIFF,
2663 "Model",
2664 exif.fModel,
2665 readOnly + removable);
2666
2667 // Exif version number:
2668
2669 {
2670
2671 // Find version number in XMP, if any.
2672
2673 uint32 xmpVersion = 0;
2674
2675 {
2676
2677 dng_string s;
2678
2679 if (GetString (XMP_NS_EXIF, "ExifVersion", s))
2680 {
2681
2682 unsigned b0;
2683 unsigned b1;
2684 unsigned b2;
2685 unsigned b3;
2686
2687 if (sscanf (s.Get (),
2688 "%1u%1u%1u%1u",
2689 &b0,
2690 &b1,
2691 &b2,
2692 &b3) == 4)
2693 {
2694
2695 if (b0 <= 9 && b1 <= 9 && b2 <= 9 && b3 <= 9)
2696 {
2697
2698 b0 += '0';
2699 b1 += '0';
2700 b2 += '0';
2701 b3 += '0';
2702
2703 xmpVersion = (b0 << 24) |
2704 (b1 << 16) |
2705 (b2 << 8) |
2706 (b3 );
2707
2708 }
2709
2710 }
2711
2712 }
2713
2714 }
2715
2716 // Use maximum logic for merging.
2717
2718 exif.fExifVersion = Max_uint32 (exif.fExifVersion, xmpVersion);
2719
2720 // Provide default value for ExifVersion.
2721
2722 if (!exif.fExifVersion)
2723 {
2724 exif.SetVersion0231 ();
2725 }
2726
2727 // Update XMP.
2728
2729 dng_string xmpString;
2730
2731 if (exif.fExifVersion)
2732 {
2733
2734 unsigned b0 = ((exif.fExifVersion >> 24) & 0x0FF) - '0';
2735 unsigned b1 = ((exif.fExifVersion >> 16) & 0x0FF) - '0';
2736 unsigned b2 = ((exif.fExifVersion >> 8) & 0x0FF) - '0';
2737 unsigned b3 = ((exif.fExifVersion ) & 0x0FF) - '0';
2738
2739 if (b0 <= 9 && b1 <= 9 && b2 <= 9 && b3 <= 9)
2740 {
2741
2742 char s [5];
2743
2744 snprintf (s,
2745 5,
2746 "%1u%1u%1u%1u",
2747 b0,
2748 b1,
2749 b2,
2750 b3);
2751
2752 xmpString.Set (s);
2753
2754 }
2755
2756 }
2757
2758 if (removeFromXMP || xmpString.IsEmpty ())
2759 {
2760
2761 Remove (XMP_NS_EXIF, "ExifVersion");
2762
2763 }
2764
2765 else
2766 {
2767
2768 SetString (XMP_NS_EXIF, "ExifVersion", xmpString);
2769
2770 }
2771
2772 }
2773
2774 // ExposureTime / ShutterSpeedValue:
2775
2776 {
2777
2778 // Process twice in case XMP contains only one of the
2779 // two fields.
2780
2781 for (uint32 pass = 0; pass < 2; pass++)
2782 {
2783
2784 dng_urational et = exif.fExposureTime;
2785
2786 Sync_urational (XMP_NS_EXIF,
2787 "ExposureTime",
2788 et,
2789 readOnly);
2790
2791 if (et.IsValid ())
2792 {
2793
2794 exif.SetExposureTime (et.As_real64 (), false);
2795
2796 }
2797
2798 dng_srational ss = exif.fShutterSpeedValue;
2799
2800 Sync_srational (XMP_NS_EXIF,
2801 "ShutterSpeedValue",
2802 ss,
2803 readOnly);
2804
2805 if (ss.IsValid ())
2806 {
2807
2808 exif.SetShutterSpeedValue (ss.As_real64 ());
2809
2810 }
2811
2812 }
2813
2814 if (removeFromXMP)
2815 {
2816
2817 Remove (XMP_NS_EXIF, "ExposureTime");
2818
2819 Remove (XMP_NS_EXIF, "ShutterSpeedValue");
2820
2821 }
2822
2823 }
2824
2825 // FNumber / ApertureValue:
2826
2827 {
2828
2829 for (uint32 pass = 0; pass < 2; pass++)
2830 {
2831
2832 dng_urational fs = exif.fFNumber;
2833
2834 Sync_urational (XMP_NS_EXIF,
2835 "FNumber",
2836 fs,
2837 readOnly);
2838
2839 if (fs.IsValid ())
2840 {
2841
2842 exif.SetFNumber (fs.As_real64 ());
2843
2844 }
2845
2846 dng_urational av = exif.fApertureValue;
2847
2848 Sync_urational (XMP_NS_EXIF,
2849 "ApertureValue",
2850 av,
2851 readOnly);
2852
2853 if (av.IsValid ())
2854 {
2855
2856 exif.SetApertureValue (av.As_real64 ());
2857
2858 }
2859
2860 }
2861
2862 if (removeFromXMP)
2863 {
2864
2865 Remove (XMP_NS_EXIF, "FNumber");
2866
2867 Remove (XMP_NS_EXIF, "ApertureValue");
2868
2869 }
2870
2871 }
2872
2873 // Exposure program:
2874
2875 Sync_uint32 (XMP_NS_EXIF,
2876 "ExposureProgram",
2877 exif.fExposureProgram,
2878 exif.fExposureProgram == 0xFFFFFFFF,
2879 readOnly + removable);
2880
2881 // ISO Speed Ratings:
2882
2883 {
2884
2885 uint32 isoSpeedRatingsCount = 0;
2886
2887 uint32 isoSpeedRatingsOptions = readOnly;
2888
2889 uint32 oldISOSpeedRatings [3];
2890
2891 memcpy (oldISOSpeedRatings,
2892 exif.fISOSpeedRatings,
2893 sizeof (oldISOSpeedRatings));
2894
2895 bool checkXMPForHigherISO = false;
2896
2897 for (uint32 j = 0; j < 3; j++)
2898 {
2899
2900 // Special case: the EXIF 2.2x standard represents ISO speed ratings with
2901 // 2 bytes, which cannot hold ISO speed ratings above 65535 (e.g.,
2902 // 102400). If the EXIF ISO speed rating value is 65535, prefer the XMP
2903 // ISOSpeedRatings tag value.
2904
2905 if (exif.fISOSpeedRatings [j] == 65535)
2906 {
2907
2908 isoSpeedRatingsOptions = preferXMP;
2909
2910 checkXMPForHigherISO = true;
2911
2912 isoSpeedRatingsCount = 0;
2913
2914 break;
2915
2916 }
2917
2918 else if (exif.fISOSpeedRatings [j] == 0)
2919 {
2920 break;
2921 }
2922
2923 isoSpeedRatingsCount++;
2924
2925 }
2926
2927 Sync_uint32_array (XMP_NS_EXIF,
2928 "ISOSpeedRatings",
2929 exif.fISOSpeedRatings,
2930 isoSpeedRatingsCount,
2931 3,
2932 isoSpeedRatingsOptions);
2933
2934 // If the EXIF ISO was 65535 and we failed to find anything meaningful in the
2935 // XMP, then we fall back to the EXIF ISO.
2936
2937 if (checkXMPForHigherISO && (isoSpeedRatingsCount == 0))
2938 {
2939
2940 memcpy (exif.fISOSpeedRatings,
2941 oldISOSpeedRatings,
2942 sizeof (oldISOSpeedRatings));
2943
2944 }
2945
2946 // Only remove the ISO tag if there are not ratings over 65535.
2947
2948 if (removeFromXMP)
2949 {
2950
2951 bool hasHighISO = false;
2952
2953 for (uint32 j = 0; j < 3; j++)
2954 {
2955
2956 if (exif.fISOSpeedRatings [j] == 0)
2957 {
2958 break;
2959 }
2960
2961 hasHighISO = hasHighISO || (exif.fISOSpeedRatings [j] > 65535);
2962
2963 }
2964
2965 if (!hasHighISO)
2966 {
2967
2968 Remove (XMP_NS_EXIF, "ISOSpeedRatings");
2969
2970 }
2971
2972 }
2973
2974 }
2975
2976 // SensitivityType:
2977
2978 Sync_uint32 (XMP_NS_EXIF,
2979 "SensitivityType",
2980 exif.fSensitivityType,
2981 exif.fSensitivityType == stUnknown,
2982 readOnly + removable);
2983
2984 // StandardOutputSensitivity:
2985
2986 Sync_uint32 (XMP_NS_EXIF,
2987 "StandardOutputSensitivity",
2988 exif.fStandardOutputSensitivity,
2989 exif.fStandardOutputSensitivity == 0,
2990 readOnly + removable);
2991
2992 // RecommendedExposureIndex:
2993
2994 Sync_uint32 (XMP_NS_EXIF,
2995 "RecommendedExposureIndex",
2996 exif.fRecommendedExposureIndex,
2997 exif.fRecommendedExposureIndex == 0,
2998 readOnly + removable);
2999
3000 // ISOSpeed:
3001
3002 Sync_uint32 (XMP_NS_EXIF,
3003 "ISOSpeed",
3004 exif.fISOSpeed,
3005 exif.fISOSpeed == 0,
3006 readOnly + removable);
3007
3008 // ISOSpeedLatitudeyyy:
3009
3010 Sync_uint32 (XMP_NS_EXIF,
3011 "ISOSpeedLatitudeyyy",
3012 exif.fISOSpeedLatitudeyyy,
3013 exif.fISOSpeedLatitudeyyy == 0,
3014 readOnly + removable);
3015
3016 // ISOSpeedLatitudezzz:
3017
3018 Sync_uint32 (XMP_NS_EXIF,
3019 "ISOSpeedLatitudezzz",
3020 exif.fISOSpeedLatitudezzz,
3021 exif.fISOSpeedLatitudezzz == 0,
3022 readOnly + removable);
3023
3024 // ExposureIndex:
3025
3026 Sync_urational (XMP_NS_EXIF,
3027 "ExposureIndex",
3028 exif.fExposureIndex,
3029 readOnly + removable);
3030
3031 // Brightness Value:
3032
3033 Sync_srational (XMP_NS_EXIF,
3034 "BrightnessValue",
3035 exif.fBrightnessValue,
3036 readOnly + removable);
3037
3038 // Exposure Bias:
3039
3040 Sync_srational (XMP_NS_EXIF,
3041 "ExposureBiasValue",
3042 exif.fExposureBiasValue,
3043 readOnly + removable);
3044
3045 // Max Aperture:
3046
3047 Sync_urational (XMP_NS_EXIF,
3048 "MaxApertureValue",
3049 exif.fMaxApertureValue,
3050 readOnly + removable);
3051
3052 // Subject Distance:
3053
3054 Sync_urational (XMP_NS_EXIF,
3055 "SubjectDistance",
3056 exif.fSubjectDistance,
3057 readOnly + removable);
3058
3059 // Metering Mode:
3060
3061 Sync_uint32 (XMP_NS_EXIF,
3062 "MeteringMode",
3063 exif.fMeteringMode,
3064 exif.fMeteringMode == 0xFFFFFFFF,
3065 readOnly + removable);
3066
3067 // Light Source:
3068
3069 Sync_uint32 (XMP_NS_EXIF,
3070 "LightSource",
3071 exif.fLightSource,
3072 exif.fLightSource > 0x0FFFF,
3073 readOnly + removable);
3074
3075 // Flash State:
3076
3077 SyncFlash (exif.fFlash,
3078 exif.fFlashMask,
3079 readOnly);
3080
3081 if (removeFromXMP)
3082 {
3083 Remove (XMP_NS_EXIF, "Flash");
3084 }
3085
3086 // Focal Length:
3087
3088 Sync_urational (XMP_NS_EXIF,
3089 "FocalLength",
3090 exif.fFocalLength,
3091 readOnly + removable);
3092
3093 // Sensing Method.
3094
3095 Sync_uint32 (XMP_NS_EXIF,
3096 "SensingMethod",
3097 exif.fSensingMethod,
3098 exif.fSensingMethod > 0x0FFFF,
3099 readOnly + removable);
3100
3101 // File Source.
3102
3103 Sync_uint32 (XMP_NS_EXIF,
3104 "FileSource",
3105 exif.fFileSource,
3106 exif.fFileSource > 0x0FF,
3107 readOnly + removable);
3108
3109 // Scene Type.
3110
3111 Sync_uint32 (XMP_NS_EXIF,
3112 "SceneType",
3113 exif.fSceneType,
3114 exif.fSceneType > 0x0FF,
3115 readOnly + removable);
3116
3117 // Focal Length in 35mm Film:
3118
3119 Sync_uint32 (XMP_NS_EXIF,
3120 "FocalLengthIn35mmFilm",
3121 exif.fFocalLengthIn35mmFilm,
3122 exif.fFocalLengthIn35mmFilm == 0,
3123 readOnly + removable);
3124
3125 // Custom Rendered:
3126
3127 Sync_uint32 (XMP_NS_EXIF,
3128 "CustomRendered",
3129 exif.fCustomRendered,
3130 exif.fCustomRendered > 0x0FFFF,
3131 readOnly + removable);
3132
3133 // Exposure Mode:
3134
3135 Sync_uint32 (XMP_NS_EXIF,
3136 "ExposureMode",
3137 exif.fExposureMode,
3138 exif.fExposureMode > 0x0FFFF,
3139 readOnly + removable);
3140
3141 // White Balance:
3142
3143 Sync_uint32 (XMP_NS_EXIF,
3144 "WhiteBalance",
3145 exif.fWhiteBalance,
3146 exif.fWhiteBalance > 0x0FFFF,
3147 readOnly + removable);
3148
3149 // Scene Capture Type:
3150
3151 Sync_uint32 (XMP_NS_EXIF,
3152 "SceneCaptureType",
3153 exif.fSceneCaptureType,
3154 exif.fSceneCaptureType > 0x0FFFF,
3155 readOnly + removable);
3156
3157 // Gain Control:
3158
3159 Sync_uint32 (XMP_NS_EXIF,
3160 "GainControl",
3161 exif.fGainControl,
3162 exif.fGainControl > 0x0FFFF,
3163 readOnly + removable);
3164
3165 // Contrast:
3166
3167 Sync_uint32 (XMP_NS_EXIF,
3168 "Contrast",
3169 exif.fContrast,
3170 exif.fContrast > 0x0FFFF,
3171 readOnly + removable);
3172
3173 // Saturation:
3174
3175 Sync_uint32 (XMP_NS_EXIF,
3176 "Saturation",
3177 exif.fSaturation,
3178 exif.fSaturation > 0x0FFFF,
3179 readOnly + removable);
3180
3181 // Sharpness:
3182
3183 Sync_uint32 (XMP_NS_EXIF,
3184 "Sharpness",
3185 exif.fSharpness,
3186 exif.fSharpness > 0x0FFFF,
3187 readOnly + removable);
3188
3189 // Subject Distance Range:
3190
3191 Sync_uint32 (XMP_NS_EXIF,
3192 "SubjectDistanceRange",
3193 exif.fSubjectDistanceRange,
3194 exif.fSubjectDistanceRange > 0x0FFFF,
3195 readOnly + removable);
3196
3197 // Subject Area:
3198
3199 Sync_uint32_array (XMP_NS_EXIF,
3200 "SubjectArea",
3201 exif.fSubjectArea,
3202 exif.fSubjectAreaCount,
3203 sizeof (exif.fSubjectArea ) /
3204 sizeof (exif.fSubjectArea [0]),
3205 readOnly);
3206
3207 if (removeFromXMP)
3208 {
3209 Remove (XMP_NS_EXIF, "SubjectArea");
3210 }
3211
3212 // Digital Zoom Ratio:
3213
3214 Sync_urational (XMP_NS_EXIF,
3215 "DigitalZoomRatio",
3216 exif.fDigitalZoomRatio,
3217 readOnly + removable);
3218
3219 // Focal Plane Resolution:
3220
3221 Sync_urational (XMP_NS_EXIF,
3222 "FocalPlaneXResolution",
3223 exif.fFocalPlaneXResolution,
3224 readOnly + removable);
3225
3226 Sync_urational (XMP_NS_EXIF,
3227 "FocalPlaneYResolution",
3228 exif.fFocalPlaneYResolution,
3229 readOnly + removable);
3230
3231 Sync_uint32 (XMP_NS_EXIF,
3232 "FocalPlaneResolutionUnit",
3233 exif.fFocalPlaneResolutionUnit,
3234 exif.fFocalPlaneResolutionUnit > 0x0FFFF,
3235 readOnly + removable);
3236
3237 // ImageDescription: (XMP is is always preferred)
3238
3239 if (fSDK->GetAltLangDefault (XMP_NS_DC,
3240 "description",
3241 exif.fImageDescription))
3242
3243 {
3244
3245 }
3246
3247 else if (doingUpdateFromXMP)
3248 {
3249
3250 exif.fImageDescription.Clear ();
3251
3252 if (originalExif->fImageDescription.NotEmpty ())
3253 {
3254
3255 fSDK->SetAltLangDefault (XMP_NS_DC,
3256 "description",
3257 dng_string ());
3258
3259 }
3260
3261 }
3262
3263 else if (exif.fImageDescription.NotEmpty ())
3264 {
3265
3266 fSDK->SetAltLangDefault (XMP_NS_DC,
3267 "description",
3268 exif.fImageDescription);
3269
3270 }
3271
3272 // Artist: (XMP is is always preferred)
3273
3274 {
3275
3276 dng_string_list xmpList;
3277
3278 if (fSDK->GetStringList (XMP_NS_DC,
3279 "creator",
3280 xmpList))
3281 {
3282
3283 exif.fArtist.Clear ();
3284
3285 if (xmpList.Count () > 0)
3286 {
3287
3288 uint32 j;
3289
3290 uint32 bufferSize = xmpList.Count () * 4 + 1;
3291
3292 for (j = 0; j < xmpList.Count (); j++)
3293 {
3294
3295 bufferSize += xmpList [j].Length () * 2;
3296
3297 }
3298
3299 dng_memory_data temp (bufferSize);
3300
3301 char *t = temp.Buffer_char ();
3302
3303 for (j = 0; j < xmpList.Count (); j++)
3304 {
3305
3306 const char *s = xmpList [j].Get ();
3307
3308 bool needQuotes = xmpList [j].Contains ("; ") ||
3309 s [0] == '\"';
3310
3311 if (needQuotes)
3312 {
3313 *(t++) = '\"';
3314 }
3315
3316 while (s [0] != 0)
3317 {
3318
3319 if (s [0] == '\"' && needQuotes)
3320 {
3321 *(t++) = '\"';
3322 }
3323
3324 *(t++) = *(s++);
3325
3326 }
3327
3328 if (needQuotes)
3329 {
3330 *(t++) = '\"';
3331 }
3332
3333 if (j != xmpList.Count () - 1)
3334 {
3335 *(t++) = ';';
3336 *(t++) = ' ';
3337 }
3338 else
3339 {
3340 *t = 0;
3341 }
3342
3343 }
3344
3345 exif.fArtist.Set (temp.Buffer_char ());
3346
3347 }
3348
3349 }
3350
3351 else if (doingUpdateFromXMP)
3352 {
3353
3354 exif.fArtist.Clear ();
3355
3356 if (originalExif->fArtist.NotEmpty ())
3357 {
3358
3359 dng_string_list fakeList;
3360
3361 fakeList.Append (dng_string ());
3362
3363 SetStringList (XMP_NS_DC,
3364 "creator",
3365 fakeList,
3366 false);
3367
3368 }
3369
3370 }
3371
3372 else if (exif.fArtist.NotEmpty ())
3373 {
3374
3375 dng_string_list newList;
3376
3377 dng_memory_data temp (exif.fArtist.Length () + 1);
3378
3379 const char *s = exif.fArtist.Get ();
3380
3381 char *t = temp.Buffer_char ();
3382
3383 bool first = true;
3384
3385 bool quoted = false;
3386
3387 bool valid = true;
3388
3389 while (s [0] != 0 && valid)
3390 {
3391
3392 if (first)
3393 {
3394
3395 if (s [0] == '\"')
3396 {
3397
3398 quoted = true;
3399
3400 s++;
3401
3402 }
3403
3404 }
3405
3406 first = false;
3407
3408 if (quoted)
3409 {
3410
3411 if (s [0] == '\"' &&
3412 s [1] == '\"')
3413 {
3414
3415 s+= 2;
3416
3417 *(t++) = '\"';
3418
3419 }
3420
3421 else if (s [0] == '\"')
3422 {
3423
3424 s++;
3425
3426 quoted = false;
3427
3428 valid = valid && ((s [0] == 0) || ((s [0] == ';' && s [1] == ' ')));
3429
3430 }
3431
3432 else if (s [0] == 0)
3433 {
3434
3435 valid = false;
3436
3437 }
3438
3439 else
3440 {
3441
3442 *(t++) = *(s++);
3443
3444 }
3445
3446 }
3447
3448 else if (s [0] == ';' &&
3449 s [1] == ' ')
3450 {
3451
3452 s += 2;
3453
3454 t [0] = 0;
3455
3456 dng_string ss;
3457
3458 ss.Set (temp.Buffer_char ());
3459
3460 newList.Append (ss);
3461
3462 t = temp.Buffer_char ();
3463
3464 first = true;
3465
3466 }
3467
3468 else
3469 {
3470
3471 *(t++) = *(s++);
3472
3473 }
3474
3475 }
3476
3477 if (quoted)
3478 {
3479
3480 valid = false;
3481
3482 }
3483
3484 if (valid)
3485 {
3486
3487 if (t != temp.Buffer_char ())
3488 {
3489
3490 t [0] = 0;
3491
3492 dng_string ss;
3493
3494 ss.Set (temp.Buffer_char ());
3495
3496 newList.Append (ss);
3497
3498 }
3499
3500 }
3501
3502 else
3503 {
3504
3505 newList.Clear ();
3506
3507 newList.Append (exif.fArtist);
3508
3509 }
3510
3511 SetStringList (XMP_NS_DC,
3512 "creator",
3513 newList,
3514 false);
3515
3516 }
3517
3518 }
3519
3520 // Software: (XMP is is always preferred)
3521
3522 if (fSDK->GetString (XMP_NS_XAP,
3523 "CreatorTool",
3524 exif.fSoftware))
3525
3526 {
3527
3528 }
3529
3530 else if (doingUpdateFromXMP)
3531 {
3532
3533 exif.fSoftware.Clear ();
3534
3535 if (originalExif->fSoftware.NotEmpty ())
3536 {
3537
3538 fSDK->SetString (XMP_NS_XAP,
3539 "CreatorTool",
3540 dng_string ());
3541
3542 }
3543
3544 }
3545
3546 else if (exif.fSoftware.NotEmpty ())
3547 {
3548
3549 fSDK->SetString (XMP_NS_XAP,
3550 "CreatorTool",
3551 exif.fSoftware);
3552
3553 }
3554
3555 // Copyright: (XMP is is always preferred)
3556
3557 if (fSDK->GetAltLangDefault (XMP_NS_DC,
3558 "rights",
3559 exif.fCopyright))
3560
3561 {
3562
3563 }
3564
3565 else if (doingUpdateFromXMP)
3566 {
3567
3568 exif.fCopyright.Clear ();
3569
3570 if (originalExif->fCopyright.NotEmpty ())
3571 {
3572
3573 fSDK->SetAltLangDefault (XMP_NS_DC,
3574 "rights",
3575 dng_string ());
3576
3577 }
3578
3579 }
3580
3581 else if (exif.fCopyright.NotEmpty ())
3582 {
3583
3584 fSDK->SetAltLangDefault (XMP_NS_DC,
3585 "rights",
3586 exif.fCopyright);
3587
3588 }
3589
3590 // Camera serial number private tag:
3591
3592 SyncString (XMP_NS_AUX,
3593 "SerialNumber",
3594 exif.fCameraSerialNumber,
3595 readOnly);
3596
3597 // Do some sanity checking on the camera serial number.
3598
3599 if (exif.fCameraSerialNumber.NotEmpty ())
3600 {
3601
3602 // The new edit defaults system exposes camera serial numbers in the
3603 // UI, and camera makes sometimes write bad values into this metadata,
3604 // so clean up some common mistakes.
3605
3606 dng_string s = exif.fCameraSerialNumber;
3607
3608 s.TrimTrailingBlanks ();
3609 s.TrimLeadingBlanks ();
3610
3611 bool hasDigit = false;
3612 bool hasNonZero = false;
3613 bool hasNonAscii = false;
3614
3615 const char *c = s.Get ();
3616
3617 while (*c)
3618 {
3619
3620 hasDigit = hasDigit || (*c >= '0' && *c <= '9');
3621 hasNonZero = hasNonZero || (*c != '0');
3622 hasNonAscii = hasNonAscii || (*c < ' ' || *c > 0x7F);
3623
3624 c++;
3625
3626 }
3627
3628 if (!(hasDigit && hasNonZero) || hasNonAscii || s.IsEmpty ())
3629 {
3630
3631 DNG_REPORT ("Ignoring likely bogus camera serial number");
3632
3633 exif.fCameraSerialNumber.Clear ();
3634
3635 Remove (XMP_NS_AUX, "SerialNumber");
3636
3637 }
3638
3639 }
3640
3641 // Lens Info:
3642
3643 {
3644
3645 dng_string s;
3646
3647 if (exif.fLensInfo [0].IsValid ())
3648 {
3649
3650 char ss [256];
3651
3652 snprintf (ss,
3653 256,
3654 "%u/%u %u/%u %u/%u %u/%u",
3655 (unsigned) exif.fLensInfo [0].n,
3656 (unsigned) exif.fLensInfo [0].d,
3657 (unsigned) exif.fLensInfo [1].n,
3658 (unsigned) exif.fLensInfo [1].d,
3659 (unsigned) exif.fLensInfo [2].n,
3660 (unsigned) exif.fLensInfo [2].d,
3661 (unsigned) exif.fLensInfo [3].n,
3662 (unsigned) exif.fLensInfo [3].d);
3663
3664 s.Set (ss);
3665
3666 }
3667
3668 // Check XMP for the lens specification in the aux namespace first. If
3669 // not there, then check the exifEX namespace.
3670
3671 SyncString (XMP_NS_AUX,
3672 "LensInfo",
3673 s,
3674 readOnly);
3675
3676 if (s.NotEmpty ())
3677 {
3678
3679 unsigned n [4];
3680 unsigned d [4];
3681
3682 if (sscanf (s.Get (),
3683 "%u/%u %u/%u %u/%u %u/%u",
3684 &n [0],
3685 &d [0],
3686 &n [1],
3687 &d [1],
3688 &n [2],
3689 &d [2],
3690 &n [3],
3691 &d [3]) == 8)
3692 {
3693
3694 for (uint32 j = 0; j < 4; j++)
3695 {
3696
3697 exif.fLensInfo [j] = dng_urational (n [j], d [j]);
3698
3699 }
3700
3701 }
3702
3703
3704 }
3705
3706 else
3707 {
3708
3709 // Not found in aux, so examine exifEX.
3710
3711 dng_string_list strList;
3712
3713 SyncStringList (XMP_NS_EXIFEX,
3714 "LensSpecification",
3715 strList,
3716 false,
3717 readOnly);
3718
3719 if (strList.Count () == 4)
3720 {
3721
3722 const dng_string &s0 = strList [0];
3723 const dng_string &s1 = strList [1];
3724 const dng_string &s2 = strList [2];
3725 const dng_string &s3 = strList [3];
3726
3727 unsigned n [4];
3728 unsigned d [4];
3729
3730 if (sscanf (s0.Get (), "%u/%u", &n [0], &d [0]) == 2 &&
3731 sscanf (s1.Get (), "%u/%u", &n [1], &d [1]) == 2 &&
3732 sscanf (s2.Get (), "%u/%u", &n [2], &d [2]) == 2 &&
3733 sscanf (s3.Get (), "%u/%u", &n [3], &d [3]) == 2)
3734 {
3735
3736 for (uint32 j = 0; j < 4; j++)
3737 {
3738
3739 exif.fLensInfo [j] = dng_urational (n [j], d [j]);
3740
3741 }
3742
3743 }
3744
3745 }
3746
3747 }
3748
3749 }
3750
3751 // Lens name:
3752
3753 SyncLensName (exif);
3754
3755 // Lens ID:
3756
3757 SyncString (XMP_NS_AUX,
3758 "LensID",
3759 exif.fLensID,
3760 readOnly);
3761
3762 // Lens Make:
3763
3764 if (!SyncString (XMP_NS_EXIF,
3765 "LensMake",
3766 exif.fLensMake,
3767 readOnly + removable))
3768
3769 {
3770
3771 SyncString (XMP_NS_EXIFEX,
3772 "LensMake",
3773 exif.fLensMake,
3774 readOnly + removable);
3775
3776 }
3777
3778 // Lens Serial Number:
3779
3780 SyncString (XMP_NS_AUX,
3781 "LensSerialNumber",
3782 exif.fLensSerialNumber,
3783 readOnly);
3784
3785 // Image Number:
3786
3787 Sync_uint32 (XMP_NS_AUX,
3788 "ImageNumber",
3789 exif.fImageNumber,
3790 exif.fImageNumber == 0xFFFFFFFF,
3791 preferXMP); // CR-4197237: Preserve aux:ImageNumber in XMP when Updating Metadata
3792
3793 // User Comment:
3794
3795 if (exif.fUserComment.NotEmpty ())
3796 {
3797
3798 fSDK->SetAltLangDefault (XMP_NS_EXIF,
3799 "UserComment",
3800 exif.fUserComment);
3801
3802 }
3803
3804 else
3805 {
3806
3807 (void) fSDK->GetAltLangDefault (XMP_NS_EXIF,
3808 "UserComment",
3809 exif.fUserComment);
3810
3811 }
3812
3813 if (removeFromXMP)
3814 {
3815 Remove (XMP_NS_EXIF, "UserComment");
3816 }
3817
3818 // Approximate focus distance:
3819
3820 SyncApproximateFocusDistance (exif,
3821 readOnly);
3822
3823 // LensDistortInfo:
3824
3825 {
3826
3827 dng_string s;
3828
3829 if (exif.HasLensDistortInfo ())
3830 {
3831
3832 char ss [256];
3833
3834 snprintf (ss,
3835 256,
3836 "%d/%d %d/%d %d/%d %d/%d",
3837 (int) exif.fLensDistortInfo [0].n,
3838 (int) exif.fLensDistortInfo [0].d,
3839 (int) exif.fLensDistortInfo [1].n,
3840 (int) exif.fLensDistortInfo [1].d,
3841 (int) exif.fLensDistortInfo [2].n,
3842 (int) exif.fLensDistortInfo [2].d,
3843 (int) exif.fLensDistortInfo [3].n,
3844 (int) exif.fLensDistortInfo [3].d);
3845
3846 s.Set (ss);
3847
3848 }
3849
3850 SyncString (XMP_NS_AUX,
3851 "LensDistortInfo",
3852 s,
3853 readOnly);
3854
3855 if (s.NotEmpty ())
3856 {
3857
3858 int n [4];
3859 int d [4];
3860
3861 if (sscanf (s.Get (),
3862 "%d/%d %d/%d %d/%d %d/%d",
3863 &n [0],
3864 &d [0],
3865 &n [1],
3866 &d [1],
3867 &n [2],
3868 &d [2],
3869 &n [3],
3870 &d [3]) == 8)
3871 {
3872
3873 for (uint32 j = 0; j < 4; j++)
3874 {
3875
3876 exif.fLensDistortInfo [j] = dng_srational (n [j], d [j]);
3877
3878 }
3879
3880 }
3881
3882
3883 }
3884
3885 }
3886
3887 // Flash Compensation:
3888
3889 Sync_srational (XMP_NS_AUX,
3890 "FlashCompensation",
3891 exif.fFlashCompensation,
3892 readOnly);
3893
3894 // Owner Name: (allow XMP updates)
3895
3896 SyncString (XMP_NS_AUX,
3897 "OwnerName",
3898 exif.fOwnerName,
3899 preferXMP);
3900
3901 // Firmware:
3902
3903 SyncString (XMP_NS_AUX,
3904 "Firmware",
3905 exif.fFirmware,
3906 readOnly);
3907
3908 // Image Unique ID:
3909
3910 {
3911
3912 dng_string s = EncodeFingerprint (exif.fImageUniqueID);
3913
3914 SyncString (XMP_NS_EXIF,
3915 "ImageUniqueID",
3916 s,
3917 readOnly + removable);
3918
3919 exif.fImageUniqueID = DecodeFingerprint (s);
3920
3921 }
3922
3923 // Allow EXIF GPS to be updated via updates from XMP.
3924
3925 if (doingUpdateFromXMP)
3926 {
3927
3928 // Clear out the GPS info from the EXIF so it will
3929 // replaced by the GPS info from the XMP.
3930
3931 dng_exif blankExif;
3932
3933 exif.CopyGPSFrom (blankExif);
3934
3935 }
3936
3937 // GPS Version ID:
3938
3939 {
3940
3941 dng_string s = EncodeGPSVersion (exif.fGPSVersionID);
3942
3943 uint32 require = (doingUpdateFromXMP &&
3944 originalExif->fGPSVersionID != 0)
3945 ? requireXMP : 0;
3946
3947 if (SyncString (XMP_NS_EXIF,
3948 "GPSVersionID",
3949 s,
3950 preferXMP + removable + require))
3951 {
3952
3953 exif.fGPSVersionID = DecodeGPSVersion (s);
3954
3955 }
3956
3957 }
3958
3959 // GPS Latitude:
3960
3961 {
3962
3963 dng_string s = EncodeGPSCoordinate (exif.fGPSLatitudeRef,
3964 exif.fGPSLatitude);
3965
3966 uint32 require = (doingUpdateFromXMP &&
3967 EncodeGPSCoordinate (originalExif->fGPSLatitudeRef,
3968 originalExif->fGPSLatitude).NotEmpty ())
3969 ? requireXMP : 0;
3970
3971 if (SyncString (XMP_NS_EXIF,
3972 "GPSLatitude",
3973 s,
3974 preferXMP + removable + require))
3975 {
3976
3977 DecodeGPSCoordinate (s,
3978 exif.fGPSLatitudeRef,
3979 exif.fGPSLatitude);
3980
3981 }
3982
3983 }
3984
3985 // GPS Longitude:
3986
3987 {
3988
3989 dng_string s = EncodeGPSCoordinate (exif.fGPSLongitudeRef,
3990 exif.fGPSLongitude);
3991
3992 uint32 require = (doingUpdateFromXMP &&
3993 EncodeGPSCoordinate (originalExif->fGPSLongitudeRef,
3994 originalExif->fGPSLongitude).NotEmpty ())
3995 ? requireXMP : 0;
3996
3997 if (SyncString (XMP_NS_EXIF,
3998 "GPSLongitude",
3999 s,
4000 preferXMP + removable + require))
4001 {
4002
4003 DecodeGPSCoordinate (s,
4004 exif.fGPSLongitudeRef,
4005 exif.fGPSLongitude);
4006
4007 }
4008
4009 }
4010
4011 // Handle simple case of incorrectly written GPS altitude where someone didn't understand
4012 // the GPSAltitudeRef and assumed the GPSAltitude RATIONAL is signed.
4013 // Only handle this case as we do not want to misinterpret e.g. a fixed point
4014 // representation of very high GPS altitudes.
4015
4016 uint32 &altitudeRef = exif.fGPSAltitudeRef;
4017 dng_urational &altitude = exif.fGPSAltitude;
4018
4019 if (altitude.IsValid () &&
4020 (altitudeRef == 0 || altitudeRef == 0xFFFFFFFF)) // If the file contains a "below sea level" altitudeRef,
4021 // assume the writing software is working according to the spec.
4022 {
4023
4024 if ((altitude.n & (1U << 31)) &&
4025 altitude.d < 7) // As the denominator increases, large numerator values become possibly valid distances.
4026 // Pick a limit on the conservative side (approx 33e6m) to prevent misinterpretation.
4027 // Noting that the normal case for this mistake has a denominator of 1
4028 {
4029
4030 altitude.n = ~altitude.n + 1;
4031 altitudeRef = 1;
4032
4033 }
4034
4035 }
4036
4037 // GPS Altitude Reference:
4038
4039 {
4040
4041 uint32 require = (doingUpdateFromXMP &&
4042 originalExif->fGPSAltitudeRef != 0xFFFFFFFF)
4043 ? requireXMP : 0;
4044
4045 Sync_uint32 (XMP_NS_EXIF,
4046 "GPSAltitudeRef",
4047 altitudeRef,
4048 altitudeRef == 0xFFFFFFFF,
4049 preferXMP + removable + require,
4050 0xFFFFFFFF);
4051
4052 }
4053
4054 // GPS Altitude:
4055
4056 {
4057
4058 uint32 require = (doingUpdateFromXMP &&
4059 originalExif->fGPSAltitude.IsValid ())
4060 ? requireXMP : 0;
4061
4062 Sync_urational (XMP_NS_EXIF,
4063 "GPSAltitude",
4064 altitude,
4065 preferXMP + removable + require);
4066
4067 }
4068
4069 // GPS Date/Time:
4070
4071 {
4072
4073 dng_string s = EncodeGPSDateTime (exif.fGPSDateStamp,
4074 exif.fGPSTimeStamp);
4075
4076 uint32 require = (doingUpdateFromXMP &&
4077 EncodeGPSDateTime (originalExif->fGPSDateStamp,
4078 originalExif->fGPSTimeStamp).NotEmpty ())
4079 ? requireXMP : 0;
4080
4081 if (SyncString (XMP_NS_EXIF,
4082 "GPSTimeStamp",
4083 s,
4084 preferXMP + removable + require))
4085 {
4086
4087 DecodeGPSDateTime (s,
4088 exif.fGPSDateStamp,
4089 exif.fGPSTimeStamp);
4090
4091 }
4092
4093 }
4094
4095 // GPS Satellites:
4096
4097 {
4098
4099 uint32 require = (doingUpdateFromXMP &&
4100 originalExif->fGPSSatellites.NotEmpty ())
4101 ? requireXMP : 0;
4102
4103 SyncString (XMP_NS_EXIF,
4104 "GPSSatellites",
4105 exif.fGPSSatellites,
4106 preferXMP + removable + require);
4107
4108 }
4109
4110 // GPS Status:
4111
4112 {
4113
4114 uint32 require = (doingUpdateFromXMP &&
4115 originalExif->fGPSStatus.NotEmpty ())
4116 ? requireXMP : 0;
4117
4118 SyncString (XMP_NS_EXIF,
4119 "GPSStatus",
4120 exif.fGPSStatus,
4121 preferXMP + removable + require);
4122
4123 }
4124
4125 // GPS Measure Mode:
4126
4127 {
4128
4129 uint32 require = (doingUpdateFromXMP &&
4130 originalExif->fGPSMeasureMode.NotEmpty ())
4131 ? requireXMP : 0;
4132
4133 SyncString (XMP_NS_EXIF,
4134 "GPSMeasureMode",
4135 exif.fGPSMeasureMode,
4136 preferXMP + removable + require);
4137
4138 }
4139
4140 // GPS DOP:
4141
4142 {
4143
4144 uint32 require = (doingUpdateFromXMP &&
4145 originalExif->fGPSDOP.IsValid ())
4146 ? requireXMP : 0;
4147
4148 Sync_urational (XMP_NS_EXIF,
4149 "GPSDOP",
4150 exif.fGPSDOP,
4151 preferXMP + removable + require);
4152
4153 }
4154
4155 // GPS Speed Reference:
4156
4157 {
4158
4159 uint32 require = (doingUpdateFromXMP &&
4160 originalExif->fGPSSpeedRef.NotEmpty ())
4161 ? requireXMP : 0;
4162
4163 SyncString (XMP_NS_EXIF,
4164 "GPSSpeedRef",
4165 exif.fGPSSpeedRef,
4166 preferXMP + removable + require);
4167
4168 }
4169
4170 // GPS Speed:
4171
4172 {
4173
4174 uint32 require = (doingUpdateFromXMP &&
4175 originalExif->fGPSSpeed.IsValid ())
4176 ? requireXMP : 0;
4177
4178 Sync_urational (XMP_NS_EXIF,
4179 "GPSSpeed",
4180 exif.fGPSSpeed,
4181 preferXMP + removable + require);
4182
4183 }
4184
4185 // GPS Track Reference:
4186
4187 {
4188
4189 uint32 require = (doingUpdateFromXMP &&
4190 originalExif->fGPSTrackRef.NotEmpty ())
4191 ? requireXMP : 0;
4192
4193 SyncString (XMP_NS_EXIF,
4194 "GPSTrackRef",
4195 exif.fGPSTrackRef,
4196 preferXMP + removable + require);
4197
4198 }
4199
4200 // GPS Track:
4201
4202 {
4203
4204 uint32 require = (doingUpdateFromXMP &&
4205 originalExif->fGPSTrack.IsValid ())
4206 ? requireXMP : 0;
4207
4208 Sync_urational (XMP_NS_EXIF,
4209 "GPSTrack",
4210 exif.fGPSTrack,
4211 preferXMP + removable + require);
4212
4213 }
4214
4215 // GPS Image Direction Reference:
4216
4217 {
4218
4219 uint32 require = (doingUpdateFromXMP &&
4220 originalExif->fGPSImgDirectionRef.NotEmpty ())
4221 ? requireXMP : 0;
4222
4223 SyncString (XMP_NS_EXIF,
4224 "GPSImgDirectionRef",
4225 exif.fGPSImgDirectionRef,
4226 preferXMP + removable + require);
4227
4228 }
4229
4230 // GPS Image Direction:
4231
4232 {
4233
4234 uint32 require = (doingUpdateFromXMP &&
4235 originalExif->fGPSImgDirection.IsValid ())
4236 ? requireXMP : 0;
4237
4238 Sync_urational (XMP_NS_EXIF,
4239 "GPSImgDirection",
4240 exif.fGPSImgDirection,
4241 preferXMP + removable + require);
4242
4243 }
4244
4245 // GPS Map Datum:
4246
4247 {
4248
4249 uint32 require = (doingUpdateFromXMP &&
4250 originalExif->fGPSMapDatum.NotEmpty ())
4251 ? requireXMP : 0;
4252
4253 SyncString (XMP_NS_EXIF,
4254 "GPSMapDatum",
4255 exif.fGPSMapDatum,
4256 preferXMP + removable + require);
4257
4258 }
4259
4260 // GPS Destination Latitude:
4261
4262 {
4263
4264 dng_string s = EncodeGPSCoordinate (exif.fGPSDestLatitudeRef,
4265 exif.fGPSDestLatitude);
4266
4267 uint32 require = (doingUpdateFromXMP &&
4268 EncodeGPSCoordinate (originalExif->fGPSDestLatitudeRef,
4269 originalExif->fGPSDestLatitude).NotEmpty ())
4270 ? requireXMP : 0;
4271
4272 if (SyncString (XMP_NS_EXIF,
4273 "GPSDestLatitude",
4274 s,
4275 preferXMP + removable + require))
4276 {
4277
4278 DecodeGPSCoordinate (s,
4279 exif.fGPSDestLatitudeRef,
4280 exif.fGPSDestLatitude);
4281
4282 }
4283
4284 }
4285
4286 // GPS Destination Longitude:
4287
4288 {
4289
4290 dng_string s = EncodeGPSCoordinate (exif.fGPSDestLongitudeRef,
4291 exif.fGPSDestLongitude);
4292
4293 uint32 require = (doingUpdateFromXMP &&
4294 EncodeGPSCoordinate (originalExif->fGPSDestLongitudeRef,
4295 originalExif->fGPSDestLongitude).NotEmpty ())
4296 ? requireXMP : 0;
4297
4298 if (SyncString (XMP_NS_EXIF,
4299 "GPSDestLongitude",
4300 s,
4301 preferXMP + removable + require))
4302 {
4303
4304 DecodeGPSCoordinate (s,
4305 exif.fGPSDestLongitudeRef,
4306 exif.fGPSDestLongitude);
4307
4308 }
4309
4310 }
4311
4312 // GPS Destination Bearing Reference:
4313
4314 {
4315
4316 uint32 require = (doingUpdateFromXMP &&
4317 originalExif->fGPSMapDatum.NotEmpty ())
4318 ? requireXMP : 0;
4319
4320 SyncString (XMP_NS_EXIF,
4321 "GPSDestBearingRef",
4322 exif.fGPSDestBearingRef,
4323 preferXMP + removable + require);
4324
4325 }
4326
4327 // GPS Destination Bearing:
4328
4329 {
4330
4331 uint32 require = (doingUpdateFromXMP &&
4332 originalExif->fGPSDestBearing.IsValid ())
4333 ? requireXMP : 0;
4334
4335 Sync_urational (XMP_NS_EXIF,
4336 "GPSDestBearing",
4337 exif.fGPSDestBearing,
4338 preferXMP + removable + require);
4339
4340 }
4341
4342 // GPS Destination Distance Reference:
4343
4344 {
4345
4346 uint32 require = (doingUpdateFromXMP &&
4347 originalExif->fGPSDestDistanceRef.NotEmpty ())
4348 ? requireXMP : 0;
4349
4350 SyncString (XMP_NS_EXIF,
4351 "GPSDestDistanceRef",
4352 exif.fGPSDestDistanceRef,
4353 preferXMP + removable + require);
4354
4355 }
4356
4357 // GPS Destination Distance:
4358
4359 {
4360
4361 uint32 require = (doingUpdateFromXMP &&
4362 originalExif->fGPSDestDistance.IsValid ())
4363 ? requireXMP : 0;
4364
4365 Sync_urational (XMP_NS_EXIF,
4366 "GPSDestDistance",
4367 exif.fGPSDestDistance,
4368 preferXMP + removable + require);
4369
4370 }
4371
4372 // GPS Processing Method:
4373
4374 {
4375
4376 uint32 require = (doingUpdateFromXMP &&
4377 originalExif->fGPSProcessingMethod.NotEmpty ())
4378 ? requireXMP : 0;
4379
4380 SyncString (XMP_NS_EXIF,
4381 "GPSProcessingMethod",
4382 exif.fGPSProcessingMethod,
4383 preferXMP + removable + require);
4384
4385 }
4386
4387 // GPS Area Information:
4388
4389 {
4390
4391 uint32 require = (doingUpdateFromXMP &&
4392 originalExif->fGPSAreaInformation.NotEmpty ())
4393 ? requireXMP : 0;
4394
4395 SyncString (XMP_NS_EXIF,
4396 "GPSAreaInformation",
4397 exif.fGPSAreaInformation,
4398 preferXMP + removable + require);
4399
4400 }
4401
4402 // GPS Differential:
4403
4404 {
4405
4406 uint32 require = (doingUpdateFromXMP &&
4407 originalExif->fGPSDifferential != 0xFFFFFFFF)
4408 ? requireXMP : 0;
4409
4410 Sync_uint32 (XMP_NS_EXIF,
4411 "GPSDifferential",
4412 exif.fGPSDifferential,
4413 exif.fGPSDifferential == 0xFFFFFFFF,
4414 preferXMP + removable + require,
4415 0xFFFFFFFF);
4416
4417 }
4418
4419 // GPS Horizontal Positioning Error:
4420
4421 {
4422
4423 uint32 require = (doingUpdateFromXMP &&
4424 originalExif->fGPSHPositioningError.IsValid ())
4425 ? requireXMP : 0;
4426
4427 Sync_urational (XMP_NS_EXIF,
4428 "GPSHPositioningError",
4429 exif.fGPSHPositioningError,
4430 preferXMP + removable + require);
4431
4432 }
4433
4434 // Sync date/times.
4435
4436 UpdateExifDates (exif, removeFromXMP);
4437
4438 // EXIF 2.3.1 tags.
4439
4440 Sync_srational (XMP_NS_EXIFEX,
4441 "Temperature",
4442 exif.fTemperature,
4443 readOnly + removable);
4444
4445 Sync_urational (XMP_NS_EXIFEX,
4446 "Humidity",
4447 exif.fHumidity,
4448 readOnly + removable);
4449
4450 Sync_urational (XMP_NS_EXIFEX,
4451 "Pressure",
4452 exif.fPressure,
4453 readOnly + removable);
4454
4455 Sync_srational (XMP_NS_EXIFEX,
4456 "WaterDepth",
4457 exif.fWaterDepth,
4458 readOnly + removable);
4459
4460 Sync_urational (XMP_NS_EXIFEX,
4461 "Acceleration",
4462 exif.fAcceleration,
4463 readOnly + removable);
4464
4465 Sync_srational (XMP_NS_EXIFEX,
4466 "CameraElevationAngle",
4467 exif.fCameraElevationAngle,
4468 readOnly + removable);
4469
4470 // Neutral density factor.
4471
4472 Sync_urational (XMP_NS_AUX,
4473 "NeutralDensityFactor",
4474 exif.fNeutralDensityFactor,
4475 readOnly);
4476
4477 // We are syncing EXIF and XMP, but we are not updating the
4478 // NativeDigest tags. It is better to just delete them than leave
4479 // the stale values around.
4480
4481 Remove (XMP_NS_EXIF, "NativeDigest");
4482 Remove (XMP_NS_TIFF, "NativeDigest");
4483
4484 // Fake EXIF fields.
4485
4486 SyncAltLangDefault (XMP_NS_DC,
4487 "title",
4488 exif.fTitle,
4489 preferXMP);
4490
4491 }
4492
4493 /*****************************************************************************/
4494
4495 void dng_xmp::SyncApproximateFocusDistance (dng_exif &exif,
4496 const uint32 readOnly)
4497 {
4498
4499 Sync_urational (XMP_NS_AUX,
4500 "ApproximateFocusDistance",
4501 exif.fApproxFocusDistance,
4502 readOnly);
4503
4504 }
4505
4506 /******************************************************************************/
4507
4508 void dng_xmp::ValidateStringList (const char *ns,
4509 const char *path)
4510 {
4511
4512 fSDK->ValidateStringList (ns, path);
4513
4514 }
4515
4516 /******************************************************************************/
4517
4518 void dng_xmp::ValidateMetadata ()
4519 {
4520
4521 // The following values should be arrays, but are not always. So
4522 // fix them up because Photoshop sometimes has problems parsing invalid
4523 // tags.
4524
4525 ValidateStringList (XMP_NS_DC, "creator");
4526
4527 ValidateStringList (XMP_NS_PHOTOSHOP, "Keywords");
4528 ValidateStringList (XMP_NS_PHOTOSHOP, "SupplementalCategories");
4529
4530 }
4531
4532 /******************************************************************************/
4533
4534 void dng_xmp::SyncExifDate (const char *ns,
4535 const char *path,
4536 dng_date_time_info &exifDateTime,
4537 bool canRemoveFromXMP,
4538 bool removeFromXMP,
4539 const dng_time_zone &fakeTimeZone)
4540 {
4541
4542 dng_string s;
4543
4544 // Find information on XMP side.
4545
4546 dng_date_time_info xmpDateTime;
4547
4548 if (GetString (ns, path, s))
4549 {
4550
4551 if (s.IsEmpty ())
4552 {
4553
4554 // XMP contains an NULL string. Clear EXIF date,
4555 // and remove XMP tag if possible.
4556
4557 exifDateTime.Clear ();
4558
4559 if (canRemoveFromXMP && removeFromXMP)
4560 {
4561 Remove (ns, path);
4562 }
4563
4564 return;
4565
4566 }
4567
4568 xmpDateTime.Decode_ISO_8601 (s.Get ());
4569
4570 // If the time zone matches the fake time zone,
4571 // ignore it on the XMP side.
4572
4573 if (fakeTimeZone.IsValid () &&
4574 xmpDateTime.TimeZone ().IsValid () &&
4575 xmpDateTime.TimeZone ().OffsetMinutes () == fakeTimeZone.OffsetMinutes ())
4576 {
4577
4578 xmpDateTime.ClearZone ();
4579
4580 }
4581
4582 }
4583
4584 // If both are valid, we need to resolve.
4585
4586 if (exifDateTime.IsValid () && xmpDateTime.IsValid ())
4587 {
4588
4589 // Kludge: The Nikon D4 is writing date only date/times into XMP, so
4590 // prefer the EXIF values if the XMP only contains a date.
4591
4592 if (xmpDateTime.IsDateOnly ())
4593 {
4594
4595 xmpDateTime = exifDateTime;
4596
4597 }
4598
4599 // Kludge: Nikon sometimes writes XMP values without a time zone
4600 // but the EXIF contains a valid time zone. So in that case,
4601 // prefer the EXIF. This case also deals with sidecar files
4602 // created by pre-Exif 2.3.1 aware cr_sdk versions.
4603
4604 else if (exifDateTime.DateTime () == xmpDateTime.DateTime () &&
4605 exifDateTime.TimeZone ().IsValid () &&
4606 !xmpDateTime.TimeZone ().IsValid ())
4607 {
4608
4609 xmpDateTime = exifDateTime;
4610
4611 }
4612
4613 // Else assume that XMP is correct.
4614
4615 else
4616 {
4617
4618 exifDateTime = xmpDateTime;
4619
4620 }
4621
4622 }
4623
4624 // Else just pick the valid one.
4625
4626 else if (xmpDateTime.IsValid ())
4627 {
4628
4629 exifDateTime = xmpDateTime;
4630
4631 }
4632
4633 else if (exifDateTime.IsValid ())
4634 {
4635
4636 xmpDateTime = exifDateTime;
4637
4638 }
4639
4640 // Else nothing is valid.
4641
4642 else
4643 {
4644
4645 // Remove XMP side, if any.
4646
4647 Remove (ns, path);
4648
4649 return;
4650
4651 }
4652
4653 // Should we just remove the XMP version?
4654
4655 if (canRemoveFromXMP && removeFromXMP)
4656 {
4657
4658 Remove (ns, path);
4659
4660 }
4661
4662 else
4663 {
4664
4665 s = exifDateTime.Encode_ISO_8601 ();
4666
4667 SetString (ns, path, s);
4668
4669 }
4670
4671 }
4672
4673 /******************************************************************************/
4674
4675 void dng_xmp::UpdateExifDates (dng_exif &exif,
4676 bool removeFromXMP)
4677 {
4678
4679 // Kludge: Early versions of the XMP library did not support date
4680 // encodings without explicit time zones, so software had to fill in
4681 // fake time zones on the XMP side. The usual way was to fill in
4682 // local time zone for the date/time at the import location.
4683 // Attempt to detect these cases and ignore the fake time zones.
4684
4685 dng_time_zone fakeTimeZone; // Initialized to invalid
4686
4687 #if 0
4688
4689 // Disabling this code due to CR-4198757: [Regression] Lightroom has started stripping
4690 // timezone information from the "Date Created" field. Apparently some external tools
4691 // were tagging the sidecar XMP files with time zone information that was at least somewhat
4692 // valid, and the fake time zone detection logic was stripping this information. It is probably
4693 // better to have some fake time zone information floating around from old sidecar files than
4694 // to strip possibly valid information.
4695
4696 if (!exif.AtLeastVersion0231 ()) // Real time zones supported in EXIF 2.3.1
4697 {
4698
4699 // Look at DateTimeOriginal since it an EXIF only field (not aliased
4700 // to other fields in XMP)
4701
4702 dng_string s;
4703
4704 if (GetString (XMP_NS_EXIF, "DateTimeOriginal", s) && s.NotEmpty ())
4705 {
4706
4707 dng_date_time_info xmpDateTimeOriginal;
4708
4709 xmpDateTimeOriginal.Decode_ISO_8601 (s.Get ());
4710
4711 // If this field has a time zone in XMP, it can only
4712 // be fake.
4713
4714 if (xmpDateTimeOriginal.TimeZone ().IsValid ())
4715 {
4716
4717 fakeTimeZone = xmpDateTimeOriginal.TimeZone ();
4718
4719 }
4720
4721 }
4722
4723 }
4724
4725 #endif
4726
4727 // For the following three date/time fields, we generally prefer XMP to
4728 // the EXIF values. This is to allow the user to correct the date/times
4729 // via changes in a sidecar XMP file, without modifying the original
4730 // raw file.
4731
4732 // Modification Date/Time:
4733 // exif.fDateTime
4734 // kXMP_NS_XMP:"ModifyDate" & kXMP_NS_TIFF:"DateTime" are aliased
4735
4736 SyncExifDate (XMP_NS_TIFF,
4737 "DateTime",
4738 exif.fDateTime,
4739 false, // Cannot remove because aliased
4740 removeFromXMP,
4741 fakeTimeZone);
4742
4743 // Original Date/Time:
4744 // exif.fDateTimeOriginal
4745 // IPTC: DateCreated
4746 // XMP_NS_EXIF:"DateTimeOriginal" & XMP_NS_PHOTOSHOP:"DateCreated"
4747 // Adobe has decided to keep the two XMP fields separate.
4748
4749 {
4750
4751 SyncExifDate (XMP_NS_EXIF,
4752 "DateTimeOriginal",
4753 exif.fDateTimeOriginal,
4754 true,
4755 removeFromXMP,
4756 fakeTimeZone);
4757
4758 // Sync the IPTC value to the EXIF value if only the EXIF
4759 // value exists.
4760
4761 if (exif.fDateTimeOriginal.IsValid ())
4762 {
4763
4764 // See if the fake time zone was cloned into DateCreated
4765 // field.
4766
4767 bool forceUpdate = false;
4768
4769 if (fakeTimeZone.IsValid ())
4770 {
4771
4772 dng_string s;
4773
4774 if (GetString (XMP_NS_PHOTOSHOP, "DateCreated", s) && s.NotEmpty ())
4775 {
4776
4777 dng_date_time_info info;
4778
4779 info.Decode_ISO_8601 (s.Get ());
4780
4781 if (info.DateTime () == exif.fDateTimeOriginal.DateTime ())
4782 {
4783
4784 forceUpdate = true;
4785
4786 }
4787
4788 }
4789
4790 }
4791
4792 if (!Exists (XMP_NS_PHOTOSHOP, "DateCreated") || forceUpdate)
4793 {
4794
4795 dng_string s = exif.fDateTimeOriginal.Encode_ISO_8601 ();
4796
4797 SetString (XMP_NS_PHOTOSHOP, "DateCreated", s);
4798
4799 }
4800
4801 }
4802
4803 }
4804
4805 // Date Time Digitized:
4806 // XMP_NS_EXIF:"DateTimeDigitized" & kXMP_NS_XMP:"CreateDate" are aliased
4807
4808 SyncExifDate (XMP_NS_EXIF,
4809 "DateTimeDigitized",
4810 exif.fDateTimeDigitized,
4811 false, // Cannot remove because aliased
4812 removeFromXMP,
4813 fakeTimeZone);
4814
4815 }
4816
4817 /******************************************************************************/
4818
4819 void dng_xmp::UpdateDateTime (const dng_date_time_info &dt)
4820 {
4821
4822 dng_string s = dt.Encode_ISO_8601 ();
4823
4824 SetString (XMP_NS_TIFF,
4825 "DateTime",
4826 s);
4827
4828 }
4829
4830 /******************************************************************************/
4831
4832 void dng_xmp::UpdateMetadataDate (const dng_date_time_info &dt)
4833 {
4834
4835 dng_string s = dt.Encode_ISO_8601 ();
4836
4837 SetString (XMP_NS_XAP,
4838 "MetadataDate",
4839 s);
4840
4841 }
4842
4843 /*****************************************************************************/
4844
4845 bool dng_xmp::HasOrientation () const
4846 {
4847
4848 uint32 x = 0;
4849
4850 if (Get_uint32 (XMP_NS_TIFF,
4851 "Orientation",
4852 x))
4853 {
4854
4855 return (x >= 1) && (x <= 8);
4856
4857 }
4858
4859 return false;
4860
4861 }
4862
4863 /*****************************************************************************/
4864
4865 dng_orientation dng_xmp::GetOrientation () const
4866 {
4867
4868 dng_orientation result;
4869
4870 uint32 x = 0;
4871
4872 if (Get_uint32 (XMP_NS_TIFF,
4873 "Orientation",
4874 x))
4875 {
4876
4877 if ((x >= 1) && (x <= 8))
4878 {
4879
4880 result.SetTIFF (x);
4881
4882 }
4883
4884 }
4885
4886 return result;
4887
4888 }
4889
4890 /******************************************************************************/
4891
4892 void dng_xmp::ClearOrientation ()
4893 {
4894
4895 fSDK->Remove (XMP_NS_TIFF, "Orientation");
4896
4897 }
4898
4899 /******************************************************************************/
4900
4901 void dng_xmp::SetOrientation (const dng_orientation &orientation)
4902 {
4903
4904 Set_uint32 (XMP_NS_TIFF,
4905 "Orientation",
4906 orientation.GetTIFF ());
4907
4908 }
4909
4910 /*****************************************************************************/
4911
4912 void dng_xmp::SyncOrientation (dng_negative &negative,
4913 bool xmpIsMaster)
4914 {
4915
4916 SyncOrientation (negative.Metadata (), xmpIsMaster);
4917
4918 }
4919
4920 /*****************************************************************************/
4921
4922 void dng_xmp::SyncOrientation (dng_metadata &metadata,
4923 bool xmpIsMaster)
4924 {
4925
4926 // See if XMP contains the orientation.
4927
4928 bool xmpHasOrientation = HasOrientation ();
4929
4930 // See if XMP is the master value.
4931
4932 if (xmpHasOrientation && (xmpIsMaster || !metadata.HasBaseOrientation ()))
4933 {
4934
4935 metadata.SetBaseOrientation (GetOrientation ());
4936
4937 }
4938
4939 else
4940 {
4941
4942 SetOrientation (metadata.BaseOrientation ());
4943
4944 }
4945
4946 }
4947
4948 /******************************************************************************/
4949
4950 void dng_xmp::ClearImageInfo ()
4951 {
4952
4953 Remove (XMP_NS_TIFF, "ImageWidth" );
4954 Remove (XMP_NS_TIFF, "ImageLength");
4955
4956 Remove (XMP_NS_EXIF, "PixelXDimension");
4957 Remove (XMP_NS_EXIF, "PixelYDimension");
4958
4959 Remove (XMP_NS_TIFF, "BitsPerSample");
4960
4961 Remove (XMP_NS_TIFF, "Compression");
4962
4963 Remove (XMP_NS_TIFF, "PhotometricInterpretation");
4964
4965 // "Orientation" is handled separately.
4966
4967 Remove (XMP_NS_TIFF, "SamplesPerPixel");
4968
4969 Remove (XMP_NS_TIFF, "PlanarConfiguration");
4970
4971 Remove (XMP_NS_TIFF, "XResolution");
4972 Remove (XMP_NS_TIFF, "YResolution");
4973
4974 Remove (XMP_NS_TIFF, "ResolutionUnit");
4975
4976 Remove (XMP_NS_PHOTOSHOP, "ColorMode" );
4977 Remove (XMP_NS_PHOTOSHOP, "ICCProfile");
4978
4979 }
4980
4981 /******************************************************************************/
4982
4983 void dng_xmp::SetImageSize (const dng_point &size)
4984 {
4985
4986 Set_uint32 (XMP_NS_TIFF, "ImageWidth" , size.h);
4987 Set_uint32 (XMP_NS_TIFF, "ImageLength", size.v);
4988
4989 // Mirror these values to the EXIF tags.
4990
4991 Set_uint32 (XMP_NS_EXIF, "PixelXDimension" , size.h);
4992 Set_uint32 (XMP_NS_EXIF, "PixelYDimension" , size.v);
4993
4994 }
4995
4996 /******************************************************************************/
4997
4998 void dng_xmp::SetSampleInfo (uint32 samplesPerPixel,
4999 uint32 bitsPerSample)
5000 {
5001
5002 Set_uint32 (XMP_NS_TIFF, "SamplesPerPixel", samplesPerPixel);
5003
5004 char s [32];
5005
5006 snprintf (s, 32, "%u", (unsigned) bitsPerSample);
5007
5008 dng_string ss;
5009
5010 ss.Set (s);
5011
5012 dng_string_list list;
5013
5014 for (uint32 j = 0; j < samplesPerPixel; j++)
5015 {
5016 list.Append (ss);
5017 }
5018
5019 SetStringList (XMP_NS_TIFF, "BitsPerSample", list, false);
5020
5021 }
5022
5023 /******************************************************************************/
5024
5025 void dng_xmp::SetPhotometricInterpretation (uint32 pi)
5026 {
5027
5028 Set_uint32 (XMP_NS_TIFF, "PhotometricInterpretation", pi);
5029
5030 }
5031
5032 /******************************************************************************/
5033
5034 void dng_xmp::SetResolution (const dng_resolution &res)
5035 {
5036
5037 Set_urational (XMP_NS_TIFF, "XResolution", res.fXResolution);
5038 Set_urational (XMP_NS_TIFF, "YResolution", res.fYResolution);
5039
5040 Set_uint32 (XMP_NS_TIFF, "ResolutionUnit", res.fResolutionUnit);
5041
5042 }
5043
5044 /*****************************************************************************/
5045
5046 void dng_xmp::ComposeArrayItemPath (const char *ns,
5047 const char *arrayName,
5048 int32 itemNumber,
5049 dng_string &s) const
5050 {
5051
5052 fSDK->ComposeArrayItemPath (ns, arrayName, itemNumber, s);
5053
5054 }
5055
5056 /*****************************************************************************/
5057
5058 void dng_xmp::ComposeStructFieldPath (const char *ns,
5059 const char *structName,
5060 const char *fieldNS,
5061 const char *fieldName,
5062 dng_string &s) const
5063 {
5064
5065 fSDK->ComposeStructFieldPath (ns, structName, fieldNS, fieldName, s);
5066
5067 }
5068
5069 /*****************************************************************************/
5070
5071 int32 dng_xmp::CountArrayItems (const char *ns,
5072 const char *path) const
5073 {
5074
5075 return fSDK->CountArrayItems (ns, path);
5076
5077 }
5078
5079 /*****************************************************************************/
5080
5081 void dng_xmp::AppendArrayItem (const char *ns,
5082 const char *arrayName,
5083 const char *itemValue,
5084 bool isBag,
5085 bool propIsStruct)
5086 {
5087
5088 fSDK->AppendArrayItem (ns,
5089 arrayName,
5090 itemValue,
5091 isBag,
5092 propIsStruct);
5093 }
5094
5095 /*****************************************************************************/
5096
5097 #if qDNGXMPDocOps
5098
5099 /*****************************************************************************/
5100
5101 void dng_xmp::DocOpsOpenXMP (const char *srcMIME)
5102 {
5103
5104 fSDK->DocOpsOpenXMP (srcMIME);
5105
5106 }
5107
5108 /*****************************************************************************/
5109
5110 void dng_xmp::DocOpsPrepareForSave (const char *srcMIME,
5111 const char *dstMIME,
5112 bool newPath)
5113 {
5114
5115 fSDK->DocOpsPrepareForSave (srcMIME,
5116 dstMIME,
5117 newPath);
5118
5119 }
5120
5121 /*****************************************************************************/
5122
5123 void dng_xmp::DocOpsUpdateMetadata (const char *srcMIME)
5124 {
5125
5126 fSDK->DocOpsUpdateMetadata (srcMIME);
5127
5128 }
5129
5130 /*****************************************************************************/
5131
5132 #endif // qDNGXMPDocOps
5133
5134 /*****************************************************************************/
5135
5136 #endif // qDNGUseXMP
5137
5138 /*****************************************************************************/