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  * Functions and classes for working with a digital negative (image data and
11  * corresponding metadata).
12  */
13 
14 /*****************************************************************************/
15 
16 #ifndef __dng_negative__
17 #define __dng_negative__
18 
19 /*****************************************************************************/
20 
21 #include "dng_1d_function.h"
22 #include "dng_auto_ptr.h"
23 #include "dng_classes.h"
24 #include "dng_fingerprint.h"
25 #include "dng_image.h"
26 #include "dng_linearization_info.h"
27 #include "dng_matrix.h"
28 #include "dng_mosaic_info.h"
29 #include "dng_mutex.h"
30 #include "dng_opcode_list.h"
31 #include "dng_orientation.h"
32 #include "dng_rational.h"
33 #include "dng_sdk_limits.h"
34 #include "dng_string.h"
35 #include "dng_tag_types.h"
36 #include "dng_tag_values.h"
37 #include "dng_types.h"
38 #include "dng_utils.h"
39 #include "dng_xy_coord.h"
40 
41 #include <vector>
42 
43 /*****************************************************************************/
44 
45 // To prevent using the internal metadata when we meant to use override
46 // metadata, the following definitions allow us to only allow access to
47 // the internal metadata on non-const negatives. This allows the old API
48 // to keep working essentially unchanged provided one does not use const
49 // negatives, but will prevent access to the embedded data on const
50 // negatives.
51 
52 #if 1
53 
54 #define qMetadataOnConst 0
55 #define METACONST
56 
57 #else
58 
59 #define qMetadataOnConst 1
60 #define METACONST const
61 
62 #endif
63 
64 /*****************************************************************************/
65 
66 /// \brief Noise model for photon and sensor read noise, assuming that they are
67 /// independent random variables and spatially invariant.
68 ///
69 /// The noise model is N (x) = sqrt (scale*x + offset), where x represents a linear
70 /// signal value in the range [0,1], and N (x) is the standard deviation (i.e.,
71 /// noise). The parameters scale and offset are both sensor-dependent and
72 /// ISO-dependent. scale must be positive, and offset must be non-negative.
73 
74 class dng_noise_function: public dng_1d_function
75 	{
76 
77 	protected:
78 
79 		real64 fScale;
80 		real64 fOffset;
81 
82 	public:
83 
84 		/// Create empty and invalid noise function.
85 
dng_noise_function()86 		dng_noise_function ()
87 
88 			:	fScale	(0.0)
89 			,	fOffset (0.0)
90 
91 			{
92 
93 			}
94 
95 		/// Create noise function with the specified scale and offset.
96 
dng_noise_function(real64 scale,real64 offset)97 		dng_noise_function (real64 scale,
98 							real64 offset)
99 
100 			:	fScale	(scale)
101 			,	fOffset (offset)
102 
103 			{
104 
105 			}
106 
107 		/// Compute noise (standard deviation) at the specified average signal level
108 		/// x.
109 
Evaluate(real64 x)110 		virtual real64 Evaluate (real64 x) const
111 			{
112 			return sqrt (fScale * x + fOffset);
113 			}
114 
115 		/// The scale (slope, gain) of the noise function.
116 
Scale()117 		real64 Scale () const
118 			{
119 			return fScale;
120 			}
121 
122 		/// The offset (square of the noise floor) of the noise function.
123 
Offset()124 		real64 Offset () const
125 			{
126 			return fOffset;
127 			}
128 
129 		/// Set the scale (slope, gain) of the noise function.
130 
SetScale(real64 scale)131 		void SetScale (real64 scale)
132 			{
133 			fScale = scale;
134 			}
135 
136 		/// Set the offset (square of the noise floor) of the noise function.
137 
SetOffset(real64 offset)138 		void SetOffset (real64 offset)
139 			{
140 			fOffset = offset;
141 			}
142 
143 		/// Is the noise function valid?
144 
IsValid()145 		bool IsValid () const
146 			{
147 			return (fScale > 0.0 && fOffset >= 0.0);
148 			}
149 
150 	};
151 
152 /*****************************************************************************/
153 
154 /// \brief Noise profile for a negative.
155 ///
156 /// For mosaiced negatives, the noise profile describes the approximate noise
157 /// characteristics of a mosaic negative after linearization, but prior to
158 /// demosaicing. For demosaiced negatives (i.e., linear DNGs), the noise profile
159 /// describes the approximate noise characteristics of the image data immediately
160 /// following the demosaic step, prior to the processing of opcode list 3.
161 ///
162 /// A noise profile may contain 1 or N noise functions, where N is the number of
163 /// color planes for the negative. Otherwise the noise profile is considered to be
164 /// invalid for that negative. If the noise profile contains 1 noise function, then
165 /// it is assumed that this single noise function applies to all color planes of the
166 /// negative. Otherwise, the N noise functions map to the N planes of the negative in
167 /// order specified in the CFAPlaneColor tag.
168 
169 class dng_noise_profile
170 	{
171 
172 	protected:
173 
174 		dng_std_vector<dng_noise_function> fNoiseFunctions;
175 
176 	public:
177 
178 		/// Create empty (invalid) noise profile.
179 
180 		dng_noise_profile ();
181 
182 		/// Create noise profile with the specified noise functions (1 per plane).
183 
184 		explicit dng_noise_profile (const dng_std_vector<dng_noise_function> &functions);
185 
186 		/// Is the noise profile valid?
187 
188 		bool IsValid () const;
189 
190 		/// Is the noise profile valid for the specified negative?
191 
192 		bool IsValidForNegative (const dng_negative &negative) const;
193 
194 		/// The noise function for the specified plane.
195 
196 		const dng_noise_function & NoiseFunction (uint32 plane) const;
197 
198 		/// The number of noise functions in this profile.
199 
200 		uint32 NumFunctions () const;
201 
202         /// Equality test.
203 
204         bool operator== (const dng_noise_profile &profile) const;
205 
206         bool operator!= (const dng_noise_profile &profile) const
207             {
208             return !(*this == profile);
209             }
210 
211 	};
212 
213 /*****************************************************************************/
214 
215 /// \brief Main class for holding metadata.
216 
217 class dng_metadata
218 	{
219 
220 	private:
221 
222 		// Base orientation of both the thumbnail and raw data. This is
223 		// generally based on the EXIF values.
224 
225 		bool fHasBaseOrientation;
226 
227 		dng_orientation fBaseOrientation;
228 
229 		// Is the maker note safe to copy from file to file? Defaults to false
230 		// because many maker notes are not safe.
231 
232 		bool fIsMakerNoteSafe;
233 
234 		// MakerNote binary data block.
235 
236 		AutoPtr<dng_memory_block> fMakerNote;
237 
238 		// EXIF data.
239 
240 		AutoPtr<dng_exif> fExif;
241 
242 		// A copy of the EXIF data before is was synchronized with other metadata sources.
243 
244 		AutoPtr<dng_exif> fOriginalExif;
245 
246 		// IPTC binary data block and offset in original file.
247 
248 		AutoPtr<dng_memory_block> fIPTCBlock;
249 
250 		uint64 fIPTCOffset;
251 
252 		// XMP data.
253 
254 		AutoPtr<dng_xmp> fXMP;
255 
256 		// If there a valid embedded XMP block, has is its digest?  NULL if no valid
257 		// embedded XMP.
258 
259 		dng_fingerprint fEmbeddedXMPDigest;
260 
261 		// Is the XMP data from a sidecar file?
262 
263 		bool fXMPinSidecar;
264 
265 		// If the XMP data is from a sidecar file, is the sidecar file newer
266 		// than the raw file?
267 
268 		bool fXMPisNewer;
269 
270 		// Source file mimi-type, if known.
271 
272 		dng_string fSourceMIME;
273 
274 	public:
275 
276 		dng_metadata (dng_host &host);
277 
278 		dng_metadata (const dng_metadata &rhs,
279 					  dng_memory_allocator &allocator);
280 
281 		virtual ~dng_metadata ();
282 
283 		/// Copy this metadata.
284 
285 		virtual dng_metadata * Clone (dng_memory_allocator &allocator) const;
286 
287 		/// Setter for BaseOrientation.
288 
289 		void SetBaseOrientation (const dng_orientation &orientation);
290 
291 		/// Has BaseOrientation been set?
292 
HasBaseOrientation()293 		bool HasBaseOrientation () const
294 			{
295 			return fHasBaseOrientation;
296 			}
297 
298 		/// Getter for BaseOrientation.
299 
BaseOrientation()300 		const dng_orientation & BaseOrientation () const
301 			{
302 			return fBaseOrientation;
303 			}
304 
305 		/// Logically rotates the image by changing the orientation values.
306 		/// This will also update the XMP data.
307 
308 		void ApplyOrientation (const dng_orientation &orientation);
309 
310 		// API for IPTC metadata:
311 
312 		void SetIPTC (AutoPtr<dng_memory_block> &block,
313 					  uint64 offset);
314 
315 		void SetIPTC (AutoPtr<dng_memory_block> &block);
316 
317 		void ClearIPTC ();
318 
319 		const void * IPTCData () const;
320 
321 		uint32 IPTCLength () const;
322 
323 		uint64 IPTCOffset () const;
324 
325 		dng_fingerprint IPTCDigest (bool includePadding = true) const;
326 
327 		void RebuildIPTC (dng_memory_allocator &allocator,
328 						  bool padForTIFF);
329 
330 		// API for MakerNote data:
331 
SetMakerNoteSafety(bool safe)332 		void SetMakerNoteSafety (bool safe)
333 			{
334 			fIsMakerNoteSafe = safe;
335 			}
336 
IsMakerNoteSafe()337 		bool IsMakerNoteSafe () const
338 			{
339 			return fIsMakerNoteSafe;
340 			}
341 
SetMakerNote(AutoPtr<dng_memory_block> & block)342 		void SetMakerNote (AutoPtr<dng_memory_block> &block)
343 			{
344 			fMakerNote.Reset (block.Release ());
345 			}
346 
ClearMakerNote()347 		void ClearMakerNote ()
348 			{
349 			fIsMakerNoteSafe = false;
350 			fMakerNote.Reset ();
351 			}
352 
MakerNoteData()353 		const void * MakerNoteData () const
354 			{
355 			return fMakerNote.Get () ? fMakerNote->Buffer ()
356 									 : NULL;
357 			}
358 
MakerNoteLength()359 		uint32 MakerNoteLength () const
360 			{
361 			return fMakerNote.Get () ? fMakerNote->LogicalSize ()
362 									 : 0;
363 			}
364 
365 		// API for EXIF metadata:
366 
GetExif()367 		dng_exif * GetExif ()
368 			{
369 			return fExif.Get ();
370 			}
371 
GetExif()372 		const dng_exif * GetExif () const
373 			{
374 			return fExif.Get ();
375 			}
376 
377 		template< class E >
378 		E & Exif ();
379 
380 		template< class E >
381 		const E & Exif () const;
382 
383 		void ResetExif (dng_exif * newExif);
384 
385 		dng_memory_block * BuildExifBlock (dng_memory_allocator &allocator,
386 										   const dng_resolution *resolution = NULL,
387 										   bool includeIPTC = false,
388 										   const dng_jpeg_preview *thumbnail = NULL) const;
389 
390 		// API for original EXIF metadata.
391 
GetOriginalExif()392 		dng_exif * GetOriginalExif ()
393 			{
394 			return fOriginalExif.Get ();
395 			}
396 
GetOriginalExif()397 		const dng_exif * GetOriginalExif () const
398 			{
399 			return fOriginalExif.Get ();
400 			}
401 
402 		// API for XMP metadata:
403 
404 		bool SetXMP (dng_host &host,
405 					 const void *buffer,
406 					 uint32 count,
407 					 bool xmpInSidecar = false,
408 					 bool xmpIsNewer = false);
409 
410 		void SetEmbeddedXMP (dng_host &host,
411 							 const void *buffer,
412 							 uint32 count);
413 
GetXMP()414 		dng_xmp * GetXMP ()
415 			{
416 			return fXMP.Get ();
417 			}
418 
GetXMP()419 		const dng_xmp * GetXMP () const
420 			{
421 			return fXMP.Get ();
422 			}
423 
424 		template< class X >
425 		X & XMP ();
426 
427 		template< class X >
428 		const X & XMP () const;
429 
XMPinSidecar()430 		bool XMPinSidecar () const
431 			{
432 			return fXMPinSidecar;
433 			}
434 
EmbeddedXMPDigest()435 		const dng_fingerprint & EmbeddedXMPDigest () const
436 			{
437 			return fEmbeddedXMPDigest;
438 			}
439 
HaveValidEmbeddedXMP()440 		bool HaveValidEmbeddedXMP () const
441 			{
442 			return fEmbeddedXMPDigest.IsValid ();
443 			}
444 
445 		void ResetXMP (dng_xmp * newXMP);
446 
447 		void ResetXMPSidecarNewer (dng_xmp * newXMP, bool inSidecar, bool isNewer );
448 
449 		// Synchronize metadata sources.
450 
451 		void SynchronizeMetadata ();
452 
453 		// Routines to update the date/time field in the EXIF and XMP
454 		// metadata.
455 
456 		void UpdateDateTime (const dng_date_time_info &dt);
457 
458 		void UpdateDateTimeToNow ();
459 
460 		void UpdateMetadataDateTimeToNow ();
461 
462 		// Routines to set and get the source file MIME type.
463 
SetSourceMIME(const char * s)464 		void SetSourceMIME (const char *s)
465 			{
466 			fSourceMIME.Set (s);
467 			}
468 
SourceMIME()469 		const dng_string & SourceMIME () const
470 			{
471 			return fSourceMIME;
472 			}
473 
474 	};
475 
476 /*****************************************************************************/
477 
478 template< class E >
Exif()479 E & dng_metadata::Exif ()
480 	{
481 	dng_exif * exif = GetExif ();
482 	if (!exif) ThrowProgramError ("EXIF object is NULL.");
483 	return dynamic_cast< E & > (*exif);
484 	}
485 
486 /*****************************************************************************/
487 
488 template< class E >
Exif()489 const E & dng_metadata::Exif () const
490 	{
491 	const dng_exif * exif = GetExif ();
492 	if (!exif) ThrowProgramError ("EXIF object is NULL.");
493 	return dynamic_cast< const E & > (*exif);
494 	}
495 
496 /*****************************************************************************/
497 
498 template< class X >
XMP()499 X & dng_metadata::XMP ()
500 	{
501 	dng_xmp * xmp = GetXMP ();
502 	if (!xmp) ThrowProgramError ("XMP object is NULL.");
503 	return dynamic_cast< X & > (*xmp);
504 	}
505 
506 /*****************************************************************************/
507 
508 template< class X >
XMP()509 const X & dng_metadata::XMP () const
510 	{
511 	const dng_xmp * xmp = GetXMP ();
512 	if (!xmp) ThrowProgramError ("XMP object is NULL.");
513 	return dynamic_cast< const X & > (*xmp);
514 	}
515 
516 /*****************************************************************************/
517 
518 /// \brief Main class for holding DNG image data and associated metadata.
519 
520 class dng_negative
521 	{
522 
523 	public:
524 
525 		enum RawImageStageEnum
526 			{
527 			rawImageStagePreOpcode1,
528 			rawImageStagePostOpcode1,
529 			rawImageStagePostOpcode2,
530 			rawImageStagePreOpcode3,
531 			rawImageStagePostOpcode3,
532 			rawImageStageNone
533 			};
534 
535 	protected:
536 
537 		// The negative stores an associated allocator. It does not do
538 		// anything to keep it alive or to release it when the object destructs.
539 		// Hence, clients will need to make sure that the allocator's lifespan
540 		// encompasses that of the dng_factory object which is generally
541 		// directly bound to the dng_negative object.
542 
543 		dng_memory_allocator &fAllocator;
544 
545 		// Non-localized ASCII model name.
546 
547 		dng_string fModelName;
548 
549 		// Localized UTF-8 model name.
550 
551 		dng_string fLocalName;
552 
553 		// The area of raw image that should be included in the final converted
554 		// image. This stems from extra pixels around the edges of the sensor
555 		// including both the black mask and some additional padding.
556 
557 		// The default crop can be smaller than the "active" area which includes
558 		// the padding but not the black masked pixels.
559 
560 		dng_urational fDefaultCropSizeH;
561 		dng_urational fDefaultCropSizeV;
562 
563 		dng_urational fDefaultCropOriginH;
564 		dng_urational fDefaultCropOriginV;
565 
566 		// Default user crop, in relative coordinates.
567 
568 		dng_urational fDefaultUserCropT;
569 		dng_urational fDefaultUserCropL;
570 		dng_urational fDefaultUserCropB;
571 		dng_urational fDefaultUserCropR;
572 
573 		// Default scale factors. Generally, 1.0 for square pixel cameras. They
574 		// can compensate for non-square pixels. The choice of exact values will
575 		// generally depend on what the camera does. These are particularly
576 		// interesting for the Nikon D1X and the Fuji diamond mosaic.
577 
578 		dng_urational fDefaultScaleH;
579 		dng_urational fDefaultScaleV;
580 
581 		// Best quality scale factor. Used for the Nikon D1X and Fuji cameras
582 		// to force everything to be a scale up rather than scale down. So,
583 		// generally this is 1.0 / min (fDefaultScaleH, fDefaultScaleV) but
584 		// this isn't used if the scale factors are only slightly different
585 		// from 1.0.
586 
587 		dng_urational fBestQualityScale;
588 
589 		// Proxy image support.  Remember certain sizes for the original image
590 		// this proxy was derived from.
591 
592 		dng_point fOriginalDefaultFinalSize;
593 		dng_point fOriginalBestQualityFinalSize;
594 
595 		dng_urational fOriginalDefaultCropSizeH;
596 		dng_urational fOriginalDefaultCropSizeV;
597 
598 		// Scale factors used in demosaic algorithm (calculated).
599 		// Maps raw image coordinates to full image coordinates -- i.e.,
600 		// original image coordinates on raw sensor data to coordinates
601 		// in fStage3Image which is the output of the interpolation step.
602 		// So, if we downsample when interpolating, these numbers get
603 		// smaller.
604 
605 		real64 fRawToFullScaleH;
606 		real64 fRawToFullScaleV;
607 
608 		// Relative amount of noise at ISO 100. This is measured per camera model
609 		// based on looking at flat areas of color.
610 
611 		dng_urational fBaselineNoise;
612 
613 		// How much noise reduction has already been applied (0.0 to 1.0) to the
614 		// the raw image data?  0.0 = none, 1.0 = "ideal" amount--i.e. don't apply any
615 		// more by default.  0/0 for unknown.
616 
617 		dng_urational fNoiseReductionApplied;
618 
619         // Enhanced images can change the applied noise reduction, so we
620         // need to keep around the original value.
621 
622         dng_urational fRawNoiseReductionApplied;
623 
624 		// Amount of noise for this negative (see dng_noise_profile for details).
625 
626 		dng_noise_profile fNoiseProfile;
627 
628         // Enhanced images can change the noise profile, so we
629         // need to keep around the original value.
630 
631         dng_noise_profile fRawNoiseProfile;
632 
633 		// Zero point for the exposure compensation slider. This reflects how
634 		// the manufacturer sets up the camera and its conversions.
635 
636 		dng_srational fBaselineExposure;
637 
638 		// Relative amount of sharpening required. This is chosen per camera
639 		// model based on how strong the anti-alias filter is on the camera
640 		// and the quality of the lenses. This scales the sharpness slider
641 		// value.
642 
643 		dng_urational fBaselineSharpness;
644 
645         // Enhanced images can change the baseline sharpness, so we
646         // need to keep around the original value.
647 
648         dng_urational fRawBaselineSharpness;
649 
650 		// Chroma blur radius (or 0/0 for auto). Set to 0/1 to disable
651 		// chroma blurring.
652 
653 		dng_urational fChromaBlurRadius;
654 
655 		// Anti-alias filter strength (0.0 to 1.0).  Used as a hint
656 		// to the demosaic algorithms.
657 
658 		dng_urational fAntiAliasStrength;
659 
660 		// Linear response limit. The point at which the sensor goes
661 		// non-linear and color information becomes unreliable. Used in
662 		// the highlight-recovery logic.
663 
664 		dng_urational fLinearResponseLimit;
665 
666 		// Scale factor for shadows slider. The Fuji HDR cameras, for example,
667 		// need a more sensitive shadow slider.
668 
669 		dng_urational fShadowScale;
670 
671 		// Colormetric reference.
672 
673 		uint32 fColorimetricReference;
674 
675         // Is the stage 3 image floating point?
676 
677         bool fFloatingPoint;
678 
679 		// Number of color channels for this image (e.g. 1, 3, or 4).
680 
681 		uint32 fColorChannels;
682 
683 		// Amount by which each channel has already been scaled. Some cameras
684 		// have analog amplifiers on the color channels and these can result
685 		// in different scalings per channel. This provides some level of
686 		// analog white balancing. The Nikon D1 also did digital scaling but
687 		// this caused problems with highlight recovery.
688 
689 		dng_vector fAnalogBalance;
690 
691 		// The "As Shot" neutral color coordinates in native camera space.
692 		// This overrides fCameraWhiteXY if both are specified. This
693 		// specifies the values per channel that would result in a neutral
694 		// color for the "As Shot" case. This is generally supplied by
695 		// the camera.
696 
697 		dng_vector fCameraNeutral;
698 
699 		// The "As Shot" white balance xy coordinates. Sometimes this is
700 		// supplied by the camera. Sometimes the camera just supplies a name
701 		// for the white balance.
702 
703 		dng_xy_coord fCameraWhiteXY;
704 
705 		// Individual camera calibrations.
706 
707 		// Camera data --> camera calibration --> "inverse" of color matrix
708 
709 		// This will be a 4x4 matrix for a 4-color camera. The defaults are
710 		// almost always the identity matrix and for the cases where they
711 		// aren't, they are diagonal matrices.
712 
713 		dng_matrix fCameraCalibration1;
714 		dng_matrix fCameraCalibration2;
715 
716 		// Signature which allows a profile to announce that it is compatible
717 		// with these calibration matrices.
718 
719 		dng_string fCameraCalibrationSignature;
720 
721 		// List of camera profiles.
722 
723 		dng_std_vector<dng_camera_profile *> fCameraProfile;
724 
725 		// "As shot" camera profile name.
726 
727 		dng_string fAsShotProfileName;
728 
729 		// Raw image data digests. These are MD5 fingerprints of the raw image data
730 		// in the file, computed using a specific algorithms.  They can be used
731 		// verify the raw data has not been corrupted.  The new version is faster
732 		// to compute on MP machines, and is used starting with DNG version 1.4.
733 
734 		mutable dng_fingerprint fRawImageDigest;
735 
736 		mutable dng_fingerprint fNewRawImageDigest;
737 
738 		// Raw data unique ID.  This is an unique identifer for the actual
739 		// raw image data in the file.  It can be used to index into caches
740 		// for this data.
741 
742 		mutable dng_fingerprint fRawDataUniqueID;
743 
744 		mutable dng_std_mutex fRawDataUniqueIDMutex;
745 
746 		// Original raw file name.  Just the file name, not the full path.
747 
748 		dng_string fOriginalRawFileName;
749 
750 		// Is the original raw file data availaible?
751 
752 		bool fHasOriginalRawFileData;
753 
754 		// The compressed original raw file data.
755 
756 		AutoPtr<dng_memory_block> fOriginalRawFileData;
757 
758 		// MD5 digest of original raw file data block.
759 
760 		mutable dng_fingerprint fOriginalRawFileDigest;
761 
762 		// DNG private data block.
763 
764 		AutoPtr<dng_memory_block> fDNGPrivateData;
765 
766 		// Metadata information (XMP, IPTC, EXIF, orientation)
767 
768 		dng_metadata fMetadata;
769 
770 		// Information required to linearize and range map the raw data.
771 
772 		AutoPtr<dng_linearization_info> fLinearizationInfo;
773 
774 		// Information required to demoasic the raw data.
775 
776 		AutoPtr<dng_mosaic_info> fMosaicInfo;
777 
778 		// Opcode list 1. (Applied to stored data)
779 
780 		dng_opcode_list fOpcodeList1;
781 
782 		// Opcode list 2. (Applied to range mapped data)
783 
784 		dng_opcode_list fOpcodeList2;
785 
786 		// Opcode list 3. (Post demosaic)
787 
788 		dng_opcode_list fOpcodeList3;
789 
790 		// Stage 1 image, which is image data stored in a DNG file.
791 
792 		AutoPtr<dng_image> fStage1Image;
793 
794 		// Stage 2 image, which is the stage 1 image after it has been
795 		// linearized and range mapped.
796 
797 		AutoPtr<dng_image> fStage2Image;
798 
799 		// Stage 3 image, which is the stage 2 image after it has been
800 		// demosaiced.
801 
802 		AutoPtr<dng_image> fStage3Image;
803 
804 		// Additional gain applied when building the stage 3 image.
805 
806 		real64 fStage3Gain;
807 
808 		// Optical black level of stage 3 image (in [0,65535]).
809 
810 		uint16 fStage3BlackLevel;
811 
812 		// Were any approximations (e.g. downsampling, etc.) applied
813 		// file reading this image?
814 
815 		bool fIsPreview;
816 
817 		// Does the file appear to be damaged?
818 
819 		bool fIsDamaged;
820 
821 		// At what processing stage did we grab a copy of raw image data?
822 
823 		RawImageStageEnum fRawImageStage;
824 
825 		// The raw image data that we grabbed, if any.
826 
827 		AutoPtr<dng_image> fRawImage;
828 
829         // The black level of the raw image (if not encoded by linearization info).
830 
831         uint16 fRawImageBlackLevel;
832 
833 		// The floating point bit depth of the raw file, if any.
834 
835 		uint32 fRawFloatBitDepth;
836 
837 		// The raw image JPEG data that we grabbed, if any.
838 
839 		AutoPtr<dng_jpeg_image> fRawJPEGImage;
840 
841 		// Keep a separate digest for the compressed JPEG data, if any.
842 
843 		mutable dng_fingerprint fRawJPEGImageDigest;
844 
845 		// Transparency mask image, if any.
846 
847 		AutoPtr<dng_image> fTransparencyMask;
848 
849 		// Grabbed transparency mask, if we are not saving the current mask.
850 
851 		AutoPtr<dng_image> fRawTransparencyMask;
852 
853 		// The bit depth for the raw transparancy mask, if known.
854 
855 		uint32 fRawTransparencyMaskBitDepth;
856 
857 		// We sometimes need to keep of copy of the stage3 image before
858 		// flattening the transparency.
859 
860 		AutoPtr<dng_image> fUnflattenedStage3Image;
861 
862         // Depth map.
863 
864         bool fHasDepthMap;
865 
866         AutoPtr<dng_image> fDepthMap;
867 
868         // Grabbed depth map, if we are not saving the current map.
869 
870         AutoPtr<dng_image> fRawDepthMap;
871 
872         // Depth metadata.
873 
874         uint32        fDepthFormat;
875         dng_urational fDepthNear;
876         dng_urational fDepthFar;
877         uint32        fDepthUnits;
878         uint32        fDepthMeasureType;
879 
880         // Enhance metadata.
881 
882         dng_string fEnhanceParams;
883 
884 	public:
885 
886 		virtual ~dng_negative ();
887 
888 		static dng_negative * Make (dng_host &host);
889 
890 		/// Provide access to the memory allocator used for this object.
891 
Allocator()892 		dng_memory_allocator & Allocator () const
893 			{
894 			return fAllocator;
895 			}
896 
897 		/// Getter for ModelName.
898 
SetModelName(const char * name)899 		void SetModelName (const char *name)
900 			{
901 			fModelName.Set_ASCII (name);
902 			}
903 
904 		/// Setter for ModelName.
905 
ModelName()906 		const dng_string & ModelName () const
907 			{
908 			return fModelName;
909 			}
910 
911 		/// Setter for LocalName.
912 
SetLocalName(const char * name)913 		void SetLocalName (const char *name)
914 			{
915 			fLocalName.Set (name);
916 			}
917 
918 		/// Getter for LocalName.
919 
LocalName()920 		const dng_string & LocalName () const
921 			{
922 			return fLocalName;
923 			}
924 
925 		/// Getter for metadata
926 
Metadata()927 		dng_metadata &Metadata ()
928 			{
929 			return fMetadata;
930 			}
931 
932 		#if qMetadataOnConst
933 
Metadata()934 		const dng_metadata &Metadata () const
935 			{
936 			return fMetadata;
937 			}
938 
939 		#endif // qMetadataOnConst
940 
941 		/// Make a copy of the internal metadata generally as a basis for further
942 		/// changes.
943 
944 		dng_metadata * CloneInternalMetadata () const;
945 
946 	protected:
947 
948 		/// An accessor for the internal metadata that works even when we
949 		/// have general access turned off. This is needed to provide
950 		/// access to EXIF ISO information.
951 
InternalMetadata()952 		const dng_metadata &InternalMetadata () const
953 			{
954 			return fMetadata;
955 			}
956 
957 	public:
958 
959 		/// Setter for BaseOrientation.
960 
SetBaseOrientation(const dng_orientation & orientation)961 		void SetBaseOrientation (const dng_orientation &orientation)
962 			{
963 			Metadata ().SetBaseOrientation (orientation);
964 			}
965 
966 		/// Has BaseOrientation been set?
967 
HasBaseOrientation()968 		bool HasBaseOrientation () METACONST
969 			{
970 			return Metadata ().HasBaseOrientation ();
971 			}
972 
973 		/// Getter for BaseOrientation.
974 
BaseOrientation()975 		const dng_orientation & BaseOrientation () METACONST
976 			{
977 			return Metadata ().BaseOrientation ();
978 			}
979 
980 		/// Hook to allow SDK host code to add additional rotations.
981 
982 		virtual dng_orientation ComputeOrientation (const dng_metadata &metadata) const;
983 
984 		/// For non-const negatives, we simply default to using the metadata attached to the negative.
985 
Orientation()986 		dng_orientation Orientation ()
987 			{
988 			return ComputeOrientation (Metadata ());
989 			}
990 
991 		/// Logically rotates the image by changing the orientation values.
992 		/// This will also update the XMP data.
993 
ApplyOrientation(const dng_orientation & orientation)994 		void ApplyOrientation (const dng_orientation &orientation)
995 			{
996 			Metadata ().ApplyOrientation (orientation);
997 			}
998 
999 		/// Setter for DefaultCropSize.
1000 
SetDefaultCropSize(const dng_urational & sizeH,const dng_urational & sizeV)1001 		void SetDefaultCropSize (const dng_urational &sizeH,
1002 						         const dng_urational &sizeV)
1003 			{
1004 			fDefaultCropSizeH = sizeH;
1005 			fDefaultCropSizeV = sizeV;
1006 			}
1007 
1008 		/// Setter for DefaultCropSize.
1009 
SetDefaultCropSize(uint32 sizeH,uint32 sizeV)1010 		void SetDefaultCropSize (uint32 sizeH,
1011 						         uint32 sizeV)
1012 			{
1013 			SetDefaultCropSize (dng_urational (sizeH, 1),
1014 						        dng_urational (sizeV, 1));
1015 			}
1016 
1017 		/// Getter for DefaultCropSize horizontal.
1018 
DefaultCropSizeH()1019 		const dng_urational & DefaultCropSizeH () const
1020 			{
1021 			return fDefaultCropSizeH;
1022 			}
1023 
1024 		/// Getter for DefaultCropSize vertical.
1025 
DefaultCropSizeV()1026 		const dng_urational & DefaultCropSizeV () const
1027 			{
1028 			return fDefaultCropSizeV;
1029 			}
1030 
1031 		/// Setter for DefaultCropOrigin.
1032 
SetDefaultCropOrigin(const dng_urational & originH,const dng_urational & originV)1033 		void SetDefaultCropOrigin (const dng_urational &originH,
1034 							       const dng_urational &originV)
1035 			{
1036 			fDefaultCropOriginH = originH;
1037 			fDefaultCropOriginV = originV;
1038 			}
1039 
1040 		/// Setter for DefaultCropOrigin.
1041 
SetDefaultCropOrigin(uint32 originH,uint32 originV)1042 		void SetDefaultCropOrigin (uint32 originH,
1043 							       uint32 originV)
1044 			{
1045 			SetDefaultCropOrigin (dng_urational (originH, 1),
1046 						   		  dng_urational (originV, 1));
1047 			}
1048 
1049 		/// Set default crop around center of image.
1050 
SetDefaultCropCentered(const dng_point & rawSize)1051 		void SetDefaultCropCentered (const dng_point &rawSize)
1052 			{
1053 
1054 			uint32 sizeH = Round_uint32 (fDefaultCropSizeH.As_real64 ());
1055 			uint32 sizeV = Round_uint32 (fDefaultCropSizeV.As_real64 ());
1056 
1057 			SetDefaultCropOrigin ((rawSize.h - sizeH) >> 1,
1058 								  (rawSize.v - sizeV) >> 1);
1059 
1060 			}
1061 
1062 		/// Get default crop origin horizontal value.
1063 
DefaultCropOriginH()1064 		const dng_urational & DefaultCropOriginH () const
1065 			{
1066 			return fDefaultCropOriginH;
1067 			}
1068 
1069 		/// Get default crop origin vertical value.
1070 
DefaultCropOriginV()1071 		const dng_urational & DefaultCropOriginV () const
1072 			{
1073 			return fDefaultCropOriginV;
1074 			}
1075 
1076 		/// Is there a default user crop?
1077 
HasDefaultUserCrop()1078 		bool HasDefaultUserCrop () const
1079 			{
1080 			return (fDefaultUserCropT.As_real64 () != 0.0 ||
1081 					fDefaultUserCropL.As_real64 () != 0.0 ||
1082 					fDefaultUserCropB.As_real64 () != 1.0 ||
1083 					fDefaultUserCropR.As_real64 () != 1.0);
1084 			}
1085 
1086 		/// Getter for top coordinate of default user crop.
1087 
DefaultUserCropT()1088 		const dng_urational & DefaultUserCropT () const
1089 			{
1090 			return fDefaultUserCropT;
1091 			}
1092 
1093 		/// Getter for left coordinate of default user crop.
1094 
DefaultUserCropL()1095 		const dng_urational & DefaultUserCropL () const
1096 			{
1097 			return fDefaultUserCropL;
1098 			}
1099 
1100 		/// Getter for bottom coordinate of default user crop.
1101 
DefaultUserCropB()1102 		const dng_urational & DefaultUserCropB () const
1103 			{
1104 			return fDefaultUserCropB;
1105 			}
1106 
1107 		/// Getter for right coordinate of default user crop.
1108 
DefaultUserCropR()1109 		const dng_urational & DefaultUserCropR () const
1110 			{
1111 			return fDefaultUserCropR;
1112 			}
1113 
1114 		/// Reset default user crop to default crop area.
1115 
ResetDefaultUserCrop()1116 		void ResetDefaultUserCrop ()
1117 			{
1118 			fDefaultUserCropT = dng_urational (0, 1);
1119 			fDefaultUserCropL = dng_urational (0, 1);
1120 			fDefaultUserCropB = dng_urational (1, 1);
1121 			fDefaultUserCropR = dng_urational (1, 1);
1122 			}
1123 
1124 		/// Setter for all 4 coordinates of default user crop.
1125 
SetDefaultUserCrop(const dng_urational & t,const dng_urational & l,const dng_urational & b,const dng_urational & r)1126 		void SetDefaultUserCrop (const dng_urational &t,
1127 								 const dng_urational &l,
1128 								 const dng_urational &b,
1129 								 const dng_urational &r)
1130 			{
1131 			fDefaultUserCropT = t;
1132 			fDefaultUserCropL = l;
1133 			fDefaultUserCropB = b;
1134 			fDefaultUserCropR = r;
1135 			}
1136 
1137 		/// Setter for top coordinate of default user crop.
1138 
SetDefaultUserCropT(const dng_urational & value)1139 		void SetDefaultUserCropT (const dng_urational &value)
1140 			{
1141 			fDefaultUserCropT = value;
1142 			}
1143 
1144 		/// Setter for left coordinate of default user crop.
1145 
SetDefaultUserCropL(const dng_urational & value)1146 		void SetDefaultUserCropL (const dng_urational &value)
1147 			{
1148 			fDefaultUserCropL = value;
1149 			}
1150 
1151 		/// Setter for bottom coordinate of default user crop.
1152 
SetDefaultUserCropB(const dng_urational & value)1153 		void SetDefaultUserCropB (const dng_urational &value)
1154 			{
1155 			fDefaultUserCropB = value;
1156 			}
1157 
1158 		/// Setter for right coordinate of default user crop.
1159 
SetDefaultUserCropR(const dng_urational & value)1160 		void SetDefaultUserCropR (const dng_urational &value)
1161 			{
1162 			fDefaultUserCropR = value;
1163 			}
1164 
1165 		/// Setter for DefaultScale.
1166 
SetDefaultScale(const dng_urational & scaleH,const dng_urational & scaleV)1167 		void SetDefaultScale (const dng_urational &scaleH,
1168 							  const dng_urational &scaleV)
1169 			{
1170 			fDefaultScaleH = scaleH;
1171 			fDefaultScaleV = scaleV;
1172 			}
1173 
1174 		/// Get default scale horizontal value.
1175 
DefaultScaleH()1176 		const dng_urational & DefaultScaleH () const
1177 			{
1178 			return fDefaultScaleH;
1179 			}
1180 
1181 		/// Get default scale vertical value.
1182 
DefaultScaleV()1183 		const dng_urational & DefaultScaleV () const
1184 			{
1185 			return fDefaultScaleV;
1186 			}
1187 
1188 		/// Setter for BestQualityScale.
1189 
SetBestQualityScale(const dng_urational & scale)1190 		void SetBestQualityScale (const dng_urational &scale)
1191 			{
1192 			fBestQualityScale = scale;
1193 			}
1194 
1195 		/// Getter for BestQualityScale.
1196 
BestQualityScale()1197 		const dng_urational & BestQualityScale () const
1198 			{
1199 			return fBestQualityScale;
1200 			}
1201 
1202         /// Is the best quality scale different than the default scale?
1203 
HasBestQualityScale()1204         bool HasBestQualityScale () const
1205             {
1206             return fBestQualityScale.As_real64 () != 1.0;
1207             }
1208 
1209 		/// API for raw to full image scaling factors horizontal.
1210 
RawToFullScaleH()1211 		real64 RawToFullScaleH () const
1212 			{
1213 			return fRawToFullScaleH;
1214 			}
1215 
1216 		/// API for raw to full image scaling factors vertical.
1217 
RawToFullScaleV()1218 		real64 RawToFullScaleV () const
1219 			{
1220 			return fRawToFullScaleV;
1221 			}
1222 
1223 		/// Setter for raw to full scales.
1224 
SetRawToFullScale(real64 scaleH,real64 scaleV)1225 		void SetRawToFullScale (real64 scaleH,
1226 							    real64 scaleV)
1227 			{
1228 			fRawToFullScaleH = scaleH;
1229 			fRawToFullScaleV = scaleV;
1230 			}
1231 
1232 		/// Get default scale factor.
1233 		/// When specifing a single scale factor, we use the horizontal
1234 		/// scale factor,  and let the vertical scale factor be calculated
1235 		/// based on the pixel aspect ratio.
1236 
DefaultScale()1237 		real64 DefaultScale () const
1238 			{
1239 			return DefaultScaleH ().As_real64 ();
1240 			}
1241 
1242 		/// Default cropped image size (at scale == 1.0) width.
1243 
SquareWidth()1244 		real64 SquareWidth () const
1245 			{
1246 			return DefaultCropSizeH ().As_real64 ();
1247 			}
1248 
1249 		/// Default cropped image size (at scale == 1.0) height.
1250 
SquareHeight()1251 		real64 SquareHeight () const
1252 			{
1253 			return DefaultCropSizeV ().As_real64 () *
1254 				   DefaultScaleV    ().As_real64 () /
1255 				   DefaultScaleH    ().As_real64 ();
1256 			}
1257 
1258 		/// Default cropped image aspect ratio.
1259 
AspectRatio()1260 		real64 AspectRatio () const
1261 			{
1262 			return SquareWidth  () /
1263 				   SquareHeight ();
1264 			}
1265 
1266 		/// Pixel aspect ratio of stage 3 image.
1267 
PixelAspectRatio()1268 		real64 PixelAspectRatio () const
1269 			{
1270 			return (DefaultScaleH ().As_real64 () / RawToFullScaleH ()) /
1271 				   (DefaultScaleV ().As_real64 () / RawToFullScaleV ());
1272 			}
1273 
1274 		/// Default cropped image size at given scale factor width.
1275 
FinalWidth(real64 scale)1276 		uint32 FinalWidth (real64 scale) const
1277 			{
1278 			return Round_uint32 (SquareWidth () * scale);
1279 			}
1280 
1281 		/// Default cropped image size at given scale factor height.
1282 
FinalHeight(real64 scale)1283 		uint32 FinalHeight (real64 scale) const
1284 			{
1285 			return Round_uint32 (SquareHeight () * scale);
1286 			}
1287 
1288 		/// Default cropped image size at default scale factor width.
1289 
DefaultFinalWidth()1290 		uint32 DefaultFinalWidth () const
1291 			{
1292 			return FinalWidth (DefaultScale ());
1293 			}
1294 
1295 		/// Default cropped image size at default scale factor height.
1296 
DefaultFinalHeight()1297 		uint32 DefaultFinalHeight () const
1298 			{
1299 			return FinalHeight (DefaultScale ());
1300 			}
1301 
1302 		/// Get best quality width.
1303 		/// For a naive conversion, one could use either the default size,
1304 		/// or the best quality size.
1305 
BestQualityFinalWidth()1306 		uint32 BestQualityFinalWidth () const
1307 			{
1308 			return FinalWidth (DefaultScale () * BestQualityScale ().As_real64 ());
1309 			}
1310 
1311 		/// Get best quality height.
1312 		/// For a naive conversion, one could use either the default size,
1313 		/// or the best quality size.
1314 
BestQualityFinalHeight()1315 		uint32 BestQualityFinalHeight () const
1316 			{
1317 			return FinalHeight (DefaultScale () * BestQualityScale ().As_real64 ());
1318 			}
1319 
1320 		/// Default size of original (non-proxy) image.  For non-proxy images, this
1321 		/// is equal to DefaultFinalWidth/DefaultFinalHight.  For proxy images, this
1322 		/// is equal to the DefaultFinalWidth/DefaultFinalHeight of the image this
1323 		/// proxy was derived from.
1324 
OriginalDefaultFinalSize()1325 		const dng_point & OriginalDefaultFinalSize () const
1326 			{
1327 			return fOriginalDefaultFinalSize;
1328 			}
1329 
1330 		/// Setter for OriginalDefaultFinalSize.
1331 
SetOriginalDefaultFinalSize(const dng_point & size)1332 		void SetOriginalDefaultFinalSize (const dng_point &size)
1333 			{
1334 			fOriginalDefaultFinalSize = size;
1335 			}
1336 
1337 		/// Best quality size of original (non-proxy) image.  For non-proxy images, this
1338 		/// is equal to BestQualityFinalWidth/BestQualityFinalHeight.  For proxy images, this
1339 		/// is equal to the BestQualityFinalWidth/BestQualityFinalHeight of the image this
1340 		/// proxy was derived from.
1341 
OriginalBestQualityFinalSize()1342 		const dng_point & OriginalBestQualityFinalSize () const
1343 			{
1344 			return fOriginalBestQualityFinalSize;
1345 			}
1346 
1347 		/// Setter for OriginalBestQualityFinalSize.
1348 
SetOriginalBestQualityFinalSize(const dng_point & size)1349 		void SetOriginalBestQualityFinalSize (const dng_point &size)
1350 			{
1351 			fOriginalBestQualityFinalSize = size;
1352 			}
1353 
1354 		/// DefaultCropSize for original (non-proxy) image.  For non-proxy images,
1355 		/// this is equal to the DefaultCropSize.  for proxy images, this is
1356 		/// equal size of the DefaultCropSize of the image this proxy was derived from.
1357 
OriginalDefaultCropSizeH()1358 		const dng_urational & OriginalDefaultCropSizeH () const
1359 			{
1360 			return fOriginalDefaultCropSizeH;
1361 			}
1362 
OriginalDefaultCropSizeV()1363 		const dng_urational & OriginalDefaultCropSizeV () const
1364 			{
1365 			return fOriginalDefaultCropSizeV;
1366 			}
1367 
1368 		/// Setter for OriginalDefaultCropSize.
1369 
SetOriginalDefaultCropSize(const dng_urational & sizeH,const dng_urational & sizeV)1370 		void SetOriginalDefaultCropSize (const dng_urational &sizeH,
1371 										 const dng_urational &sizeV)
1372 			{
1373 			fOriginalDefaultCropSizeH = sizeH;
1374 			fOriginalDefaultCropSizeV = sizeV;
1375 			}
1376 
1377 		/// If the original size fields are undefined, set them to the
1378 		/// current sizes.
1379 
1380 		void SetDefaultOriginalSizes ();
1381 
1382 		/// Set all the original size fields to a specific size.
1383 
1384 		void SetOriginalSizes (const dng_point &size);
1385 
1386 		/// The default crop area in the stage 3 image coordinates.
1387 
1388 		dng_rect DefaultCropArea () const;
1389 
1390 		/// Setter for BaselineNoise.
1391 
SetBaselineNoise(real64 noise)1392 		void SetBaselineNoise (real64 noise)
1393 			{
1394 			fBaselineNoise.Set_real64 (noise, 100);
1395 			}
1396 
1397 		/// Getter for BaselineNoise as dng_urational.
1398 
BaselineNoiseR()1399 		const dng_urational & BaselineNoiseR () const
1400 			{
1401 			return fBaselineNoise;
1402 			}
1403 
1404 		/// Getter for BaselineNoise as real64.
1405 
BaselineNoise()1406 		real64 BaselineNoise () const
1407 			{
1408 			return fBaselineNoise.As_real64 ();
1409 			}
1410 
1411 		/// Setter for NoiseReductionApplied.
1412 
SetNoiseReductionApplied(const dng_urational & value)1413 		void SetNoiseReductionApplied (const dng_urational &value)
1414 			{
1415 			fNoiseReductionApplied = value;
1416 			}
1417 
1418 		/// Getter for NoiseReductionApplied.
1419 
NoiseReductionApplied()1420 		const dng_urational & NoiseReductionApplied () const
1421 			{
1422 			return fNoiseReductionApplied;
1423 			}
1424 
1425         // Sets the raw noise reduction applied to be a copy of the unenhanced
1426         // noise reduction applied, if not set yet.
1427 
SetRawNoiseReductionApplied()1428         void SetRawNoiseReductionApplied ()
1429             {
1430             if (fRawNoiseReductionApplied.NotValid ())
1431                 {
1432                 fRawNoiseReductionApplied = fNoiseReductionApplied;
1433                 }
1434             }
1435 
1436         // Gets the raw NoiseReductionApplied value.
1437 
RawNoiseReductionApplied()1438         const dng_urational & RawNoiseReductionApplied () const
1439             {
1440             return fRawNoiseReductionApplied;
1441             }
1442 
1443 		/// Setter for noise profile.
1444 
SetNoiseProfile(const dng_noise_profile & noiseProfile)1445 		void SetNoiseProfile (const dng_noise_profile &noiseProfile)
1446 			{
1447 			fNoiseProfile = noiseProfile;
1448 			}
1449 
1450 		/// Does this negative have a valid noise profile?
1451 
HasNoiseProfile()1452 		bool HasNoiseProfile () const
1453 			{
1454 			return fNoiseProfile.IsValidForNegative (*this);
1455 			}
1456 
1457 		/// Getter for noise profile.
1458 
NoiseProfile()1459 		const dng_noise_profile & NoiseProfile () const
1460 			{
1461 			return fNoiseProfile;
1462 			}
1463 
1464         // Does this negative have a valid raw noise profile?
1465 
HasRawNoiseProfile()1466         bool HasRawNoiseProfile () const
1467             {
1468             return fRawNoiseProfile.IsValidForNegative (*this);
1469             }
1470 
1471         // Sets the raw noise profile to be a copy of the unenhanced
1472         // noise profile, if not set yet.
1473 
SetRawNoiseProfile()1474         void SetRawNoiseProfile ()
1475             {
1476             if (!HasRawNoiseProfile ())
1477                 {
1478                 fRawNoiseProfile = fNoiseProfile;
1479                 }
1480             }
1481 
1482         // Getter for raw noise profile.
1483 
RawNoiseProfile()1484         const dng_noise_profile & RawNoiseProfile () const
1485             {
1486             return fRawNoiseProfile;
1487             }
1488 
1489 		/// Setter for BaselineExposure.
1490 
SetBaselineExposure(real64 exposure)1491 		void SetBaselineExposure (real64 exposure)
1492 			{
1493 			fBaselineExposure.Set_real64 (exposure, 100);
1494 			}
1495 
1496 		/// Getter for BaselineExposure as dng_urational.
1497 
BaselineExposureR()1498 		const dng_srational & BaselineExposureR () const
1499 			{
1500 			return fBaselineExposure;
1501 			}
1502 
1503 		/// Getter for BaselineExposure as real64.
1504 
BaselineExposure()1505 		real64 BaselineExposure () const
1506 			{
1507 			return BaselineExposureR ().As_real64 ();
1508 			}
1509 
1510 		/// Compute total baseline exposure (sum of negative's BaselineExposure and
1511 		/// profile's BaselineExposureOffset).
1512 
1513 		real64 TotalBaselineExposure (const dng_camera_profile_id &profileID) const;
1514 
1515 		/// Setter for BaselineSharpness.
1516 
SetBaselineSharpness(real64 sharpness)1517 		void SetBaselineSharpness (real64 sharpness)
1518 			{
1519 			fBaselineSharpness.Set_real64 (sharpness, 100);
1520 			}
1521 
1522 		/// Getter for BaselineSharpness as dng_urational.
1523 
BaselineSharpnessR()1524 		const dng_urational & BaselineSharpnessR () const
1525 			{
1526 			return fBaselineSharpness;
1527 			}
1528 
1529 		/// Getter for BaselineSharpness as real64.
1530 
BaselineSharpness()1531 		real64 BaselineSharpness () const
1532 			{
1533 			return BaselineSharpnessR ().As_real64 ();
1534 			}
1535 
1536         // Sets the raw baseline sharpness to be a copy of the baseline
1537         // sharpness, if not set yet.
1538 
SetRawBaselineSharpness()1539         void SetRawBaselineSharpness ()
1540             {
1541             if (fRawBaselineSharpness.d == 0)
1542                 {
1543                 fRawBaselineSharpness = fBaselineSharpness;
1544                 }
1545             }
1546 
1547         // Gets the raw baseline sharpness value.
1548 
RawBaselineSharpness()1549         const dng_urational & RawBaselineSharpness () const
1550             {
1551             if (fRawBaselineSharpness.d != 0)
1552                 {
1553                 return fRawBaselineSharpness;
1554                 }
1555             return fBaselineSharpness;
1556             }
1557 
1558 		/// Setter for ChromaBlurRadius.
1559 
SetChromaBlurRadius(const dng_urational & radius)1560 		void SetChromaBlurRadius (const dng_urational &radius)
1561 			{
1562 			fChromaBlurRadius = radius;
1563 			}
1564 
1565 		/// Getter for ChromaBlurRadius as dng_urational.
1566 
ChromaBlurRadius()1567 		const dng_urational & ChromaBlurRadius () const
1568 			{
1569 			return fChromaBlurRadius;
1570 			}
1571 
1572 		/// Setter for AntiAliasStrength.
1573 
SetAntiAliasStrength(const dng_urational & strength)1574 		void SetAntiAliasStrength (const dng_urational &strength)
1575 			{
1576 			fAntiAliasStrength = strength;
1577 			}
1578 
1579 		/// Getter for AntiAliasStrength as dng_urational.
1580 
AntiAliasStrength()1581 		const dng_urational & AntiAliasStrength () const
1582 			{
1583 			return fAntiAliasStrength;
1584 			}
1585 
1586 		/// Setter for LinearResponseLimit.
1587 
SetLinearResponseLimit(real64 limit)1588 		void SetLinearResponseLimit (real64 limit)
1589 			{
1590 			fLinearResponseLimit.Set_real64 (limit, 100);
1591 			}
1592 
1593 		/// Getter for LinearResponseLimit as dng_urational.
1594 
LinearResponseLimitR()1595 		const dng_urational & LinearResponseLimitR () const
1596 			{
1597 			return fLinearResponseLimit;
1598 			}
1599 
1600 		/// Getter for LinearResponseLimit as real64.
1601 
LinearResponseLimit()1602 		real64 LinearResponseLimit () const
1603 			{
1604 			return LinearResponseLimitR ().As_real64 ();
1605 			}
1606 
1607 		/// Setter for ShadowScale.
1608 
1609 		void SetShadowScale (const dng_urational &scale);
1610 
1611 		/// Getter for ShadowScale as dng_urational.
1612 
ShadowScaleR()1613 		const dng_urational & ShadowScaleR () const
1614 			{
1615 			return fShadowScale;
1616 			}
1617 
1618 		/// Getter for ShadowScale as real64.
1619 
ShadowScale()1620 		real64 ShadowScale () const
1621 			{
1622 			return ShadowScaleR ().As_real64 ();
1623 			}
1624 
1625 		// API for ColorimetricReference.
1626 
SetColorimetricReference(uint32 ref)1627 		void SetColorimetricReference (uint32 ref)
1628 			{
1629 			fColorimetricReference = ref;
1630 			}
1631 
ColorimetricReference()1632 		uint32 ColorimetricReference () const
1633 			{
1634 			return fColorimetricReference;
1635 			}
1636 
1637         // Floating point flag.
1638 
SetFloatingPoint(bool isFloatingPoint)1639         void SetFloatingPoint (bool isFloatingPoint)
1640             {
1641             fFloatingPoint = isFloatingPoint;
1642             }
1643 
IsFloatingPoint()1644         bool IsFloatingPoint () const
1645             {
1646             return fFloatingPoint;
1647             }
1648 
1649         // HDR/NDR.
1650 
IsHighDynamicRange()1651         bool IsHighDynamicRange () const
1652             {
1653             return IsFloatingPoint () &&
1654                    ColorimetricReference () == crSceneReferred;
1655             }
1656 
IsNormalDynamicRange()1657         bool IsNormalDynamicRange () const
1658             {
1659             return !IsHighDynamicRange ();
1660             }
1661 
1662 		/// Setter for ColorChannels.
1663 
SetColorChannels(uint32 channels)1664 		void SetColorChannels (uint32 channels)
1665 			{
1666 			fColorChannels = channels;
1667 			}
1668 
1669 		/// Getter for ColorChannels.
1670 
ColorChannels()1671 		uint32 ColorChannels () const
1672 			{
1673 			return fColorChannels;
1674 			}
1675 
1676 		/// Setter for Monochrome.
1677 
SetMonochrome()1678 		void SetMonochrome ()
1679 			{
1680 			SetColorChannels (1);
1681 			}
1682 
1683 		/// Getter for Monochrome.
1684 
IsMonochrome()1685 		bool IsMonochrome () const
1686 			{
1687 			return ColorChannels () == 1;
1688 			}
1689 
1690 		/// Setter for AnalogBalance.
1691 
1692 		void SetAnalogBalance (const dng_vector &b);
1693 
1694 		/// Getter for AnalogBalance as dng_urational.
1695 
1696 		dng_urational AnalogBalanceR (uint32 channel) const;
1697 
1698 		/// Getter for AnalogBalance as real64.
1699 
1700 		real64 AnalogBalance (uint32 channel) const;
1701 
1702 		/// Setter for CameraNeutral.
1703 
1704 		void SetCameraNeutral (const dng_vector &n);
1705 
1706 		/// Clear CameraNeutral.
1707 
ClearCameraNeutral()1708 		void ClearCameraNeutral ()
1709 			{
1710 			fCameraNeutral.Clear ();
1711 			}
1712 
1713 		/// Determine if CameraNeutral has been set but not cleared.
1714 
HasCameraNeutral()1715 		bool HasCameraNeutral () const
1716 			{
1717 			return fCameraNeutral.NotEmpty ();
1718 			}
1719 
1720 		/// Getter for CameraNeutral.
1721 
CameraNeutral()1722 		const dng_vector & CameraNeutral () const
1723 			{
1724 			return fCameraNeutral;
1725 			}
1726 
1727 		dng_urational CameraNeutralR (uint32 channel) const;
1728 
1729 		/// Setter for CameraWhiteXY.
1730 
1731 		void SetCameraWhiteXY (const dng_xy_coord &coord);
1732 
HasCameraWhiteXY()1733 		bool HasCameraWhiteXY () const
1734 			{
1735 			return fCameraWhiteXY.IsValid ();
1736 			}
1737 
1738 		const dng_xy_coord & CameraWhiteXY () const;
1739 
1740 		void GetCameraWhiteXY (dng_urational &x,
1741 							   dng_urational &y) const;
1742 
1743 		// API for camera calibration:
1744 
1745 		/// Setter for first of up to two color matrices used for individual camera calibrations.
1746 		///
1747 		/// The sequence of matrix transforms is:
1748 		/// Camera data --> camera calibration --> "inverse" of color matrix
1749 		///
1750 		/// This will be a 4x4 matrix for a four-color camera. The defaults are
1751 		/// almost always the identity matrix, and for the cases where they
1752 		/// aren't, they are diagonal matrices.
1753 
1754 		void SetCameraCalibration1 (const dng_matrix &m);
1755 
1756 		/// Setter for second of up to two color matrices used for individual camera calibrations.
1757 		///
1758 		/// The sequence of matrix transforms is:
1759 		/// Camera data --> camera calibration --> "inverse" of color matrix
1760 		///
1761 		/// This will be a 4x4 matrix for a four-color camera. The defaults are
1762 		/// almost always the identity matrix, and for the cases where they
1763 		/// aren't, they are diagonal matrices.
1764 
1765 		void SetCameraCalibration2 (const dng_matrix &m);
1766 
1767 		/// Getter for first of up to two color matrices used for individual camera calibrations.
1768 
CameraCalibration1()1769 		const dng_matrix & CameraCalibration1 () const
1770 			{
1771 			return fCameraCalibration1;
1772 			}
1773 
1774 		/// Getter for second of up to two color matrices used for individual camera calibrations.
1775 
CameraCalibration2()1776 		const dng_matrix & CameraCalibration2 () const
1777 			{
1778 			return fCameraCalibration2;
1779 			}
1780 
SetCameraCalibrationSignature(const char * signature)1781 		void SetCameraCalibrationSignature (const char *signature)
1782 			{
1783 			fCameraCalibrationSignature.Set (signature);
1784 			}
1785 
CameraCalibrationSignature()1786 		const dng_string & CameraCalibrationSignature () const
1787 			{
1788 			return fCameraCalibrationSignature;
1789 			}
1790 
1791 		// Camera Profile API:
1792 
1793 		void AddProfile (AutoPtr<dng_camera_profile> &profile);
1794 
1795 		void ClearProfiles ();
1796 
1797 		void ClearProfiles (bool clearBuiltinMatrixProfiles,
1798 							bool clearReadFromDisk);
1799 
1800 		uint32 ProfileCount () const;
1801 
1802 		const dng_camera_profile & ProfileByIndex (uint32 index) const;
1803 
1804 		virtual const dng_camera_profile * ProfileByID (const dng_camera_profile_id &id,
1805 														bool useDefaultIfNoMatch = true) const;
1806 
HasProfileID(const dng_camera_profile_id & id)1807 		bool HasProfileID (const dng_camera_profile_id &id) const
1808 			{
1809 			return ProfileByID (id, false) != NULL;
1810 			}
1811 
1812 		// Returns the camera profile to embed when saving to DNG:
1813 
1814 		virtual const dng_camera_profile * ComputeCameraProfileToEmbed
1815 													(const dng_metadata &metadata) const;
1816 
1817 		// For non-const negatives, we can use the embedded metadata.
1818 
CameraProfileToEmbed()1819 		const dng_camera_profile * CameraProfileToEmbed ()
1820 			{
1821 			return ComputeCameraProfileToEmbed (Metadata ());
1822 			}
1823 
1824 		// API for AsShotProfileName.
1825 
SetAsShotProfileName(const char * name)1826 		void SetAsShotProfileName (const char *name)
1827 			{
1828 			fAsShotProfileName.Set (name);
1829 			}
1830 
AsShotProfileName()1831 		const dng_string & AsShotProfileName () const
1832 			{
1833 			return fAsShotProfileName;
1834 			}
1835 
1836 		// Makes a dng_color_spec object for this negative.
1837 
1838 		virtual dng_color_spec * MakeColorSpec (const dng_camera_profile_id &id) const;
1839 
1840 		// Compute a MD5 hash on an image, using a fixed algorithm.
1841 		// The results must be stable across different hardware, OSes,
1842 		// and software versions.
1843 
1844 		static dng_fingerprint FindImageDigest (dng_host &host,
1845                                                 const dng_image &image);
1846 
1847 		// API for RawImageDigest and NewRawImageDigest:
1848 
SetRawImageDigest(const dng_fingerprint & digest)1849 		void SetRawImageDigest (const dng_fingerprint &digest)
1850 			{
1851 			fRawImageDigest = digest;
1852 			}
1853 
SetNewRawImageDigest(const dng_fingerprint & digest)1854 		void SetNewRawImageDigest (const dng_fingerprint &digest)
1855 			{
1856 			fNewRawImageDigest = digest;
1857 			}
1858 
ClearRawImageDigest()1859 		void ClearRawImageDigest () const
1860 			{
1861 			fRawImageDigest   .Clear ();
1862 			fNewRawImageDigest.Clear ();
1863 			}
1864 
RawImageDigest()1865 		const dng_fingerprint & RawImageDigest () const
1866 			{
1867 			return fRawImageDigest;
1868 			}
1869 
NewRawImageDigest()1870 		const dng_fingerprint & NewRawImageDigest () const
1871 			{
1872 			return fNewRawImageDigest;
1873 			}
1874 
1875 		void FindRawImageDigest (dng_host &host) const;
1876 
1877 		void FindNewRawImageDigest (dng_host &host) const;
1878 
1879 		void ValidateRawImageDigest (dng_host &host);
1880 
1881 		// API for RawDataUniqueID:
1882 
SetRawDataUniqueID(const dng_fingerprint & id)1883 		void SetRawDataUniqueID (const dng_fingerprint &id)
1884 			{
1885 			fRawDataUniqueID = id;
1886 			}
1887 
1888 		dng_fingerprint RawDataUniqueID () const;
1889 
1890 		void FindRawDataUniqueID (dng_host &host) const;
1891 
1892 		virtual void RecomputeRawDataUniqueID (dng_host &host);
1893 
1894 		// API for original raw file name:
1895 
SetOriginalRawFileName(const char * name)1896 		void SetOriginalRawFileName (const char *name)
1897 			{
1898 			fOriginalRawFileName.Set (name);
1899 			}
1900 
HasOriginalRawFileName()1901 		bool HasOriginalRawFileName () const
1902 			{
1903 			return fOriginalRawFileName.NotEmpty ();
1904 			}
1905 
OriginalRawFileName()1906 		const dng_string & OriginalRawFileName () const
1907 			{
1908 			return fOriginalRawFileName;
1909 			}
1910 
1911 		// API for original raw file data:
1912 
SetHasOriginalRawFileData(bool hasData)1913 		void SetHasOriginalRawFileData (bool hasData)
1914 			{
1915 			fHasOriginalRawFileData = hasData;
1916 			}
1917 
CanEmbedOriginalRaw()1918 		bool CanEmbedOriginalRaw () const
1919 			{
1920 			return fHasOriginalRawFileData && HasOriginalRawFileName ();
1921 			}
1922 
SetOriginalRawFileData(AutoPtr<dng_memory_block> & data)1923 		void SetOriginalRawFileData (AutoPtr<dng_memory_block> &data)
1924 			{
1925 			fOriginalRawFileData.Reset (data.Release ());
1926 			}
1927 
OriginalRawFileData()1928 		const void * OriginalRawFileData () const
1929 			{
1930 			return fOriginalRawFileData.Get () ? fOriginalRawFileData->Buffer ()
1931 											   : NULL;
1932 			}
1933 
OriginalRawFileDataLength()1934 		uint32 OriginalRawFileDataLength () const
1935 			{
1936 			return fOriginalRawFileData.Get () ? fOriginalRawFileData->LogicalSize ()
1937 											   : 0;
1938 			}
1939 
1940 		// API for original raw file data digest.
1941 
SetOriginalRawFileDigest(const dng_fingerprint & digest)1942 		void SetOriginalRawFileDigest (const dng_fingerprint &digest)
1943 			{
1944 			fOriginalRawFileDigest = digest;
1945 			}
1946 
OriginalRawFileDigest()1947 		const dng_fingerprint & OriginalRawFileDigest () const
1948 			{
1949 			return fOriginalRawFileDigest;
1950 			}
1951 
1952 		void FindOriginalRawFileDigest () const;
1953 
1954 		void ValidateOriginalRawFileDigest ();
1955 
1956 		// API for DNG private data:
1957 
SetPrivateData(AutoPtr<dng_memory_block> & block)1958 		void SetPrivateData (AutoPtr<dng_memory_block> &block)
1959 			{
1960 			fDNGPrivateData.Reset (block.Release ());
1961 			}
1962 
ClearPrivateData()1963 		void ClearPrivateData ()
1964 			{
1965 			fDNGPrivateData.Reset ();
1966 			}
1967 
PrivateData()1968 		const uint8 * PrivateData () const
1969 			{
1970 			return fDNGPrivateData.Get () ? fDNGPrivateData->Buffer_uint8 ()
1971 										  : NULL;
1972 			}
1973 
PrivateLength()1974 		uint32 PrivateLength () const
1975 			{
1976 			return fDNGPrivateData.Get () ? fDNGPrivateData->LogicalSize ()
1977 										  : 0;
1978 			}
1979 
1980 		// API for MakerNote data:
1981 
SetMakerNoteSafety(bool safe)1982 		void SetMakerNoteSafety (bool safe)
1983 			{
1984 			Metadata ().SetMakerNoteSafety (safe);
1985 			}
1986 
IsMakerNoteSafe()1987 		bool IsMakerNoteSafe () METACONST
1988 			{
1989 			return Metadata ().IsMakerNoteSafe ();
1990 			}
1991 
SetMakerNote(AutoPtr<dng_memory_block> & block)1992 		void SetMakerNote (AutoPtr<dng_memory_block> &block)
1993 			{
1994 			Metadata ().SetMakerNote (block);
1995 			}
1996 
ClearMakerNote()1997 		void ClearMakerNote ()
1998 			{
1999 			Metadata ().ClearMakerNote ();
2000 			}
2001 
MakerNoteData()2002 		const void * MakerNoteData () METACONST
2003 			{
2004 			return Metadata ().MakerNoteData ();
2005 			}
2006 
MakerNoteLength()2007 		uint32 MakerNoteLength () METACONST
2008 			{
2009 			return Metadata ().MakerNoteLength ();
2010 			}
2011 
2012 		// API for EXIF metadata:
2013 
GetExif()2014 		dng_exif * GetExif ()
2015 			{
2016 			return Metadata ().GetExif ();
2017 			}
2018 
2019 		#if qMetadataOnConst
2020 
GetExif()2021 		const dng_exif * GetExif () const
2022 			{
2023 			return Metadata ().GetExif ();
2024 			}
2025 
2026 		#endif // qMetadataOnConst
2027 
ResetExif(dng_exif * newExif)2028 		void ResetExif (dng_exif * newExif)
2029 			{
2030 			Metadata ().ResetExif (newExif);
2031 			}
2032 
2033 		// API for original EXIF metadata.
2034 
GetOriginalExif()2035 		dng_exif * GetOriginalExif ()
2036 			{
2037 			return Metadata ().GetOriginalExif ();
2038 			}
2039 
2040 		#if qMetadataOnConst
2041 
GetOriginalExif()2042 		const dng_exif * GetOriginalExif () const
2043 			{
2044 			return Metadata ().GetOriginalExif ();
2045 			}
2046 
2047 		#endif // qMetadataOnConst
2048 
2049 		// API for IPTC metadata:
2050 
SetIPTC(AutoPtr<dng_memory_block> & block,uint64 offset)2051 		void SetIPTC (AutoPtr<dng_memory_block> &block,
2052 					  uint64 offset)
2053 			{
2054 			Metadata ().SetIPTC (block, offset);
2055 			}
2056 
SetIPTC(AutoPtr<dng_memory_block> & block)2057 		void SetIPTC (AutoPtr<dng_memory_block> &block)
2058 			{
2059 			Metadata ().SetIPTC (block);
2060 			}
2061 
ClearIPTC()2062 		void ClearIPTC ()
2063 			{
2064 			Metadata ().ClearIPTC ();
2065 			}
2066 
IPTCData()2067 		const void * IPTCData () METACONST
2068 			{
2069 			return Metadata ().IPTCData ();
2070 			}
2071 
IPTCLength()2072 		uint32 IPTCLength () METACONST
2073 			{
2074 			return Metadata ().IPTCLength ();
2075 			}
2076 
IPTCOffset()2077 		uint64 IPTCOffset () METACONST
2078 			{
2079 			return Metadata ().IPTCOffset ();
2080 			}
2081 
2082 		dng_fingerprint IPTCDigest (bool includePadding = true) METACONST
2083 			{
2084 			return Metadata ().IPTCDigest (includePadding);
2085 			}
2086 
RebuildIPTC(bool padForTIFF)2087 		void RebuildIPTC (bool padForTIFF)
2088 			{
2089 			Metadata ().RebuildIPTC (Allocator (), padForTIFF);
2090 			}
2091 
2092 		// API for XMP metadata:
2093 
2094 		bool SetXMP (dng_host &host,
2095 					 const void *buffer,
2096 					 uint32 count,
2097 					 bool xmpInSidecar = false,
2098 					 bool xmpIsNewer = false)
2099 			{
2100 			return Metadata ().SetXMP (host,
2101 									   buffer,
2102 									   count,
2103 									   xmpInSidecar,
2104 									   xmpIsNewer);
2105 			}
2106 
GetXMP()2107 		dng_xmp * GetXMP ()
2108 			{
2109 			return Metadata ().GetXMP ();
2110 			}
2111 
2112 		#if qMetadataOnConst
2113 
GetXMP()2114 		const dng_xmp * GetXMP () const
2115 			{
2116 			return Metadata ().GetXMP ();
2117 			}
2118 
2119 		#endif // qMetadataOnConst
2120 
XMPinSidecar()2121 		bool XMPinSidecar () METACONST
2122 			{
2123 			return Metadata ().XMPinSidecar ();
2124 			}
2125 
ResetXMP(dng_xmp * newXMP)2126 		void ResetXMP (dng_xmp * newXMP)
2127 			{
2128 			Metadata ().ResetXMP (newXMP);
2129 			}
2130 
ResetXMPSidecarNewer(dng_xmp * newXMP,bool inSidecar,bool isNewer)2131 		void ResetXMPSidecarNewer (dng_xmp * newXMP, bool inSidecar, bool isNewer )
2132 			{
2133 			Metadata ().ResetXMPSidecarNewer (newXMP, inSidecar, isNewer);
2134 			}
2135 
HaveValidEmbeddedXMP()2136 		bool HaveValidEmbeddedXMP () METACONST
2137 			{
2138 			return Metadata ().HaveValidEmbeddedXMP ();
2139 			}
2140 
2141 		// API for source MIME type.
2142 
SetSourceMIME(const char * s)2143 		void SetSourceMIME (const char *s)
2144 			{
2145 			Metadata ().SetSourceMIME (s);
2146 			}
2147 
2148 		// API for linearization information:
2149 
GetLinearizationInfo()2150 		const dng_linearization_info * GetLinearizationInfo () const
2151 			{
2152 			return fLinearizationInfo.Get ();
2153 			}
2154 
ClearLinearizationInfo()2155 		void ClearLinearizationInfo ()
2156 			{
2157 			fLinearizationInfo.Reset ();
2158 			}
2159 
2160 		// Linearization curve.  Usually used to increase compression ratios
2161 		// by storing the compressed data in a more visually uniform space.
2162 		// This is a 16-bit LUT that maps the stored data back to linear.
2163 
2164 		void SetLinearization (AutoPtr<dng_memory_block> &curve);
2165 
2166 		// Active area (non-black masked pixels).  These pixels are trimmed
2167 		// during linearization step.
2168 
2169 		void SetActiveArea (const dng_rect &area);
2170 
2171 		// Areas that are known to contain black masked pixels that can
2172 		// be used to estimate black levels.
2173 
2174 		void SetMaskedAreas (uint32 count,
2175 							 const dng_rect *area);
2176 
SetMaskedArea(const dng_rect & area)2177 		void SetMaskedArea (const dng_rect &area)
2178 			{
2179 			SetMaskedAreas (1, &area);
2180 			}
2181 
2182 		// Sensor black level information.
2183 
2184 		void SetBlackLevel (real64 black,
2185 							int32 plane = -1);
2186 
2187 		void SetQuadBlacks (real64 black0,
2188 						    real64 black1,
2189 						    real64 black2,
2190 						    real64 black3,
2191 							int32 plane = -1);
2192 
2193 		void Set6x6Blacks (real64 blacks6x6 [36],
2194 						   int32 plane = -1);
2195 
2196 		void SetRowBlacks (const real64 *blacks,
2197 						   uint32 count);
2198 
2199 		void SetColumnBlacks (const real64 *blacks,
2200 							  uint32 count);
2201 
2202 		// Sensor white level information.
2203 
2204 		uint32 WhiteLevel (uint32 plane = 0) const;
2205 
2206 		void SetWhiteLevel (uint32 white,
2207 							int32 plane = -1);
2208 
2209 		// API for mosaic information:
2210 
GetMosaicInfo()2211 		const dng_mosaic_info * GetMosaicInfo () const
2212 			{
2213 			return fMosaicInfo.Get ();
2214 			}
2215 
ClearMosaicInfo()2216 		void ClearMosaicInfo ()
2217 			{
2218 			fMosaicInfo.Reset ();
2219 			}
2220 
2221 		// ColorKeys APIs:
2222 
2223 		void SetColorKeys (ColorKeyCode color0,
2224 						   ColorKeyCode color1,
2225 						   ColorKeyCode color2,
2226 						   ColorKeyCode color3 = colorKeyMaxEnum);
2227 
SetRGB()2228 		void SetRGB ()
2229 			{
2230 
2231 			SetColorChannels (3);
2232 
2233 			SetColorKeys (colorKeyRed,
2234 						  colorKeyGreen,
2235 						  colorKeyBlue);
2236 
2237 			}
2238 
SetCMY()2239 		void SetCMY ()
2240 			{
2241 
2242 			SetColorChannels (3);
2243 
2244 			SetColorKeys (colorKeyCyan,
2245 						  colorKeyMagenta,
2246 						  colorKeyYellow);
2247 
2248 			}
2249 
SetGMCY()2250 		void SetGMCY ()
2251 			{
2252 
2253 			SetColorChannels (4);
2254 
2255 			SetColorKeys (colorKeyGreen,
2256 						  colorKeyMagenta,
2257 					      colorKeyCyan,
2258 						  colorKeyYellow);
2259 
2260 			}
2261 
2262 		// APIs to set mosaic patterns.
2263 
2264 		void SetBayerMosaic (uint32 phase);
2265 
2266 		void SetFujiMosaic (uint32 phase);
2267 
2268 		void SetFujiMosaic6x6 (uint32 phase);
2269 
2270 		void SetQuadMosaic (uint32 pattern);
2271 
2272 		// BayerGreenSplit.
2273 
2274 		void SetGreenSplit (uint32 split);
2275 
2276 		// APIs for opcode lists.
2277 
OpcodeList1()2278 		const dng_opcode_list & OpcodeList1 () const
2279 			{
2280 			return fOpcodeList1;
2281 			}
2282 
OpcodeList1()2283 		dng_opcode_list & OpcodeList1 ()
2284 			{
2285 			return fOpcodeList1;
2286 			}
2287 
OpcodeList2()2288 		const dng_opcode_list & OpcodeList2 () const
2289 			{
2290 			return fOpcodeList2;
2291 			}
2292 
OpcodeList2()2293 		dng_opcode_list & OpcodeList2 ()
2294 			{
2295 			return fOpcodeList2;
2296 			}
2297 
OpcodeList3()2298 		const dng_opcode_list & OpcodeList3 () const
2299 			{
2300 			return fOpcodeList3;
2301 			}
2302 
OpcodeList3()2303 		dng_opcode_list & OpcodeList3 ()
2304 			{
2305 			return fOpcodeList3;
2306 			}
2307 
2308 		// First part of parsing logic.
2309 
2310 		virtual void Parse (dng_host &host,
2311 							dng_stream &stream,
2312 							dng_info &info);
2313 
2314 		// Second part of parsing logic.  This is split off from the
2315 		// first part because these operations are useful when extending
2316 		// this sdk to support non-DNG raw formats.
2317 
2318 		virtual void PostParse (dng_host &host,
2319 								dng_stream &stream,
2320 								dng_info &info);
2321 
2322 		// Synchronize metadata sources.
2323 
SynchronizeMetadata()2324 		void SynchronizeMetadata ()
2325 			{
2326 			Metadata ().SynchronizeMetadata ();
2327 			}
2328 
2329 		// Routines to update the date/time field in the EXIF and XMP
2330 		// metadata.
2331 
UpdateDateTime(const dng_date_time_info & dt)2332 		void UpdateDateTime (const dng_date_time_info &dt)
2333 			{
2334 			Metadata ().UpdateDateTime (dt);
2335 			}
2336 
UpdateDateTimeToNow()2337 		void UpdateDateTimeToNow ()
2338 			{
2339 			Metadata ().UpdateDateTimeToNow ();
2340 			}
2341 
2342 		// Developer's utility function to switch to four color Bayer
2343 		// interpolation.  This is useful for evaluating how much green
2344 		// split a Bayer pattern sensor has.
2345 
2346 		virtual bool SetFourColorBayer ();
2347 
2348 		// Access routines for the image stages.
2349 
Stage1Image()2350 		const dng_image * Stage1Image () const
2351 			{
2352 			return fStage1Image.Get ();
2353 			}
2354 
Stage2Image()2355 		const dng_image * Stage2Image () const
2356 			{
2357 			return fStage2Image.Get ();
2358 			}
2359 
Stage3Image()2360 		const dng_image * Stage3Image () const
2361 			{
2362 			return fStage3Image.Get ();
2363 			}
2364 
2365 		// Returns the processing stage of the raw image data.
2366 
RawImageStage()2367 		RawImageStageEnum RawImageStage () const
2368 			{
2369 			return fRawImageStage;
2370 			}
2371 
2372 		// Returns the raw image data.
2373 
2374 		const dng_image & RawImage () const;
2375 
2376         // Returns the raw image black level in 16-bit space.
2377 
2378         uint16 RawImageBlackLevel () const;
2379 
2380 		// API for raw floating point bit depth.
2381 
RawFloatBitDepth()2382 		uint32 RawFloatBitDepth () const
2383 			{
2384 			return fRawFloatBitDepth;
2385 			}
2386 
SetRawFloatBitDepth(uint32 bitDepth)2387 		void SetRawFloatBitDepth (uint32 bitDepth)
2388 			{
2389 			fRawFloatBitDepth = bitDepth;
2390 			}
2391 
2392 		// API for raw jpeg image.
2393 
2394 		const dng_jpeg_image * RawJPEGImage () const;
2395 
2396 		void SetRawJPEGImage (AutoPtr<dng_jpeg_image> &jpegImage);
2397 
2398 		void ClearRawJPEGImage ();
2399 
2400 		// API for RawJPEGImageDigest:
2401 
SetRawJPEGImageDigest(const dng_fingerprint & digest)2402 		void SetRawJPEGImageDigest (const dng_fingerprint &digest)
2403 			{
2404 			fRawJPEGImageDigest = digest;
2405 			}
2406 
ClearRawJPEGImageDigest()2407 		void ClearRawJPEGImageDigest () const
2408 			{
2409 			fRawJPEGImageDigest.Clear ();
2410 			}
2411 
RawJPEGImageDigest()2412 		const dng_fingerprint & RawJPEGImageDigest () const
2413 			{
2414 			return fRawJPEGImageDigest;
2415 			}
2416 
2417 		void FindRawJPEGImageDigest (dng_host &host) const;
2418 
2419         // Read the opcode lists.
2420 
2421         virtual void ReadOpcodeLists (dng_host &host,
2422                                       dng_stream &stream,
2423                                       dng_info &info);
2424 
2425         // Read the stage 1 image.
2426 
2427         virtual void ReadStage1Image (dng_host &host,
2428                                       dng_stream &stream,
2429                                       dng_info &info);
2430 
2431         // Read the enhanced image directly into the stage 3 image.
2432 
2433         virtual void ReadEnhancedImage (dng_host &host,
2434                                         dng_stream &stream,
2435                                         dng_info &info);
2436 
2437 		// Assign the stage 1 image.
2438 
2439 		void SetStage1Image (AutoPtr<dng_image> &image);
2440 
2441 		// Assign the stage 2 image.
2442 
2443 		void SetStage2Image (AutoPtr<dng_image> &image);
2444 
2445 		// Assign the stage 3 image.
2446 
2447 		void SetStage3Image (AutoPtr<dng_image> &image);
2448 
2449 		// Build the stage 2 (linearized and range mapped) image.
2450 
2451 		void BuildStage2Image (dng_host &host);
2452 
2453 		// Build the stage 3 (demosaiced) image.
2454 
2455 		void BuildStage3Image (dng_host &host,
2456 							   int32 srcPlane = -1);
2457 
2458 		// Additional gain applied when building the stage 3 image.
2459 
SetStage3Gain(real64 gain)2460 		void SetStage3Gain (real64 gain)
2461 			{
2462 			fStage3Gain = gain;
2463 			}
2464 
Stage3Gain()2465 		real64 Stage3Gain () const
2466 			{
2467 			return fStage3Gain;
2468 			}
2469 
2470 		// Optical black level of stage 3 image (in [0,65535]).
2471 
SetStage3BlackLevel(uint16 level)2472         void SetStage3BlackLevel (uint16 level)
2473             {
2474             fStage3BlackLevel = level;
2475             }
2476 
Stage3BlackLevel()2477 		uint16 Stage3BlackLevel () const
2478 			{
2479 			return fStage3BlackLevel;
2480 			}
2481 
2482 		// Optical black level of stage 3 image (in [0,1]).
2483 
Stage3BlackLevelNormalized()2484 		real64 Stage3BlackLevelNormalized () const
2485 			{
2486 			return fStage3BlackLevel * (1.0 / 65535.0);
2487 			}
2488 
2489 		// Is this negative permitted to support deferred black subtraction
2490 		// (by preserving offset or negative black values in the stage 3
2491 		// image)?
2492 		//
2493 		// If false, then fStage3BlackLevel must be zero.
2494 		// If true, then fStage3BlackLevel may or may not be zero.
2495 		//
2496 		// Default implementation return false.
2497 
2498 		virtual bool SupportsPreservedBlackLevels (dng_host &host);
2499 
2500 		// Adaptively encode a proxy image down to 8-bits/channel.
2501 
2502 		dng_image * EncodeRawProxy (dng_host &host,
2503 									const dng_image &srcImage,
2504 									dng_opcode_list &opcodeList,
2505                                     real64 *blackLevel) const;
2506 
2507 		// Convert to a proxy negative.
2508 
2509 		void ConvertToProxy (dng_host &host,
2510 							 dng_image_writer &writer,
2511 							 uint32 proxySize = 0,
2512 							 uint64 proxyCount = 0);
2513 
2514         // IsProxy API:
2515 
2516         bool IsProxy () const;
2517 
2518 		// IsPreview API:
2519 
SetIsPreview(bool preview)2520 		void SetIsPreview (bool preview)
2521 			{
2522 			fIsPreview = preview;
2523 			}
2524 
IsPreview()2525 		bool IsPreview () const
2526 			{
2527 			return fIsPreview;
2528 			}
2529 
2530 		// IsDamaged API:
2531 
SetIsDamaged(bool damaged)2532 		void SetIsDamaged (bool damaged)
2533 			{
2534 			fIsDamaged = damaged;
2535 			}
2536 
IsDamaged()2537 		bool IsDamaged () const
2538 			{
2539 			return fIsDamaged;
2540 			}
2541 
2542 		// Transparancy Mask API:
2543 
2544 		void SetTransparencyMask (AutoPtr<dng_image> &image,
2545 								  uint32 bitDepth = 0);
2546 
2547 		const dng_image * TransparencyMask () const;
2548 
2549 		const dng_image * RawTransparencyMask () const;
2550 
2551 		uint32 RawTransparencyMaskBitDepth () const;
2552 
2553 		void ReadTransparencyMask (dng_host &host,
2554 								   dng_stream &stream,
2555 								   dng_info &info);
2556 
2557         virtual void ResizeTransparencyToMatchStage3 (dng_host &host,
2558                                                       bool convertTo8Bit = false);
2559 
2560 		virtual bool NeedFlattenTransparency (dng_host &host);
2561 
2562 		virtual void FlattenTransparency (dng_host &host);
2563 
2564 		const dng_image * UnflattenedStage3Image () const;
2565 
2566 		// Depth map API:
2567 
HasDepthMap()2568 		bool HasDepthMap () const
2569             {
2570             return fHasDepthMap;
2571             }
2572 
SetHasDepthMap(bool hasDepthMap)2573 		void SetHasDepthMap (bool hasDepthMap)
2574 			{
2575 			fHasDepthMap = hasDepthMap;
2576 			}
2577 
DepthMap()2578 		const dng_image * DepthMap () const
2579 			{
2580 			return fDepthMap.Get ();
2581 			}
2582 
2583 		void SetDepthMap (AutoPtr<dng_image> &depthMap);
2584 
HasDepthMapImage()2585 		bool HasDepthMapImage () const
2586 			{
2587 			return (fDepthMap.Get () != NULL);
2588 			}
2589 
RawDepthMap()2590         const dng_image * RawDepthMap () const
2591             {
2592             if (fRawDepthMap.Get ())
2593                 {
2594                 return fRawDepthMap.Get ();
2595                 }
2596             return DepthMap ();
2597             }
2598 
2599         void ReadDepthMap (dng_host &host,
2600                            dng_stream &stream,
2601                            dng_info &info);
2602 
2603         virtual void ResizeDepthToMatchStage3 (dng_host &host);
2604 
DepthFormat()2605         uint32 DepthFormat () const
2606             {
2607             return fDepthFormat;
2608             }
2609 
SetDepthFormat(uint32 format)2610         void SetDepthFormat (uint32 format)
2611             {
2612             fDepthFormat = format;
2613             }
2614 
DepthNear()2615         const dng_urational & DepthNear () const
2616             {
2617             return fDepthNear;
2618             }
2619 
SetDepthNear(const dng_urational & dist)2620         void SetDepthNear (const dng_urational &dist)
2621             {
2622             fDepthNear = dist;
2623             }
2624 
DepthFar()2625         const dng_urational & DepthFar () const
2626             {
2627             return fDepthFar;
2628             }
2629 
SetDepthFar(const dng_urational & dist)2630         void SetDepthFar (const dng_urational &dist)
2631             {
2632             fDepthFar = dist;
2633             }
2634 
DepthUnits()2635         uint32 DepthUnits () const
2636             {
2637             return fDepthUnits;
2638             }
2639 
SetDepthUnits(uint32 units)2640         void SetDepthUnits (uint32 units)
2641             {
2642             fDepthUnits = units;
2643             }
2644 
DepthMeasureType()2645         uint32 DepthMeasureType () const
2646             {
2647             return fDepthMeasureType;
2648             }
2649 
SetDepthMeasureType(uint32 measure)2650         void SetDepthMeasureType (uint32 measure)
2651             {
2652             fDepthMeasureType = measure;
2653             }
2654 
2655          // EnhanceParams API:
2656 
EnhanceParams()2657         const dng_string & EnhanceParams () const
2658             {
2659             return fEnhanceParams;
2660             }
2661 
SetEnhanceParams(const dng_string & s)2662         void SetEnhanceParams (const dng_string &s)
2663             {
2664             fEnhanceParams = s;
2665             }
2666 
SetEnhanceParams(const char * s)2667         void SetEnhanceParams (const char *s)
2668             {
2669             fEnhanceParams.Set (s);
2670             }
2671 
2672 	protected:
2673 
2674 		dng_negative (dng_host &host);
2675 
2676 		virtual void Initialize ();
2677 
2678 		virtual dng_linearization_info * MakeLinearizationInfo ();
2679 
2680 		void NeedLinearizationInfo ();
2681 
2682 		virtual dng_mosaic_info * MakeMosaicInfo ();
2683 
2684 		void NeedMosaicInfo ();
2685 
2686 		virtual void DoBuildStage2 (dng_host &host);
2687 
2688 		virtual void DoPostOpcodeList2 (dng_host &host);
2689 
2690 		virtual bool NeedDefloatStage2 (dng_host &host);
2691 
2692 		virtual void DefloatStage2 (dng_host &host);
2693 
2694 		virtual void DoInterpolateStage3 (dng_host &host,
2695 									      int32 srcPlane,
2696                                           dng_matrix *scaleTransforms);
2697 
2698 		virtual void DoMergeStage3 (dng_host &host,
2699                                     dng_matrix *scaleTransforms);
2700 
2701 		virtual void DoBuildStage3 (dng_host &host,
2702 									int32 srcPlane,
2703                                     dng_matrix *scaleTransforms);
2704 
2705 		virtual void AdjustProfileForStage3 ();
2706 
2707 	};
2708 
2709 /*****************************************************************************/
2710 
2711 #endif
2712 
2713 /*****************************************************************************/
2714