dng_xmp.h revision ffee7a66caebb7027d7591405e8494e3c9e8517e
1/*****************************************************************************/ 2// Copyright 2006-2011 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/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_xmp.h#1 $ */ 10/* $DateTime: 2012/05/30 13:28:51 $ */ 11/* $Change: 832332 $ */ 12/* $Author: tknoll $ */ 13 14/*****************************************************************************/ 15 16#ifndef __dng_xmp__ 17#define __dng_xmp__ 18 19/*****************************************************************************/ 20 21#include "dng_classes.h" 22#include "dng_types.h" 23#include "dng_xmp_sdk.h" 24 25/*****************************************************************************/ 26 27class dng_xmp 28 { 29 30 protected: 31 32 // Sync option bits. 33 34 enum 35 { 36 ignoreXMP = 1, // Force XMP values to match non-XMP 37 preferXMP = 2, // Prefer XMP values if conflict 38 preferNonXMP = 4, // Prefer non-XMP values if conflict 39 removeXMP = 8 // Remove XMP value after syncing 40 }; 41 42 dng_memory_allocator &fAllocator; 43 44 dng_xmp_sdk *fSDK; 45 46 public: 47 48 dng_xmp (dng_memory_allocator &allocator); 49 50 dng_xmp (const dng_xmp &xmp); 51 52 virtual ~dng_xmp (); 53 54 virtual dng_xmp * Clone () const; 55 56 void Parse (dng_host &host, 57 const void *buffer, 58 uint32 count); 59 60 dng_memory_block * Serialize (bool asPacket = false, 61 uint32 targetBytes = 0, 62 uint32 padBytes = 4096, 63 bool forJPEG = false, 64 bool compact = true) const; 65 66 // Kludge: Due to a bug in Premere Elements 9, we need to pass non-compact XMP 67 // to the host, until we drop support for this Premere version. This bug 68 // is fixed in Premere Elements 10 and later. 69 70 dng_memory_block * SerializeNonCompact () const 71 { 72 return Serialize (false, 73 0, 74 4096, 75 false, 76 false); 77 } 78 79 void PackageForJPEG (AutoPtr<dng_memory_block> &stdBlock, 80 AutoPtr<dng_memory_block> &extBlock, 81 dng_string &extDigest) const; 82 83 void MergeFromJPEG (const dng_xmp &xmp); 84 85 bool HasMeta () const; 86 87 void * GetPrivateMeta (); 88 89 bool Exists (const char *ns, 90 const char *path) const; 91 92 bool HasNameSpace (const char *ns) const; 93 94 bool IteratePaths (IteratePathsCallback *callback, 95 void *callbackData, 96 const char *ns = 0, 97 const char *path = 0); 98 99 void Remove (const char *ns, 100 const char *path); 101 102 void RemoveProperties (const char *ns); 103 104 void RemoveEmptyStringOrArray (const char *ns, 105 const char *path); 106 107 void RemoveEmptyStringsAndArrays (const char *ns = 0); 108 109 void Set (const char *ns, 110 const char *path, 111 const char *text); 112 113 bool GetString (const char *ns, 114 const char *path, 115 dng_string &s) const; 116 117 void SetString (const char *ns, 118 const char *path, 119 const dng_string &s); 120 121 bool GetStringList (const char *ns, 122 const char *path, 123 dng_string_list &list) const; 124 125 void SetStringList (const char *ns, 126 const char *path, 127 const dng_string_list &list, 128 bool isBag = false); 129 130 void SetStructField (const char *ns, 131 const char *path, 132 const char *fieldNS, 133 const char *fieldName, 134 const dng_string &s); 135 136 void SetStructField (const char *ns, 137 const char *path, 138 const char *fieldNS, 139 const char *fieldName, 140 const char *s); 141 142 void DeleteStructField (const char *ns, 143 const char *path, 144 const char *fieldNS, 145 const char *fieldName); 146 147 bool GetStructField (const char *ns, 148 const char *path, 149 const char *fieldNS, 150 const char *fieldName, 151 dng_string &s) const; 152 153 void SetAltLangDefault (const char *ns, 154 const char *path, 155 const dng_string &s); 156 157 bool GetAltLangDefault (const char *ns, 158 const char *path, 159 dng_string &s) const; 160 161 bool GetBoolean (const char *ns, 162 const char *path, 163 bool &x) const; 164 165 void SetBoolean (const char *ns, 166 const char *path, 167 bool x); 168 169 bool Get_int32 (const char *ns, 170 const char *path, 171 int32 &x) const; 172 173 void Set_int32 (const char *ns, 174 const char *path, 175 int32 x, 176 bool usePlus = false); 177 178 bool Get_uint32 (const char *ns, 179 const char *path, 180 uint32 &x) const; 181 182 void Set_uint32 (const char *ns, 183 const char *path, 184 uint32 x); 185 186 bool Get_real64 (const char *ns, 187 const char *path, 188 real64 &x) const; 189 190 void Set_real64 (const char *ns, 191 const char *path, 192 real64 x, 193 uint32 places = 6, 194 bool trim = true, 195 bool usePlus = false); 196 197 bool Get_urational (const char *ns, 198 const char *path, 199 dng_urational &r) const; 200 201 void Set_urational (const char *ns, 202 const char *path, 203 const dng_urational &r); 204 205 bool Get_srational (const char *ns, 206 const char *path, 207 dng_srational &r) const; 208 209 void Set_srational (const char *ns, 210 const char *path, 211 const dng_srational &r); 212 213 bool GetFingerprint (const char *ns, 214 const char *path, 215 dng_fingerprint &print) const; 216 217 void SetFingerprint (const char *ns, 218 const char *path, 219 const dng_fingerprint &print, 220 bool allowInvalid = false); 221 222 void SetVersion2to4 (const char *ns, 223 const char *path, 224 uint32 version); 225 226 dng_fingerprint GetIPTCDigest () const; 227 228 void SetIPTCDigest (dng_fingerprint &digest); 229 230 void ClearIPTCDigest (); 231 232 void IngestIPTC (dng_metadata &metadata, 233 bool xmpIsNewer = false); 234 235 void RebuildIPTC (dng_metadata &metadata, 236 dng_memory_allocator &allocator, 237 bool padForTIFF); 238 239 virtual void SyncExif (dng_exif &exif, 240 const dng_exif *originalExif = NULL, 241 bool doingUpdateFromXMP = false, 242 bool removeFromXMP = false); 243 244 void ValidateStringList (const char *ns, 245 const char *path); 246 247 void ValidateMetadata (); 248 249 void UpdateDateTime (const dng_date_time_info &dt); 250 251 void UpdateMetadataDate (const dng_date_time_info &dt); 252 253 void UpdateExifDates (dng_exif &exif, 254 bool removeFromXMP = false); 255 256 bool HasOrientation () const; 257 258 dng_orientation GetOrientation () const; 259 260 void ClearOrientation (); 261 262 void SetOrientation (const dng_orientation &orientation); 263 264 void SyncOrientation (dng_negative &negative, 265 bool xmpIsMaster); 266 // FIX_ME_API: Backwards compatibility 267 268 void SyncOrientation (dng_metadata &metadata, 269 bool xmpIsMaster); 270 271 void ClearImageInfo (); 272 273 void SetImageSize (const dng_point &size); 274 275 void SetSampleInfo (uint32 samplesPerPixel, 276 uint32 bitsPerSample); 277 278 void SetPhotometricInterpretation (uint32 pi); 279 280 void SetResolution (const dng_resolution &res); 281 282 void ComposeArrayItemPath (const char *ns, 283 const char *arrayName, 284 int32 itemNumber, 285 dng_string &s) const; 286 287 void ComposeStructFieldPath (const char *ns, 288 const char *structName, 289 const char *fieldNS, 290 const char *fieldName, 291 dng_string &s) const; 292 293 int32 CountArrayItems (const char *ns, 294 const char *path) const; 295 296 void AppendArrayItem (const char *ns, 297 const char *arrayName, 298 const char *itemValue, 299 bool isBag = true, 300 bool propIsStruct = false); 301 302 static dng_string EncodeFingerprint (const dng_fingerprint &f, 303 bool allowInvalid = false); 304 305 static dng_fingerprint DecodeFingerprint (const dng_string &s); 306 307 #if qDNGXMPDocOps 308 309 void DocOpsOpenXMP (const char *srcMIMI); 310 311 void DocOpsPrepareForSave (const char *srcMIMI, 312 const char *dstMIMI, 313 bool newPath = true); 314 315 void DocOpsUpdateMetadata (const char *srcMIMI); 316 317 #endif 318 319 protected: 320 321 static void TrimDecimal (char *s); 322 323 static dng_string EncodeGPSVersion (uint32 version); 324 325 static uint32 DecodeGPSVersion (const dng_string &s); 326 327 static dng_string EncodeGPSCoordinate (const dng_string &ref, 328 const dng_urational *coord); 329 330 static void DecodeGPSCoordinate (const dng_string &s, 331 dng_string &ref, 332 dng_urational *coord); 333 334 static dng_string EncodeGPSDateTime (const dng_string &dateStamp, 335 const dng_urational *timeStamp); 336 337 static void DecodeGPSDateTime (const dng_string &s, 338 dng_string &dateStamp, 339 dng_urational *timeStamp); 340 341 bool SyncString (const char *ns, 342 const char *path, 343 dng_string &s, 344 uint32 options = 0); 345 346 void SyncStringList (const char *ns, 347 const char *path, 348 dng_string_list &list, 349 bool isBag = false, 350 uint32 options = 0); 351 352 bool SyncAltLangDefault (const char *ns, 353 const char *path, 354 dng_string &s, 355 uint32 options = 0); 356 357 void Sync_uint32 (const char *ns, 358 const char *path, 359 uint32 &x, 360 bool isDefault = false, 361 uint32 options = 0); 362 363 void Sync_uint32_array (const char *ns, 364 const char *path, 365 uint32 *data, 366 uint32 &count, 367 uint32 maxCount, 368 uint32 options = 0); 369 370 void Sync_urational (const char *ns, 371 const char *path, 372 dng_urational &r, 373 uint32 options = 0); 374 375 void Sync_srational (const char *ns, 376 const char *path, 377 dng_srational &r, 378 uint32 options = 0); 379 380 void SyncIPTC (dng_iptc &iptc, 381 uint32 options); 382 383 void SyncFlash (uint32 &flashState, 384 uint32 &flashMask, 385 uint32 options); 386 387 bool DateTimeIsDateOnly (const char *ns, 388 const char *path); 389 390 virtual void SyncApproximateFocusDistance (dng_exif &exif, 391 const uint32 readOnly); 392 393 private: 394 395 // Hidden assignment operator. 396 397 dng_xmp & operator= (const dng_xmp &xmp); 398 399 }; 400 401/*****************************************************************************/ 402 403#endif 404 405/*****************************************************************************/ 406