Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_exif.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_exif.h"
10
11 #include "dng_tag_codes.h"
12 #include "dng_tag_types.h"
13 #include "dng_parse_utils.h"
14 #include "dng_globals.h"
15 #include "dng_exceptions.h"
16 #include "dng_tag_values.h"
17 #include "dng_utils.h"
18
19 /*****************************************************************************/
20
21 dng_exif::dng_exif ()
22
23 : fImageDescription ()
24 , fMake ()
25 , fModel ()
26 , fSoftware ()
27 , fArtist ()
28 , fCopyright ()
29 , fCopyright2 ()
30 , fUserComment ()
31
32 , fDateTime ()
33 , fDateTimeStorageInfo ()
34
35 , fDateTimeOriginal ()
36 , fDateTimeOriginalStorageInfo ()
37
38 , fDateTimeDigitized ()
39 , fDateTimeDigitizedStorageInfo ()
40
41 , fTIFF_EP_StandardID (0)
42 , fExifVersion (0)
43 , fFlashPixVersion (0)
44
45 , fExposureTime ()
46 , fFNumber ()
47 , fShutterSpeedValue ()
48 , fApertureValue ()
49 , fBrightnessValue ()
50 , fExposureBiasValue ()
51 , fMaxApertureValue ()
52 , fFocalLength ()
53 , fDigitalZoomRatio ()
54 , fExposureIndex ()
55 , fSubjectDistance ()
56 , fGamma ()
57
58 , fBatteryLevelR ()
59 , fBatteryLevelA ()
60
61 , fExposureProgram (0xFFFFFFFF)
62 , fMeteringMode (0xFFFFFFFF)
63 , fLightSource (0xFFFFFFFF)
64 , fFlash (0xFFFFFFFF)
65 , fFlashMask (0x0000FFFF)
66 , fSensingMethod (0xFFFFFFFF)
67 , fColorSpace (0xFFFFFFFF)
68 , fFileSource (0xFFFFFFFF)
69 , fSceneType (0xFFFFFFFF)
70 , fCustomRendered (0xFFFFFFFF)
71 , fExposureMode (0xFFFFFFFF)
72 , fWhiteBalance (0xFFFFFFFF)
73 , fSceneCaptureType (0xFFFFFFFF)
74 , fGainControl (0xFFFFFFFF)
75 , fContrast (0xFFFFFFFF)
76 , fSaturation (0xFFFFFFFF)
77 , fSharpness (0xFFFFFFFF)
78 , fSubjectDistanceRange (0xFFFFFFFF)
79 , fSelfTimerMode (0xFFFFFFFF)
80 , fImageNumber (0xFFFFFFFF)
81
82 , fFocalLengthIn35mmFilm (0)
83
84 , fSensitivityType (0)
85 , fStandardOutputSensitivity (0)
86 , fRecommendedExposureIndex (0)
87 , fISOSpeed (0)
88 , fISOSpeedLatitudeyyy (0)
89 , fISOSpeedLatitudezzz (0)
90
91 , fSubjectAreaCount (0)
92
93 , fComponentsConfiguration (0)
94
95 , fCompresssedBitsPerPixel ()
96
97 , fPixelXDimension (0)
98 , fPixelYDimension (0)
99
100 , fFocalPlaneXResolution ()
101 , fFocalPlaneYResolution ()
102
103 , fFocalPlaneResolutionUnit (0xFFFFFFFF)
104
105 , fCFARepeatPatternRows (0)
106 , fCFARepeatPatternCols (0)
107
108 , fImageUniqueID ()
109
110 , fGPSVersionID (0)
111 , fGPSLatitudeRef ()
112 , fGPSLongitudeRef ()
113 , fGPSAltitudeRef (0xFFFFFFFF)
114 , fGPSAltitude ()
115 , fGPSSatellites ()
116 , fGPSStatus ()
117 , fGPSMeasureMode ()
118 , fGPSDOP ()
119 , fGPSSpeedRef ()
120 , fGPSSpeed ()
121 , fGPSTrackRef ()
122 , fGPSTrack ()
123 , fGPSImgDirectionRef ()
124 , fGPSImgDirection ()
125 , fGPSMapDatum ()
126 , fGPSDestLatitudeRef ()
127 , fGPSDestLongitudeRef ()
128 , fGPSDestBearingRef ()
129 , fGPSDestBearing ()
130 , fGPSDestDistanceRef ()
131 , fGPSDestDistance ()
132 , fGPSProcessingMethod ()
133 , fGPSAreaInformation ()
134 , fGPSDateStamp ()
135 , fGPSDifferential (0xFFFFFFFF)
136 , fGPSHPositioningError ()
137
138 , fInteroperabilityIndex ()
139
140 , fInteroperabilityVersion (0)
141
142 , fRelatedImageFileFormat ()
143
144 , fRelatedImageWidth (0)
145 , fRelatedImageLength (0)
146
147 , fCameraSerialNumber ()
148
149 , fLensID ()
150 , fLensMake ()
151 , fLensName ()
152 , fLensSerialNumber ()
153
154 , fLensNameWasReadFromExif (false)
155
156 , fApproxFocusDistance ()
157
158 , fFlashCompensation ()
159
160 , fOwnerName ()
161 , fFirmware ()
162
163 , fTemperature ()
164 , fHumidity ()
165 , fPressure ()
166 , fWaterDepth ()
167 , fAcceleration ()
168 , fCameraElevationAngle ()
169
170 , fTitle ()
171
172 {
173
174 uint32 j;
175 uint32 k;
176
177 fISOSpeedRatings [0] = 0;
178 fISOSpeedRatings [1] = 0;
179 fISOSpeedRatings [2] = 0;
180
181 for (j = 0; j < kMaxCFAPattern; j++)
182 for (k = 0; k < kMaxCFAPattern; k++)
183 {
184 fCFAPattern [j] [k] = 255;
185 }
186
187 memset (fLensDistortInfo, 0, sizeof (fLensDistortInfo));
188
189 }
190
191 /*****************************************************************************/
192
193 dng_exif::~dng_exif ()
194 {
195
196 }
197
198 /*****************************************************************************/
199
200 dng_exif * dng_exif::Clone () const
201 {
202
203 dng_exif *result = new dng_exif (*this);
204
205 if (!result)
206 {
207 ThrowMemoryFull ();
208 }
209
210 return result;
211
212 }
213
214 /*****************************************************************************/
215
216 void dng_exif::SetEmpty ()
217 {
218
219 *this = dng_exif ();
220
221 }
222
223 /*****************************************************************************/
224
225 void dng_exif::CopyDateFrom (const dng_exif &exif)
226 {
227
228 fDateTimeOriginal = exif.fDateTimeOriginal;
229 fDateTimeOriginalStorageInfo = exif.fDateTimeOriginalStorageInfo;
230 fDateTimeDigitized = exif.fDateTimeDigitized;
231 fDateTimeDigitizedStorageInfo = exif.fDateTimeDigitizedStorageInfo;
232 fDateTime = exif.fDateTime;
233 fDateTimeStorageInfo = exif.fDateTimeStorageInfo;
234
235 }
236
237 /*****************************************************************************/
238
239 void dng_exif::CopyGPSFrom (const dng_exif &exif)
240 {
241
242 fGPSVersionID = exif.fGPSVersionID;
243 fGPSLatitudeRef = exif.fGPSLatitudeRef;
244 fGPSLatitude [0] = exif.fGPSLatitude [0];
245 fGPSLatitude [1] = exif.fGPSLatitude [1];
246 fGPSLatitude [2] = exif.fGPSLatitude [2];
247 fGPSLongitudeRef = exif.fGPSLongitudeRef;
248 fGPSLongitude [0] = exif.fGPSLongitude [0];
249 fGPSLongitude [1] = exif.fGPSLongitude [1];
250 fGPSLongitude [2] = exif.fGPSLongitude [2];
251 fGPSAltitudeRef = exif.fGPSAltitudeRef;
252 fGPSAltitude = exif.fGPSAltitude;
253 fGPSTimeStamp [0] = exif.fGPSTimeStamp [0];
254 fGPSTimeStamp [1] = exif.fGPSTimeStamp [1];
255 fGPSTimeStamp [2] = exif.fGPSTimeStamp [2];
256 fGPSSatellites = exif.fGPSSatellites;
257 fGPSStatus = exif.fGPSStatus;
258 fGPSMeasureMode = exif.fGPSMeasureMode;
259 fGPSDOP = exif.fGPSDOP;
260 fGPSSpeedRef = exif.fGPSSpeedRef;
261 fGPSSpeed = exif.fGPSSpeed;
262 fGPSTrackRef = exif.fGPSTrackRef;
263 fGPSTrack = exif.fGPSTrack;
264 fGPSImgDirectionRef = exif.fGPSImgDirectionRef;
265 fGPSImgDirection = exif.fGPSImgDirection;
266 fGPSMapDatum = exif.fGPSMapDatum;
267 fGPSDestLatitudeRef = exif.fGPSDestLatitudeRef;
268 fGPSDestLatitude [0] = exif.fGPSDestLatitude [0];
269 fGPSDestLatitude [1] = exif.fGPSDestLatitude [1];
270 fGPSDestLatitude [2] = exif.fGPSDestLatitude [2];
271 fGPSDestLongitudeRef = exif.fGPSDestLongitudeRef;
272 fGPSDestLongitude [0] = exif.fGPSDestLongitude [0];
273 fGPSDestLongitude [1] = exif.fGPSDestLongitude [1];
274 fGPSDestLongitude [2] = exif.fGPSDestLongitude [2];
275 fGPSDestBearingRef = exif.fGPSDestBearingRef;
276 fGPSDestBearing = exif.fGPSDestBearing;
277 fGPSDestDistanceRef = exif.fGPSDestDistanceRef;
278 fGPSDestDistance = exif.fGPSDestDistance;
279 fGPSProcessingMethod = exif.fGPSProcessingMethod;
280 fGPSAreaInformation = exif.fGPSAreaInformation;
281 fGPSDateStamp = exif.fGPSDateStamp;
282 fGPSDifferential = exif.fGPSDifferential;
283 fGPSHPositioningError = exif.fGPSHPositioningError;
284
285 }
286
287 /*****************************************************************************/
288
289 // Fix up common errors and rounding issues with EXIF exposure times.
290
291 real64 dng_exif::SnapExposureTime (real64 et)
292 {
293
294 // Protection against invalid values.
295
296 if (et <= 0.0)
297 return 0.0;
298
299 // If near a standard shutter speed, snap to it.
300
301 static const real64 kStandardSpeed [] =
302 {
303 30.0,
304 25.0,
305 20.0,
306 15.0,
307 13.0,
308 10.0,
309 8.0,
310 6.0,
311 5.0,
312 4.0,
313 3.2,
314 3.0,
315 2.5,
316 2.0,
317 1.6,
318 1.5,
319 1.3,
320 1.0,
321 0.8,
322 0.7,
323 0.6,
324 0.5,
325 0.4,
326 0.3,
327 1.0 / 4.0,
328 1.0 / 5.0,
329 1.0 / 6.0,
330 1.0 / 8.0,
331 1.0 / 10.0,
332 1.0 / 13.0,
333 1.0 / 15.0,
334 1.0 / 20.0,
335 1.0 / 25.0,
336 1.0 / 30.0,
337 1.0 / 40.0,
338 1.0 / 45.0,
339 1.0 / 50.0,
340 1.0 / 60.0,
341 1.0 / 80.0,
342 1.0 / 90.0,
343 1.0 / 100.0,
344 1.0 / 125.0,
345 1.0 / 160.0,
346 1.0 / 180.0,
347 1.0 / 200.0,
348 1.0 / 250.0,
349 1.0 / 320.0,
350 1.0 / 350.0,
351 1.0 / 400.0,
352 1.0 / 500.0,
353 1.0 / 640.0,
354 1.0 / 750.0,
355 1.0 / 800.0,
356 1.0 / 1000.0,
357 1.0 / 1250.0,
358 1.0 / 1500.0,
359 1.0 / 1600.0,
360 1.0 / 2000.0,
361 1.0 / 2500.0,
362 1.0 / 3000.0,
363 1.0 / 3200.0,
364 1.0 / 4000.0,
365 1.0 / 5000.0,
366 1.0 / 6000.0,
367 1.0 / 6400.0,
368 1.0 / 8000.0,
369 1.0 / 10000.0,
370 1.0 / 12000.0,
371 1.0 / 12800.0,
372 1.0 / 16000.0
373 };
374
375 uint32 count = sizeof (kStandardSpeed ) /
376 sizeof (kStandardSpeed [0]);
377
378 for (uint32 pass = 1; pass <= 2; pass++)
379 {
380
381 for (uint32 fudge = 0; fudge <= 1; fudge++)
382 {
383
384 real64 testSpeed = et;
385
386 if (fudge == 1)
387 {
388
389 // Often APEX values are rounded to a power of two,
390 // which results in non-standard shutter speeds.
391
392 if (et >= 0.1)
393 {
394
395 // No fudging slower than 1/10 second
396
397 break;
398
399 }
400
401 else if (et >= 0.01)
402 {
403
404 // Between 1/10 and 1/100 the commonly misrounded
405 // speeds are 1/15, 1/30, 1/60, which are often encoded as
406 // 1/16, 1/32, 1/64. Try fudging and see if we get
407 // near a standard speed.
408
409 testSpeed *= 16.0 / 15.0;
410
411 }
412
413 else
414 {
415
416 // Faster than 1/100, the commonly misrounded
417 // speeds are 1/125, 1/250, 1/500, etc., which
418 // are often encoded as 1/128, 1/256, 1/512.
419
420 testSpeed *= 128.0 / 125.0;
421
422 }
423
424 }
425
426 for (uint32 index = 0; index < count; index++)
427 {
428
429 if (testSpeed >= kStandardSpeed [index] * 0.98 &&
430 testSpeed <= kStandardSpeed [index] * 1.02)
431 {
432
433 return kStandardSpeed [index];
434
435 }
436
437 }
438
439 }
440
441 // We are not near any standard speeds. Round the non-standard value to something
442 // that looks reasonable.
443
444 if (pass == 1)
445 {
446
447 if (et >= 10.0)
448 {
449
450 // Round to nearest second.
451
452 et = floor (et + 0.5);
453
454 }
455
456 else if (et >= 0.5)
457 {
458
459 // Round to nearest 1/10 second
460
461 et = floor (et * 10.0 + 0.5) * 0.1;
462
463 }
464
465 else if (et >= 1.0 / 20.0)
466 {
467
468 // Round to an exact inverse.
469
470 et = 1.0 / floor (1.0 / et + 0.5);
471
472 }
473
474 else if (et >= 1.0 / 130.0)
475 {
476
477 // Round inverse to multiple of 5
478
479 et = 0.2 / floor (0.2 / et + 0.5);
480
481 }
482
483 else if (et >= 1.0 / 750.0)
484 {
485
486 // Round inverse to multiple of 10
487
488 et = 0.1 / floor (0.1 / et + 0.5);
489
490 }
491
492 else if (et >= 1.0 / 1300.0)
493 {
494
495 // Round inverse to multiple of 50
496
497 et = 0.02 / floor (0.02 / et + 0.5);
498
499 }
500
501 else if (et >= 1.0 / 15000.0)
502 {
503
504 // Round inverse to multiple of 100
505
506 et = 0.01 / floor (0.01 / et + 0.5);
507
508 }
509
510 else
511 {
512
513 // Round inverse to multiple of 1000
514
515 et = 0.001 / floor (0.001 / et + 0.5);
516
517 }
518
519 }
520
521 }
522
523 return et;
524
525 }
526
527 /*****************************************************************************/
528
529 void dng_exif::SetExposureTime (real64 et, bool snap)
530 {
531
532 fExposureTime.Clear ();
533
534 fShutterSpeedValue.Clear ();
535
536 if (snap)
537 {
538
539 et = SnapExposureTime (et);
540
541 }
542
543 if (et >= 1.0 / 1073741824.0 && et <= 1073741824.0)
544 {
545
546 if (et >= 100.0)
547 {
548
549 fExposureTime.Set_real64 (et, 1);
550
551 }
552
553 else if (et >= 1.0)
554 {
555
556 fExposureTime.Set_real64 (et, 10);
557
558 fExposureTime.ReduceByFactor (10);
559
560 }
561
562 else if (et <= 0.1)
563 {
564
565 fExposureTime = dng_urational (1, Round_uint32 (1.0 / et));
566
567 }
568
569 else
570 {
571
572 fExposureTime.Set_real64 (et, 100);
573
574 fExposureTime.ReduceByFactor (10);
575
576 for (uint32 f = 2; f <= 9; f++)
577 {
578
579 real64 z = 1.0 / (real64) f / et;
580
581 if (z >= 0.99 && z <= 1.01)
582 {
583
584 fExposureTime = dng_urational (1, f);
585
586 break;
587
588 }
589
590 }
591
592 }
593
594 // Now mirror this value to the ShutterSpeedValue field.
595
596 et = fExposureTime.As_real64 ();
597
598 fShutterSpeedValue.Set_real64 (-log (et) / log (2.0), 1000000);
599
600 fShutterSpeedValue.ReduceByFactor (10);
601 fShutterSpeedValue.ReduceByFactor (10);
602 fShutterSpeedValue.ReduceByFactor (10);
603 fShutterSpeedValue.ReduceByFactor (10);
604 fShutterSpeedValue.ReduceByFactor (10);
605 fShutterSpeedValue.ReduceByFactor (10);
606
607 }
608
609 }
610
611 /*****************************************************************************/
612
613 void dng_exif::SetShutterSpeedValue (real64 ss)
614 {
615
616 if (fExposureTime.NotValid ())
617 {
618
619 real64 et = pow (2.0, -ss);
620
621 SetExposureTime (et, true);
622
623 }
624
625 }
626
627 /******************************************************************************/
628
629 dng_urational dng_exif::EncodeFNumber (real64 fs)
630 {
631
632 dng_urational y;
633
634 if (fs > 10.0)
635 {
636
637 y.Set_real64 (fs, 1);
638
639 }
640
641 else if (fs < 1.0)
642 {
643
644 y.Set_real64 (fs, 100);
645
646 y.ReduceByFactor (10);
647 y.ReduceByFactor (10);
648
649 }
650
651 else
652 {
653
654 y.Set_real64 (fs, 10);
655
656 y.ReduceByFactor (10);
657
658 }
659
660 return y;
661
662 }
663
664 /*****************************************************************************/
665
666 void dng_exif::SetFNumber (real64 fs)
667 {
668
669 fFNumber.Clear ();
670
671 fApertureValue.Clear ();
672
673 // Allow f-number values less than 1.0 (e.g., f/0.95), even though they would
674 // correspond to negative APEX values, which the EXIF specification does not
675 // support (ApertureValue is a rational, not srational). The ApertureValue tag
676 // will be omitted in the case where fs < 1.0.
677
678 if (fs > 0.0 && fs <= 32768.0)
679 {
680
681 fFNumber = EncodeFNumber (fs);
682
683 // Now mirror this value to the ApertureValue field.
684
685 real64 av = FNumberToApertureValue (fFNumber);
686
687 if (av >= 0.0 && av <= 99.99)
688 {
689
690 fApertureValue.Set_real64 (av, 1000000);
691
692 fApertureValue.ReduceByFactor (10);
693 fApertureValue.ReduceByFactor (10);
694 fApertureValue.ReduceByFactor (10);
695 fApertureValue.ReduceByFactor (10);
696 fApertureValue.ReduceByFactor (10);
697 fApertureValue.ReduceByFactor (10);
698
699 }
700
701 }
702
703 }
704
705 /*****************************************************************************/
706
707 void dng_exif::SetApertureValue (real64 av)
708 {
709
710 if (fFNumber.NotValid ())
711 {
712
713 SetFNumber (ApertureValueToFNumber (av));
714
715 }
716
717 }
718
719 /*****************************************************************************/
720
721 real64 dng_exif::ApertureValueToFNumber (real64 av)
722 {
723
724 return pow (2.0, 0.5 * av);
725
726 }
727
728 /*****************************************************************************/
729
730 real64 dng_exif::ApertureValueToFNumber (const dng_urational &av)
731 {
732
733 return ApertureValueToFNumber (av.As_real64 ());
734
735 }
736
737 /*****************************************************************************/
738
739 real64 dng_exif::FNumberToApertureValue (real64 fNumber)
740 {
741
742 return 2.0 * log (fNumber) / log (2.0);
743
744 }
745
746 /*****************************************************************************/
747
748 real64 dng_exif::FNumberToApertureValue (const dng_urational &fNumber)
749 {
750
751 return FNumberToApertureValue (fNumber.As_real64 ());
752
753 }
754
755 /*****************************************************************************/
756
757 void dng_exif::UpdateDateTime (const dng_date_time_info &dt)
758 {
759
760 fDateTime = dt;
761
762 }
763
764 /*****************************************************************************/
765
766 bool dng_exif::AtLeastVersion0230 () const
767 {
768
769 return fExifVersion >= DNG_CHAR4 ('0','2','3','0');
770
771 }
772
773 /*****************************************************************************/
774
775 bool dng_exif::AtLeastVersion0231 () const
776 {
777
778 return fExifVersion >= DNG_CHAR4 ('0','2','3','1');
779
780 }
781
782 /*****************************************************************************/
783
784 void dng_exif::SetVersion0231 ()
785 {
786
787 fExifVersion = DNG_CHAR4 ('0','2','3','1');
788
789 }
790
791 /*****************************************************************************/
792
793 bool dng_exif::HasLensDistortInfo () const
794 {
795
796 return (fLensDistortInfo [0] . IsValid () &&
797 fLensDistortInfo [1] . IsValid () &&
798 fLensDistortInfo [2] . IsValid () &&
799 fLensDistortInfo [3] . IsValid ());
800
801 }
802
803 /*****************************************************************************/
804
805 void dng_exif::SetLensDistortInfo (const dng_vector &params)
806 {
807
808 if (params.Count () != 4)
809 {
810 return;
811 }
812
813 fLensDistortInfo [0] . Set_real64 (params [0]);
814 fLensDistortInfo [1] . Set_real64 (params [1]);
815 fLensDistortInfo [2] . Set_real64 (params [2]);
816 fLensDistortInfo [3] . Set_real64 (params [3]);
817
818 }
819
820 /*****************************************************************************/
821
822 bool dng_exif::ParseTag (dng_stream &stream,
823 dng_shared &shared,
824 uint32 parentCode,
825 bool isMainIFD,
826 uint32 tagCode,
827 uint32 tagType,
828 uint32 tagCount,
829 uint64 tagOffset)
830 {
831
832 if (parentCode == 0)
833 {
834
835 if (Parse_ifd0 (stream,
836 shared,
837 parentCode,
838 tagCode,
839 tagType,
840 tagCount,
841 tagOffset))
842 {
843
844 return true;
845
846 }
847
848 }
849
850 if (parentCode == 0 || isMainIFD)
851 {
852
853 if (Parse_ifd0_main (stream,
854 shared,
855 parentCode,
856 tagCode,
857 tagType,
858 tagCount,
859 tagOffset))
860 {
861
862 return true;
863
864 }
865
866 }
867
868 if (parentCode == 0 ||
869 parentCode == tcExifIFD)
870 {
871
872 if (Parse_ifd0_exif (stream,
873 shared,
874 parentCode,
875 tagCode,
876 tagType,
877 tagCount,
878 tagOffset))
879 {
880
881 return true;
882
883 }
884
885 }
886
887 if (parentCode == tcGPSInfo)
888 {
889
890 if (Parse_gps (stream,
891 shared,
892 parentCode,
893 tagCode,
894 tagType,
895 tagCount,
896 tagOffset))
897 {
898
899 return true;
900
901 }
902
903 }
904
905 if (parentCode == tcInteroperabilityIFD)
906 {
907
908 if (Parse_interoperability (stream,
909 shared,
910 parentCode,
911 tagCode,
912 tagType,
913 tagCount,
914 tagOffset))
915 {
916
917 return true;
918
919 }
920
921 }
922
923 return false;
924
925 }
926
927 /*****************************************************************************/
928
929 // Parses tags that should only appear in IFD 0.
930
931 bool dng_exif::Parse_ifd0 (dng_stream &stream,
932 dng_shared & /* shared */,
933 uint32 parentCode,
934 uint32 tagCode,
935 uint32 tagType,
936 uint32 tagCount,
937 uint64 /* tagOffset */)
938 {
939
940 switch (tagCode)
941 {
942
943 case tcImageDescription:
944 {
945
946 CheckTagType (parentCode, tagCode, tagType, ttAscii);
947
948 ParseStringTag (stream,
949 parentCode,
950 tagCode,
951 tagCount,
952 fImageDescription);
953
954 #if qDNGValidate
955
956 if (gVerbose)
957 {
958
959 printf ("ImageDescription: ");
960
961 DumpString (fImageDescription);
962
963 printf ("\n");
964
965 }
966
967 #endif
968
969 break;
970
971 }
972
973 case tcMake:
974 {
975
976 CheckTagType (parentCode, tagCode, tagType, ttAscii);
977
978 ParseStringTag (stream,
979 parentCode,
980 tagCode,
981 tagCount,
982 fMake);
983
984 #if qDNGValidate
985
986 if (gVerbose)
987 {
988
989 printf ("Make: ");
990
991 DumpString (fMake);
992
993 printf ("\n");
994
995 }
996
997 #endif
998
999 break;
1000
1001 }
1002
1003 case tcModel:
1004 {
1005
1006 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1007
1008 ParseStringTag (stream,
1009 parentCode,
1010 tagCode,
1011 tagCount,
1012 fModel);
1013
1014 #if qDNGValidate
1015
1016 if (gVerbose)
1017 {
1018
1019 printf ("Model: ");
1020
1021 DumpString (fModel);
1022
1023 printf ("\n");
1024
1025 }
1026
1027 #endif
1028
1029 break;
1030
1031 }
1032
1033 case tcSoftware:
1034 {
1035
1036 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1037
1038 ParseStringTag (stream,
1039 parentCode,
1040 tagCode,
1041 tagCount,
1042 fSoftware);
1043
1044 #if qDNGValidate
1045
1046 if (gVerbose)
1047 {
1048
1049 printf ("Software: ");
1050
1051 DumpString (fSoftware);
1052
1053 printf ("\n");
1054
1055 }
1056
1057 #endif
1058
1059 break;
1060
1061 }
1062
1063 case tcDateTime:
1064 {
1065
1066 uint64 tagPosition = stream.PositionInOriginalFile ();
1067
1068 dng_date_time dt;
1069
1070 if (!ParseDateTimeTag (stream,
1071 parentCode,
1072 tagCode,
1073 tagType,
1074 tagCount,
1075 dt))
1076 {
1077 return false;
1078 }
1079
1080 fDateTime.SetDateTime (dt);
1081
1082 fDateTimeStorageInfo = dng_date_time_storage_info (tagPosition,
1083 dng_date_time_format_exif);
1084
1085 #if qDNGValidate
1086
1087 if (gVerbose)
1088 {
1089
1090 printf ("DateTime: ");
1091
1092 DumpDateTime (fDateTime.DateTime ());
1093
1094 printf ("\n");
1095
1096 }
1097
1098 #endif
1099
1100 break;
1101
1102 }
1103
1104 case tcArtist:
1105 {
1106
1107 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1108
1109 ParseStringTag (stream,
1110 parentCode,
1111 tagCode,
1112 tagCount,
1113 fArtist);
1114
1115 #if qDNGValidate
1116
1117 if (gVerbose)
1118 {
1119
1120 printf ("Artist: ");
1121
1122 DumpString (fArtist);
1123
1124 printf ("\n");
1125
1126 }
1127
1128 #endif
1129
1130 break;
1131
1132 }
1133
1134 case tcCopyright:
1135 {
1136
1137 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1138
1139 ParseDualStringTag (stream,
1140 parentCode,
1141 tagCode,
1142 tagCount,
1143 fCopyright,
1144 fCopyright2);
1145
1146 #if qDNGValidate
1147
1148 if (gVerbose)
1149 {
1150
1151 printf ("Copyright: ");
1152
1153 DumpString (fCopyright);
1154
1155 if (fCopyright2.Get () [0] != 0)
1156 {
1157
1158 printf (" ");
1159
1160 DumpString (fCopyright2);
1161
1162 }
1163
1164 printf ("\n");
1165
1166 }
1167
1168 #endif
1169
1170 break;
1171
1172 }
1173
1174 case tcTIFF_EP_StandardID:
1175 {
1176
1177 CheckTagType (parentCode, tagCode, tagType, ttByte);
1178
1179 CheckTagCount (parentCode, tagCode, tagCount, 4);
1180
1181 uint32 b0 = stream.Get_uint8 ();
1182 uint32 b1 = stream.Get_uint8 ();
1183 uint32 b2 = stream.Get_uint8 ();
1184 uint32 b3 = stream.Get_uint8 ();
1185
1186 fTIFF_EP_StandardID = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
1187
1188 #if qDNGValidate
1189
1190 if (gVerbose)
1191 {
1192 printf ("TIFF/EPStandardID: %u.%u.%u.%u\n",
1193 (unsigned) b0,
1194 (unsigned) b1,
1195 (unsigned) b2,
1196 (unsigned) b3);
1197 }
1198
1199 #endif
1200
1201 break;
1202
1203 }
1204
1205 case tcCameraSerialNumber:
1206 case tcKodakCameraSerialNumber: // Kodak uses a very similar tag.
1207 {
1208
1209 CheckTagType (parentCode, tagCode, tagType, ttAscii);
1210
1211 ParseStringTag (stream,
1212 parentCode,
1213 tagCode,
1214 tagCount,
1215 fCameraSerialNumber);
1216
1217 #if qDNGValidate
1218
1219 if (gVerbose)
1220 {
1221
1222 printf ("%s: ", LookupTagCode (parentCode, tagCode));
1223
1224 DumpString (fCameraSerialNumber);
1225
1226 printf ("\n");
1227
1228 }
1229
1230 #endif
1231
1232 break;
1233
1234 }
1235
1236 case tcLensInfo:
1237 {
1238
1239 CheckTagType (parentCode, tagCode, tagType, ttRational);
1240
1241 if (!CheckTagCount (parentCode, tagCode, tagCount, 4))
1242 return false;
1243
1244 fLensInfo [0] = stream.TagValue_urational (tagType);
1245 fLensInfo [1] = stream.TagValue_urational (tagType);
1246 fLensInfo [2] = stream.TagValue_urational (tagType);
1247 fLensInfo [3] = stream.TagValue_urational (tagType);
1248
1249 // Some third party software wrote zero rather and undefined values
1250 // for unknown entries. Work around this bug.
1251
1252 for (uint32 j = 0; j < 4; j++)
1253 {
1254
1255 if (fLensInfo [j].IsValid () && fLensInfo [j].As_real64 () <= 0.0)
1256 {
1257
1258 fLensInfo [j] = dng_urational (0, 0);
1259
1260 #if qDNGValidate
1261
1262 ReportWarning ("Zero entry in LensInfo tag--should be undefined");
1263
1264 #endif
1265
1266 }
1267
1268 }
1269
1270 #if qDNGValidate
1271
1272 if (gVerbose)
1273 {
1274
1275 printf ("LensInfo: ");
1276
1277 real64 minFL = fLensInfo [0].As_real64 ();
1278 real64 maxFL = fLensInfo [1].As_real64 ();
1279
1280 if (minFL == maxFL)
1281 printf ("%0.1f mm", minFL);
1282 else
1283 printf ("%0.1f-%0.1f mm", minFL, maxFL);
1284
1285 if (fLensInfo [2].d)
1286 {
1287
1288 real64 minFS = fLensInfo [2].As_real64 ();
1289 real64 maxFS = fLensInfo [3].As_real64 ();
1290
1291 if (minFS == maxFS)
1292 printf (" f/%0.1f", minFS);
1293 else
1294 printf (" f/%0.1f-%0.1f", minFS, maxFS);
1295
1296 }
1297
1298 printf ("\n");
1299
1300 }
1301
1302 #endif
1303
1304 break;
1305
1306 }
1307
1308 default:
1309 {
1310
1311 return false;
1312
1313 }
1314
1315 }
1316
1317 return true;
1318
1319 }
1320
1321 /*****************************************************************************/
1322
1323 // Parses tags that should only appear in IFD 0 or the main image IFD.
1324
1325 bool dng_exif::Parse_ifd0_main (dng_stream &stream,
1326 dng_shared & /* shared */,
1327 uint32 parentCode,
1328 uint32 tagCode,
1329 uint32 tagType,
1330 uint32 tagCount,
1331 uint64 /* tagOffset */)
1332 {
1333
1334 switch (tagCode)
1335 {
1336
1337 case tcFocalPlaneXResolution:
1338 {
1339
1340 CheckTagType (parentCode, tagCode, tagType, ttRational);
1341
1342 CheckTagCount (parentCode, tagCode, tagCount, 1);
1343
1344 fFocalPlaneXResolution = stream.TagValue_urational (tagType);
1345
1346 #if qDNGValidate
1347
1348 if (gVerbose)
1349 {
1350
1351 printf ("FocalPlaneXResolution: %0.4f\n",
1352 fFocalPlaneXResolution.As_real64 ());
1353
1354 }
1355
1356 #endif
1357
1358 break;
1359
1360 }
1361
1362 case tcFocalPlaneYResolution:
1363 {
1364
1365 CheckTagType (parentCode, tagCode, tagType, ttRational);
1366
1367 CheckTagCount (parentCode, tagCode, tagCount, 1);
1368
1369 fFocalPlaneYResolution = stream.TagValue_urational (tagType);
1370
1371 #if qDNGValidate
1372
1373 if (gVerbose)
1374 {
1375
1376 printf ("FocalPlaneYResolution: %0.4f\n",
1377 fFocalPlaneYResolution.As_real64 ());
1378
1379 }
1380
1381 #endif
1382
1383 break;
1384
1385 }
1386
1387 case tcFocalPlaneResolutionUnit:
1388 {
1389
1390 CheckTagType (parentCode, tagCode, tagType, ttShort);
1391
1392 CheckTagCount (parentCode, tagCode, tagCount, 1);
1393
1394 fFocalPlaneResolutionUnit = stream.TagValue_uint32 (tagType);
1395
1396 #if qDNGValidate
1397
1398 if (gVerbose)
1399 {
1400
1401 printf ("FocalPlaneResolutionUnit: %s\n",
1402 LookupResolutionUnit (fFocalPlaneResolutionUnit));
1403
1404 }
1405
1406 #endif
1407
1408 break;
1409
1410 }
1411
1412 case tcSensingMethod:
1413 {
1414
1415 CheckTagType (parentCode, tagCode, tagType, ttShort);
1416
1417 CheckTagCount (parentCode, tagCode, tagCount, 1);
1418
1419 fSensingMethod = stream.TagValue_uint32 (tagType);
1420
1421 #if qDNGValidate
1422
1423 if (gVerbose)
1424 {
1425
1426 printf ("SensingMethod: %s\n",
1427 LookupSensingMethod (fSensingMethod));
1428
1429 }
1430
1431 #endif
1432
1433 break;
1434
1435 }
1436
1437 default:
1438 {
1439
1440 return false;
1441
1442 }
1443
1444 }
1445
1446 return true;
1447
1448 }
1449
1450 /*****************************************************************************/
1451
1452 // Parses tags that should only appear in IFD 0 or EXIF IFD.
1453
1454 bool dng_exif::Parse_ifd0_exif (dng_stream &stream,
1455 dng_shared & /* shared */,
1456 uint32 parentCode,
1457 uint32 tagCode,
1458 uint32 tagType,
1459 uint32 tagCount,
1460 uint64 /* tagOffset */)
1461 {
1462
1463 switch (tagCode)
1464 {
1465
1466 case tcBatteryLevel:
1467 {
1468
1469 CheckTagType (parentCode, tagCode, tagType, ttRational, ttAscii);
1470
1471 if (tagType == ttAscii)
1472 {
1473
1474 ParseStringTag (stream,
1475 parentCode,
1476 tagCode,
1477 tagCount,
1478 fBatteryLevelA);
1479
1480 }
1481
1482 else
1483 {
1484
1485 CheckTagCount (parentCode, tagCode, tagCount, 1);
1486
1487 fBatteryLevelR = stream.TagValue_urational (tagType);
1488
1489 }
1490
1491 #if qDNGValidate
1492
1493 if (gVerbose)
1494 {
1495
1496 printf ("BatteryLevel: ");
1497
1498 if (tagType == ttAscii)
1499 {
1500
1501 DumpString (fBatteryLevelA);
1502
1503 }
1504
1505 else
1506 {
1507
1508 printf ("%0.2f", fBatteryLevelR.As_real64 ());
1509
1510 }
1511
1512 printf ("\n");
1513
1514 }
1515
1516 #endif
1517
1518 break;
1519
1520 }
1521
1522 case tcExposureTime:
1523 {
1524
1525 CheckTagType (parentCode, tagCode, tagType, ttRational);
1526
1527 CheckTagCount (parentCode, tagCode, tagCount, 1);
1528
1529 dng_urational et = stream.TagValue_urational (tagType);
1530
1531 SetExposureTime (et.As_real64 (), true);
1532
1533 #if qDNGValidate
1534
1535 if (gVerbose)
1536 {
1537
1538 printf ("ExposureTime: ");
1539
1540 DumpExposureTime (et.As_real64 ());
1541
1542 printf ("\n");
1543
1544 }
1545
1546 if (et.As_real64 () <= 0.0)
1547 {
1548
1549 ReportWarning ("The ExposureTime is <= 0");
1550
1551 }
1552
1553 #endif
1554
1555 break;
1556
1557 }
1558
1559 case tcFNumber:
1560 {
1561
1562 CheckTagType (parentCode, tagCode, tagType, ttRational);
1563
1564 CheckTagCount (parentCode, tagCode, tagCount, 1);
1565
1566 dng_urational fs = stream.TagValue_urational (tagType);
1567
1568 // Sometimes "unknown" is recorded as zero.
1569
1570 if (fs.As_real64 () <= 0.0)
1571 {
1572 fs.Clear ();
1573 }
1574
1575 #if qDNGValidate
1576
1577 if (gVerbose)
1578 {
1579
1580 printf ("FNumber: f/%0.2f\n",
1581 fs.As_real64 ());
1582
1583 }
1584
1585 #endif
1586
1587 SetFNumber (fs.As_real64 ());
1588
1589 break;
1590
1591 }
1592
1593 case tcExposureProgram:
1594 {
1595
1596 CheckTagType (parentCode, tagCode, tagType, ttShort);
1597
1598 CheckTagCount (parentCode, tagCode, tagCount, 1);
1599
1600 fExposureProgram = stream.TagValue_uint32 (tagType);
1601
1602 #if qDNGValidate
1603
1604 if (gVerbose)
1605 {
1606
1607 printf ("ExposureProgram: %s\n",
1608 LookupExposureProgram (fExposureProgram));
1609
1610 }
1611
1612 #endif
1613
1614 break;
1615
1616 }
1617
1618 case tcISOSpeedRatings:
1619 {
1620
1621 CheckTagType (parentCode, tagCode, tagType, ttShort);
1622
1623 CheckTagCount (parentCode, tagCode, tagCount, 1, 3);
1624
1625 for (uint32 j = 0; j < tagCount && j < 3; j++)
1626 {
1627
1628 fISOSpeedRatings [j] = stream.TagValue_uint32 (tagType);
1629
1630 }
1631
1632 #if qDNGValidate
1633
1634 if (gVerbose)
1635 {
1636
1637 printf ("ISOSpeedRatings:");
1638
1639 for (uint32 j = 0; j < tagCount && j < 3; j++)
1640 {
1641
1642 printf (" %u", (unsigned) fISOSpeedRatings [j]);
1643
1644 }
1645
1646 printf ("\n");
1647
1648 }
1649
1650 #endif
1651
1652 break;
1653
1654 }
1655
1656 case tcSensitivityType:
1657 {
1658
1659 CheckTagType (parentCode, tagCode, tagType, ttShort);
1660
1661 CheckTagCount (parentCode, tagCode, tagCount, 1);
1662
1663 fSensitivityType = (uint32) stream.Get_uint16 ();
1664
1665 #if qDNGValidate
1666
1667 if (gVerbose)
1668 {
1669
1670 printf ("SensitivityType: %s\n",
1671 LookupSensitivityType (fSensitivityType));
1672
1673 }
1674
1675 #endif
1676
1677 break;
1678
1679 }
1680
1681 case tcStandardOutputSensitivity:
1682 {
1683
1684 CheckTagType (parentCode, tagCode, tagType, ttLong);
1685
1686 CheckTagCount (parentCode, tagCode, tagCount, 1);
1687
1688 fStandardOutputSensitivity = stream.TagValue_uint32 (tagType);
1689
1690 #if qDNGValidate
1691
1692 if (gVerbose)
1693 {
1694
1695 printf ("StandardOutputSensitivity: %u\n",
1696 (unsigned) fStandardOutputSensitivity);
1697
1698 }
1699
1700 #endif
1701
1702 break;
1703
1704 }
1705
1706 case tcRecommendedExposureIndex:
1707 {
1708
1709 CheckTagType (parentCode, tagCode, tagType, ttLong);
1710
1711 CheckTagCount (parentCode, tagCode, tagCount, 1);
1712
1713 fRecommendedExposureIndex = stream.TagValue_uint32 (tagType);
1714
1715 #if qDNGValidate
1716
1717 if (gVerbose)
1718 {
1719
1720 printf ("RecommendedExposureIndex: %u\n",
1721 (unsigned) fRecommendedExposureIndex);
1722
1723 }
1724
1725 #endif
1726
1727 break;
1728
1729 }
1730
1731 case tcISOSpeed:
1732 {
1733
1734 CheckTagType (parentCode, tagCode, tagType, ttLong);
1735
1736 CheckTagCount (parentCode, tagCode, tagCount, 1);
1737
1738 fISOSpeed = stream.TagValue_uint32 (tagType);
1739
1740 #if qDNGValidate
1741
1742 if (gVerbose)
1743 {
1744
1745 printf ("ISOSpeed: %u\n",
1746 (unsigned) fISOSpeed);
1747
1748 }
1749
1750 #endif
1751
1752 break;
1753
1754 }
1755
1756 case tcISOSpeedLatitudeyyy:
1757 {
1758
1759 CheckTagType (parentCode, tagCode, tagType, ttLong);
1760
1761 CheckTagCount (parentCode, tagCode, tagCount, 1);
1762
1763 fISOSpeedLatitudeyyy = stream.TagValue_uint32 (tagType);
1764
1765 #if qDNGValidate
1766
1767 if (gVerbose)
1768 {
1769
1770 printf ("ISOSpeedLatitudeyyy: %u\n",
1771 (unsigned) fISOSpeedLatitudeyyy);
1772
1773 }
1774
1775 #endif
1776
1777 break;
1778
1779 }
1780
1781 case tcISOSpeedLatitudezzz:
1782 {
1783
1784 CheckTagType (parentCode, tagCode, tagType, ttLong);
1785
1786 CheckTagCount (parentCode, tagCode, tagCount, 1);
1787
1788 fISOSpeedLatitudezzz = stream.TagValue_uint32 (tagType);
1789
1790 #if qDNGValidate
1791
1792 if (gVerbose)
1793 {
1794
1795 printf ("ISOSpeedLatitudezzz: %u\n",
1796 (unsigned) fISOSpeedLatitudezzz);
1797
1798 }
1799
1800 #endif
1801
1802 break;
1803
1804 }
1805
1806 case tcTimeZoneOffset:
1807 {
1808
1809 CheckTagType (parentCode, tagCode, tagType, ttSShort);
1810
1811 CheckTagCount (parentCode, tagCode, tagCount, 1, 2);
1812
1813 dng_time_zone zoneOriginal;
1814
1815 zoneOriginal.SetOffsetHours (stream.TagValue_int32 (tagType));
1816
1817 fDateTimeOriginal.SetZone (zoneOriginal);
1818
1819 #if 0 // MWG: Not filling in time zones unless we are sure.
1820
1821 // Note that there is no "TimeZoneOffsetDigitized" field, so
1822 // we assume the same tone zone as the original.
1823
1824 fDateTimeDigitized.SetZone (zoneOriginal);
1825
1826 #endif
1827
1828 dng_time_zone zoneCurrent;
1829
1830 if (tagCount >= 2)
1831 {
1832
1833 zoneCurrent.SetOffsetHours (stream.TagValue_int32 (tagType));
1834
1835 fDateTime.SetZone (zoneCurrent);
1836
1837 }
1838
1839 #if qDNGValidate
1840
1841 if (gVerbose)
1842 {
1843
1844 printf ("TimeZoneOffset: DateTimeOriginal = %d",
1845 (int) zoneOriginal.ExactHourOffset ());
1846
1847 if (tagCount >= 2)
1848 {
1849
1850 printf (", DateTime = %d",
1851 (int) zoneCurrent.ExactHourOffset ());
1852
1853 }
1854
1855 printf ("\n");
1856
1857 }
1858
1859 #endif
1860
1861 break;
1862
1863 }
1864
1865 case tcSelfTimerMode:
1866 {
1867
1868 CheckTagType (parentCode, tagCode, tagType, ttShort);
1869
1870 CheckTagCount (parentCode, tagCode, tagCount, 1);
1871
1872 fSelfTimerMode = stream.TagValue_uint32 (tagType);
1873
1874 #if qDNGValidate
1875
1876 if (gVerbose)
1877 {
1878
1879 printf ("SelfTimerMode: ");
1880
1881 if (fSelfTimerMode)
1882 {
1883
1884 printf ("%u sec", (unsigned) fSelfTimerMode);
1885
1886 }
1887
1888 else
1889 {
1890
1891 printf ("Off");
1892
1893 }
1894
1895 printf ("\n");
1896
1897 }
1898
1899 #endif
1900
1901 break;
1902
1903 }
1904
1905 case tcExifVersion:
1906 {
1907
1908 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
1909
1910 CheckTagCount (parentCode, tagCode, tagCount, 4);
1911
1912 uint32 b0 = stream.Get_uint8 ();
1913 uint32 b1 = stream.Get_uint8 ();
1914 uint32 b2 = stream.Get_uint8 ();
1915 uint32 b3 = stream.Get_uint8 ();
1916
1917 fExifVersion = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
1918
1919 #if qDNGValidate
1920
1921 if (gVerbose)
1922 {
1923
1924 real64 x = (b0 - '0') * 10.00 +
1925 (b1 - '0') * 1.00 +
1926 (b2 - '0') * 0.10 +
1927 (b3 - '0') * 0.01;
1928
1929 printf ("ExifVersion: %0.2f\n", x);
1930
1931 }
1932
1933 #endif
1934
1935 break;
1936
1937 }
1938
1939 case tcDateTimeOriginal:
1940 {
1941
1942 uint64 tagPosition = stream.PositionInOriginalFile ();
1943
1944 dng_date_time dt;
1945
1946 if (!ParseDateTimeTag (stream,
1947 parentCode,
1948 tagCode,
1949 tagType,
1950 tagCount,
1951 dt))
1952 {
1953 return false;
1954 }
1955
1956 fDateTimeOriginal.SetDateTime (dt);
1957
1958 fDateTimeOriginalStorageInfo = dng_date_time_storage_info (tagPosition,
1959 dng_date_time_format_exif);
1960
1961 #if qDNGValidate
1962
1963 if (gVerbose)
1964 {
1965
1966 printf ("DateTimeOriginal: ");
1967
1968 DumpDateTime (fDateTimeOriginal.DateTime ());
1969
1970 printf ("\n");
1971
1972 }
1973
1974 #endif
1975
1976 break;
1977
1978 }
1979
1980 case tcDateTimeDigitized:
1981 {
1982
1983 uint64 tagPosition = stream.PositionInOriginalFile ();
1984
1985 dng_date_time dt;
1986
1987 if (!ParseDateTimeTag (stream,
1988 parentCode,
1989 tagCode,
1990 tagType,
1991 tagCount,
1992 dt))
1993 {
1994 return false;
1995 }
1996
1997 fDateTimeDigitized.SetDateTime (dt);
1998
1999 fDateTimeDigitizedStorageInfo = dng_date_time_storage_info (tagPosition,
2000 dng_date_time_format_exif);
2001
2002 #if qDNGValidate
2003
2004 if (gVerbose)
2005 {
2006
2007 printf ("DateTimeDigitized: ");
2008
2009 DumpDateTime (fDateTimeDigitized.DateTime ());
2010
2011 printf ("\n");
2012
2013 }
2014
2015 #endif
2016
2017 break;
2018
2019 }
2020
2021 case tcOffsetTime:
2022 {
2023
2024 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2025
2026 dng_string offsetTime;
2027
2028 ParseStringTag (stream,
2029 parentCode,
2030 tagCode,
2031 tagCount,
2032 offsetTime);
2033
2034 fDateTime.SetOffsetTime (offsetTime);
2035
2036 // The offset time tags were added to EXIF spec 2.3.1.
2037 // We need EXIF spec version to figure out legacy fake time
2038 // zones in XMP, so force a correct exif spec version if
2039 // these EXIF tags are used.
2040
2041 if (!AtLeastVersion0231 ())
2042 {
2043 SetVersion0231 ();
2044 }
2045
2046 #if qDNGValidate
2047
2048 if (gVerbose)
2049 {
2050
2051 printf ("OffsetTime: ");
2052
2053 DumpString (offsetTime);
2054
2055 printf ("\n");
2056
2057 }
2058
2059 #endif
2060
2061 break;
2062
2063 }
2064
2065 case tcOffsetTimeOriginal:
2066 {
2067
2068 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2069
2070 dng_string offsetTime;
2071
2072 ParseStringTag (stream,
2073 parentCode,
2074 tagCode,
2075 tagCount,
2076 offsetTime);
2077
2078 fDateTimeOriginal.SetOffsetTime (offsetTime);
2079
2080 // The offset time tags were added to EXIF spec 2.3.1.
2081 // We need EXIF spec version to figure out legacy fake time
2082 // zones in XMP, so force a correct exif spec version if
2083 // these EXIF tags are used.
2084
2085 if (!AtLeastVersion0231 ())
2086 {
2087 SetVersion0231 ();
2088 }
2089
2090 #if qDNGValidate
2091
2092 if (gVerbose)
2093 {
2094
2095 printf ("OffsetTimeOriginal: ");
2096
2097 DumpString (offsetTime);
2098
2099 printf ("\n");
2100
2101 }
2102
2103 #endif
2104
2105 break;
2106
2107 }
2108
2109 case tcOffsetTimeDigitized:
2110 {
2111
2112 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2113
2114 dng_string offsetTime;
2115
2116 ParseStringTag (stream,
2117 parentCode,
2118 tagCode,
2119 tagCount,
2120 offsetTime);
2121
2122 fDateTimeDigitized.SetOffsetTime (offsetTime);
2123
2124 // The offset time tags were added to EXIF spec 2.3.1.
2125 // We need EXIF spec version to figure out legacy fake time
2126 // zones in XMP, so force a correct exif spec version if
2127 // these EXIF tags are used.
2128
2129 if (!AtLeastVersion0231 ())
2130 {
2131 SetVersion0231 ();
2132 }
2133
2134 #if qDNGValidate
2135
2136 if (gVerbose)
2137 {
2138
2139 printf ("OffsetTimeDigitized: ");
2140
2141 DumpString (offsetTime);
2142
2143 printf ("\n");
2144
2145 }
2146
2147 #endif
2148
2149 break;
2150
2151 }
2152
2153 case tcComponentsConfiguration:
2154 {
2155
2156 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2157
2158 CheckTagCount (parentCode, tagCode, tagCount, 4);
2159
2160 uint32 b0 = stream.Get_uint8 ();
2161 uint32 b1 = stream.Get_uint8 ();
2162 uint32 b2 = stream.Get_uint8 ();
2163 uint32 b3 = stream.Get_uint8 ();
2164
2165 fComponentsConfiguration = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
2166
2167 #if qDNGValidate
2168
2169 if (gVerbose)
2170 {
2171
2172 printf ("ComponentsConfiguration: %s %s %s %s\n",
2173 LookupComponent (b0),
2174 LookupComponent (b1),
2175 LookupComponent (b2),
2176 LookupComponent (b3));
2177
2178 }
2179
2180 #endif
2181
2182 break;
2183
2184 }
2185
2186 case tcCompressedBitsPerPixel:
2187 {
2188
2189 CheckTagType (parentCode, tagCode, tagType, ttRational);
2190
2191 CheckTagCount (parentCode, tagCode, tagCount, 1);
2192
2193 fCompresssedBitsPerPixel = stream.TagValue_urational (tagType);
2194
2195 #if qDNGValidate
2196
2197 if (gVerbose)
2198 {
2199
2200 printf ("CompressedBitsPerPixel: %0.2f\n",
2201 fCompresssedBitsPerPixel.As_real64 ());
2202
2203 }
2204
2205 #endif
2206
2207 break;
2208
2209 }
2210
2211 case tcShutterSpeedValue:
2212 {
2213
2214 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2215
2216 CheckTagCount (parentCode, tagCode, tagCount, 1);
2217
2218 dng_srational ss = stream.TagValue_srational (tagType);
2219
2220 #if qDNGValidate
2221
2222 if (gVerbose)
2223 {
2224
2225 printf ("ShutterSpeedValue: ");
2226
2227 real64 x = pow (2.0, -ss.As_real64 ());
2228
2229 DumpExposureTime (x);
2230
2231 printf ("\n");
2232
2233 }
2234
2235 // The ExposureTime and ShutterSpeedValue tags should be consistent.
2236
2237 if (fExposureTime.IsValid ())
2238 {
2239
2240 real64 et = fExposureTime.As_real64 ();
2241
2242 real64 tv1 = -1.0 * log (et) / log (2.0);
2243
2244 real64 tv2 = ss.As_real64 ();
2245
2246 // Make sure they are within 0.25 APEX values.
2247
2248 if (Abs_real64 (tv1 - tv2) > 0.25)
2249 {
2250
2251 ReportWarning ("The ExposureTime and ShutterSpeedValue tags have conflicting values");
2252
2253 }
2254
2255 }
2256
2257 #endif
2258
2259 SetShutterSpeedValue (ss.As_real64 ());
2260
2261 break;
2262
2263 }
2264
2265 case tcApertureValue:
2266 {
2267
2268 CheckTagType (parentCode, tagCode, tagType, ttRational);
2269
2270 CheckTagCount (parentCode, tagCode, tagCount, 1);
2271
2272 dng_urational av = stream.TagValue_urational (tagType);
2273
2274 #if qDNGValidate
2275
2276 if (gVerbose)
2277 {
2278
2279 real64 x = pow (2.0, 0.5 * av.As_real64 ());
2280
2281 printf ("ApertureValue: f/%0.2f\n", x);
2282
2283 }
2284
2285 // The FNumber and ApertureValue tags should be consistent.
2286
2287 if (fFNumber.IsValid () && av.IsValid ())
2288 {
2289
2290 real64 fs = fFNumber.As_real64 ();
2291
2292 real64 av1 = FNumberToApertureValue (fs);
2293
2294 real64 av2 = av.As_real64 ();
2295
2296 if (Abs_real64 (av1 - av2) > 0.25)
2297 {
2298
2299 ReportWarning ("The FNumber and ApertureValue tags have conflicting values");
2300
2301 }
2302
2303 }
2304
2305 #endif
2306
2307 SetApertureValue (av.As_real64 ());
2308
2309 break;
2310
2311 }
2312
2313 case tcBrightnessValue:
2314 {
2315
2316 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2317
2318 CheckTagCount (parentCode, tagCode, tagCount, 1);
2319
2320 fBrightnessValue = stream.TagValue_srational (tagType);
2321
2322 #if qDNGValidate
2323
2324 if (gVerbose)
2325 {
2326
2327 printf ("BrightnessValue: %0.2f\n",
2328 fBrightnessValue.As_real64 ());
2329
2330 }
2331
2332 #endif
2333
2334 break;
2335
2336 }
2337
2338 case tcExposureBiasValue:
2339 {
2340
2341 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2342
2343 CheckTagCount (parentCode, tagCode, tagCount, 1);
2344
2345 fExposureBiasValue = stream.TagValue_srational (tagType);
2346
2347 #if qDNGValidate
2348
2349 if (gVerbose)
2350 {
2351
2352 printf ("ExposureBiasValue: %0.2f\n",
2353 fExposureBiasValue.As_real64 ());
2354
2355 }
2356
2357 #endif
2358
2359 break;
2360
2361 }
2362
2363 case tcMaxApertureValue:
2364 {
2365
2366 CheckTagType (parentCode, tagCode, tagType, ttRational);
2367
2368 CheckTagCount (parentCode, tagCode, tagCount, 1);
2369
2370 fMaxApertureValue = stream.TagValue_urational (tagType);
2371
2372 #if qDNGValidate
2373
2374 if (gVerbose)
2375 {
2376
2377 real64 x = pow (2.0, 0.5 * fMaxApertureValue.As_real64 ());
2378
2379 printf ("MaxApertureValue: f/%0.1f\n", x);
2380
2381 }
2382
2383 #endif
2384
2385 break;
2386
2387 }
2388
2389 case tcSubjectDistance:
2390 {
2391
2392 CheckTagType (parentCode, tagCode, tagType, ttRational);
2393
2394 CheckTagCount (parentCode, tagCode, tagCount, 1);
2395
2396 fSubjectDistance = stream.TagValue_urational (tagType);
2397
2398 fApproxFocusDistance = fSubjectDistance;
2399
2400 #if qDNGValidate
2401
2402 if (gVerbose)
2403 {
2404
2405 printf ("SubjectDistance: %u/%u\n",
2406 (unsigned) fSubjectDistance.n,
2407 (unsigned) fSubjectDistance.d);
2408
2409 }
2410
2411 #endif
2412
2413 break;
2414
2415 }
2416
2417 case tcMeteringMode:
2418 {
2419
2420 CheckTagType (parentCode, tagCode, tagType, ttShort);
2421
2422 CheckTagCount (parentCode, tagCode, tagCount, 1);
2423
2424 fMeteringMode = stream.TagValue_uint32 (tagType);
2425
2426 #if qDNGValidate
2427
2428 if (gVerbose)
2429 {
2430
2431 printf ("MeteringMode: %s\n",
2432 LookupMeteringMode (fMeteringMode));
2433
2434 }
2435
2436 #endif
2437
2438 break;
2439
2440 }
2441
2442 case tcLightSource:
2443 {
2444
2445 CheckTagType (parentCode, tagCode, tagType, ttShort);
2446
2447 CheckTagCount (parentCode, tagCode, tagCount, 1);
2448
2449 fLightSource = stream.TagValue_uint32 (tagType);
2450
2451 #if qDNGValidate
2452
2453 if (gVerbose)
2454 {
2455
2456 printf ("LightSource: %s\n",
2457 LookupLightSource (fLightSource));
2458
2459 }
2460
2461 #endif
2462
2463 break;
2464
2465 }
2466
2467 case tcFlash:
2468 {
2469
2470 CheckTagType (parentCode, tagCode, tagType, ttShort);
2471
2472 CheckTagCount (parentCode, tagCode, tagCount, 1);
2473
2474 fFlash = stream.TagValue_uint32 (tagType);
2475
2476 #if qDNGValidate
2477
2478 if (gVerbose)
2479 {
2480
2481 printf ("Flash: %u\n", (unsigned) fFlash);
2482
2483 if ((fFlash >> 5) & 1)
2484 {
2485 printf ("\tNo flash function\n");
2486 }
2487
2488 else
2489 {
2490
2491 if (fFlash & 0x1)
2492 {
2493
2494 printf ("\tFlash fired\n");
2495
2496 switch ((fFlash >> 1) & 0x3)
2497 {
2498
2499 case 2:
2500 printf ("\tStrobe return light not detected\n");
2501 break;
2502
2503 case 3:
2504 printf ("\tStrobe return light detected\n");
2505 break;
2506
2507 }
2508
2509 }
2510
2511 else
2512 {
2513 printf ("\tFlash did not fire\n");
2514 }
2515
2516 switch ((fFlash >> 3) & 0x3)
2517 {
2518
2519 case 1:
2520 printf ("\tCompulsory flash firing\n");
2521 break;
2522
2523 case 2:
2524 printf ("\tCompulsory flash suppression\n");
2525 break;
2526
2527 case 3:
2528 printf ("\tAuto mode\n");
2529 break;
2530
2531 }
2532
2533 if ((fFlash >> 6) & 1)
2534 {
2535 printf ("\tRed-eye reduction supported\n");
2536 }
2537
2538 }
2539
2540 }
2541
2542 #endif
2543
2544 break;
2545
2546 }
2547
2548 case tcFocalLength:
2549 {
2550
2551 CheckTagType (parentCode, tagCode, tagType, ttRational);
2552
2553 CheckTagCount (parentCode, tagCode, tagCount, 1);
2554
2555 fFocalLength = stream.TagValue_urational (tagType);
2556
2557 // Sometimes "unknown" is recorded as zero.
2558
2559 if (fFocalLength.As_real64 () <= 0.0)
2560 {
2561 fFocalLength.Clear ();
2562 }
2563
2564 #if qDNGValidate
2565
2566 if (gVerbose)
2567 {
2568
2569 printf ("FocalLength: %0.1f mm\n",
2570 fFocalLength.As_real64 ());
2571
2572 }
2573
2574 #endif
2575
2576 break;
2577
2578 }
2579
2580 case tcImageNumber:
2581 {
2582
2583 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
2584
2585 CheckTagCount (parentCode, tagCode, tagCount, 1);
2586
2587 fImageNumber = stream.TagValue_uint32 (tagType);
2588
2589 #if qDNGValidate
2590
2591 if (gVerbose)
2592 {
2593 printf ("ImageNumber: %u\n", (unsigned) fImageNumber);
2594 }
2595
2596 #endif
2597
2598 break;
2599
2600 }
2601
2602 case tcExposureIndex:
2603 case tcExposureIndexExif:
2604 {
2605
2606 CheckTagType (parentCode, tagCode, tagType, ttRational);
2607
2608 CheckTagCount (parentCode, tagCode, tagCount, 1);
2609
2610 fExposureIndex = stream.TagValue_urational (tagType);
2611
2612 #if qDNGValidate
2613
2614 if (gVerbose)
2615 {
2616
2617 printf ("%s: ISO %0.1f\n",
2618 LookupTagCode (parentCode, tagCode),
2619 fExposureIndex.As_real64 ());
2620
2621 }
2622
2623 #endif
2624
2625 break;
2626
2627 }
2628
2629 case tcUserComment:
2630 {
2631
2632 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2633
2634 ParseEncodedStringTag (stream,
2635 parentCode,
2636 tagCode,
2637 tagCount,
2638 fUserComment);
2639
2640 #if qDNGValidate
2641
2642 if (gVerbose)
2643 {
2644
2645 printf ("UserComment: ");
2646
2647 DumpString (fUserComment);
2648
2649 printf ("\n");
2650
2651 }
2652
2653 #endif
2654
2655 break;
2656
2657 }
2658
2659 case tcSubsecTime:
2660 {
2661
2662 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2663
2664 dng_string subsecs;
2665
2666 ParseStringTag (stream,
2667 parentCode,
2668 tagCode,
2669 tagCount,
2670 subsecs);
2671
2672 fDateTime.SetSubseconds (subsecs);
2673
2674 #if qDNGValidate
2675
2676 if (gVerbose)
2677 {
2678
2679 printf ("SubsecTime: ");
2680
2681 DumpString (subsecs);
2682
2683 printf ("\n");
2684
2685 }
2686
2687 #endif
2688
2689 break;
2690
2691 }
2692
2693 case tcSubsecTimeOriginal:
2694 {
2695
2696 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2697
2698 dng_string subsecs;
2699
2700 ParseStringTag (stream,
2701 parentCode,
2702 tagCode,
2703 tagCount,
2704 subsecs);
2705
2706 fDateTimeOriginal.SetSubseconds (subsecs);
2707
2708 #if qDNGValidate
2709
2710 if (gVerbose)
2711 {
2712
2713 printf ("SubsecTimeOriginal: ");
2714
2715 DumpString (subsecs);
2716
2717 printf ("\n");
2718
2719 }
2720
2721 #endif
2722
2723 break;
2724
2725 }
2726
2727 case tcSubsecTimeDigitized:
2728 {
2729
2730 CheckTagType (parentCode, tagCode, tagType, ttAscii);
2731
2732 dng_string subsecs;
2733
2734 ParseStringTag (stream,
2735 parentCode,
2736 tagCode,
2737 tagCount,
2738 subsecs);
2739
2740 fDateTimeDigitized.SetSubseconds (subsecs);
2741
2742 #if qDNGValidate
2743
2744 if (gVerbose)
2745 {
2746
2747 printf ("SubsecTimeDigitized: ");
2748
2749 DumpString (subsecs);
2750
2751 printf ("\n");
2752
2753 }
2754
2755 #endif
2756
2757 break;
2758
2759 }
2760
2761 case tcTemperature:
2762 {
2763
2764 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2765
2766 CheckTagCount (parentCode, tagCode, tagCount, 1);
2767
2768 fTemperature = stream.TagValue_srational (tagType);
2769
2770 if (!AtLeastVersion0231 ())
2771 {
2772 SetVersion0231 ();
2773 }
2774
2775 #if qDNGValidate
2776
2777 if (gVerbose)
2778 {
2779
2780 printf ("Temperature: %0.1f\n",
2781 fTemperature.As_real64 ());
2782
2783 }
2784
2785 #endif
2786
2787 break;
2788
2789 }
2790
2791 case tcHumidity:
2792 {
2793
2794 CheckTagType (parentCode, tagCode, tagType, ttRational);
2795
2796 CheckTagCount (parentCode, tagCode, tagCount, 1);
2797
2798 fHumidity = stream.TagValue_urational (tagType);
2799
2800 if (!AtLeastVersion0231 ())
2801 {
2802 SetVersion0231 ();
2803 }
2804
2805 #if qDNGValidate
2806
2807 if (gVerbose)
2808 {
2809
2810 printf ("Humidity: %0.1f\n",
2811 fHumidity.As_real64 ());
2812
2813 }
2814
2815 #endif
2816
2817 break;
2818
2819 }
2820
2821 case tcPressure:
2822 {
2823
2824 CheckTagType (parentCode, tagCode, tagType, ttRational);
2825
2826 CheckTagCount (parentCode, tagCode, tagCount, 1);
2827
2828 fPressure = stream.TagValue_urational (tagType);
2829
2830 if (!AtLeastVersion0231 ())
2831 {
2832 SetVersion0231 ();
2833 }
2834
2835 #if qDNGValidate
2836
2837 if (gVerbose)
2838 {
2839
2840 printf ("Pressure: %0.1f\n",
2841 fPressure.As_real64 ());
2842
2843 }
2844
2845 #endif
2846
2847 break;
2848
2849 }
2850
2851 case tcWaterDepth:
2852 {
2853
2854 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2855
2856 CheckTagCount (parentCode, tagCode, tagCount, 1);
2857
2858 fWaterDepth = stream.TagValue_srational (tagType);
2859
2860 if (!AtLeastVersion0231 ())
2861 {
2862 SetVersion0231 ();
2863 }
2864
2865 #if qDNGValidate
2866
2867 if (gVerbose)
2868 {
2869
2870 printf ("WaterDepth: %0.1f\n",
2871 fWaterDepth.As_real64 ());
2872
2873 }
2874
2875 #endif
2876
2877 break;
2878
2879 }
2880
2881 case tcAcceleration:
2882 {
2883
2884 CheckTagType (parentCode, tagCode, tagType, ttRational);
2885
2886 CheckTagCount (parentCode, tagCode, tagCount, 1);
2887
2888 fAcceleration = stream.TagValue_urational (tagType);
2889
2890 if (!AtLeastVersion0231 ())
2891 {
2892 SetVersion0231 ();
2893 }
2894
2895 #if qDNGValidate
2896
2897 if (gVerbose)
2898 {
2899
2900 printf ("Acceleration: %0.1f\n",
2901 fAcceleration.As_real64 ());
2902
2903 }
2904
2905 #endif
2906
2907 break;
2908
2909 }
2910
2911 case tcCameraElevationAngle:
2912 {
2913
2914 CheckTagType (parentCode, tagCode, tagType, ttSRational);
2915
2916 CheckTagCount (parentCode, tagCode, tagCount, 1);
2917
2918 fCameraElevationAngle = stream.TagValue_srational (tagType);
2919
2920 if (!AtLeastVersion0231 ())
2921 {
2922 SetVersion0231 ();
2923 }
2924
2925 #if qDNGValidate
2926
2927 if (gVerbose)
2928 {
2929
2930 printf ("CameraElevationAngle: %0.1f\n",
2931 fCameraElevationAngle.As_real64 ());
2932
2933 }
2934
2935 #endif
2936
2937 break;
2938
2939 }
2940
2941 case tcFlashPixVersion:
2942 {
2943
2944 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
2945
2946 CheckTagCount (parentCode, tagCode, tagCount, 4);
2947
2948 uint32 b0 = stream.Get_uint8 ();
2949 uint32 b1 = stream.Get_uint8 ();
2950 uint32 b2 = stream.Get_uint8 ();
2951 uint32 b3 = stream.Get_uint8 ();
2952
2953 fFlashPixVersion = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
2954
2955 #if qDNGValidate
2956
2957 if (gVerbose)
2958 {
2959
2960 real64 x = (b0 - '0') * 10.00 +
2961 (b1 - '0') * 1.00 +
2962 (b2 - '0') * 0.10 +
2963 (b3 - '0') * 0.01;
2964
2965 printf ("FlashPixVersion: %0.2f\n", x);
2966
2967 }
2968
2969 #endif
2970
2971 break;
2972
2973 }
2974
2975 case tcColorSpace:
2976 {
2977
2978 CheckTagType (parentCode, tagCode, tagType, ttShort);
2979
2980 CheckTagCount (parentCode, tagCode, tagCount, 1);
2981
2982 fColorSpace = stream.TagValue_uint32 (tagType);
2983
2984 #if qDNGValidate
2985
2986 if (gVerbose)
2987 {
2988
2989 printf ("ColorSpace: %s\n",
2990 LookupColorSpace (fColorSpace));
2991
2992 }
2993
2994 #endif
2995
2996 break;
2997
2998 }
2999
3000 case tcPixelXDimension:
3001 {
3002
3003 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
3004
3005 CheckTagCount (parentCode, tagCode, tagCount, 1);
3006
3007 fPixelXDimension = stream.TagValue_uint32 (tagType);
3008
3009 #if qDNGValidate
3010
3011 if (gVerbose)
3012 {
3013 printf ("PixelXDimension: %u\n", (unsigned) fPixelXDimension);
3014 }
3015
3016 #endif
3017
3018 break;
3019
3020 }
3021
3022 case tcPixelYDimension:
3023 {
3024
3025 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
3026
3027 CheckTagCount (parentCode, tagCode, tagCount, 1);
3028
3029 fPixelYDimension = stream.TagValue_uint32 (tagType);
3030
3031 #if qDNGValidate
3032
3033 if (gVerbose)
3034 {
3035 printf ("PixelYDimension: %u\n", (unsigned) fPixelYDimension);
3036 }
3037
3038 #endif
3039
3040 break;
3041
3042 }
3043
3044 case tcFocalPlaneXResolutionExif:
3045 {
3046
3047 CheckTagType (parentCode, tagCode, tagType, ttRational);
3048
3049 CheckTagCount (parentCode, tagCode, tagCount, 1);
3050
3051 fFocalPlaneXResolution = stream.TagValue_urational (tagType);
3052
3053 #if qDNGValidate
3054
3055 if (gVerbose)
3056 {
3057
3058 printf ("FocalPlaneXResolutionExif: %0.4f\n",
3059 fFocalPlaneXResolution.As_real64 ());
3060
3061 }
3062
3063 #endif
3064
3065 break;
3066
3067 }
3068
3069 case tcFocalPlaneYResolutionExif:
3070 {
3071
3072 CheckTagType (parentCode, tagCode, tagType, ttRational);
3073
3074 CheckTagCount (parentCode, tagCode, tagCount, 1);
3075
3076 fFocalPlaneYResolution = stream.TagValue_urational (tagType);
3077
3078 #if qDNGValidate
3079
3080 if (gVerbose)
3081 {
3082
3083 printf ("FocalPlaneYResolutionExif: %0.4f\n",
3084 fFocalPlaneYResolution.As_real64 ());
3085
3086 }
3087
3088 #endif
3089
3090 break;
3091
3092 }
3093
3094 case tcFocalPlaneResolutionUnitExif:
3095 {
3096
3097 CheckTagType (parentCode, tagCode, tagType, ttShort);
3098
3099 CheckTagCount (parentCode, tagCode, tagCount, 1);
3100
3101 fFocalPlaneResolutionUnit = stream.TagValue_uint32 (tagType);
3102
3103 #if qDNGValidate
3104
3105 if (gVerbose)
3106 {
3107
3108 printf ("FocalPlaneResolutionUnitExif: %s\n",
3109 LookupResolutionUnit (fFocalPlaneResolutionUnit));
3110
3111 }
3112
3113 #endif
3114
3115 break;
3116
3117 }
3118
3119 case tcSensingMethodExif:
3120 {
3121
3122 CheckTagType (parentCode, tagCode, tagType, ttShort);
3123
3124 CheckTagCount (parentCode, tagCode, tagCount, 1);
3125
3126 fSensingMethod = stream.TagValue_uint32 (tagType);
3127
3128 #if qDNGValidate
3129
3130 if (gVerbose)
3131 {
3132
3133 printf ("SensingMethodExif: %s\n",
3134 LookupSensingMethod (fSensingMethod));
3135
3136 }
3137
3138 #endif
3139
3140 break;
3141
3142 }
3143
3144 case tcFileSource:
3145 {
3146
3147 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
3148
3149 CheckTagCount (parentCode, tagCode, tagCount, 1);
3150
3151 fFileSource = stream.Get_uint8 ();
3152
3153 #if qDNGValidate
3154
3155 if (gVerbose)
3156 {
3157
3158 printf ("FileSource: %s\n",
3159 LookupFileSource (fFileSource));
3160
3161 }
3162
3163 #endif
3164
3165 break;
3166
3167 }
3168
3169 case tcSceneType:
3170 {
3171
3172 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
3173
3174 CheckTagCount (parentCode, tagCode, tagCount, 1);
3175
3176 fSceneType = stream.Get_uint8 ();
3177
3178 #if qDNGValidate
3179
3180 if (gVerbose)
3181 {
3182
3183 printf ("SceneType: %s\n",
3184 LookupSceneType (fSceneType));
3185
3186 }
3187
3188 #endif
3189
3190 break;
3191
3192 }
3193
3194 case tcCFAPatternExif:
3195 {
3196
3197 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
3198
3199 if (tagCount <= 4)
3200 {
3201 return false;
3202 }
3203
3204 uint32 cols = stream.Get_uint16 ();
3205 uint32 rows = stream.Get_uint16 ();
3206
3207 if (tagCount != 4 + cols * rows)
3208 {
3209 return false;
3210 }
3211
3212 if (cols < 1 || cols > kMaxCFAPattern ||
3213 rows < 1 || rows > kMaxCFAPattern)
3214 {
3215 return false;
3216 }
3217
3218 fCFARepeatPatternCols = cols;
3219 fCFARepeatPatternRows = rows;
3220
3221 // Note that the Exif spec stores this array in a different
3222 // scan order than the TIFF-EP spec.
3223
3224 for (uint32 j = 0; j < fCFARepeatPatternCols; j++)
3225 for (uint32 k = 0; k < fCFARepeatPatternRows; k++)
3226 {
3227
3228 fCFAPattern [k] [j] = stream.Get_uint8 ();
3229
3230 }
3231
3232 #if qDNGValidate
3233
3234 if (gVerbose)
3235 {
3236
3237 printf ("CFAPatternExif:\n");
3238
3239 for (uint32 j = 0; j < fCFARepeatPatternRows; j++)
3240 {
3241
3242 int32 spaces = 4;
3243
3244 for (uint32 k = 0; k < fCFARepeatPatternCols; k++)
3245 {
3246
3247 while (spaces-- > 0)
3248 {
3249 printf (" ");
3250 }
3251
3252 const char *name = LookupCFAColor (fCFAPattern [j] [k]);
3253
3254 spaces = 9 - (int32) strlen (name);
3255
3256 printf ("%s", name);
3257
3258 }
3259
3260 printf ("\n");
3261
3262 }
3263
3264 }
3265
3266 #endif
3267
3268 break;
3269
3270 }
3271
3272 case tcCustomRendered:
3273 {
3274
3275 CheckTagType (parentCode, tagCode, tagType, ttShort);
3276
3277 CheckTagCount (parentCode, tagCode, tagCount, 1);
3278
3279 fCustomRendered = stream.TagValue_uint32 (tagType);
3280
3281 #if qDNGValidate
3282
3283 if (gVerbose)
3284 {
3285
3286 printf ("CustomRendered: %s\n",
3287 LookupCustomRendered (fCustomRendered));
3288
3289 }
3290
3291 #endif
3292
3293 break;
3294
3295 }
3296
3297 case tcExposureMode:
3298 {
3299
3300 CheckTagType (parentCode, tagCode, tagType, ttShort);
3301
3302 CheckTagCount (parentCode, tagCode, tagCount, 1);
3303
3304 fExposureMode = stream.TagValue_uint32 (tagType);
3305
3306 #if qDNGValidate
3307
3308 if (gVerbose)
3309 {
3310
3311 printf ("ExposureMode: %s\n",
3312 LookupExposureMode (fExposureMode));
3313
3314 }
3315
3316 #endif
3317
3318 break;
3319
3320 }
3321
3322 case tcWhiteBalance:
3323 {
3324
3325 CheckTagType (parentCode, tagCode, tagType, ttShort);
3326
3327 CheckTagCount (parentCode, tagCode, tagCount, 1);
3328
3329 fWhiteBalance = stream.TagValue_uint32 (tagType);
3330
3331 #if qDNGValidate
3332
3333 if (gVerbose)
3334 {
3335
3336 printf ("WhiteBalance: %s\n",
3337 LookupWhiteBalance (fWhiteBalance));
3338
3339 }
3340
3341 #endif
3342
3343 break;
3344
3345 }
3346
3347 case tcDigitalZoomRatio:
3348 {
3349
3350 CheckTagType (parentCode, tagCode, tagType, ttRational);
3351
3352 CheckTagCount (parentCode, tagCode, tagCount, 1);
3353
3354 fDigitalZoomRatio = stream.TagValue_urational (tagType);
3355
3356 #if qDNGValidate
3357
3358 if (gVerbose)
3359 {
3360
3361 printf ("DigitalZoomRatio: ");
3362
3363 if (fDigitalZoomRatio.n == 0 ||
3364 fDigitalZoomRatio.d == 0)
3365 {
3366
3367 printf ("Not used\n");
3368
3369 }
3370
3371 else
3372 {
3373
3374 printf ("%0.2f\n", fDigitalZoomRatio.As_real64 ());
3375
3376 }
3377
3378 }
3379
3380 #endif
3381
3382 break;
3383
3384 }
3385
3386 case tcFocalLengthIn35mmFilm:
3387 {
3388
3389 CheckTagType (parentCode, tagCode, tagType, ttShort);
3390
3391 CheckTagCount (parentCode, tagCode, tagCount, 1);
3392
3393 fFocalLengthIn35mmFilm = stream.TagValue_uint32 (tagType);
3394
3395 #if qDNGValidate
3396
3397 if (gVerbose)
3398 {
3399
3400 printf ("FocalLengthIn35mmFilm: %u mm\n",
3401 (unsigned) fFocalLengthIn35mmFilm);
3402
3403 }
3404
3405 #endif
3406
3407 break;
3408
3409 }
3410
3411 case tcSceneCaptureType:
3412 {
3413
3414 CheckTagType (parentCode, tagCode, tagType, ttShort);
3415
3416 CheckTagCount (parentCode, tagCode, tagCount, 1);
3417
3418 fSceneCaptureType = stream.TagValue_uint32 (tagType);
3419
3420 #if qDNGValidate
3421
3422 if (gVerbose)
3423 {
3424
3425 printf ("SceneCaptureType: %s\n",
3426 LookupSceneCaptureType (fSceneCaptureType));
3427
3428 }
3429
3430 #endif
3431
3432 break;
3433
3434 }
3435
3436 case tcGainControl:
3437 {
3438
3439 CheckTagType (parentCode, tagCode, tagType, ttShort);
3440
3441 CheckTagCount (parentCode, tagCode, tagCount, 1);
3442
3443 fGainControl = stream.TagValue_uint32 (tagType);
3444
3445 #if qDNGValidate
3446
3447 if (gVerbose)
3448 {
3449
3450 printf ("GainControl: %s\n",
3451 LookupGainControl (fGainControl));
3452
3453 }
3454
3455 #endif
3456
3457 break;
3458
3459 }
3460
3461 case tcContrast:
3462 {
3463
3464 CheckTagType (parentCode, tagCode, tagType, ttShort);
3465
3466 CheckTagCount (parentCode, tagCode, tagCount, 1);
3467
3468 fContrast = stream.TagValue_uint32 (tagType);
3469
3470 #if qDNGValidate
3471
3472 if (gVerbose)
3473 {
3474
3475 printf ("Contrast: %s\n",
3476 LookupContrast (fContrast));
3477
3478 }
3479
3480 #endif
3481
3482 break;
3483
3484 }
3485
3486 case tcSaturation:
3487 {
3488
3489 CheckTagType (parentCode, tagCode, tagType, ttShort);
3490
3491 CheckTagCount (parentCode, tagCode, tagCount, 1);
3492
3493 fSaturation = stream.TagValue_uint32 (tagType);
3494
3495 #if qDNGValidate
3496
3497 if (gVerbose)
3498 {
3499
3500 printf ("Saturation: %s\n",
3501 LookupSaturation (fSaturation));
3502
3503 }
3504
3505 #endif
3506
3507 break;
3508
3509 }
3510
3511 case tcSharpness:
3512 {
3513
3514 CheckTagType (parentCode, tagCode, tagType, ttShort);
3515
3516 CheckTagCount (parentCode, tagCode, tagCount, 1);
3517
3518 fSharpness = stream.TagValue_uint32 (tagType);
3519
3520 #if qDNGValidate
3521
3522 if (gVerbose)
3523 {
3524
3525 printf ("Sharpness: %s\n",
3526 LookupSharpness (fSharpness));
3527
3528 }
3529
3530 #endif
3531
3532 break;
3533
3534 }
3535
3536 case tcSubjectDistanceRange:
3537 {
3538
3539 CheckTagType (parentCode, tagCode, tagType, ttShort);
3540
3541 CheckTagCount (parentCode, tagCode, tagCount, 1);
3542
3543 fSubjectDistanceRange = stream.TagValue_uint32 (tagType);
3544
3545 #if qDNGValidate
3546
3547 if (gVerbose)
3548 {
3549
3550 printf ("SubjectDistanceRange: %s\n",
3551 LookupSubjectDistanceRange (fSubjectDistanceRange));
3552
3553 }
3554
3555 #endif
3556
3557 break;
3558
3559 }
3560
3561 case tcSubjectArea:
3562 case tcSubjectLocation:
3563 {
3564
3565 CheckTagType (parentCode, tagCode, tagType, ttShort);
3566
3567 if (!CheckTagCount (parentCode, tagCode, tagCount, 2, 4))
3568 {
3569 return false;
3570 }
3571
3572 if (tagCode == tcSubjectLocation)
3573 {
3574 CheckTagCount (parentCode, tagCode, tagCount, 2);
3575 }
3576
3577 fSubjectAreaCount = tagCount;
3578
3579 for (uint32 j = 0; j < tagCount; j++)
3580 {
3581
3582 fSubjectArea [j] = stream.TagValue_uint32 (tagType);
3583
3584 }
3585
3586 #if qDNGValidate
3587
3588 if (gVerbose)
3589 {
3590
3591 printf ("%s:", LookupTagCode (parentCode, tagCode));
3592
3593 for (uint32 j = 0; j < fSubjectAreaCount; j++)
3594 {
3595
3596 printf (" %u", (unsigned) fSubjectArea [j]);
3597
3598 }
3599
3600 printf ("\n");
3601
3602 }
3603
3604 #endif
3605
3606 break;
3607
3608 }
3609
3610 case tcGamma:
3611 {
3612
3613 CheckTagType (parentCode, tagCode, tagType, ttRational);
3614
3615 CheckTagCount (parentCode, tagCode, tagCount, 1);
3616
3617 fGamma = stream.TagValue_urational (tagType);
3618
3619 #if qDNGValidate
3620
3621 if (gVerbose)
3622 {
3623
3624 printf ("Gamma: %0.2f\n",
3625 fGamma.As_real64 ());
3626
3627 }
3628
3629 #endif
3630
3631 break;
3632
3633 }
3634
3635 case tcImageUniqueID:
3636 {
3637
3638 if (!CheckTagType (parentCode, tagCode, tagType, ttAscii))
3639 return false;
3640
3641 if (!CheckTagCount (parentCode, tagCode, tagCount, 33))
3642 return false;
3643
3644 dng_string s;
3645
3646 ParseStringTag (stream,
3647 parentCode,
3648 tagCode,
3649 tagCount,
3650 s);
3651
3652 if (s.Length () != 32)
3653 return false;
3654
3655 dng_fingerprint f;
3656
3657 for (uint32 j = 0; j < 32; j++)
3658 {
3659
3660 char c = ForceUppercase (s.Get () [j]);
3661
3662 uint32 digit;
3663
3664 if (c >= '0' && c <= '9')
3665 {
3666 digit = c - '0';
3667 }
3668
3669 else if (c >= 'A' && c <= 'F')
3670 {
3671 digit = c - 'A' + 10;
3672 }
3673
3674 else
3675 return false;
3676
3677 f.data [j >> 1] *= 16;
3678 f.data [j >> 1] += (uint8) digit;
3679
3680 }
3681
3682 fImageUniqueID = f;
3683
3684 #if qDNGValidate
3685
3686 if (gVerbose)
3687 {
3688
3689 printf ("ImageUniqueID: ");
3690
3691 DumpFingerprint (fImageUniqueID);
3692
3693 printf ("\n");
3694
3695 }
3696
3697 #endif
3698
3699 break;
3700
3701 }
3702
3703 case tcCameraOwnerNameExif:
3704 {
3705
3706 CheckTagType (parentCode, tagCode, tagType, ttAscii);
3707
3708 ParseStringTag (stream,
3709 parentCode,
3710 tagCode,
3711 tagCount,
3712 fOwnerName);
3713
3714 #if qDNGValidate
3715
3716 if (gVerbose)
3717 {
3718
3719 printf ("CameraOwnerName: ");
3720
3721 DumpString (fOwnerName);
3722
3723 printf ("\n");
3724
3725 }
3726
3727 #endif
3728
3729 break;
3730
3731 }
3732
3733 case tcCameraSerialNumberExif:
3734 {
3735
3736 CheckTagType (parentCode, tagCode, tagType, ttAscii);
3737
3738 ParseStringTag (stream,
3739 parentCode,
3740 tagCode,
3741 tagCount,
3742 fCameraSerialNumber);
3743
3744 #if qDNGValidate
3745
3746 if (gVerbose)
3747 {
3748
3749 printf ("%s: ", LookupTagCode (parentCode, tagCode));
3750
3751 DumpString (fCameraSerialNumber);
3752
3753 printf ("\n");
3754
3755 }
3756
3757 #endif
3758
3759 break;
3760
3761 }
3762
3763 case tcLensSpecificationExif:
3764 {
3765
3766 CheckTagType (parentCode, tagCode, tagType, ttRational);
3767
3768 if (!CheckTagCount (parentCode, tagCode, tagCount, 4))
3769 return false;
3770
3771 fLensInfo [0] = stream.TagValue_urational (tagType);
3772 fLensInfo [1] = stream.TagValue_urational (tagType);
3773 fLensInfo [2] = stream.TagValue_urational (tagType);
3774 fLensInfo [3] = stream.TagValue_urational (tagType);
3775
3776 // Some third party software wrote zero rather than undefined values for
3777 // unknown entries. Work around this bug.
3778
3779 for (uint32 j = 0; j < 4; j++)
3780 {
3781
3782 if (fLensInfo [j].IsValid () && fLensInfo [j].As_real64 () <= 0.0)
3783 {
3784
3785 fLensInfo [j] = dng_urational (0, 0);
3786
3787 #if qDNGValidate
3788
3789 ReportWarning ("Zero entry in LensSpecification tag--should be undefined");
3790
3791 #endif
3792
3793 }
3794
3795 }
3796
3797 #if qDNGValidate
3798
3799 if (gVerbose)
3800 {
3801
3802 printf ("LensSpecificationExif: ");
3803
3804 real64 minFL = fLensInfo [0].As_real64 ();
3805 real64 maxFL = fLensInfo [1].As_real64 ();
3806
3807 if (minFL == maxFL)
3808 printf ("%0.1f mm", minFL);
3809 else
3810 printf ("%0.1f-%0.1f mm", minFL, maxFL);
3811
3812 if (fLensInfo [2].d)
3813 {
3814
3815 real64 minFS = fLensInfo [2].As_real64 ();
3816 real64 maxFS = fLensInfo [3].As_real64 ();
3817
3818 if (minFS == maxFS)
3819 printf (" f/%0.1f", minFS);
3820 else
3821 printf (" f/%0.1f-%0.1f", minFS, maxFS);
3822
3823 }
3824
3825 printf ("\n");
3826
3827 }
3828
3829 #endif
3830
3831 break;
3832
3833 }
3834
3835 case tcLensMakeExif:
3836 {
3837
3838 CheckTagType (parentCode, tagCode, tagType, ttAscii);
3839
3840 ParseStringTag (stream,
3841 parentCode,
3842 tagCode,
3843 tagCount,
3844 fLensMake);
3845
3846 #if qDNGValidate
3847
3848 if (gVerbose)
3849 {
3850
3851 printf ("%s: ", LookupTagCode (parentCode, tagCode));
3852
3853 DumpString (fLensMake);
3854
3855 printf ("\n");
3856
3857 }
3858
3859 #endif
3860
3861 break;
3862
3863 }
3864
3865 case tcLensModelExif:
3866 {
3867
3868 CheckTagType (parentCode, tagCode, tagType, ttAscii);
3869
3870 ParseStringTag (stream,
3871 parentCode,
3872 tagCode,
3873 tagCount,
3874 fLensName);
3875
3876 fLensNameWasReadFromExif = fLensName.NotEmpty ();
3877
3878 #if qDNGValidate
3879
3880 if (gVerbose)
3881 {
3882
3883 printf ("%s: ", LookupTagCode (parentCode, tagCode));
3884
3885 DumpString (fLensName);
3886
3887 printf ("\n");
3888
3889 }
3890
3891 #endif
3892
3893 break;
3894
3895 }
3896
3897 case tcLensSerialNumberExif:
3898 {
3899
3900 CheckTagType (parentCode, tagCode, tagType, ttAscii);
3901
3902 ParseStringTag (stream,
3903 parentCode,
3904 tagCode,
3905 tagCount,
3906 fLensSerialNumber);
3907
3908 #if qDNGValidate
3909
3910 if (gVerbose)
3911 {
3912
3913 printf ("%s: ", LookupTagCode (parentCode, tagCode));
3914
3915 DumpString (fLensSerialNumber);
3916
3917 printf ("\n");
3918
3919 }
3920
3921 #endif
3922
3923 break;
3924
3925 }
3926
3927 default:
3928 {
3929
3930 return false;
3931
3932 }
3933
3934 }
3935
3936 return true;
3937
3938 }
3939
3940 /*****************************************************************************/
3941
3942 // Parses tags that should only appear in GPS IFD
3943
3944 bool dng_exif::Parse_gps (dng_stream &stream,
3945 dng_shared & /* shared */,
3946 uint32 parentCode,
3947 uint32 tagCode,
3948 uint32 tagType,
3949 uint32 tagCount,
3950 uint64 /* tagOffset */)
3951 {
3952
3953 switch (tagCode)
3954 {
3955
3956 case tcGPSVersionID:
3957 {
3958
3959 CheckTagType (parentCode, tagCode, tagType, ttByte);
3960
3961 CheckTagCount (parentCode, tagCode, tagCount, 4);
3962
3963 uint32 b0 = stream.Get_uint8 ();
3964 uint32 b1 = stream.Get_uint8 ();
3965 uint32 b2 = stream.Get_uint8 ();
3966 uint32 b3 = stream.Get_uint8 ();
3967
3968 fGPSVersionID = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
3969
3970 #if qDNGValidate
3971
3972 if (gVerbose)
3973 {
3974 printf ("GPSVersionID: %u.%u.%u.%u\n",
3975 (unsigned) b0,
3976 (unsigned) b1,
3977 (unsigned) b2,
3978 (unsigned) b3);
3979 }
3980
3981 #endif
3982
3983 break;
3984
3985 }
3986
3987 case tcGPSLatitudeRef:
3988 case tcGPSLongitudeRef:
3989 case tcGPSSatellites:
3990 case tcGPSStatus:
3991 case tcGPSMeasureMode:
3992 case tcGPSSpeedRef:
3993 case tcGPSTrackRef:
3994 case tcGPSImgDirectionRef:
3995 case tcGPSMapDatum:
3996 case tcGPSDestLatitudeRef:
3997 case tcGPSDestLongitudeRef:
3998 case tcGPSDestBearingRef:
3999 case tcGPSDestDistanceRef:
4000 case tcGPSDateStamp:
4001 {
4002
4003 if (!CheckTagType (parentCode, tagCode, tagType, ttAscii))
4004 return false;
4005
4006 dng_string *s;
4007
4008 switch (tagCode)
4009 {
4010
4011 case tcGPSLatitudeRef:
4012 s = &fGPSLatitudeRef;
4013 break;
4014
4015 case tcGPSLongitudeRef:
4016 s = &fGPSLongitudeRef;
4017 break;
4018
4019 case tcGPSSatellites:
4020 s = &fGPSSatellites;
4021 break;
4022
4023 case tcGPSStatus:
4024 s = &fGPSStatus;
4025 break;
4026
4027 case tcGPSMeasureMode:
4028 s = &fGPSMeasureMode;
4029 break;
4030
4031 case tcGPSSpeedRef:
4032 s = &fGPSSpeedRef;
4033 break;
4034
4035 case tcGPSTrackRef:
4036 s = &fGPSTrackRef;
4037 break;
4038
4039 case tcGPSImgDirectionRef:
4040 s = &fGPSImgDirectionRef;
4041 break;
4042
4043 case tcGPSMapDatum:
4044 s = &fGPSMapDatum;
4045 break;
4046
4047 case tcGPSDestLatitudeRef:
4048 s = &fGPSDestLatitudeRef;
4049 break;
4050
4051 case tcGPSDestLongitudeRef:
4052 s = &fGPSDestLongitudeRef;
4053 break;
4054
4055 case tcGPSDestBearingRef:
4056 s = &fGPSDestBearingRef;
4057 break;
4058
4059 case tcGPSDestDistanceRef:
4060 s = &fGPSDestDistanceRef;
4061 break;
4062
4063 case tcGPSDateStamp:
4064 s = &fGPSDateStamp;
4065 break;
4066
4067 default:
4068 return false;
4069
4070 }
4071
4072 ParseStringTag (stream,
4073 parentCode,
4074 tagCode,
4075 tagCount,
4076 *s);
4077
4078 #if qDNGValidate
4079
4080 if (gVerbose)
4081 {
4082
4083 printf ("%s: ", LookupTagCode (parentCode, tagCode));
4084
4085 DumpString (*s);
4086
4087 printf ("\n");
4088
4089 }
4090
4091 #endif
4092
4093 break;
4094
4095 }
4096
4097 case tcGPSLatitude:
4098 case tcGPSLongitude:
4099 case tcGPSTimeStamp:
4100 case tcGPSDestLatitude:
4101 case tcGPSDestLongitude:
4102 {
4103
4104 // Should really be ttRational per EXIF spec, but allow
4105 // ttSRational too because some JPEGs from Nexus 5
4106 // apparently use ttSRational type.
4107
4108 if (!CheckTagType (parentCode, tagCode, tagType, ttRational) &&
4109 !CheckTagType (parentCode, tagCode, tagType, ttSRational))
4110 return false;
4111
4112 if (!CheckTagCount (parentCode, tagCode, tagCount, 3))
4113 return false;
4114
4115 dng_urational *u;
4116
4117 switch (tagCode)
4118 {
4119
4120 case tcGPSLatitude:
4121 u = fGPSLatitude;
4122 break;
4123
4124 case tcGPSLongitude:
4125 u = fGPSLongitude;
4126 break;
4127
4128 case tcGPSTimeStamp:
4129 u = fGPSTimeStamp;
4130 break;
4131
4132 case tcGPSDestLatitude:
4133 u = fGPSDestLatitude;
4134 break;
4135
4136 case tcGPSDestLongitude:
4137 u = fGPSDestLongitude;
4138 break;
4139
4140 default:
4141 return false;
4142
4143 }
4144
4145 u [0] = stream.TagValue_urational (tagType);
4146 u [1] = stream.TagValue_urational (tagType);
4147 u [2] = stream.TagValue_urational (tagType);
4148
4149 #if qDNGValidate
4150
4151 if (gVerbose)
4152 {
4153
4154 printf ("%s:", LookupTagCode (parentCode, tagCode));
4155
4156 for (uint32 j = 0; j < 3; j++)
4157 {
4158
4159 if (u [j].d == 0)
4160 printf (" -");
4161
4162 else
4163 printf (" %0.4f", u [j].As_real64 ());
4164
4165 }
4166
4167 printf ("\n");
4168
4169 }
4170
4171 #endif
4172
4173 break;
4174
4175 }
4176
4177 case tcGPSAltitudeRef:
4178 {
4179
4180 CheckTagType (parentCode, tagCode, tagType, ttByte);
4181
4182 CheckTagCount (parentCode, tagCode, tagCount, 1);
4183
4184 fGPSAltitudeRef = stream.TagValue_uint32 (tagType);
4185
4186 #if qDNGValidate
4187
4188 if (gVerbose)
4189 {
4190
4191 printf ("GPSAltitudeRef: ");
4192
4193 switch (fGPSAltitudeRef)
4194 {
4195
4196 case 0:
4197 printf ("Sea level");
4198 break;
4199
4200 case 1:
4201 printf ("Sea level reference (negative value)");
4202 break;
4203
4204 default:
4205 printf ("%u", (unsigned) fGPSAltitudeRef);
4206 break;
4207
4208 }
4209
4210 printf ("\n");
4211
4212 }
4213
4214 #endif
4215
4216 break;
4217
4218 }
4219
4220 case tcGPSAltitude:
4221 case tcGPSDOP:
4222 case tcGPSSpeed:
4223 case tcGPSTrack:
4224 case tcGPSImgDirection:
4225 case tcGPSDestBearing:
4226 case tcGPSDestDistance:
4227 case tcGPSHPositioningError:
4228 {
4229
4230 if (!CheckTagType (parentCode, tagCode, tagType, ttRational))
4231 return false;
4232
4233 CheckTagCount (parentCode, tagCode, tagCount, 1);
4234
4235 dng_urational *u;
4236
4237 switch (tagCode)
4238 {
4239
4240 case tcGPSAltitude:
4241 u = &fGPSAltitude;
4242 break;
4243
4244 case tcGPSDOP:
4245 u = &fGPSDOP;
4246 break;
4247
4248 case tcGPSSpeed:
4249 u = &fGPSSpeed;
4250 break;
4251
4252 case tcGPSTrack:
4253 u = &fGPSTrack;
4254 break;
4255
4256 case tcGPSImgDirection:
4257 u = &fGPSImgDirection;
4258 break;
4259
4260 case tcGPSDestBearing:
4261 u = &fGPSDestBearing;
4262 break;
4263
4264 case tcGPSDestDistance:
4265 u = &fGPSDestDistance;
4266 break;
4267
4268 case tcGPSHPositioningError:
4269 u = &fGPSHPositioningError;
4270 break;
4271
4272 default:
4273 return false;
4274
4275 }
4276
4277 *u = stream.TagValue_urational (tagType);
4278
4279 #if qDNGValidate
4280
4281 if (gVerbose)
4282 {
4283
4284 printf ("%s:", LookupTagCode (parentCode, tagCode));
4285
4286 if (u->d == 0)
4287 printf (" -");
4288
4289 else
4290 printf (" %0.4f", u->As_real64 ());
4291
4292 printf ("\n");
4293
4294 }
4295
4296 #endif
4297
4298 break;
4299
4300 }
4301
4302 case tcGPSProcessingMethod:
4303 case tcGPSAreaInformation:
4304 {
4305
4306 if (!CheckTagType (parentCode, tagCode, tagType, ttUndefined))
4307 return false;
4308
4309 dng_string *s;
4310
4311 switch (tagCode)
4312 {
4313
4314 case tcGPSProcessingMethod:
4315 s = &fGPSProcessingMethod;
4316 break;
4317
4318 case tcGPSAreaInformation:
4319 s = &fGPSAreaInformation;
4320 break;
4321
4322 default:
4323 return false;
4324
4325 }
4326
4327 ParseEncodedStringTag (stream,
4328 parentCode,
4329 tagCode,
4330 tagCount,
4331 *s);
4332
4333 #if qDNGValidate
4334
4335 if (gVerbose)
4336 {
4337
4338 printf ("%s: ", LookupTagCode (parentCode, tagCode));
4339
4340 DumpString (*s);
4341
4342 printf ("\n");
4343
4344 }
4345
4346 #endif
4347
4348 break;
4349
4350 }
4351
4352 case tcGPSDifferential:
4353 {
4354
4355 CheckTagType (parentCode, tagCode, tagType, ttShort);
4356
4357 CheckTagCount (parentCode, tagCode, tagCount, 1);
4358
4359 fGPSDifferential = stream.TagValue_uint32 (tagType);
4360
4361 #if qDNGValidate
4362
4363 if (gVerbose)
4364 {
4365
4366 printf ("GPSDifferential: ");
4367
4368 switch (fGPSDifferential)
4369 {
4370
4371 case 0:
4372 printf ("Measurement without differential correction");
4373 break;
4374
4375 case 1:
4376 printf ("Differential correction applied");
4377 break;
4378
4379 default:
4380 printf ("%u", (unsigned) fGPSDifferential);
4381
4382 }
4383
4384 printf ("\n");
4385
4386 }
4387
4388 #endif
4389
4390 break;
4391
4392 }
4393
4394 default:
4395 {
4396
4397 return false;
4398
4399 }
4400
4401 }
4402
4403 return true;
4404
4405 }
4406
4407 /*****************************************************************************/
4408
4409 // Parses tags that should only appear in Interoperability IFD
4410
4411 bool dng_exif::Parse_interoperability (dng_stream &stream,
4412 dng_shared & /* shared */,
4413 uint32 parentCode,
4414 uint32 tagCode,
4415 uint32 tagType,
4416 uint32 tagCount,
4417 uint64 /* tagOffset */)
4418 {
4419
4420 switch (tagCode)
4421 {
4422
4423 case tcInteroperabilityIndex:
4424 {
4425
4426 CheckTagType (parentCode, tagCode, tagType, ttAscii);
4427
4428 CheckTagCount (parentCode, tagCode, tagCount, 4);
4429
4430 ParseStringTag (stream,
4431 parentCode,
4432 tagCode,
4433 tagCount,
4434 fInteroperabilityIndex);
4435
4436 #if qDNGValidate
4437
4438 if (gVerbose)
4439 {
4440
4441 printf ("InteroperabilityIndex: ");
4442
4443 DumpString (fInteroperabilityIndex);
4444
4445 printf ("\n");
4446
4447 }
4448
4449 #endif
4450
4451 break;
4452
4453 }
4454
4455 case tcInteroperabilityVersion:
4456 {
4457
4458 CheckTagType (parentCode, tagCode, tagType, ttUndefined);
4459
4460 CheckTagCount (parentCode, tagCode, tagCount, 4);
4461
4462 uint32 b0 = stream.Get_uint8 ();
4463 uint32 b1 = stream.Get_uint8 ();
4464 uint32 b2 = stream.Get_uint8 ();
4465 uint32 b3 = stream.Get_uint8 ();
4466
4467 fInteroperabilityVersion = (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
4468
4469 #if qDNGValidate
4470
4471 if (gVerbose)
4472 {
4473
4474 real64 x = (b0 - '0') * 10.00 +
4475 (b1 - '0') * 1.00 +
4476 (b2 - '0') * 0.10 +
4477 (b3 - '0') * 0.01;
4478
4479 printf ("InteroperabilityVersion: %0.2f\n", x);
4480
4481 }
4482
4483 #endif
4484
4485 break;
4486
4487 }
4488
4489 case tcRelatedImageFileFormat:
4490 {
4491
4492 CheckTagType (parentCode, tagCode, tagType, ttAscii);
4493
4494 ParseStringTag (stream,
4495 parentCode,
4496 tagCode,
4497 tagCount,
4498 fRelatedImageFileFormat);
4499
4500 #if qDNGValidate
4501
4502 if (gVerbose)
4503 {
4504
4505 printf ("RelatedImageFileFormat: ");
4506
4507 DumpString (fRelatedImageFileFormat);
4508
4509 printf ("\n");
4510
4511 }
4512
4513 #endif
4514
4515 break;
4516
4517 }
4518
4519 case tcRelatedImageWidth:
4520 {
4521
4522 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
4523
4524 CheckTagCount (parentCode, tagCode, tagCount, 1);
4525
4526 fRelatedImageWidth = stream.TagValue_uint32 (tagType);
4527
4528 #if qDNGValidate
4529
4530 if (gVerbose)
4531 {
4532 printf ("RelatedImageWidth: %u\n", (unsigned) fRelatedImageWidth);
4533 }
4534
4535 #endif
4536
4537 break;
4538
4539 }
4540
4541 case tcRelatedImageLength:
4542 {
4543
4544 CheckTagType (parentCode, tagCode, tagType, ttShort, ttLong);
4545
4546 CheckTagCount (parentCode, tagCode, tagCount, 1);
4547
4548 fRelatedImageLength = stream.TagValue_uint32 (tagType);
4549
4550 #if qDNGValidate
4551
4552 if (gVerbose)
4553 {
4554 printf ("RelatedImageLength: %u\n", (unsigned) fRelatedImageLength);
4555 }
4556
4557 #endif
4558
4559 break;
4560
4561 }
4562
4563 default:
4564 {
4565
4566 return false;
4567
4568 }
4569
4570 }
4571
4572 return true;
4573
4574 }
4575
4576 /*****************************************************************************/
4577
4578 void dng_exif::PostParse (dng_host & /* host */,
4579 dng_shared & /* shared */)
4580 {
4581
4582 #if qDNGValidate
4583
4584 const real64 kAPEX_Slop = 0.25;
4585
4586 // Sanity check on MaxApertureValue.
4587
4588 if (fMaxApertureValue.d)
4589 {
4590
4591 real64 mav = fMaxApertureValue.As_real64 ();
4592
4593 // Compare against ApertureValue or FNumber.
4594
4595 real64 av = mav;
4596
4597 if (fApertureValue.d)
4598 {
4599
4600 av = fApertureValue.As_real64 ();
4601
4602 }
4603
4604 else if (fFNumber.d)
4605 {
4606
4607 real64 fs = fFNumber.As_real64 ();
4608
4609 if (fs >= 1.0)
4610 {
4611
4612 av = FNumberToApertureValue (fs);
4613
4614 }
4615
4616 }
4617
4618 if (mav > av + kAPEX_Slop)
4619 {
4620
4621 ReportWarning ("MaxApertureValue conflicts with ApertureValue and/or FNumber");
4622
4623 }
4624
4625 // Compare against LensInfo
4626
4627 if (fLensInfo [2].d && fLensInfo [3].d)
4628 {
4629
4630 real64 fs1 = fLensInfo [2].As_real64 ();
4631 real64 fs2 = fLensInfo [3].As_real64 ();
4632
4633 if (fs1 >= 1.0 && fs2 >= 1.0 && fs2 >= fs1)
4634 {
4635
4636 real64 av1 = FNumberToApertureValue (fs1);
4637 real64 av2 = FNumberToApertureValue (fs2);
4638
4639 // Wide angle adapters might create an effective
4640 // wide FS, and tele-extenders always result
4641 // in a higher FS.
4642
4643 if (mav < av1 - kAPEX_Slop - 1.0 ||
4644 mav > av2 + kAPEX_Slop + 2.0)
4645 {
4646
4647 ReportWarning ("Possible MaxApertureValue conflict with LensInfo");
4648
4649 }
4650
4651 }
4652
4653 }
4654
4655 }
4656
4657 // Sanity check on FocalLength.
4658
4659 if (fFocalLength.d)
4660 {
4661
4662 real64 fl = fFocalLength.As_real64 ();
4663
4664 if (fl < 1.0)
4665 {
4666
4667 ReportWarning ("FocalLength is less than 1.0 mm (legal but unlikely)");
4668
4669 }
4670
4671 else if (fLensInfo [0].d && fLensInfo [1].d)
4672 {
4673
4674 real64 minFL = fLensInfo [0].As_real64 ();
4675 real64 maxFL = fLensInfo [1].As_real64 ();
4676
4677 // Allow for wide-angle converters and tele-extenders.
4678
4679 if (fl < minFL * 0.6 ||
4680 fl > maxFL * 2.1)
4681 {
4682
4683 ReportWarning ("Possible FocalLength conflict with LensInfo");
4684
4685 }
4686
4687 }
4688
4689 }
4690
4691 #endif
4692
4693 // Mirror DateTimeOriginal to DateTime.
4694
4695 if (fDateTime.NotValid () && fDateTimeOriginal.IsValid ())
4696 {
4697
4698 fDateTime = fDateTimeOriginal;
4699
4700 }
4701
4702 // Mirror EXIF 2.3 sensitivity tags to ISOSpeedRatings.
4703
4704 if (fISOSpeedRatings [0] == 0 || fISOSpeedRatings [0] == 65535)
4705 {
4706
4707 // Prefer Recommended Exposure Index, then Standard Output Sensitivity, then
4708 // ISO Speed, then Exposure Index.
4709
4710 if (fRecommendedExposureIndex != 0 &&
4711 (fSensitivityType == stRecommendedExposureIndex ||
4712 fSensitivityType == stSOSandREI ||
4713 fSensitivityType == stREIandISOSpeed ||
4714 fSensitivityType == stSOSandREIandISOSpeed))
4715 {
4716
4717 fISOSpeedRatings [0] = fRecommendedExposureIndex;
4718
4719 }
4720
4721 else if (fStandardOutputSensitivity != 0 &&
4722 (fSensitivityType == stStandardOutputSensitivity ||
4723 fSensitivityType == stSOSandREI ||
4724 fSensitivityType == stSOSandISOSpeed ||
4725 fSensitivityType == stSOSandREIandISOSpeed))
4726 {
4727
4728 fISOSpeedRatings [0] = fStandardOutputSensitivity;
4729
4730 }
4731
4732 else if (fISOSpeed != 0 &&
4733 (fSensitivityType == stISOSpeed ||
4734 fSensitivityType == stSOSandISOSpeed ||
4735 fSensitivityType == stREIandISOSpeed ||
4736 fSensitivityType == stSOSandREIandISOSpeed))
4737 {
4738
4739 fISOSpeedRatings [0] = fISOSpeed;
4740
4741 }
4742
4743 }
4744
4745 // Mirror ExposureIndex to ISOSpeedRatings.
4746
4747 if (fExposureIndex.IsValid () && fISOSpeedRatings [0] == 0)
4748 {
4749
4750 fISOSpeedRatings [0] = Round_uint32 (fExposureIndex.As_real64 ());
4751
4752 }
4753
4754 // Kodak sets the GPSAltitudeRef without setting the GPSAltitude.
4755
4756 if (fGPSAltitude.NotValid ())
4757 {
4758
4759 fGPSAltitudeRef = 0xFFFFFFFF;
4760
4761 }
4762
4763 // If there is no valid GPS data, clear the GPS version number.
4764
4765 if (fGPSLatitude [0].NotValid () &&
4766 fGPSLongitude [0].NotValid () &&
4767 fGPSAltitude .NotValid () &&
4768 fGPSTimeStamp [0].NotValid () &&
4769 fGPSDateStamp .IsEmpty ())
4770 {
4771
4772 fGPSVersionID = 0;
4773
4774 }
4775
4776 }
4777
4778 /*****************************************************************************/