Debian Codegraph @

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

raw
1 /******************************************************************************/
2 // Copyright 2006-2020 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 * Support for DNG camera color profile information.
11 *
12 * Per the \ref spec_dng "DNG 1.6.0.0 specification", a DNG file can store up
13 * to three sets of color profile information for a camera in the DNG file
14 * from that camera. The second and third sets are optional and when there are
15 * multiple sets, they represent profiles made under different illumination.
16 *
17 * Profiling information is optionally separated into two parts. One part
18 * represents a profile for a reference camera. The second is a per-camera
19 * calibration that takes into account unit-to-unit variation. This is
20 * designed to allow replacing the reference color matrix with one of one's
21 * own construction while maintaining any unit-specific calibration the camera
22 * manufacturer may have provided.
23 *
24 * See Chapter 6 of the \ref spec_dng "DNG 1.6.0 specification" for more
25 * information.
26 */
27
28 #ifndef __dng_camera_profile__
29 #define __dng_camera_profile__
30
31 /******************************************************************************/
32
33 #include "dng_auto_ptr.h"
34 #include "dng_assertions.h"
35 #include "dng_classes.h"
36 #include "dng_fingerprint.h"
37 #include "dng_hue_sat_map.h"
38 #include "dng_matrix.h"
39 #include "dng_string.h"
40 #include "dng_tag_values.h"
41 #include "dng_tone_curve.h"
42 #include "dng_xy_coord.h"
43
44 /******************************************************************************/
45
46 extern const char * kProfileName_Embedded;
47
48 extern const char * kAdobeCalibrationSignature;
49
50 /******************************************************************************/
51
52 /// @brief An ID for a camera profile consisting of a name and optional fingerprint.
53
54 class dng_camera_profile_id
55 {
56
57 private:
58
59 dng_string fName;
60
61 dng_fingerprint fFingerprint;
62
63 public:
64
65 /// Construct an invalid camera profile ID (empty name and fingerprint).
66
67 dng_camera_profile_id ()
68
69 : fName ()
70 , fFingerprint ()
71
72 {
73 }
74
75 /// Construct a camera profile ID with the specified name and no fingerprint.
76 /// \param name The name of the camera profile ID.
77
78 dng_camera_profile_id (const char *name)
79
80 : fName ()
81 , fFingerprint ()
82
83 {
84 fName.Set (name);
85 }
86
87 /// Construct a camera profile ID with the specified name and no fingerprint.
88 /// \param name The name of the camera profile ID.
89
90 dng_camera_profile_id (const dng_string &name)
91
92 : fName (name)
93 , fFingerprint ()
94
95 {
96 }
97
98 /// Construct a camera profile ID with the specified name and fingerprint.
99 /// \param name The name of the camera profile ID.
100 /// \param fingerprint The fingerprint of the camera profile ID.
101
102 dng_camera_profile_id (const char *name,
103 const dng_fingerprint &fingerprint)
104
105 : fName ()
106 , fFingerprint (fingerprint)
107
108 {
109 fName.Set (name);
110 DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (),
111 "Cannot have profile fingerprint without name");
112 }
113
114 /// Construct a camera profile ID with the specified name and fingerprint.
115 /// \param name The name of the camera profile ID.
116 /// \param fingerprint The fingerprint of the camera profile ID.
117
118 dng_camera_profile_id (const dng_string &name,
119 const dng_fingerprint &fingerprint)
120
121 : fName (name)
122 , fFingerprint (fingerprint)
123
124 {
125 DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (),
126 "Cannot have profile fingerprint without name");
127 }
128
129 /// Getter for the name of the camera profile ID.
130 /// \retval The name of the camera profile ID.
131
132 const dng_string & Name () const
133 {
134 return fName;
135 }
136
137 /// Getter for the fingerprint of the camera profile ID.
138 /// \retval The fingerprint of the camera profile ID.
139
140 const dng_fingerprint & Fingerprint () const
141 {
142 return fFingerprint;
143 }
144
145 /// Test for equality of two camera profile IDs.
146 /// \param id The id of the camera profile ID to compare.
147
148 bool operator== (const dng_camera_profile_id &id) const
149 {
150 return fName == id.fName &&
151 fFingerprint == id.fFingerprint;
152 }
153
154 /// Test for inequality of two camera profile IDs.
155 /// \param id The id of the camera profile ID to compare.
156
157 bool operator!= (const dng_camera_profile_id &id) const
158 {
159 return !(*this == id);
160 }
161
162 /// Returns true iff the camera profile ID is valid.
163
164 bool IsValid () const
165 {
166 return fName.NotEmpty (); // Fingerprint is optional.
167 }
168
169 /// Resets the name and fingerprint, thereby making this camera profile ID
170 /// invalid.
171
172 void Clear ()
173 {
174 *this = dng_camera_profile_id ();
175 }
176
177 /// Adds this camera profile ID to a printer.
178
179 void AddDigest (dng_md5_printer &printer) const;
180
181 };
182
183 /*****************************************************************************/
184
185 extern const char * kProfileName_GroupPrefix;
186
187 bool HasProfileGroupPrefix (const dng_string &name);
188
189 dng_string StripProfileGroupPrefix (const dng_string &name);
190
191 /******************************************************************************/
192
193 /// @brief Information for selecting a specific profile from a profile group.
194
195 class dng_camera_profile_group_selector
196 {
197
198 public:
199
200 // Do we want the HDR version of the profile?
201
202 bool fHDR = false;
203
204 };
205
206 /******************************************************************************/
207
208 /// @brief Container for DNG camera color profile and calibration data.
209
210 class dng_camera_profile
211 {
212
213 private:
214
215 // Name of this camera profile.
216
217 dng_string fName;
218
219 // Group name of this camera profile.
220
221 dng_string fGroupName;
222
223 // Dynamic range info.
224
225 std::shared_ptr<const dng_camera_profile_dynamic_range> fDynamicRangeInfo;
226
227 // Light sources for up to three calibrations. These use the EXIF
228 // encodings for illuminant and are used to distinguish which
229 // matrix to use.
230
231 uint32 fCalibrationIlluminant1;
232 uint32 fCalibrationIlluminant2;
233 uint32 fCalibrationIlluminant3; // DNG 1.6
234
235 // Illuminant data if corresponding fCalibrationIlluminantX tag is set
236 // to 255 (Other).
237
238 dng_illuminant_data fIlluminantData1; // DNG 1.6
239 dng_illuminant_data fIlluminantData2; // DNG 1.6
240 dng_illuminant_data fIlluminantData3; // DNG 1.6
241
242 // Color matrices for up to three calibrations.
243
244 // These matrices map XYZ values to non-white balanced camera values.
245 // Adobe needs to go that direction in order to determine the clipping
246 // points for highlight recovery logic based on the white point. If
247 // cameras were all 3-color, the matrix could be stored as a forward matrix,
248 // but we need the backwards matrix to deal with 4-color cameras.
249
250 dng_matrix fColorMatrix1;
251 dng_matrix fColorMatrix2;
252 dng_matrix fColorMatrix3;
253
254 // These matrices map white balanced camera values to XYZ chromatically
255 // adapted to D50 (the ICC profile PCS white point). If the matrices
256 // exist, then this implies that white balancing should be done by scaling
257 // camera values with a diagonal matrix.
258
259 dng_matrix fForwardMatrix1;
260 dng_matrix fForwardMatrix2;
261 dng_matrix fForwardMatrix3;
262
263 // Dimensionality reduction hints for more than three color cameras.
264 // This is an optional matrix that maps the camera's color components
265 // to 3 components. These are only used if the forward matrices don't
266 // exist, and are used invert the color matrices.
267
268 dng_matrix fReductionMatrix1;
269 dng_matrix fReductionMatrix2;
270 dng_matrix fReductionMatrix3;
271
272 // MD5 hash for all data bits of the profile.
273
274 mutable dng_fingerprint fFingerprint;
275
276 // MD5 hash for all data bits of the profile that affect
277 // color rendering.
278
279 mutable dng_fingerprint fRenderDataFingerprint;
280
281 // Copyright notice from creator of profile.
282
283 dng_string fCopyright;
284
285 // Rules for how this profile can be embedded and/or copied.
286
287 uint32 fEmbedPolicy;
288
289 // 2-D (or 3-D) hue/sat tables to modify colors.
290
291 dng_hue_sat_map fHueSatDeltas1;
292 dng_hue_sat_map fHueSatDeltas2;
293 dng_hue_sat_map fHueSatDeltas3;
294
295 // Value (V of HSV) encoding for hue/sat tables.
296
297 uint32 fHueSatMapEncoding;
298
299 // 3-D hue/sat table to apply a "look".
300
301 dng_hue_sat_map fLookTable;
302
303 // Value (V of HSV) encoding for look table.
304
305 uint32 fLookTableEncoding;
306
307 // Baseline exposure offset. When using this profile, this offset value is
308 // added to the BaselineExposure value for the negative to determine the
309 // overall baseline exposure to apply.
310
311 dng_srational fBaselineExposureOffset;
312
313 // Default black rendering.
314
315 uint32 fDefaultBlackRender;
316
317 // The "as shot" tone curve for this profile. Check IsValid method
318 // to tell if one exists in profile.
319
320 dng_tone_curve fToneCurve;
321
322 // The preferred method for applying the tone curve for this profile.
323
324 uint32 fToneMethod;
325
326 // If this string matches the fCameraCalibrationSignature of the
327 // negative, then use the calibration matrix values from the negative.
328
329 dng_string fProfileCalibrationSignature;
330
331 // If non-empty, only allow use of this profile with camera having
332 // same unique model name.
333
334 dng_string fUniqueCameraModelRestriction;
335
336 // Was this profile read from inside a DNG file? (If so, we want
337 // to be sure to include it again when writing out an updated
338 // DNG file)
339
340 bool fWasReadFromDNG;
341
342 // Was this profile read from disk (i.e., an external profile)? (If so, we
343 // may need to refresh when changes are made externally to the profile
344 // directory.)
345
346 bool fWasReadFromDisk;
347
348 // Was this profile stubbed to save memory (and no longer valid
349 // for building color conversion tables)?
350
351 bool fWasStubbed;
352
353 // ProfileGainTableMap2.
354
355 std::shared_ptr<const dng_gain_table_map> fProfileGainTableMap;
356
357 // RGBTables.
358
359 std::shared_ptr<const dng_masked_rgb_tables> fMaskedRGBTables;
360
361 public:
362
363 dng_camera_profile ();
364
365 virtual ~dng_camera_profile ();
366
367 // API for profile name:
368
369 /// Setter for camera profile name.
370 /// \param name Name to use for this camera profile.
371
372 void SetName (const char *name)
373 {
374 fName.Set (name);
375 ClearFingerprint ();
376 }
377
378 /// Getter for camera profile name.
379 /// \retval Name of profile.
380
381 const dng_string & Name () const
382 {
383 return fName;
384 }
385
386 /// Setter for camera profile group name.
387 /// \param name Group name to use for this camera profile.
388
389 void SetGroupName (const dng_string &s)
390 {
391 fGroupName = s;
392 ClearFingerprint ();
393 }
394
395 /// Getter for camera profile group name.
396 /// \retval Group name of profile.
397
398 const dng_string & GroupName () const
399 {
400 return fGroupName;
401 }
402
403 /// Test if this name is embedded.
404 /// \retval true if the name matches the name of the embedded camera profile.
405
406 bool NameIsEmbedded () const
407 {
408 return fName.Matches (kProfileName_Embedded, true);
409 }
410
411 // API for calibration illuminants:
412
413 /// Getter for the illuminant model. Result will be 1, 2, or 3.
414 /// A value of 1 means the single-illuminant model, using ColorMatrix1 and related tags.
415 /// A value of 2 means the dual-illuminant model, using ColorMatrix1 and ColorMatrix2 and related tags.
416 /// A value of 3 means the triple-illuminant model, using ColorMatrix1, ColorMatrix2, ColorMatrix3 and related tags.
417
418 uint32 IlluminantModel () const;
419
420 /// Setter for first of up to three light sources used for calibration.
421 /// Uses the EXIF encodings for illuminant and is used to distinguish which
422 /// matrix to use.
423 /// Corresponds to the DNG CalibrationIlluminant1 tag.
424
425 void SetCalibrationIlluminant1 (uint32 light)
426 {
427 fCalibrationIlluminant1 = light;
428 ClearFingerprint ();
429 }
430
431 /// Setter for second of up to three light sources used for calibration.
432 /// Uses the EXIF encodings for illuminant and is used to distinguish which
433 /// matrix to use.
434 /// Corresponds to the DNG CalibrationIlluminant2 tag.
435
436 void SetCalibrationIlluminant2 (uint32 light)
437 {
438 fCalibrationIlluminant2 = light;
439 ClearFingerprint ();
440 }
441
442 /// Setter for third of up to three light sources used for calibration.
443 /// Uses the EXIF encodings for illuminant and is used to distinguish which
444 /// matrix to use.
445 /// Corresponds to the DNG CalibrationIlluminant3 tag.
446
447 void SetCalibrationIlluminant3 (uint32 light)
448 {
449 fCalibrationIlluminant3 = light;
450 ClearFingerprint ();
451 }
452
453 /// Getter for first of up to three light sources used for calibration.
454 /// Uses the EXIF encodings for illuminant and is used to distinguish which
455 /// matrix to use.
456 /// Corresponds to the DNG CalibrationIlluminant1 tag.
457
458 uint32 CalibrationIlluminant1 () const
459 {
460 return fCalibrationIlluminant1;
461 }
462
463 /// Getter for second of up to three light sources used for calibration.
464 /// Uses the EXIF encodings for illuminant and is used to distinguish which
465 /// matrix to use.
466 /// Corresponds to the DNG CalibrationIlluminant2 tag.
467
468 uint32 CalibrationIlluminant2 () const
469 {
470 return fCalibrationIlluminant2;
471 }
472
473 /// Getter for third of up to three light sources used for calibration.
474 /// Uses the EXIF encodings for illuminant and is used to distinguish which
475 /// matrix to use.
476 /// Corresponds to the DNG CalibrationIlluminant3 tag.
477
478 uint32 CalibrationIlluminant3 () const
479 {
480 return fCalibrationIlluminant3;
481 }
482
483 void SetIlluminantData1 (const dng_illuminant_data &data)
484 {
485 fIlluminantData1 = data;
486 ClearFingerprint ();
487 }
488
489 const dng_illuminant_data & IlluminantData1 () const
490 {
491 return fIlluminantData1;
492 }
493
494 void SetIlluminantData2 (const dng_illuminant_data &data)
495 {
496 fIlluminantData2 = data;
497 ClearFingerprint ();
498 }
499
500 const dng_illuminant_data & IlluminantData2 () const
501 {
502 return fIlluminantData2;
503 }
504
505 void SetIlluminantData3 (const dng_illuminant_data &data)
506 {
507 fIlluminantData3 = data;
508 ClearFingerprint ();
509 }
510
511 const dng_illuminant_data & IlluminantData3 () const
512 {
513 return fIlluminantData3;
514 }
515
516 /// Getter for first of up to three light sources used for calibration, returning
517 /// result as color temperature.
518
519 real64 CalibrationTemperature1 () const
520 {
521 return IlluminantToTemperature (CalibrationIlluminant1 (),
522 IlluminantData1 ());
523 }
524
525 /// Getter for second of up to three light sources used for calibration, returning
526 /// result as color temperature.
527
528 real64 CalibrationTemperature2 () const
529 {
530 return IlluminantToTemperature (CalibrationIlluminant2 (),
531 IlluminantData2 ());
532 }
533
534 /// Getter for third of up to three light sources used for calibration, returning
535 /// result as color temperature.
536
537 real64 CalibrationTemperature3 () const
538 {
539 return IlluminantToTemperature (CalibrationIlluminant3 (),
540 IlluminantData3 ());
541 }
542
543 // API for color matrices:
544
545 /// Utility function to normalize the scale of the color matrix.
546
547 static void NormalizeColorMatrix (dng_matrix &m);
548
549 /// Setter for first of up to three color matrices used for reference camera calibrations.
550 /// These matrices map XYZ values to camera values. The DNG SDK needs to map colors
551 /// that direction in order to determine the clipping points for
552 /// highlight recovery logic based on the white point. If cameras
553 /// were all three-color, the matrix could be stored as a forward matrix.
554 /// The inverse matrix is required to support four-color cameras.
555
556 void SetColorMatrix1 (const dng_matrix &m);
557
558 /// Setter for second of up to three color matrices used for reference camera calibrations.
559 /// These matrices map XYZ values to camera values. The DNG SDK needs to map colors
560 /// that direction in order to determine the clipping points for
561 /// highlight recovery logic based on the white point. If cameras
562 /// were all three-color, the matrix could be stored as a forward matrix.
563 /// The inverse matrix is required to support four-color cameras.
564
565 void SetColorMatrix2 (const dng_matrix &m);
566
567 /// Setter for third of up to three color matrices used for reference camera calibrations.
568 /// These matrices map XYZ values to camera values. The DNG SDK needs to map colors
569 /// that direction in order to determine the clipping points for
570 /// highlight recovery logic based on the white point. If cameras
571 /// were all three-color, the matrix could be stored as a forward matrix.
572 /// The inverse matrix is required to support four-color cameras.
573
574 void SetColorMatrix3 (const dng_matrix &m);
575
576 /// Predicate to test if first camera matrix is set
577
578 bool HasColorMatrix1 () const;
579
580 /// Predicate to test if second camera matrix is set
581
582 bool HasColorMatrix2 () const;
583
584 /// Predicate to test if third camera matrix is set
585
586 bool HasColorMatrix3 () const;
587
588 /// Getter for first of up to three color matrices used for calibrations.
589
590 const dng_matrix & ColorMatrix1 () const
591 {
592 return fColorMatrix1;
593 }
594
595 /// Getter for second of up to three color matrices used for calibrations.
596
597 const dng_matrix & ColorMatrix2 () const
598 {
599 return fColorMatrix2;
600 }
601
602 /// Getter for third of up to three color matrices used for calibrations.
603
604 const dng_matrix & ColorMatrix3 () const
605 {
606 return fColorMatrix3;
607 }
608
609 // API for forward matrices:
610
611 /// Utility function to normalize the scale of the forward matrix.
612
613 static void NormalizeForwardMatrix (dng_matrix &m);
614
615 /// Setter for first of up to three forward matrices used for calibrations.
616
617 void SetForwardMatrix1 (const dng_matrix &m);
618
619 /// Setter for second of up to three forward matrices used for calibrations.
620
621 void SetForwardMatrix2 (const dng_matrix &m);
622
623 /// Setter for third of up to three forward matrices used for calibrations.
624
625 void SetForwardMatrix3 (const dng_matrix &m);
626
627 /// Getter for first of up to three forward matrices used for calibrations.
628
629 const dng_matrix & ForwardMatrix1 () const
630 {
631 return fForwardMatrix1;
632 }
633
634 /// Getter for second of up to three forward matrices used for calibrations.
635
636 const dng_matrix & ForwardMatrix2 () const
637 {
638 return fForwardMatrix2;
639 }
640
641 /// Getter for third of up to three forward matrices used for calibrations.
642
643 const dng_matrix & ForwardMatrix3 () const
644 {
645 return fForwardMatrix3;
646 }
647
648 // API for reduction matrices:
649
650 /// Setter for first of up to three dimensionality reduction hints for four-color cameras.
651 /// This is an optional matrix that maps four components to three.
652 /// See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification."
653
654 void SetReductionMatrix1 (const dng_matrix &m);
655
656 /// Setter for second of up to three dimensionality reduction hints for four-color cameras.
657 /// This is an optional matrix that maps four components to three.
658 /// See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification."
659
660 void SetReductionMatrix2 (const dng_matrix &m);
661
662 /// Setter for third of up to three dimensionality reduction hints for four-color cameras.
663 /// This is an optional matrix that maps four components to three.
664 /// See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification."
665
666 void SetReductionMatrix3 (const dng_matrix &m);
667
668 /// Getter for first of up to three dimensionality reduction hints for four color cameras.
669
670 const dng_matrix & ReductionMatrix1 () const
671 {
672 return fReductionMatrix1;
673 }
674
675 /// Getter for second of up to three dimensionality reduction hints for four color cameras.
676
677 const dng_matrix & ReductionMatrix2 () const
678 {
679 return fReductionMatrix2;
680 }
681
682 /// Getter for third of up to three dimensionality reduction hints for four color cameras.
683
684 const dng_matrix & ReductionMatrix3 () const
685 {
686 return fReductionMatrix3;
687 }
688
689 /// Getter function for profile fingerprint.
690
691 const dng_fingerprint & Fingerprint () const
692 {
693
694 if (!fFingerprint.IsValid ())
695 {
696 fFingerprint = CalculateFingerprint (false);
697 }
698
699 return fFingerprint;
700
701 }
702
703 /// Getter function for profile render data fingerprint.
704
705 const dng_fingerprint & RenderDataFingerprint () const
706 {
707
708 if (!fRenderDataFingerprint.IsValid ())
709 {
710 fRenderDataFingerprint = CalculateFingerprint (true);
711 }
712
713 return fRenderDataFingerprint;
714
715 }
716
717 /// Getter for camera profile unique ID. Use this ID for uniquely
718 /// identifying profiles (e.g., for syncing purposes).
719
720 dng_fingerprint UniqueID () const;
721
722 /// Getter for camera profile id.
723 /// \retval ID of profile.
724
725 dng_camera_profile_id ProfileID () const
726 {
727 return dng_camera_profile_id (Name (), Fingerprint ());
728 }
729
730 /// Setter for camera profile copyright.
731 /// \param copyright Copyright string to use for this camera profile.
732
733 void SetCopyright (const char *copyright)
734 {
735 fCopyright.Set (copyright);
736 ClearFingerprint ();
737 }
738
739 /// Getter for camera profile copyright.
740 /// \retval Copyright string for profile.
741
742 const dng_string & Copyright () const
743 {
744 return fCopyright;
745 }
746
747 // Accessors for embed policy.
748
749 /// Setter for camera profile embed policy.
750 /// \param policy Policy to use for this camera profile.
751
752 void SetEmbedPolicy (uint32 policy)
753 {
754 fEmbedPolicy = policy;
755 ClearFingerprint ();
756 }
757
758 /// Getter for camera profile embed policy.
759 /// \retval Policy for profile.
760
761 uint32 EmbedPolicy () const
762 {
763 return fEmbedPolicy;
764 }
765
766 /// Returns true iff the profile is legal to embed in a DNG, per the
767 /// profile's embed policy.
768
769 bool IsLegalToEmbed () const
770 {
771 return WasReadFromDNG () ||
772 EmbedPolicy () == pepAllowCopying ||
773 EmbedPolicy () == pepEmbedIfUsed ||
774 EmbedPolicy () == pepNoRestrictions;
775 }
776
777 // Accessors for hue sat maps.
778
779 /// Returns true iff the profile has a valid HueSatMap color table.
780
781 bool HasHueSatDeltas () const
782 {
783 return fHueSatDeltas1.IsValid ();
784 }
785
786 /// Getter for first HueSatMap color table (for calibration illuminant 1).
787
788 const dng_hue_sat_map & HueSatDeltas1 () const
789 {
790 return fHueSatDeltas1;
791 }
792
793 /// Setter for first HueSatMap color table (for calibration illuminant 1).
794
795 void SetHueSatDeltas1 (const dng_hue_sat_map &deltas1);
796
797 /// Getter for second HueSatMap color table (for calibration illuminant 2).
798
799 const dng_hue_sat_map & HueSatDeltas2 () const
800 {
801 return fHueSatDeltas2;
802 }
803
804 /// Setter for second HueSatMap color table (for calibration illuminant 2).
805
806 void SetHueSatDeltas2 (const dng_hue_sat_map &deltas2);
807
808 /// Getter for third HueSatMap color table (for calibration illuminant 3).
809
810 const dng_hue_sat_map & HueSatDeltas3 () const
811 {
812 return fHueSatDeltas3;
813 }
814
815 /// Setter for third HueSatMap color table (for calibration illuminant 3).
816
817 void SetHueSatDeltas3 (const dng_hue_sat_map &deltas3);
818
819 // Accessors for hue sat map encoding.
820
821 /// Returns the hue sat map encoding (see ProfileHueSatMapEncoding tag).
822
823 uint32 HueSatMapEncoding () const
824 {
825 return fHueSatMapEncoding;
826 }
827
828 /// Sets the hue sat map encoding (see ProfileHueSatMapEncoding tag) to the
829 /// specified encoding.
830
831 void SetHueSatMapEncoding (uint32 encoding)
832 {
833 fHueSatMapEncoding = encoding;
834 ClearFingerprint ();
835 }
836
837 // Accessors for look table.
838
839 /// Returns true if the profile has a LookTable.
840
841 bool HasLookTable () const
842 {
843 return fLookTable.IsValid ();
844 }
845
846 /// Getter for LookTable.
847
848 const dng_hue_sat_map & LookTable () const
849 {
850 return fLookTable;
851 }
852
853 /// Setter for LookTable.
854
855 void SetLookTable (const dng_hue_sat_map &table);
856
857 // Accessors for look table encoding.
858
859 /// Returns the LookTable encoding (see ProfileLookTableEncoding tag).
860
861 uint32 LookTableEncoding () const
862 {
863 return fLookTableEncoding;
864 }
865
866 /// Sets the LookTable encoding (see ProfileLookTableEncoding tag) to the
867 /// specified encoding.
868
869 void SetLookTableEncoding (uint32 encoding)
870 {
871 fLookTableEncoding = encoding;
872 ClearFingerprint ();
873 }
874
875 // Accessors for baseline exposure offset.
876
877 /// Sets the baseline exposure offset of the profile (see
878 /// BaselineExposureOffset tag) to the specified value.
879
880 void SetBaselineExposureOffset (real64 exposureOffset)
881 {
882 fBaselineExposureOffset.Set_real64 (exposureOffset, 100);
883 ClearFingerprint ();
884 }
885
886 /// Returns the baseline exposure offset of the profile (see
887 /// BaselineExposureOffset tag).
888
889 const dng_srational & BaselineExposureOffset () const
890 {
891 return fBaselineExposureOffset;
892 }
893
894 // Accessors for default black render.
895
896 /// Sets the default black render of the profile (see DefaultBlackRender tag)
897 /// to the specified option.
898
899 void SetDefaultBlackRender (uint32 defaultBlackRender)
900 {
901 fDefaultBlackRender = defaultBlackRender;
902 ClearFingerprint ();
903 }
904
905 /// Returns the default black render of the profile (see DefaultBlackRender
906 /// tag).
907
908 uint32 DefaultBlackRender () const
909 {
910 return fDefaultBlackRender;
911 }
912
913 // Accessors for tone curve.
914
915 /// Returns the tone curve of the profile.
916
917 const dng_tone_curve & ToneCurve () const
918 {
919 return fToneCurve;
920 }
921
922 /// Sets the tone curve of the profile to the specified curve.
923
924 void SetToneCurve (const dng_tone_curve &curve)
925 {
926 fToneCurve = curve;
927 ClearFingerprint ();
928 }
929
930 // Accessors for tone method.
931
932 /// Sets the tone method of the profile (see ProfileToneMethod tag).
933
934 void SetToneMethod (uint32 toneMethod)
935 {
936 fToneMethod = toneMethod;
937 ClearFingerprint ();
938 }
939
940 /// Returns the tone method of the profile (see ProfileToneMethod tag).
941
942 uint32 ToneMethod () const
943 {
944 return fToneMethod;
945 }
946
947 // Accessors for profile calibration signature.
948
949 /// Sets the profile calibration signature (see ProfileCalibrationSignature
950 /// tag) to the specified string.
951
952 void SetProfileCalibrationSignature (const char *signature)
953 {
954 fProfileCalibrationSignature.Set (signature);
955 ClearFingerprint ();
956 }
957
958 /// Returns the profile calibration signature (see ProfileCalibrationSignature
959 /// tag) of the profile.
960
961 const dng_string & ProfileCalibrationSignature () const
962 {
963 return fProfileCalibrationSignature;
964 }
965
966 /// Setter for camera unique model name to restrict use of this profile.
967 /// \param camera Camera unique model name designating only camera this
968 /// profile can be used with. (Empty string for no restriction.)
969
970 void SetUniqueCameraModelRestriction (const char *camera)
971 {
972 fUniqueCameraModelRestriction.Set (camera);
973 // Not included in fingerprint, so don't need ClearFingerprint ().
974 }
975
976 /// Getter for camera unique model name to restrict use of this profile.
977 /// \retval Unique model name of only camera this profile can be used with
978 /// or empty if no restriction.
979
980 const dng_string & UniqueCameraModelRestriction () const
981 {
982 return fUniqueCameraModelRestriction;
983 }
984
985 // Accessors for was read from DNG flag.
986
987 /// Sets internal flag to indicate this profile was originally read from a
988 /// DNG file.
989
990 void SetWasReadFromDNG (bool state = true)
991 {
992 fWasReadFromDNG = state;
993 }
994
995 /// Was this profile read from a DNG?
996
997 bool WasReadFromDNG () const
998 {
999 return fWasReadFromDNG;
1000 }
1001
1002 // Accessors for was read from disk flag.
1003
1004 /// Sets internal flag to indicate this profile was originally read from
1005 /// disk.
1006
1007 void SetWasReadFromDisk (bool state = true)
1008 {
1009 fWasReadFromDisk = state;
1010 }
1011
1012 /// Was this profile read from disk?
1013
1014 bool WasReadFromDisk () const
1015 {
1016 return fWasReadFromDisk;
1017 }
1018
1019 /// Determines if this a valid profile for this number of color channels?
1020 /// \retval true if the profile is valid.
1021
1022 bool IsValid (uint32 channels) const;
1023
1024 /// Predicate to check if two camera profiles are colorwise equal, thus ignores
1025 /// the profile name.
1026 /// \param profile Camera profile to compare to.
1027
1028 bool EqualData (const dng_camera_profile &profile) const
1029 {
1030 return RenderDataFingerprint () == profile.RenderDataFingerprint ();
1031 }
1032
1033 /// Parse profile from dng_camera_profile_info data.
1034
1035 void Parse (dng_stream &stream,
1036 dng_camera_profile_info &profileInfo);
1037
1038 /// Parse from an extended profile stream, which is similar to stand alone
1039 /// TIFF file.
1040
1041 bool ParseExtended (dng_stream &stream);
1042
1043 /// Convert from a three-color to a four-color Bayer profile.
1044
1045 virtual void SetFourColorBayer ();
1046
1047 /// Find the hue/sat table to use for a given white point, if any.
1048 /// The calling routine owns the resulting table.
1049
1050 dng_hue_sat_map * HueSatMapForWhite (const dng_xy_coord &white) const;
1051
1052 /// Stub out the profile (free memory used by large tables).
1053
1054 void Stub ();
1055
1056 /// Was this profile stubbed?
1057
1058 bool WasStubbed () const
1059 {
1060 return fWasStubbed;
1061 }
1062
1063 /// ProfileGainTableMap2 API.
1064
1065 bool HasProfileGainTableMap () const;
1066
1067 std::shared_ptr<const dng_gain_table_map> ShareProfileGainTableMap () const
1068 {
1069 return fProfileGainTableMap;
1070 }
1071
1072 /// Gives profile shared ownership of gainTableMap.
1073
1074 void SetProfileGainTableMap
1075 (const std::shared_ptr<const dng_gain_table_map> &gainTableMap);
1076
1077 /// Dynamic Range API.
1078
1079 const dng_camera_profile_dynamic_range & DynamicRangeInfo () const;
1080
1081 // Is this profile intended for Standard Dynamic Range render output?
1082
1083 bool IsSDR () const;
1084
1085 // Is this profile intended for High Dynamic Range render output?
1086
1087 bool IsHDR () const;
1088
1089 void SetDynamicRangeInfo (const dng_camera_profile_dynamic_range &info);
1090
1091 // RGBTables API.
1092
1093 bool HasMaskedRGBTables () const;
1094
1095 const dng_masked_rgb_tables & MaskedRGBTables () const;
1096
1097 std::shared_ptr<const dng_masked_rgb_tables> ShareMaskedRGBTables () const
1098 {
1099 return fMaskedRGBTables;
1100 }
1101
1102 // Gives negative shared ownership of maskedRGBTables.
1103
1104 void SetMaskedRGBTables
1105 (const std::shared_ptr<const dng_masked_rgb_tables> &maskedRGBTables);
1106
1107 // Transfer ownership of maskedRGBTables to negative. After return,
1108 // maskedRGBTables will be nullptr.
1109
1110 void SetMaskedRGBTables
1111 (AutoPtr<dng_masked_rgb_tables> &maskedRGBTables);
1112
1113 // DNG 1.6 compatibility API.
1114
1115 /// Does this profile use any features introduced in DNG 1.6?
1116 /// If true, then the DNGVersion tag should be set to at least
1117 /// 1.6.0.0.
1118
1119 bool Uses_1_6_Features () const;
1120
1121 /// Does this profile require a DNG 1.6 reader?
1122 /// If true, then the DNGBackwardVersion tag must be set to
1123 /// 1.6.0.0 or later.
1124
1125 /// Note that a profile that uses DNG 1.6 tags might still be
1126 /// considered backwards compatible with older DNG readers in
1127 /// some cases.
1128
1129 bool Requires_1_6_Reader () const;
1130
1131 /// Does this profile use any features introduced in DNG 1.7?
1132 /// If true, then the DNGVersion tag should be set to at least
1133 /// 1.7.0.0.
1134
1135 bool Uses_1_7_Features () const;
1136
1137 private:
1138
1139 static real64 IlluminantToTemperature (uint32 light,
1140 const dng_illuminant_data &data);
1141
1142 void ClearFingerprint ()
1143 {
1144 fFingerprint.Clear ();
1145 fRenderDataFingerprint.Clear ();
1146 }
1147
1148 dng_fingerprint CalculateFingerprint (bool renderDataOnly) const;
1149
1150 static bool ValidForwardMatrix (const dng_matrix &m);
1151
1152 static void ReadHueSatMap (dng_stream &stream,
1153 dng_hue_sat_map &hueSatMap,
1154 uint32 hues,
1155 uint32 sats,
1156 uint32 vals,
1157 bool skipSat0);
1158
1159 dng_hue_sat_map * HueSatMapForWhite_Dual (const dng_xy_coord &white) const;
1160
1161 dng_hue_sat_map * HueSatMapForWhite_Triple (const dng_xy_coord &white) const;
1162
1163 };
1164
1165 /******************************************************************************/
1166
1167 class dng_camera_profile_metadata
1168 {
1169
1170 public:
1171
1172 dng_camera_profile_id fProfileID;
1173
1174 dng_string fGroupName;
1175
1176 bool fHDR;
1177
1178 dng_fingerprint fRenderDataFingerprint;
1179
1180 bool fIsLegalToEmbed;
1181
1182 bool fWasReadFromDNG;
1183
1184 bool fWasReadFromDisk;
1185
1186 dng_fingerprint fUniqueID; // Only valid if fWasReadFromDisk true
1187
1188 dng_string fFilePath; // Only valid if fWasReadFromDisk true
1189
1190 bool fReadOnly; // Only valid if fWasReadFromDisk true
1191
1192 int32 fIndex; // Only valid if attached to negative
1193
1194 public:
1195
1196 dng_camera_profile_metadata (const dng_camera_profile &profile,
1197 int32 index = -1);
1198
1199 bool operator== (const dng_camera_profile_metadata &metadata) const;
1200
1201 bool operator!= (const dng_camera_profile_metadata &metadata) const
1202 {
1203 return !(*this == metadata);
1204 }
1205
1206 };
1207
1208 /******************************************************************************/
1209
1210 void SplitCameraProfileName (const dng_string &name,
1211 dng_string &baseName,
1212 int32 &version);
1213
1214 /*****************************************************************************/
1215
1216 void BuildHueSatMapEncodingTable (dng_memory_allocator &allocator,
1217 uint32 encoding,
1218 AutoPtr<dng_1d_table> &encodeTable,
1219 AutoPtr<dng_1d_table> &decodeTable,
1220 bool subSample);
1221
1222 /******************************************************************************/
1223
1224 #endif
1225
1226 /******************************************************************************/