| 1 | /******************************************************************************/ |
| 2 | // Copyright 2006-2007 Adobe Systems Incorporated |
| 3 | // All Rights Reserved. |
| 4 | // |
| 5 | // NOTICE: Adobe permits you to use, modify, and distribute this file in |
| 6 | // accordance with the terms of the Adobe license agreement accompanying it. |
| 7 | /******************************************************************************/ |
| 8 | |
| 9 | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_camera_profile.h#2 $ */ |
| 10 | /* $DateTime: 2012/07/11 10:36:56 $ */ |
| 11 | /* $Change: 838485 $ */ |
| 12 | /* $Author: tknoll $ */ |
| 13 | |
| 14 | /** \file |
| 15 | * Support for DNG camera color profile information. |
| 16 | * Per the \ref spec_dng "DNG 1.1.0 specification", a DNG file can store up to |
| 17 | * two sets of color profile information for a camera in the DNG file from that |
| 18 | * camera. The second set is optional and when there are two sets, they represent |
| 19 | * profiles made under different illumination. |
| 20 | * |
| 21 | * Profiling information is optionally separated into two parts. One part represents |
| 22 | * a profile for a reference camera. (ColorMatrix1 and ColorMatrix2 here.) The |
| 23 | * second is a per-camera calibration that takes into account unit-to-unit variation. |
| 24 | * This is designed to allow replacing the reference color matrix with one of one's |
| 25 | * own construction while maintaining any unit-specific calibration the camera |
| 26 | * manufacturer may have provided. |
| 27 | * |
| 28 | * See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification" for more information. |
| 29 | */ |
| 30 | |
| 31 | #ifndef __dng_camera_profile__ |
| 32 | #define __dng_camera_profile__ |
| 33 | |
| 34 | /******************************************************************************/ |
| 35 | |
| 36 | #include "dng_auto_ptr.h" |
| 37 | #include "dng_assertions.h" |
| 38 | #include "dng_classes.h" |
| 39 | #include "dng_fingerprint.h" |
| 40 | #include "dng_hue_sat_map.h" |
| 41 | #include "dng_matrix.h" |
| 42 | #include "dng_string.h" |
| 43 | #include "dng_tag_values.h" |
| 44 | #include "dng_tone_curve.h" |
| 45 | |
| 46 | /******************************************************************************/ |
| 47 | |
| 48 | extern const char * kProfileName_Embedded; |
| 49 | |
| 50 | extern const char * kAdobeCalibrationSignature; |
| 51 | |
| 52 | /******************************************************************************/ |
| 53 | |
| 54 | /// \brief An ID for a camera profile consisting of a name and optional fingerprint. |
| 55 | |
| 56 | class dng_camera_profile_id |
| 57 | { |
| 58 | |
| 59 | private: |
| 60 | |
| 61 | dng_string fName; |
| 62 | |
| 63 | dng_fingerprint fFingerprint; |
| 64 | |
| 65 | public: |
| 66 | |
| 67 | /// Construct an invalid camera profile ID (empty name and fingerprint). |
| 68 | |
| 69 | dng_camera_profile_id () |
| 70 | |
| 71 | : fName () |
| 72 | , fFingerprint () |
| 73 | |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | /// Construct a camera profile ID with the specified name and no fingerprint. |
| 78 | /// \param name The name of the camera profile ID. |
| 79 | |
| 80 | dng_camera_profile_id (const char *name) |
| 81 | |
| 82 | : fName () |
| 83 | , fFingerprint () |
| 84 | |
| 85 | { |
| 86 | fName.Set (name); |
| 87 | } |
| 88 | |
| 89 | /// Construct a camera profile ID with the specified name and no fingerprint. |
| 90 | /// \param name The name of the camera profile ID. |
| 91 | |
| 92 | dng_camera_profile_id (const dng_string &name) |
| 93 | |
| 94 | : fName (name) |
| 95 | , fFingerprint () |
| 96 | |
| 97 | { |
| 98 | } |
| 99 | |
| 100 | /// Construct a camera profile ID with the specified name and fingerprint. |
| 101 | /// \param name The name of the camera profile ID. |
| 102 | /// \param fingerprint The fingerprint of the camera profile ID. |
| 103 | |
| 104 | dng_camera_profile_id (const char *name, |
| 105 | const dng_fingerprint &fingerprint) |
| 106 | |
| 107 | : fName () |
| 108 | , fFingerprint (fingerprint) |
| 109 | |
| 110 | { |
| 111 | fName.Set (name); |
| 112 | DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (), |
| 113 | "Cannot have profile fingerprint without name" ); |
| 114 | } |
| 115 | |
| 116 | /// Construct a camera profile ID with the specified name and fingerprint. |
| 117 | /// \param name The name of the camera profile ID. |
| 118 | /// \param fingerprint The fingerprint of the camera profile ID. |
| 119 | |
| 120 | dng_camera_profile_id (const dng_string &name, |
| 121 | const dng_fingerprint &fingerprint) |
| 122 | |
| 123 | : fName (name) |
| 124 | , fFingerprint (fingerprint) |
| 125 | |
| 126 | { |
| 127 | DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (), |
| 128 | "Cannot have profile fingerprint without name" ); |
| 129 | } |
| 130 | |
| 131 | /// Getter for the name of the camera profile ID. |
| 132 | /// \retval The name of the camera profile ID. |
| 133 | |
| 134 | const dng_string & Name () const |
| 135 | { |
| 136 | return fName; |
| 137 | } |
| 138 | |
| 139 | /// Getter for the fingerprint of the camera profile ID. |
| 140 | /// \retval The fingerprint of the camera profile ID. |
| 141 | |
| 142 | const dng_fingerprint & Fingerprint () const |
| 143 | { |
| 144 | return fFingerprint; |
| 145 | } |
| 146 | |
| 147 | /// Test for equality of two camera profile IDs. |
| 148 | /// \param The id of the camera profile ID to compare. |
| 149 | |
| 150 | bool operator== (const dng_camera_profile_id &id) const |
| 151 | { |
| 152 | return fName == id.fName && |
| 153 | fFingerprint == id.fFingerprint; |
| 154 | } |
| 155 | |
| 156 | /// Test for inequality of two camera profile IDs. |
| 157 | /// \param The id of the camera profile ID to compare. |
| 158 | |
| 159 | bool operator!= (const dng_camera_profile_id &id) const |
| 160 | { |
| 161 | return !(*this == id); |
| 162 | } |
| 163 | |
| 164 | /// Returns true iff the camera profile ID is valid. |
| 165 | |
| 166 | bool IsValid () const |
| 167 | { |
| 168 | return fName.NotEmpty (); // Fingerprint is optional. |
| 169 | } |
| 170 | |
| 171 | /// Resets the name and fingerprint, thereby making this camera profile ID |
| 172 | /// invalid. |
| 173 | |
| 174 | void Clear () |
| 175 | { |
| 176 | *this = dng_camera_profile_id (); |
| 177 | } |
| 178 | |
| 179 | }; |
| 180 | |
| 181 | /******************************************************************************/ |
| 182 | |
| 183 | /// \brief Container for DNG camera color profile and calibration data. |
| 184 | |
| 185 | class dng_camera_profile |
| 186 | { |
| 187 | |
| 188 | protected: |
| 189 | |
| 190 | // Name of this camera profile. |
| 191 | |
| 192 | dng_string fName; |
| 193 | |
| 194 | // Light sources for up to two calibrations. These use the EXIF |
| 195 | // encodings for illuminant and are used to distinguish which |
| 196 | // matrix to use. |
| 197 | |
| 198 | uint32 fCalibrationIlluminant1; |
| 199 | uint32 fCalibrationIlluminant2; |
| 200 | |
| 201 | // Color matrices for up to two calibrations. |
| 202 | |
| 203 | // These matrices map XYZ values to non-white balanced camera values. |
| 204 | // Adobe needs to go that direction in order to determine the clipping |
| 205 | // points for highlight recovery logic based on the white point. If |
| 206 | // cameras were all 3-color, the matrix could be stored as a forward matrix, |
| 207 | // but we need the backwards matrix to deal with 4-color cameras. |
| 208 | |
| 209 | dng_matrix fColorMatrix1; |
| 210 | dng_matrix fColorMatrix2; |
| 211 | |
| 212 | // These matrices map white balanced camera values to XYZ chromatically |
| 213 | // adapted to D50 (the ICC profile PCS white point). If the matrices |
| 214 | // exist, then this implies that white balancing should be done by scaling |
| 215 | // camera values with a diagonal matrix. |
| 216 | |
| 217 | dng_matrix fForwardMatrix1; |
| 218 | dng_matrix fForwardMatrix2; |
| 219 | |
| 220 | // Dimensionality reduction hints for more than three color cameras. |
| 221 | // This is an optional matrix that maps the camera's color components |
| 222 | // to 3 components. These are only used if the forward matrices don't |
| 223 | // exist, and are used invert the color matrices. |
| 224 | |
| 225 | dng_matrix fReductionMatrix1; |
| 226 | dng_matrix fReductionMatrix2; |
| 227 | |
| 228 | // MD5 hash for all data bits of the profile. |
| 229 | |
| 230 | mutable dng_fingerprint fFingerprint; |
| 231 | |
| 232 | // Copyright notice from creator of profile. |
| 233 | |
| 234 | dng_string fCopyright; |
| 235 | |
| 236 | // Rules for how this profile can be embedded and/or copied. |
| 237 | |
| 238 | uint32 fEmbedPolicy; |
| 239 | |
| 240 | // 2-D (or 3-D) hue/sat tables to modify colors. |
| 241 | |
| 242 | dng_hue_sat_map fHueSatDeltas1; |
| 243 | dng_hue_sat_map fHueSatDeltas2; |
| 244 | |
| 245 | // Value (V of HSV) encoding for hue/sat tables. |
| 246 | |
| 247 | uint32 fHueSatMapEncoding; |
| 248 | |
| 249 | // 3-D hue/sat table to apply a "look". |
| 250 | |
| 251 | dng_hue_sat_map fLookTable; |
| 252 | |
| 253 | // Value (V of HSV) encoding for look table. |
| 254 | |
| 255 | uint32 fLookTableEncoding; |
| 256 | |
| 257 | // Baseline exposure offset. When using this profile, this offset value is |
| 258 | // added to the BaselineExposure value for the negative to determine the |
| 259 | // overall baseline exposure to apply. |
| 260 | |
| 261 | dng_srational fBaselineExposureOffset; |
| 262 | |
| 263 | // Default black rendering. |
| 264 | |
| 265 | uint32 fDefaultBlackRender; |
| 266 | |
| 267 | // The "as shot" tone curve for this profile. Check IsValid method |
| 268 | // to tell if one exists in profile. |
| 269 | |
| 270 | dng_tone_curve fToneCurve; |
| 271 | |
| 272 | // If this string matches the fCameraCalibrationSignature of the |
| 273 | // negative, then use the calibration matrix values from the negative. |
| 274 | |
| 275 | dng_string fProfileCalibrationSignature; |
| 276 | |
| 277 | // If non-empty, only allow use of this profile with camera having |
| 278 | // same unique model name. |
| 279 | |
| 280 | dng_string fUniqueCameraModelRestriction; |
| 281 | |
| 282 | // Was this profile read from inside a DNG file? (If so, we wnat |
| 283 | // to be sure to include it again when writing out an updated |
| 284 | // DNG file) |
| 285 | |
| 286 | bool fWasReadFromDNG; |
| 287 | |
| 288 | // Was this profile read from disk (i.e., an external profile)? (If so, we |
| 289 | // may need to refresh when changes are made externally to the profile |
| 290 | // directory.) |
| 291 | |
| 292 | bool fWasReadFromDisk; |
| 293 | |
| 294 | // Was this profile a built-in "Matrix" profile? (If so, we may need to |
| 295 | // refresh -- i.e., remove it from the list of available profiles -- when |
| 296 | // changes are made externally to the profile directory.) |
| 297 | |
| 298 | bool fWasBuiltinMatrix; |
| 299 | |
| 300 | // Was this profile stubbed to save memory (and no longer valid |
| 301 | // for building color conversion tables)? |
| 302 | |
| 303 | bool fWasStubbed; |
| 304 | |
| 305 | public: |
| 306 | |
| 307 | dng_camera_profile (); |
| 308 | |
| 309 | virtual ~dng_camera_profile (); |
| 310 | |
| 311 | // API for profile name: |
| 312 | |
| 313 | /// Setter for camera profile name. |
| 314 | /// \param name Name to use for this camera profile. |
| 315 | |
| 316 | void SetName (const char *name) |
| 317 | { |
| 318 | fName.Set (name); |
| 319 | ClearFingerprint (); |
| 320 | } |
| 321 | |
| 322 | /// Getter for camera profile name. |
| 323 | /// \retval Name of profile. |
| 324 | |
| 325 | const dng_string & Name () const |
| 326 | { |
| 327 | return fName; |
| 328 | } |
| 329 | |
| 330 | /// Test if this name is embedded. |
| 331 | /// \retval true if the name matches the name of the embedded camera profile. |
| 332 | |
| 333 | bool NameIsEmbedded () const |
| 334 | { |
| 335 | return fName.Matches (kProfileName_Embedded, true); |
| 336 | } |
| 337 | |
| 338 | // API for calibration illuminants: |
| 339 | |
| 340 | /// Setter for first of up to two light sources used for calibration. |
| 341 | /// Uses the EXIF encodings for illuminant and is used to distinguish which |
| 342 | /// matrix to use. |
| 343 | /// Corresponds to the DNG CalibrationIlluminant1 tag. |
| 344 | |
| 345 | void SetCalibrationIlluminant1 (uint32 light) |
| 346 | { |
| 347 | fCalibrationIlluminant1 = light; |
| 348 | ClearFingerprint (); |
| 349 | } |
| 350 | |
| 351 | /// Setter for second of up to two light sources used for calibration. |
| 352 | /// Uses the EXIF encodings for illuminant and is used to distinguish which |
| 353 | /// matrix to use. |
| 354 | /// Corresponds to the DNG CalibrationIlluminant2 tag. |
| 355 | |
| 356 | void SetCalibrationIlluminant2 (uint32 light) |
| 357 | { |
| 358 | fCalibrationIlluminant2 = light; |
| 359 | ClearFingerprint (); |
| 360 | } |
| 361 | |
| 362 | /// Getter for first of up to two light sources used for calibration. |
| 363 | /// Uses the EXIF encodings for illuminant and is used to distinguish which |
| 364 | /// matrix to use. |
| 365 | /// Corresponds to the DNG CalibrationIlluminant1 tag. |
| 366 | |
| 367 | uint32 CalibrationIlluminant1 () const |
| 368 | { |
| 369 | return fCalibrationIlluminant1; |
| 370 | } |
| 371 | |
| 372 | /// Getter for second of up to two light sources used for calibration. |
| 373 | /// Uses the EXIF encodings for illuminant and is used to distinguish which |
| 374 | /// matrix to use. |
| 375 | /// Corresponds to the DNG CalibrationIlluminant2 tag. |
| 376 | |
| 377 | uint32 CalibrationIlluminant2 () const |
| 378 | { |
| 379 | return fCalibrationIlluminant2; |
| 380 | } |
| 381 | |
| 382 | /// Getter for first of up to two light sources used for calibration, returning |
| 383 | /// result as color temperature. |
| 384 | |
| 385 | real64 CalibrationTemperature1 () const |
| 386 | { |
| 387 | return IlluminantToTemperature (CalibrationIlluminant1 ()); |
| 388 | } |
| 389 | |
| 390 | /// Getter for second of up to two light sources used for calibration, returning |
| 391 | /// result as color temperature. |
| 392 | |
| 393 | real64 CalibrationTemperature2 () const |
| 394 | { |
| 395 | return IlluminantToTemperature (CalibrationIlluminant2 ()); |
| 396 | } |
| 397 | |
| 398 | // API for color matrices: |
| 399 | |
| 400 | /// Utility function to normalize the scale of the color matrix. |
| 401 | |
| 402 | static void NormalizeColorMatrix (dng_matrix &m); |
| 403 | |
| 404 | /// Setter for first of up to two color matrices used for reference camera calibrations. |
| 405 | /// These matrices map XYZ values to camera values. The DNG SDK needs to map colors |
| 406 | /// that direction in order to determine the clipping points for |
| 407 | /// highlight recovery logic based on the white point. If cameras |
| 408 | /// were all three-color, the matrix could be stored as a forward matrix. |
| 409 | /// The inverse matrix is requried to support four-color cameras. |
| 410 | |
| 411 | void SetColorMatrix1 (const dng_matrix &m); |
| 412 | |
| 413 | /// Setter for second of up to two color matrices used for reference camera calibrations. |
| 414 | /// These matrices map XYZ values to camera values. The DNG SDK needs to map colors |
| 415 | /// that direction in order to determine the clipping points for |
| 416 | /// highlight recovery logic based on the white point. If cameras |
| 417 | /// were all three-color, the matrix could be stored as a forward matrix. |
| 418 | /// The inverse matrix is requried to support four-color cameras. |
| 419 | |
| 420 | void SetColorMatrix2 (const dng_matrix &m); |
| 421 | |
| 422 | /// Predicate to test if first camera matrix is set |
| 423 | |
| 424 | bool HasColorMatrix1 () const; |
| 425 | |
| 426 | /// Predicate to test if second camera matrix is set |
| 427 | |
| 428 | bool HasColorMatrix2 () const; |
| 429 | |
| 430 | /// Getter for first of up to two color matrices used for calibrations. |
| 431 | |
| 432 | const dng_matrix & ColorMatrix1 () const |
| 433 | { |
| 434 | return fColorMatrix1; |
| 435 | } |
| 436 | |
| 437 | /// Getter for second of up to two color matrices used for calibrations. |
| 438 | |
| 439 | const dng_matrix & ColorMatrix2 () const |
| 440 | { |
| 441 | return fColorMatrix2; |
| 442 | } |
| 443 | |
| 444 | // API for forward matrices: |
| 445 | |
| 446 | /// Utility function to normalize the scale of the forward matrix. |
| 447 | |
| 448 | static void NormalizeForwardMatrix (dng_matrix &m); |
| 449 | |
| 450 | /// Setter for first of up to two forward matrices used for calibrations. |
| 451 | |
| 452 | void SetForwardMatrix1 (const dng_matrix &m); |
| 453 | |
| 454 | /// Setter for second of up to two forward matrices used for calibrations. |
| 455 | |
| 456 | void SetForwardMatrix2 (const dng_matrix &m); |
| 457 | |
| 458 | /// Getter for first of up to two forward matrices used for calibrations. |
| 459 | |
| 460 | const dng_matrix & ForwardMatrix1 () const |
| 461 | { |
| 462 | return fForwardMatrix1; |
| 463 | } |
| 464 | |
| 465 | /// Getter for second of up to two forward matrices used for calibrations. |
| 466 | |
| 467 | const dng_matrix & ForwardMatrix2 () const |
| 468 | { |
| 469 | return fForwardMatrix2; |
| 470 | } |
| 471 | |
| 472 | // API for reduction matrices: |
| 473 | |
| 474 | /// Setter for first of up to two dimensionality reduction hints for four-color cameras. |
| 475 | /// This is an optional matrix that maps four components to three. |
| 476 | /// See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification." |
| 477 | |
| 478 | void SetReductionMatrix1 (const dng_matrix &m); |
| 479 | |
| 480 | /// Setter for second of up to two dimensionality reduction hints for four-color cameras. |
| 481 | /// This is an optional matrix that maps four components to three. |
| 482 | /// See Appendix 6 of the \ref spec_dng "DNG 1.1.0 specification." |
| 483 | |
| 484 | void SetReductionMatrix2 (const dng_matrix &m); |
| 485 | |
| 486 | /// Getter for first of up to two dimensionality reduction hints for four color cameras. |
| 487 | |
| 488 | const dng_matrix & ReductionMatrix1 () const |
| 489 | { |
| 490 | return fReductionMatrix1; |
| 491 | } |
| 492 | |
| 493 | /// Getter for second of up to two dimensionality reduction hints for four color cameras. |
| 494 | |
| 495 | const dng_matrix & ReductionMatrix2 () const |
| 496 | { |
| 497 | return fReductionMatrix2; |
| 498 | } |
| 499 | |
| 500 | /// Getter function from profile fingerprint. |
| 501 | |
| 502 | const dng_fingerprint &Fingerprint () const |
| 503 | { |
| 504 | |
| 505 | if (!fFingerprint.IsValid ()) |
| 506 | CalculateFingerprint (); |
| 507 | |
| 508 | return fFingerprint; |
| 509 | |
| 510 | } |
| 511 | |
| 512 | /// Getter for camera profile id. |
| 513 | /// \retval ID of profile. |
| 514 | |
| 515 | dng_camera_profile_id ProfileID () const |
| 516 | { |
| 517 | return dng_camera_profile_id (Name (), Fingerprint ()); |
| 518 | } |
| 519 | |
| 520 | /// Setter for camera profile copyright. |
| 521 | /// \param copyright Copyright string to use for this camera profile. |
| 522 | |
| 523 | void SetCopyright (const char *copyright) |
| 524 | { |
| 525 | fCopyright.Set (copyright); |
| 526 | ClearFingerprint (); |
| 527 | } |
| 528 | |
| 529 | /// Getter for camera profile copyright. |
| 530 | /// \retval Copyright string for profile. |
| 531 | |
| 532 | const dng_string & Copyright () const |
| 533 | { |
| 534 | return fCopyright; |
| 535 | } |
| 536 | |
| 537 | // Accessors for embed policy. |
| 538 | |
| 539 | /// Setter for camera profile embed policy. |
| 540 | /// \param policy Policy to use for this camera profile. |
| 541 | |
| 542 | void SetEmbedPolicy (uint32 policy) |
| 543 | { |
| 544 | fEmbedPolicy = policy; |
| 545 | ClearFingerprint (); |
| 546 | } |
| 547 | |
| 548 | /// Getter for camera profile embed policy. |
| 549 | /// \param Policy for profile. |
| 550 | |
| 551 | uint32 EmbedPolicy () const |
| 552 | { |
| 553 | return fEmbedPolicy; |
| 554 | } |
| 555 | |
| 556 | /// Returns true iff the profile is legal to embed in a DNG, per the |
| 557 | /// profile's embed policy. |
| 558 | |
| 559 | bool IsLegalToEmbed () const |
| 560 | { |
| 561 | return WasReadFromDNG () || |
| 562 | EmbedPolicy () == pepAllowCopying || |
| 563 | EmbedPolicy () == pepEmbedIfUsed || |
| 564 | EmbedPolicy () == pepNoRestrictions; |
| 565 | } |
| 566 | |
| 567 | // Accessors for hue sat maps. |
| 568 | |
| 569 | /// Returns true iff the profile has a valid HueSatMap color table. |
| 570 | |
| 571 | bool HasHueSatDeltas () const |
| 572 | { |
| 573 | return fHueSatDeltas1.IsValid (); |
| 574 | } |
| 575 | |
| 576 | /// Getter for first HueSatMap color table (for calibration illuminant 1). |
| 577 | |
| 578 | const dng_hue_sat_map & HueSatDeltas1 () const |
| 579 | { |
| 580 | return fHueSatDeltas1; |
| 581 | } |
| 582 | |
| 583 | /// Setter for first HueSatMap color table (for calibration illuminant 1). |
| 584 | |
| 585 | void SetHueSatDeltas1 (const dng_hue_sat_map &deltas1); |
| 586 | |
| 587 | /// Getter for second HueSatMap color table (for calibration illuminant 2). |
| 588 | |
| 589 | const dng_hue_sat_map & HueSatDeltas2 () const |
| 590 | { |
| 591 | return fHueSatDeltas2; |
| 592 | } |
| 593 | |
| 594 | /// Setter for second HueSatMap color table (for calibration illuminant 2). |
| 595 | |
| 596 | void SetHueSatDeltas2 (const dng_hue_sat_map &deltas2); |
| 597 | |
| 598 | // Accessors for hue sat map encoding. |
| 599 | |
| 600 | /// Returns the hue sat map encoding (see ProfileHueSatMapEncoding tag). |
| 601 | |
| 602 | uint32 HueSatMapEncoding () const |
| 603 | { |
| 604 | return fHueSatMapEncoding; |
| 605 | } |
| 606 | |
| 607 | /// Sets the hue sat map encoding (see ProfileHueSatMapEncoding tag) to the |
| 608 | /// specified encoding. |
| 609 | |
| 610 | void SetHueSatMapEncoding (uint32 encoding) |
| 611 | { |
| 612 | fHueSatMapEncoding = encoding; |
| 613 | ClearFingerprint (); |
| 614 | } |
| 615 | |
| 616 | // Accessors for look table. |
| 617 | |
| 618 | /// Returns true if the profile has a LookTable. |
| 619 | |
| 620 | bool HasLookTable () const |
| 621 | { |
| 622 | return fLookTable.IsValid (); |
| 623 | } |
| 624 | |
| 625 | /// Getter for LookTable. |
| 626 | |
| 627 | const dng_hue_sat_map & LookTable () const |
| 628 | { |
| 629 | return fLookTable; |
| 630 | } |
| 631 | |
| 632 | /// Setter for LookTable. |
| 633 | |
| 634 | void SetLookTable (const dng_hue_sat_map &table); |
| 635 | |
| 636 | // Accessors for look table encoding. |
| 637 | |
| 638 | /// Returns the LookTable encoding (see ProfileLookTableEncoding tag). |
| 639 | |
| 640 | uint32 LookTableEncoding () const |
| 641 | { |
| 642 | return fLookTableEncoding; |
| 643 | } |
| 644 | |
| 645 | /// Sets the LookTable encoding (see ProfileLookTableEncoding tag) to the |
| 646 | /// specified encoding. |
| 647 | |
| 648 | void SetLookTableEncoding (uint32 encoding) |
| 649 | { |
| 650 | fLookTableEncoding = encoding; |
| 651 | ClearFingerprint (); |
| 652 | } |
| 653 | |
| 654 | // Accessors for baseline exposure offset. |
| 655 | |
| 656 | /// Sets the baseline exposure offset of the profile (see |
| 657 | /// BaselineExposureOffset tag) to the specified value. |
| 658 | |
| 659 | void SetBaselineExposureOffset (real64 exposureOffset) |
| 660 | { |
| 661 | fBaselineExposureOffset.Set_real64 (exposureOffset, 100); |
| 662 | ClearFingerprint (); |
| 663 | } |
| 664 | |
| 665 | /// Returns the baseline exposure offset of the profile (see |
| 666 | /// BaselineExposureOffset tag). |
| 667 | |
| 668 | const dng_srational & BaselineExposureOffset () const |
| 669 | { |
| 670 | return fBaselineExposureOffset; |
| 671 | } |
| 672 | |
| 673 | // Accessors for default black render. |
| 674 | |
| 675 | /// Sets the default black render of the profile (see DefaultBlackRender tag) |
| 676 | /// to the specified option. |
| 677 | |
| 678 | void SetDefaultBlackRender (uint32 defaultBlackRender) |
| 679 | { |
| 680 | fDefaultBlackRender = defaultBlackRender; |
| 681 | ClearFingerprint (); |
| 682 | } |
| 683 | |
| 684 | /// Returns the default black render of the profile (see DefaultBlackRender |
| 685 | /// tag). |
| 686 | |
| 687 | uint32 DefaultBlackRender () const |
| 688 | { |
| 689 | return fDefaultBlackRender; |
| 690 | } |
| 691 | |
| 692 | // Accessors for tone curve. |
| 693 | |
| 694 | /// Returns the tone curve of the profile. |
| 695 | |
| 696 | const dng_tone_curve & ToneCurve () const |
| 697 | { |
| 698 | return fToneCurve; |
| 699 | } |
| 700 | |
| 701 | /// Sets the tone curve of the profile to the specified curve. |
| 702 | |
| 703 | void SetToneCurve (const dng_tone_curve &curve) |
| 704 | { |
| 705 | fToneCurve = curve; |
| 706 | ClearFingerprint (); |
| 707 | } |
| 708 | |
| 709 | // Accessors for profile calibration signature. |
| 710 | |
| 711 | /// Sets the profile calibration signature (see ProfileCalibrationSignature |
| 712 | /// tag) to the specified string. |
| 713 | |
| 714 | void SetProfileCalibrationSignature (const char *signature) |
| 715 | { |
| 716 | fProfileCalibrationSignature.Set (signature); |
| 717 | } |
| 718 | |
| 719 | /// Returns the profile calibration signature (see ProfileCalibrationSignature |
| 720 | /// tag) of the profile. |
| 721 | |
| 722 | const dng_string & ProfileCalibrationSignature () const |
| 723 | { |
| 724 | return fProfileCalibrationSignature; |
| 725 | } |
| 726 | |
| 727 | /// Setter for camera unique model name to restrict use of this profile. |
| 728 | /// \param camera Camera unique model name designating only camera this |
| 729 | /// profile can be used with. (Empty string for no restriction.) |
| 730 | |
| 731 | void SetUniqueCameraModelRestriction (const char *camera) |
| 732 | { |
| 733 | fUniqueCameraModelRestriction.Set (camera); |
| 734 | // Not included in fingerprint, so don't need ClearFingerprint (). |
| 735 | } |
| 736 | |
| 737 | /// Getter for camera unique model name to restrict use of this profile. |
| 738 | /// \retval Unique model name of only camera this profile can be used with |
| 739 | /// or empty if no restriction. |
| 740 | |
| 741 | const dng_string & UniqueCameraModelRestriction () const |
| 742 | { |
| 743 | return fUniqueCameraModelRestriction; |
| 744 | } |
| 745 | |
| 746 | // Accessors for was read from DNG flag. |
| 747 | |
| 748 | /// Sets internal flag to indicate this profile was originally read from a |
| 749 | /// DNG file. |
| 750 | |
| 751 | void SetWasReadFromDNG (bool state = true) |
| 752 | { |
| 753 | fWasReadFromDNG = state; |
| 754 | } |
| 755 | |
| 756 | /// Was this profile read from a DNG? |
| 757 | |
| 758 | bool WasReadFromDNG () const |
| 759 | { |
| 760 | return fWasReadFromDNG; |
| 761 | } |
| 762 | |
| 763 | // Accessors for was read from disk flag. |
| 764 | |
| 765 | /// Sets internal flag to indicate this profile was originally read from |
| 766 | /// disk. |
| 767 | |
| 768 | void SetWasReadFromDisk (bool state = true) |
| 769 | { |
| 770 | fWasReadFromDisk = state; |
| 771 | } |
| 772 | |
| 773 | /// Was this profile read from disk? |
| 774 | |
| 775 | bool WasReadFromDisk () const |
| 776 | { |
| 777 | return fWasReadFromDisk; |
| 778 | } |
| 779 | |
| 780 | // Accessors for was built-in matrix flag. |
| 781 | |
| 782 | /// Sets internal flag to indicate this profile was originally a built-in |
| 783 | /// matrix profile. |
| 784 | |
| 785 | void SetWasBuiltinMatrix (bool state = true) |
| 786 | { |
| 787 | fWasBuiltinMatrix = state; |
| 788 | } |
| 789 | |
| 790 | /// Was this profile a built-in matrix profile? |
| 791 | |
| 792 | bool WasBuiltinMatrix () const |
| 793 | { |
| 794 | return fWasBuiltinMatrix; |
| 795 | } |
| 796 | |
| 797 | /// Determines if this a valid profile for this number of color channels? |
| 798 | /// \retval true if the profile is valid. |
| 799 | |
| 800 | bool IsValid (uint32 channels) const; |
| 801 | |
| 802 | /// Predicate to check if two camera profiles are colorwise equal, thus ignores |
| 803 | /// the profile name. |
| 804 | /// \param profile Camera profile to compare to. |
| 805 | |
| 806 | bool EqualData (const dng_camera_profile &profile) const; |
| 807 | |
| 808 | /// Parse profile from dng_camera_profile_info data. |
| 809 | |
| 810 | void Parse (dng_stream &stream, |
| 811 | dng_camera_profile_info &profileInfo); |
| 812 | |
| 813 | /// Parse from an extended profile stream, which is similar to stand alone |
| 814 | /// TIFF file. |
| 815 | |
| 816 | bool ParseExtended (dng_stream &stream); |
| 817 | |
| 818 | /// Convert from a three-color to a four-color Bayer profile. |
| 819 | |
| 820 | virtual void SetFourColorBayer (); |
| 821 | |
| 822 | /// Find the hue/sat table to use for a given white point, if any. |
| 823 | /// The calling routine owns the resulting table. |
| 824 | |
| 825 | dng_hue_sat_map * HueSatMapForWhite (const dng_xy_coord &white) const; |
| 826 | |
| 827 | /// Stub out the profile (free memory used by large tables). |
| 828 | |
| 829 | void Stub (); |
| 830 | |
| 831 | /// Was this profile stubbed? |
| 832 | |
| 833 | bool WasStubbed () const |
| 834 | { |
| 835 | return fWasStubbed; |
| 836 | } |
| 837 | |
| 838 | protected: |
| 839 | |
| 840 | static real64 IlluminantToTemperature (uint32 light); |
| 841 | |
| 842 | void ClearFingerprint () |
| 843 | { |
| 844 | fFingerprint.Clear (); |
| 845 | } |
| 846 | |
| 847 | void CalculateFingerprint () const; |
| 848 | |
| 849 | static bool ValidForwardMatrix (const dng_matrix &m); |
| 850 | |
| 851 | static void ReadHueSatMap (dng_stream &stream, |
| 852 | dng_hue_sat_map &hueSatMap, |
| 853 | uint32 hues, |
| 854 | uint32 sats, |
| 855 | uint32 vals, |
| 856 | bool skipSat0); |
| 857 | |
| 858 | }; |
| 859 | |
| 860 | /******************************************************************************/ |
| 861 | |
| 862 | void SplitCameraProfileName (const dng_string &name, |
| 863 | dng_string &baseName, |
| 864 | int32 &version); |
| 865 | |
| 866 | /*****************************************************************************/ |
| 867 | |
| 868 | void BuildHueSatMapEncodingTable (dng_memory_allocator &allocator, |
| 869 | uint32 encoding, |
| 870 | AutoPtr<dng_1d_table> &encodeTable, |
| 871 | AutoPtr<dng_1d_table> &decodeTable, |
| 872 | bool subSample); |
| 873 | |
| 874 | /******************************************************************************/ |
| 875 | |
| 876 | #endif |
| 877 | |
| 878 | /******************************************************************************/ |
| 879 | |