File indexing completed on 2025-01-19 03:55:20

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 #ifndef __dng_xmp__
0010 #define __dng_xmp__
0011 
0012 /*****************************************************************************/
0013 
0014 #include "dng_classes.h"
0015 #include "dng_types.h"
0016 #include "dng_xmp_sdk.h"
0017 
0018 /*****************************************************************************/
0019 
0020 class dng_xmp
0021     {
0022 
0023     protected:
0024 
0025         // Sync option bits.
0026 
0027         enum
0028             {
0029             ignoreXMP       = 1,        // Force XMP values to match non-XMP
0030             preferXMP       = 2,        // Prefer XMP values if conflict
0031             preferNonXMP    = 4,        // Prefer non-XMP values if conflict
0032             removeXMP       = 8         // Remove XMP value after syncing
0033             };
0034 
0035         dng_memory_allocator &fAllocator;
0036 
0037         dng_xmp_sdk *fSDK;
0038 
0039     public:
0040 
0041         dng_xmp (dng_memory_allocator &allocator);
0042 
0043         dng_xmp (const dng_xmp &xmp);
0044 
0045         virtual ~dng_xmp ();
0046 
0047         virtual dng_xmp * Clone () const;
0048 
0049         dng_memory_allocator & Allocator () const
0050             {
0051             return fAllocator;
0052             }
0053 
0054         void Parse (dng_host &host,
0055                     const void *buffer,
0056                     uint32 count);
0057 
0058         dng_memory_block * Serialize (bool asPacket = false,
0059                                       uint32 targetBytes = 0,
0060                                       uint32 padBytes = 4096,
0061                                       bool forJPEG = false,
0062                                       bool compact = true) const;
0063 
0064         // Kludge: Due to a bug in Premere Elements 9, we need to pass non-compact XMP
0065         // to the host, until we drop support for this Premere version.  This bug
0066         // is fixed in Premere Elements 10 and later.
0067 
0068         dng_memory_block * SerializeNonCompact () const
0069             {
0070             return Serialize (false,
0071                               0,
0072                               4096,
0073                               false,
0074                               false);
0075             }
0076 
0077         void PackageForJPEG (AutoPtr<dng_memory_block> &stdBlock,
0078                              AutoPtr<dng_memory_block> &extBlock,
0079                              dng_string &extDigest) const;
0080 
0081         void MergeFromJPEG (const dng_xmp &xmp);
0082 
0083         bool HasMeta () const;
0084 
0085         void RequireMeta ()
0086             {
0087             fSDK->RequireMeta ();
0088             }
0089 
0090         void * GetPrivateMeta ();
0091 
0092         bool Exists (const char *ns,
0093                      const char *path) const;
0094 
0095         bool HasNameSpace (const char *ns) const;
0096 
0097         bool IteratePaths (IteratePathsCallback *callback,
0098                            void *callbackData,
0099                            const char *ns = 0,
0100                            const char *path = 0);
0101 
0102         void Remove (const char *ns,
0103                      const char *path);
0104 
0105         void RemoveProperties (const char *ns);
0106 
0107         void RemoveEmptyStringOrArray (const char *ns,
0108                                        const char *path);
0109 
0110         void RemoveEmptyStringsAndArrays (const char *ns = 0);
0111 
0112         void Set (const char *ns,
0113                   const char *path,
0114                   const char *text);
0115 
0116         bool GetString (const char *ns,
0117                         const char *path,
0118                         dng_string &s) const;
0119 
0120         void SetString (const char *ns,
0121                         const char *path,
0122                         const dng_string &s);
0123 
0124         bool GetStringList (const char *ns,
0125                             const char *path,
0126                             dng_string_list &list) const;
0127 
0128         void SetStringList (const char *ns,
0129                             const char *path,
0130                             const dng_string_list &list,
0131                             bool isBag = false);
0132 
0133         void SetStructField (const char *ns,
0134                              const char *path,
0135                              const char *fieldNS,
0136                              const char *fieldName,
0137                              const dng_string &s);
0138 
0139         void SetStructField (const char *ns,
0140                              const char *path,
0141                              const char *fieldNS,
0142                              const char *fieldName,
0143                              const char *s);
0144 
0145         void DeleteStructField (const char *ns,
0146                                 const char *path,
0147                                 const char *fieldNS,
0148                                 const char *fieldName);
0149 
0150         bool GetStructField (const char *ns,
0151                              const char *path,
0152                              const char *fieldNS,
0153                              const char *fieldName,
0154                              dng_string &s) const;
0155 
0156         void SetAltLangDefault (const char *ns,
0157                                 const char *path,
0158                                 const dng_string &s);
0159 
0160         void SetLocalString (const char *ns,
0161                              const char *path,
0162                              const dng_local_string &s);
0163 
0164         bool GetAltLangDefault (const char *ns,
0165                                 const char *path,
0166                                 dng_string &s,
0167                                 bool silent = false) const;
0168 
0169         bool GetLocalString (const char *ns,
0170                              const char *path,
0171                              dng_local_string &s) const;
0172 
0173         bool GetBoolean (const char *ns,
0174                          const char *path,
0175                          bool &x) const;
0176 
0177         void SetBoolean (const char *ns,
0178                          const char *path,
0179                          bool x);
0180 
0181         bool Get_int32 (const char *ns,
0182                         const char *path,
0183                         int32 &x) const;
0184 
0185         void Set_int32 (const char *ns,
0186                         const char *path,
0187                         int32 x,
0188                         bool usePlus = false);
0189 
0190         bool Get_uint32 (const char *ns,
0191                          const char *path,
0192                          uint32 &x) const;
0193 
0194         void Set_uint32 (const char *ns,
0195                          const char *path,
0196                          uint32 x);
0197 
0198         bool Get_real64 (const char *ns,
0199                          const char *path,
0200                          real64 &x) const;
0201 
0202         void Set_real64 (const char *ns,
0203                          const char *path,
0204                          real64 x,
0205                          uint32 places = 6,
0206                          bool trim = true,
0207                          bool usePlus = false);
0208 
0209         bool Get_urational (const char *ns,
0210                             const char *path,
0211                             dng_urational &r) const;
0212 
0213         void Set_urational (const char *ns,
0214                             const char *path,
0215                             const dng_urational &r);
0216 
0217         bool Get_srational (const char *ns,
0218                             const char *path,
0219                             dng_srational &r) const;
0220 
0221         void Set_srational (const char *ns,
0222                             const char *path,
0223                             const dng_srational &r);
0224 
0225         bool GetFingerprint (const char *ns,
0226                              const char *path,
0227                              dng_fingerprint &print) const;
0228 
0229         void SetFingerprint (const char *ns,
0230                              const char *path,
0231                              const dng_fingerprint &print,
0232                              bool allowInvalid = false);
0233 
0234         void SetVersion2to4 (const char *ns,
0235                              const char *path,
0236                              uint32 version);
0237 
0238         dng_fingerprint GetIPTCDigest () const;
0239 
0240         void SetIPTCDigest (dng_fingerprint &digest);
0241 
0242         void ClearIPTCDigest ();
0243 
0244         void IngestIPTC (dng_metadata &metadata,
0245                          bool xmpIsNewer = false);
0246 
0247         void RebuildIPTC (dng_metadata &metadata,
0248                           dng_memory_allocator &allocator,
0249                           bool padForTIFF);
0250 
0251         virtual void SyncExif (dng_exif &exif,
0252                                const dng_exif *originalExif = NULL,
0253                                bool doingUpdateFromXMP = false,
0254                                bool removeFromXMP = false);
0255 
0256         void ValidateStringList (const char *ns,
0257                                  const char *path);
0258 
0259         void ValidateMetadata ();
0260 
0261         void UpdateDateTime (const dng_date_time_info &dt);
0262 
0263         void UpdateMetadataDate (const dng_date_time_info &dt);
0264 
0265         void UpdateExifDates (dng_exif &exif,
0266                               bool removeFromXMP = false);
0267 
0268         bool HasOrientation () const;
0269 
0270         dng_orientation GetOrientation () const;
0271 
0272         void ClearOrientation ();
0273 
0274         void SetOrientation (const dng_orientation &orientation);
0275 
0276         void SyncOrientation (dng_negative &negative,
0277                               bool xmpIsMaster);
0278             // FIX_ME_API: Backwards compatibility
0279 
0280         void SyncOrientation (dng_metadata &metadata,
0281                               bool xmpIsMaster);
0282 
0283         void ClearImageInfo ();
0284 
0285         void SetImageSize (const dng_point &size);
0286 
0287         void SetSampleInfo (uint32 samplesPerPixel,
0288                             uint32 bitsPerSample);
0289 
0290         void SetPhotometricInterpretation (uint32 pi);
0291 
0292         void SetResolution (const dng_resolution &res);
0293 
0294         void ComposeArrayItemPath (const char *ns,
0295                                    const char *arrayName,
0296                                    int32 itemNumber,
0297                                    dng_string &s) const;
0298 
0299         void ComposeStructFieldPath (const char *ns,
0300                                      const char *structName,
0301                                      const char *fieldNS,
0302                                      const char *fieldName,
0303                                      dng_string &s) const;
0304 
0305         int32 CountArrayItems (const char *ns,
0306                                const char *path) const;
0307 
0308         void AppendArrayItem (const char *ns,
0309                               const char *arrayName,
0310                               const char *itemValue,
0311                               bool isBag = true,
0312                               bool propIsStruct = false);
0313 
0314         static dng_string EncodeFingerprint (const dng_fingerprint &f,
0315                                              bool allowInvalid = false);
0316 
0317         static dng_fingerprint DecodeFingerprint (const dng_string &s);
0318 
0319         #if qDNGXMPDocOps
0320 
0321         void DocOpsOpenXMP (const char *srcMIME);
0322 
0323         void DocOpsPrepareForSave (const char *srcMIME,
0324                                    const char *dstMIME,
0325                                    bool newPath = true);
0326 
0327         void DocOpsUpdateMetadata (const char *srcMIME);
0328 
0329         #endif
0330 
0331     protected:
0332 
0333         static void TrimDecimal (char *s);
0334 
0335         static dng_string EncodeGPSVersion (uint32 version);
0336 
0337         static uint32 DecodeGPSVersion (const dng_string &s);
0338 
0339         static dng_string EncodeGPSCoordinate (const dng_string &ref,
0340                                                const dng_urational *coord);
0341 
0342         static void DecodeGPSCoordinate (const dng_string &s,
0343                                          dng_string &ref,
0344                                          dng_urational *coord);
0345 
0346         static dng_string EncodeGPSDateTime (const dng_string &dateStamp,
0347                                              const dng_urational *timeStamp);
0348 
0349         static void DecodeGPSDateTime (const dng_string &s,
0350                                        dng_string &dateStamp,
0351                                        dng_urational *timeStamp);
0352 
0353         bool SyncString (const char *ns,
0354                          const char *path,
0355                          dng_string &s,
0356                          uint32 options = 0);
0357 
0358         void SyncStringList (const char *ns,
0359                              const char *path,
0360                              dng_string_list &list,
0361                              bool isBag = false,
0362                              uint32 options = 0);
0363 
0364         bool SyncAltLangDefault (const char *ns,
0365                                  const char *path,
0366                                  dng_string &s,
0367                                  uint32 options = 0);
0368 
0369         void Sync_uint32 (const char *ns,
0370                           const char *path,
0371                           uint32 &x,
0372                           bool isDefault = false,
0373                           uint32 options = 0);
0374 
0375         void Sync_uint32_array (const char *ns,
0376                                 const char *path,
0377                                 uint32 *data,
0378                                 uint32 &count,
0379                                 uint32 maxCount,
0380                                 uint32 options = 0);
0381 
0382         void Sync_urational (const char *ns,
0383                              const char *path,
0384                              dng_urational &r,
0385                              uint32 options = 0);
0386 
0387         void Sync_srational (const char *ns,
0388                              const char *path,
0389                              dng_srational &r,
0390                              uint32 options = 0);
0391 
0392         void SyncIPTC (dng_iptc &iptc,
0393                        uint32 options);
0394 
0395         void SyncFlash (uint32 &flashState,
0396                         uint32 &flashMask,
0397                         uint32 options);
0398 
0399         void SyncExifDate (const char *ns,
0400                            const char *path,
0401                            dng_date_time_info &exifDateTime,
0402                            bool canRemoveFromXMP,
0403                            bool removeFromXMP,
0404                            const dng_time_zone &fakeTimeZone);
0405 
0406         virtual void SyncApproximateFocusDistance (dng_exif &exif,
0407                                                    const uint32 readOnly);
0408 
0409         virtual void SyncLensName (dng_exif &exif);
0410 
0411         virtual void GenerateDefaultLensName (dng_exif &exif);
0412 
0413     private:
0414 
0415         // Hidden assignment operator.
0416 
0417         dng_xmp & operator= (const dng_xmp &xmp);
0418 
0419     };
0420 
0421 /*****************************************************************************/
0422 
0423 #endif
0424 
0425 /*****************************************************************************/