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