File indexing completed on 2025-01-19 03:54:57

0001 /*****************************************************************************/
0002 // Copyright 2006-2019 Adobe Systems Incorporated
0003 // All Rights Reserved.
0004 //
0005 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
0006 // accordance with the terms of the Adobe license agreement accompanying it.
0007 /*****************************************************************************/
0008 
0009 /** \file
0010  * EXIF read access support. See the \ref spec_exif "EXIF specification" for full
0011  * description of tags.
0012  */
0013 
0014 /*****************************************************************************/
0015 
0016 #ifndef __dng_exif__
0017 #define __dng_exif__
0018 
0019 /*****************************************************************************/
0020 
0021 #include "dng_classes.h"
0022 #include "dng_date_time.h"
0023 #include "dng_fingerprint.h"
0024 #include "dng_types.h"
0025 #include "dng_matrix.h"
0026 #include "dng_rational.h"
0027 #include "dng_string.h"
0028 #include "dng_stream.h"
0029 #include "dng_sdk_limits.h"
0030 
0031 /*****************************************************************************/
0032 
0033 /// \brief Container class for parsing and holding EXIF tags.
0034 ///
0035 /// Public member fields are documented in \ref spec_exif "EXIF specification."
0036 
0037 class dng_exif
0038     {
0039 
0040     public:
0041 
0042         dng_string fImageDescription;
0043         dng_string fMake;
0044         dng_string fModel;
0045         dng_string fSoftware;
0046         dng_string fArtist;
0047         dng_string fCopyright;
0048         dng_string fCopyright2;
0049         dng_string fUserComment;
0050 
0051         dng_date_time_info         fDateTime;
0052         dng_date_time_storage_info fDateTimeStorageInfo;
0053 
0054         dng_date_time_info         fDateTimeOriginal;
0055         dng_date_time_storage_info fDateTimeOriginalStorageInfo;
0056 
0057         dng_date_time_info         fDateTimeDigitized;
0058         dng_date_time_storage_info fDateTimeDigitizedStorageInfo;
0059 
0060         uint32 fTIFF_EP_StandardID;
0061         uint32 fExifVersion;
0062         uint32 fFlashPixVersion;
0063 
0064         dng_urational fExposureTime;
0065         dng_urational fFNumber;
0066         dng_srational fShutterSpeedValue;
0067         dng_urational fApertureValue;
0068         dng_srational fBrightnessValue;
0069         dng_srational fExposureBiasValue;
0070         dng_urational fMaxApertureValue;
0071         dng_urational fFocalLength;
0072         dng_urational fDigitalZoomRatio;
0073         dng_urational fExposureIndex;
0074         dng_urational fSubjectDistance;
0075         dng_urational fGamma;
0076 
0077         dng_urational fBatteryLevelR;
0078         dng_string    fBatteryLevelA;
0079 
0080         uint32 fExposureProgram;
0081         uint32 fMeteringMode;
0082         uint32 fLightSource;
0083         uint32 fFlash;
0084         uint32 fFlashMask;
0085         uint32 fSensingMethod;
0086         uint32 fColorSpace;
0087         uint32 fFileSource;
0088         uint32 fSceneType;
0089         uint32 fCustomRendered;
0090         uint32 fExposureMode;
0091         uint32 fWhiteBalance;
0092         uint32 fSceneCaptureType;
0093         uint32 fGainControl;
0094         uint32 fContrast;
0095         uint32 fSaturation;
0096         uint32 fSharpness;
0097         uint32 fSubjectDistanceRange;
0098         uint32 fSelfTimerMode;
0099         uint32 fImageNumber;
0100 
0101         uint32 fFocalLengthIn35mmFilm;
0102 
0103         uint32 fISOSpeedRatings [3];         // EXIF 2.3: PhotographicSensitivity.
0104 
0105         // Sensitivity tags added in EXIF 2.3.
0106 
0107         uint32 fSensitivityType;
0108         uint32 fStandardOutputSensitivity;
0109         uint32 fRecommendedExposureIndex;
0110         uint32 fISOSpeed;
0111         uint32 fISOSpeedLatitudeyyy;
0112         uint32 fISOSpeedLatitudezzz;
0113 
0114         uint32 fSubjectAreaCount;
0115         uint32 fSubjectArea [4];
0116 
0117         uint32 fComponentsConfiguration;
0118 
0119         dng_urational fCompresssedBitsPerPixel;
0120 
0121         uint32 fPixelXDimension;
0122         uint32 fPixelYDimension;
0123 
0124         dng_urational fFocalPlaneXResolution;
0125         dng_urational fFocalPlaneYResolution;
0126 
0127         uint32 fFocalPlaneResolutionUnit;
0128 
0129         uint32 fCFARepeatPatternRows;
0130         uint32 fCFARepeatPatternCols;
0131 
0132         uint8 fCFAPattern [kMaxCFAPattern] [kMaxCFAPattern];
0133 
0134         dng_fingerprint fImageUniqueID;
0135 
0136         uint32        fGPSVersionID;
0137         dng_string    fGPSLatitudeRef;
0138         dng_urational fGPSLatitude [3];
0139         dng_string    fGPSLongitudeRef;
0140         dng_urational fGPSLongitude [3];
0141         uint32        fGPSAltitudeRef;
0142         dng_urational fGPSAltitude;
0143         dng_urational fGPSTimeStamp [3];
0144         dng_string    fGPSSatellites;
0145         dng_string    fGPSStatus;
0146         dng_string    fGPSMeasureMode;
0147         dng_urational fGPSDOP;
0148         dng_string    fGPSSpeedRef;
0149         dng_urational fGPSSpeed;
0150         dng_string    fGPSTrackRef;
0151         dng_urational fGPSTrack;
0152         dng_string    fGPSImgDirectionRef;
0153         dng_urational fGPSImgDirection;
0154         dng_string    fGPSMapDatum;
0155         dng_string    fGPSDestLatitudeRef;
0156         dng_urational fGPSDestLatitude [3];
0157         dng_string    fGPSDestLongitudeRef;
0158         dng_urational fGPSDestLongitude [3];
0159         dng_string    fGPSDestBearingRef;
0160         dng_urational fGPSDestBearing;
0161         dng_string    fGPSDestDistanceRef;
0162         dng_urational fGPSDestDistance;
0163         dng_string    fGPSProcessingMethod;
0164         dng_string    fGPSAreaInformation;
0165         dng_string    fGPSDateStamp;
0166         uint32        fGPSDifferential;
0167         dng_urational fGPSHPositioningError;
0168 
0169         dng_string fInteroperabilityIndex;
0170 
0171         uint32 fInteroperabilityVersion;
0172 
0173         dng_string fRelatedImageFileFormat;
0174 
0175         uint32 fRelatedImageWidth;
0176         uint32 fRelatedImageLength;
0177 
0178         dng_string fCameraSerialNumber;      // EXIF 2.3: BodySerialNumber.
0179 
0180         dng_urational fLensInfo [4];         // EXIF 2.3: LensSpecification.
0181 
0182         dng_string fLensID;
0183         dng_string fLensMake;
0184         dng_string fLensName;                // EXIF 2.3: LensModel.
0185         dng_string fLensSerialNumber;
0186 
0187         // Was the lens name field read from a LensModel tag?
0188 
0189         bool fLensNameWasReadFromExif;
0190 
0191         // Private field to hold the approximate focus distance of the lens, in
0192         // meters. This value is often coarsely measured/reported and hence should be
0193         // interpreted only as a rough estimate of the true distance from the plane
0194         // of focus (in object space) to the focal plane. It is still useful for the
0195         // purposes of applying lens corrections.
0196 
0197         dng_urational fApproxFocusDistance;
0198 
0199         dng_srational fFlashCompensation;
0200 
0201         dng_string fOwnerName;               // EXIF 2.3: CameraOwnerName.
0202         dng_string fFirmware;
0203 
0204         // EXIF 2.3.1:
0205 
0206         dng_srational fTemperature;
0207         dng_urational fHumidity;
0208         dng_urational fPressure;
0209         dng_srational fWaterDepth;
0210         dng_urational fAcceleration;
0211         dng_srational fCameraElevationAngle;
0212 
0213         // Not really part of EXIF, but some formats may use.
0214 
0215         dng_string fTitle;
0216 
0217         // Image-specific radial distortion correction metadata that can be
0218         // used later during (UI-driven) lens profile corrections. Same model
0219         // as DNG opcode model.
0220 
0221         dng_srational fLensDistortInfo [4];
0222 
0223     public:
0224 
0225         dng_exif ();
0226 
0227         virtual ~dng_exif ();
0228 
0229         /// Make clone.
0230 
0231         virtual dng_exif * Clone () const;
0232 
0233         /// Clear all EXIF fields.
0234 
0235         void SetEmpty ();
0236 
0237         /// Copy all GPS-related fields.
0238         /// \param exif Source object from which to copy GPS fields.
0239 
0240         void CopyGPSFrom (const dng_exif &exif);
0241 
0242         /// Utility to fix up common errors and rounding issues with EXIF exposure
0243         /// times.
0244 
0245         static real64 SnapExposureTime (real64 et);
0246 
0247         /// Set exposure time and shutter speed fields. Optionally fix up common
0248         /// errors and rounding issues with EXIF exposure times.
0249         /// \param et Exposure time in seconds.
0250         /// \param snap Set to true to fix up common errors and rounding issues with
0251         /// EXIF exposure times.
0252 
0253         void SetExposureTime (real64 et,
0254                               bool snap = true);
0255 
0256         /// Set shutter speed value (APEX units) and exposure time.
0257         /// \param ss Shutter speed in APEX units.
0258 
0259         void SetShutterSpeedValue (real64 ss);
0260 
0261         /// Utility to encode f-number as a rational.
0262         /// \param fs The f-number to encode.
0263 
0264         static dng_urational EncodeFNumber (real64 fs);
0265 
0266         /// Set the FNumber and ApertureValue fields.
0267         /// \param fs The f-number to set.
0268 
0269         void SetFNumber (real64 fs);
0270 
0271         /// Set the FNumber and ApertureValue fields.
0272         /// \param av The aperture value (APEX units).
0273 
0274         void SetApertureValue (real64 av);
0275 
0276         /// Utility to convert aperture value (APEX units) to f-number.
0277         /// \param av The aperture value (APEX units) to convert.
0278 
0279         static real64 ApertureValueToFNumber (real64 av);
0280 
0281         /// Utility to convert aperture value (APEX units) to f-number.
0282         /// \param av The aperture value (APEX units) to convert.
0283 
0284         static real64 ApertureValueToFNumber (const dng_urational &av);
0285 
0286         /// Utility to convert f-number to aperture value (APEX units).
0287         /// \param fNumber The f-number to convert.
0288 
0289         static real64 FNumberToApertureValue (real64 fNumber);
0290 
0291         /// Utility to convert f-number to aperture value (APEX units).
0292         /// \param fNumber The f-number to convert.
0293 
0294         static real64 FNumberToApertureValue (const dng_urational &fNumber);
0295 
0296         /// Set the DateTime field.
0297         /// \param dt The DateTime value.
0298 
0299         void UpdateDateTime (const dng_date_time_info &dt);
0300 
0301         /// Returns true iff the EXIF version is at least 2.3.
0302 
0303         bool AtLeastVersion0230 () const;
0304 
0305         /// Returns true iff the EXIF version is at least 2.3.1.
0306 
0307         bool AtLeastVersion0231 () const;
0308 
0309         /// Sets the EXIF version to 2.3.1.
0310 
0311         void SetVersion0231 ();
0312 
0313         bool HasLensDistortInfo () const;
0314 
0315         void SetLensDistortInfo (const dng_vector &params);
0316 
0317         virtual bool ParseTag (dng_stream &stream,
0318                                dng_shared &shared,
0319                                uint32 parentCode,
0320                                bool isMainIFD,
0321                                uint32 tagCode,
0322                                uint32 tagType,
0323                                uint32 tagCount,
0324                                uint64 tagOffset);
0325 
0326         virtual void PostParse (dng_host &host,
0327                                 dng_shared &shared);
0328 
0329     protected:
0330 
0331         virtual bool Parse_ifd0 (dng_stream &stream,
0332                                  dng_shared &shared,
0333                                  uint32 parentCode,
0334                                  uint32 tagCode,
0335                                  uint32 tagType,
0336                                  uint32 tagCount,
0337                                  uint64 tagOffset);
0338 
0339         virtual bool Parse_ifd0_main (dng_stream &stream,
0340                                       dng_shared &shared,
0341                                       uint32 parentCode,
0342                                       uint32 tagCode,
0343                                       uint32 tagType,
0344                                       uint32 tagCount,
0345                                       uint64 tagOffset);
0346 
0347         virtual bool Parse_ifd0_exif (dng_stream &stream,
0348                                       dng_shared &shared,
0349                                       uint32 parentCode,
0350                                       uint32 tagCode,
0351                                       uint32 tagType,
0352                                       uint32 tagCount,
0353                                       uint64 tagOffset);
0354 
0355         virtual bool Parse_gps (dng_stream &stream,
0356                                 dng_shared &shared,
0357                                 uint32 parentCode,
0358                                 uint32 tagCode,
0359                                 uint32 tagType,
0360                                 uint32 tagCount,
0361                                 uint64 tagOffset);
0362 
0363         virtual bool Parse_interoperability (dng_stream &stream,
0364                                              dng_shared &shared,
0365                                              uint32 parentCode,
0366                                              uint32 tagCode,
0367                                              uint32 tagType,
0368                                              uint32 tagCount,
0369                                              uint64 tagOffset);
0370 
0371     };
0372 
0373 /*****************************************************************************/
0374 
0375 #endif
0376 
0377 /*****************************************************************************/