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 /** \file
10  * EXIF read access support. See the \ref spec_exif "EXIF specification" for full
11  * description of tags.
12  */
13 
14 /*****************************************************************************/
15 
16 #ifndef __dng_exif__
17 #define __dng_exif__
18 
19 /*****************************************************************************/
20 
21 #include "dng_classes.h"
22 #include "dng_date_time.h"
23 #include "dng_fingerprint.h"
24 #include "dng_types.h"
25 #include "dng_matrix.h"
26 #include "dng_rational.h"
27 #include "dng_string.h"
28 #include "dng_stream.h"
29 #include "dng_sdk_limits.h"
30 
31 /*****************************************************************************/
32 
33 /// \brief Container class for parsing and holding EXIF tags.
34 ///
35 /// Public member fields are documented in \ref spec_exif "EXIF specification."
36 
37 class dng_exif
38 	{
39 
40 	public:
41 
42 		dng_string fImageDescription;
43 		dng_string fMake;
44 		dng_string fModel;
45 		dng_string fSoftware;
46 		dng_string fArtist;
47 		dng_string fCopyright;
48 		dng_string fCopyright2;
49 		dng_string fUserComment;
50 
51 		dng_date_time_info         fDateTime;
52 		dng_date_time_storage_info fDateTimeStorageInfo;
53 
54 		dng_date_time_info		   fDateTimeOriginal;
55 		dng_date_time_storage_info fDateTimeOriginalStorageInfo;
56 
57 		dng_date_time_info 		   fDateTimeDigitized;
58 		dng_date_time_storage_info fDateTimeDigitizedStorageInfo;
59 
60 		uint32 fTIFF_EP_StandardID;
61 		uint32 fExifVersion;
62 		uint32 fFlashPixVersion;
63 
64 		dng_urational fExposureTime;
65 		dng_urational fFNumber;
66 		dng_srational fShutterSpeedValue;
67 		dng_urational fApertureValue;
68 		dng_srational fBrightnessValue;
69 		dng_srational fExposureBiasValue;
70 		dng_urational fMaxApertureValue;
71 		dng_urational fFocalLength;
72 		dng_urational fDigitalZoomRatio;
73 		dng_urational fExposureIndex;
74 		dng_urational fSubjectDistance;
75 		dng_urational fGamma;
76 
77 		dng_urational fBatteryLevelR;
78 		dng_string    fBatteryLevelA;
79 
80 		uint32 fExposureProgram;
81 		uint32 fMeteringMode;
82 		uint32 fLightSource;
83 		uint32 fFlash;
84 		uint32 fFlashMask;
85 		uint32 fSensingMethod;
86 		uint32 fColorSpace;
87 		uint32 fFileSource;
88 		uint32 fSceneType;
89 		uint32 fCustomRendered;
90 		uint32 fExposureMode;
91 		uint32 fWhiteBalance;
92 		uint32 fSceneCaptureType;
93 		uint32 fGainControl;
94 		uint32 fContrast;
95 		uint32 fSaturation;
96 		uint32 fSharpness;
97 		uint32 fSubjectDistanceRange;
98 		uint32 fSelfTimerMode;
99 		uint32 fImageNumber;
100 
101 		uint32 fFocalLengthIn35mmFilm;
102 
103 		uint32 fISOSpeedRatings [3];		 // EXIF 2.3: PhotographicSensitivity.
104 
105 		// Sensitivity tags added in EXIF 2.3.
106 
107 		uint32 fSensitivityType;
108 		uint32 fStandardOutputSensitivity;
109 		uint32 fRecommendedExposureIndex;
110 		uint32 fISOSpeed;
111 		uint32 fISOSpeedLatitudeyyy;
112 		uint32 fISOSpeedLatitudezzz;
113 
114 		uint32 fSubjectAreaCount;
115 		uint32 fSubjectArea [4];
116 
117 		uint32 fComponentsConfiguration;
118 
119 		dng_urational fCompresssedBitsPerPixel;
120 
121 		uint32 fPixelXDimension;
122 		uint32 fPixelYDimension;
123 
124 		dng_urational fFocalPlaneXResolution;
125 		dng_urational fFocalPlaneYResolution;
126 
127 		uint32 fFocalPlaneResolutionUnit;
128 
129 		uint32 fCFARepeatPatternRows;
130 		uint32 fCFARepeatPatternCols;
131 
132 		uint8 fCFAPattern [kMaxCFAPattern] [kMaxCFAPattern];
133 
134 		dng_fingerprint fImageUniqueID;
135 
136 		uint32 	      fGPSVersionID;
137 		dng_string    fGPSLatitudeRef;
138 		dng_urational fGPSLatitude [3];
139 		dng_string    fGPSLongitudeRef;
140 		dng_urational fGPSLongitude [3];
141 		uint32	      fGPSAltitudeRef;
142 		dng_urational fGPSAltitude;
143 		dng_urational fGPSTimeStamp [3];
144 		dng_string    fGPSSatellites;
145 		dng_string    fGPSStatus;
146 		dng_string    fGPSMeasureMode;
147 		dng_urational fGPSDOP;
148 		dng_string    fGPSSpeedRef;
149 		dng_urational fGPSSpeed;
150 		dng_string    fGPSTrackRef;
151 		dng_urational fGPSTrack;
152 		dng_string    fGPSImgDirectionRef;
153 		dng_urational fGPSImgDirection;
154 		dng_string    fGPSMapDatum;
155 		dng_string    fGPSDestLatitudeRef;
156 		dng_urational fGPSDestLatitude [3];
157 		dng_string    fGPSDestLongitudeRef;
158 		dng_urational fGPSDestLongitude [3];
159 		dng_string    fGPSDestBearingRef;
160 		dng_urational fGPSDestBearing;
161 		dng_string    fGPSDestDistanceRef;
162 		dng_urational fGPSDestDistance;
163 		dng_string    fGPSProcessingMethod;
164 		dng_string    fGPSAreaInformation;
165 		dng_string    fGPSDateStamp;
166 		uint32 	      fGPSDifferential;
167 		dng_urational fGPSHPositioningError;
168 
169 		dng_string fInteroperabilityIndex;
170 
171 		uint32 fInteroperabilityVersion;
172 
173 		dng_string fRelatedImageFileFormat;
174 
175 		uint32 fRelatedImageWidth;
176 		uint32 fRelatedImageLength;
177 
178 		dng_string fCameraSerialNumber;		 // EXIF 2.3: BodySerialNumber.
179 
180 		dng_urational fLensInfo [4];		 // EXIF 2.3: LensSpecification.
181 
182 		dng_string fLensID;
183 		dng_string fLensMake;
184 		dng_string fLensName;				 // EXIF 2.3: LensModel.
185 		dng_string fLensSerialNumber;
186 
187 		// Was the lens name field read from a LensModel tag?
188 
189 		bool fLensNameWasReadFromExif;
190 
191 		// Private field to hold the approximate focus distance of the lens, in
192 		// meters. This value is often coarsely measured/reported and hence should be
193 		// interpreted only as a rough estimate of the true distance from the plane
194 		// of focus (in object space) to the focal plane. It is still useful for the
195 		// purposes of applying lens corrections.
196 
197 		dng_urational fApproxFocusDistance;
198 
199 		dng_srational fFlashCompensation;
200 
201 		dng_string fOwnerName;				 // EXIF 2.3: CameraOwnerName.
202 		dng_string fFirmware;
203 
204         // EXIF 2.3.1:
205 
206         dng_srational fTemperature;
207         dng_urational fHumidity;
208         dng_urational fPressure;
209         dng_srational fWaterDepth;
210         dng_urational fAcceleration;
211         dng_srational fCameraElevationAngle;
212 
213         // Not really part of EXIF, but some formats may use.
214 
215         dng_string fTitle;
216 
217 		// Image-specific radial distortion correction metadata that can be
218 		// used later during (UI-driven) lens profile corrections. Same model
219 		// as DNG opcode model.
220 
221 		dng_srational fLensDistortInfo [4];
222 
223 	public:
224 
225 		dng_exif ();
226 
227 		virtual ~dng_exif ();
228 
229 		/// Make clone.
230 
231 		virtual dng_exif * Clone () const;
232 
233 		/// Clear all EXIF fields.
234 
235 		void SetEmpty ();
236 
237 		/// Copy all GPS-related fields.
238 		/// \param exif Source object from which to copy GPS fields.
239 
240 		void CopyGPSFrom (const dng_exif &exif);
241 
242 		/// Utility to fix up common errors and rounding issues with EXIF exposure
243 		/// times.
244 
245 		static real64 SnapExposureTime (real64 et);
246 
247 		/// Set exposure time and shutter speed fields. Optionally fix up common
248 		/// errors and rounding issues with EXIF exposure times.
249 		/// \param et Exposure time in seconds.
250 		/// \param snap Set to true to fix up common errors and rounding issues with
251 		/// EXIF exposure times.
252 
253 		void SetExposureTime (real64 et,
254 							  bool snap = true);
255 
256 		/// Set shutter speed value (APEX units) and exposure time.
257 		/// \param ss Shutter speed in APEX units.
258 
259 		void SetShutterSpeedValue (real64 ss);
260 
261 		/// Utility to encode f-number as a rational.
262 		/// \param fs The f-number to encode.
263 
264 		static dng_urational EncodeFNumber (real64 fs);
265 
266 		/// Set the FNumber and ApertureValue fields.
267 		/// \param fs The f-number to set.
268 
269 		void SetFNumber (real64 fs);
270 
271 		/// Set the FNumber and ApertureValue fields.
272 		/// \param av The aperture value (APEX units).
273 
274 		void SetApertureValue (real64 av);
275 
276 		/// Utility to convert aperture value (APEX units) to f-number.
277 		/// \param av The aperture value (APEX units) to convert.
278 
279 		static real64 ApertureValueToFNumber (real64 av);
280 
281 		/// Utility to convert aperture value (APEX units) to f-number.
282 		/// \param av The aperture value (APEX units) to convert.
283 
284 		static real64 ApertureValueToFNumber (const dng_urational &av);
285 
286 		/// Utility to convert f-number to aperture value (APEX units).
287 		/// \param fNumber The f-number to convert.
288 
289 		static real64 FNumberToApertureValue (real64 fNumber);
290 
291 		/// Utility to convert f-number to aperture value (APEX units).
292 		/// \param fNumber The f-number to convert.
293 
294 		static real64 FNumberToApertureValue (const dng_urational &fNumber);
295 
296 		/// Set the DateTime field.
297 		/// \param dt The DateTime value.
298 
299 		void UpdateDateTime (const dng_date_time_info &dt);
300 
301 		/// Returns true iff the EXIF version is at least 2.3.
302 
303 		bool AtLeastVersion0230 () const;
304 
305         /// Returns true iff the EXIF version is at least 2.3.1.
306 
307         bool AtLeastVersion0231 () const;
308 
309         /// Sets the EXIF version to 2.3.1.
310 
311         void SetVersion0231 ();
312 
313 		bool HasLensDistortInfo () const;
314 
315 		void SetLensDistortInfo (const dng_vector &params);
316 
317 		virtual bool ParseTag (dng_stream &stream,
318 							   dng_shared &shared,
319 							   uint32 parentCode,
320 							   bool isMainIFD,
321 							   uint32 tagCode,
322 							   uint32 tagType,
323 							   uint32 tagCount,
324 							   uint64 tagOffset);
325 
326 		virtual void PostParse (dng_host &host,
327 								dng_shared &shared);
328 
329 	protected:
330 
331 		virtual bool Parse_ifd0 (dng_stream &stream,
332 							     dng_shared &shared,
333 							 	 uint32 parentCode,
334 							 	 uint32 tagCode,
335 							 	 uint32 tagType,
336 							 	 uint32 tagCount,
337 							 	 uint64 tagOffset);
338 
339 		virtual bool Parse_ifd0_main (dng_stream &stream,
340 							          dng_shared &shared,
341 						 		 	  uint32 parentCode,
342 						 		 	  uint32 tagCode,
343 						 		 	  uint32 tagType,
344 						 		 	  uint32 tagCount,
345 						 		 	  uint64 tagOffset);
346 
347 		virtual bool Parse_ifd0_exif (dng_stream &stream,
348 							          dng_shared &shared,
349 						 		 	  uint32 parentCode,
350 						 		 	  uint32 tagCode,
351 						 		 	  uint32 tagType,
352 						 		 	  uint32 tagCount,
353 						 		 	  uint64 tagOffset);
354 
355 		virtual bool Parse_gps (dng_stream &stream,
356 							    dng_shared &shared,
357 						 		uint32 parentCode,
358 						 		uint32 tagCode,
359 						 		uint32 tagType,
360 						 		uint32 tagCount,
361 						 		uint64 tagOffset);
362 
363 		virtual bool Parse_interoperability (dng_stream &stream,
364 							    			 dng_shared &shared,
365 						 					 uint32 parentCode,
366 											 uint32 tagCode,
367 											 uint32 tagType,
368 											 uint32 tagCount,
369 											 uint64 tagOffset);
370 
371 	};
372 
373 /*****************************************************************************/
374 
375 #endif
376 
377 /*****************************************************************************/
378