Debian Codegraph @

core/libs/dngwriter/extra/dng_sdk/dng_negative.h

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