DocumentationOverviewBuilding ASL Documentation Library Wiki Docs Indices Browse Perforce More InfoRelease NotesWiki Site Search License Success Stories Contributors MediaDownloadPerforce Depots SupportASL SourceForge HomeMailing Lists Discussion Forums Report Bugs Suggest Features Contribute to ASL RSSShort-text newsFull-text news File releases Other Adobe ProjectsAdobe AirAdobe GIL Adobe Labs Adobe Media Gallery Adobe XMP Tamarin project (Mozilla Foundation) Other ResourcesBoostRIAForge SGI STL |
dng_camera_profile.hGo to the documentation of this file.00001 /******************************************************************************/ 00002 // Copyright 2006-2007 Adobe Systems Incorporated 00003 // All Rights Reserved. 00004 // 00005 // NOTICE: Adobe permits you to use, modify, and distribute this file in 00006 // accordance with the terms of the Adobe license agreement accompanying it. 00007 /******************************************************************************/ 00008 00009 /* $Id: //mondo/workarea/stern/camera_raw/dng_sdk/source/dng_camera_profile.h#19 $ */ 00010 /* $DateTime: 2008/08/25 19:37:25 $ */ 00011 /* $Change: 501929 $ */ 00012 /* $Author: stern $ */ 00013 00031 #ifndef __dng_camera_profile__ 00032 #define __dng_camera_profile__ 00033 00034 /******************************************************************************/ 00035 00036 #include "dng_assertions.h" 00037 #include "dng_classes.h" 00038 #include "dng_fingerprint.h" 00039 #include "dng_hue_sat_map.h" 00040 #include "dng_matrix.h" 00041 #include "dng_string.h" 00042 #include "dng_tag_values.h" 00043 #include "dng_tone_curve.h" 00044 00045 /******************************************************************************/ 00046 00047 extern const char * kProfileName_Embedded; 00048 00049 extern const char * kAdobeCalibrationSignature; 00050 00051 /******************************************************************************/ 00052 00053 class dng_camera_profile_id 00054 { 00055 00056 private: 00057 00058 dng_string fName; 00059 00060 dng_fingerprint fFingerprint; 00061 00062 public: 00063 00064 dng_camera_profile_id () 00065 00066 : fName () 00067 , fFingerprint () 00068 00069 { 00070 } 00071 00072 dng_camera_profile_id (const char *name) 00073 00074 : fName () 00075 , fFingerprint () 00076 00077 { 00078 fName.Set (name); 00079 } 00080 00081 dng_camera_profile_id (const dng_string &name) 00082 00083 : fName (name) 00084 , fFingerprint () 00085 00086 { 00087 } 00088 00089 dng_camera_profile_id (const char *name, 00090 const dng_fingerprint &fingerprint) 00091 00092 : fName () 00093 , fFingerprint (fingerprint) 00094 00095 { 00096 fName.Set (name); 00097 DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (), 00098 "Cannot have profile fingerprint without name"); 00099 } 00100 00101 dng_camera_profile_id (const dng_string &name, 00102 const dng_fingerprint &fingerprint) 00103 00104 : fName (name) 00105 , fFingerprint (fingerprint) 00106 00107 { 00108 DNG_ASSERT (!fFingerprint.IsValid () || fName.NotEmpty (), 00109 "Cannot have profile fingerprint without name"); 00110 } 00111 00112 const dng_string & Name () const 00113 { 00114 return fName; 00115 } 00116 00117 const dng_fingerprint & Fingerprint () const 00118 { 00119 return fFingerprint; 00120 } 00121 00122 bool operator== (const dng_camera_profile_id &id) const 00123 { 00124 return fName == id.fName && 00125 fFingerprint == id.fFingerprint; 00126 } 00127 00128 bool operator!= (const dng_camera_profile_id &id) const 00129 { 00130 return !(*this == id); 00131 } 00132 00133 bool IsValid () const 00134 { 00135 return fName.NotEmpty (); // Fingerprint is optional. 00136 } 00137 00138 void Clear () 00139 { 00140 *this = dng_camera_profile_id (); 00141 } 00142 00143 }; 00144 00145 /******************************************************************************/ 00146 00148 00149 class dng_camera_profile 00150 { 00151 00152 protected: 00153 00154 // Name of this camera profile. 00155 00156 dng_string fName; 00157 00158 // Light sources for up to two calibrations. These use the EXIF 00159 // encodings for illuminant and are used to distinguish which 00160 // matrix to use. 00161 00162 uint32 fCalibrationIlluminant1; 00163 uint32 fCalibrationIlluminant2; 00164 00165 // Color matrices for up to two calibrations. 00166 00167 // These matrices map XYZ values to non-white balanced camera values. 00168 // Adobe needs to go that direction in order to determine the clipping 00169 // points for highlight recovery logic based on the white point. If 00170 // cameras were all 3-color, the matrix could be stored as a forward matrix, 00171 // but we need the backwards matrix to deal with 4-color cameras. 00172 00173 dng_matrix fColorMatrix1; 00174 dng_matrix fColorMatrix2; 00175 00176 // These matrices map white balanced camera values to XYZ chromatically 00177 // adapted to D50 (the ICC profile PCS white point). If the matrices 00178 // exist, then this implies that white balancing should be done by scaling 00179 // camera values with a diagonal matrix. 00180 00181 dng_matrix fForwardMatrix1; 00182 dng_matrix fForwardMatrix2; 00183 00184 // Dimensionality reduction hints for more than three color cameras. 00185 // This is an optional matrix that maps the camera's color components 00186 // to 3 components. These are only used if the forward matrices don't 00187 // exist, and are used invert the color matrices. 00188 00189 dng_matrix fReductionMatrix1; 00190 dng_matrix fReductionMatrix2; 00191 00192 // MD5 hash for all data bits of the profile. 00193 00194 mutable dng_fingerprint fFingerprint; 00195 00196 // Copyright notice from creator of profile. 00197 00198 dng_string fCopyright; 00199 00200 // Rules for how this profile can be embedded and/or copied. 00201 00202 uint32 fEmbedPolicy; 00203 00204 // 2-D (or 3-D) hue/sat tables to modify colors. 00205 00206 dng_hue_sat_map fHueSatDeltas1; 00207 dng_hue_sat_map fHueSatDeltas2; 00208 00209 // 3-D hue/sat table to apply a "look". 00210 00211 dng_hue_sat_map fLookTable; 00212 00213 // The "as shot" tone curve for this profile. Check IsValid method 00214 // to tell if one exists in profile. 00215 00216 dng_tone_curve fToneCurve; 00217 00218 // If this string matches the fCameraCalibrationSignature of the 00219 // negative, then use the calibration matrix values from the negative. 00220 00221 dng_string fProfileCalibrationSignature; 00222 00223 // If non-empty, only allow use of this profile with camera having 00224 // same unique model name. 00225 00226 dng_string fUniqueCameraModelRestriction; 00227 00228 // Was this profile read from inside a DNG file? (If so, we wnat 00229 // to be sure to include it again when writing out an updated 00230 // DNG file) 00231 00232 bool fWasReadFromDNG; 00233 00234 // Was this profile stubbed to save memory (and no longer valid 00235 // for building color conversion tables)? 00236 00237 bool fWasStubbed; 00238 00239 public: 00240 00241 dng_camera_profile (); 00242 00243 virtual ~dng_camera_profile (); 00244 00245 // API for profile name: 00246 00249 00250 void SetName (const char *name) 00251 { 00252 fName.Set (name); 00253 ClearFingerprint (); 00254 } 00255 00258 00259 const dng_string & Name () const 00260 { 00261 return fName; 00262 } 00263 00266 00267 bool NameIsEmbedded () const 00268 { 00269 return fName.Matches (kProfileName_Embedded, true); 00270 } 00271 00272 // API for calibration illuminants: 00273 00278 00279 void SetCalibrationIlluminant1 (uint32 light) 00280 { 00281 fCalibrationIlluminant1 = light; 00282 ClearFingerprint (); 00283 } 00284 00289 00290 void SetCalibrationIlluminant2 (uint32 light) 00291 { 00292 fCalibrationIlluminant2 = light; 00293 ClearFingerprint (); 00294 } 00295 00300 00301 uint32 CalibrationIlluminant1 () const 00302 { 00303 return fCalibrationIlluminant1; 00304 } 00305 00310 00311 uint32 CalibrationIlluminant2 () const 00312 { 00313 return fCalibrationIlluminant2; 00314 } 00315 00318 00319 real64 CalibrationTemperature1 () const 00320 { 00321 return IlluminantToTemperature (CalibrationIlluminant1 ()); 00322 } 00323 00326 00327 real64 CalibrationTemperature2 () const 00328 { 00329 return IlluminantToTemperature (CalibrationIlluminant2 ()); 00330 } 00331 00332 // API for color matrices: 00333 00335 00336 static void NormalizeColorMatrix (dng_matrix &m); 00337 00344 00345 void SetColorMatrix1 (const dng_matrix &m); 00346 00353 00354 void SetColorMatrix2 (const dng_matrix &m); 00355 00357 00358 bool HasColorMatrix1 () const; 00359 00361 00362 bool HasColorMatrix2 () const; 00363 00365 00366 const dng_matrix & ColorMatrix1 () const 00367 { 00368 return fColorMatrix1; 00369 } 00370 00372 00373 const dng_matrix & ColorMatrix2 () const 00374 { 00375 return fColorMatrix2; 00376 } 00377 00378 // API for forward matrices: 00379 00381 00382 static void NormalizeForwardMatrix (dng_matrix &m); 00383 00385 00386 void SetForwardMatrix1 (const dng_matrix &m); 00387 00389 00390 void SetForwardMatrix2 (const dng_matrix &m); 00391 00393 00394 const dng_matrix & ForwardMatrix1 () const 00395 { 00396 return fForwardMatrix1; 00397 } 00398 00400 00401 const dng_matrix & ForwardMatrix2 () const 00402 { 00403 return fForwardMatrix2; 00404 } 00405 00406 // API for reduction matrices: 00407 00411 00412 void SetReductionMatrix1 (const dng_matrix &m); 00413 00417 00418 void SetReductionMatrix2 (const dng_matrix &m); 00419 00421 00422 const dng_matrix & ReductionMatrix1 () const 00423 { 00424 return fReductionMatrix1; 00425 } 00426 00428 00429 const dng_matrix & ReductionMatrix2 () const 00430 { 00431 return fReductionMatrix2; 00432 } 00433 00435 00436 const dng_fingerprint &Fingerprint () const 00437 { 00438 00439 if (!fFingerprint.IsValid ()) 00440 CalculateFingerprint (); 00441 00442 return fFingerprint; 00443 00444 } 00445 00448 00449 dng_camera_profile_id ProfileID () const 00450 { 00451 return dng_camera_profile_id (Name (), Fingerprint ()); 00452 } 00453 00456 00457 void SetCopyright (const char *copyright) 00458 { 00459 fCopyright.Set (copyright); 00460 ClearFingerprint (); 00461 } 00462 00465 00466 const dng_string & Copyright () const 00467 { 00468 return fCopyright; 00469 } 00470 00471 // Accessors for embed policy. 00472 00473 void SetEmbedPolicy (uint32 policy) 00474 { 00475 fEmbedPolicy = policy; 00476 ClearFingerprint (); 00477 } 00478 00479 uint32 EmbedPolicy () const 00480 { 00481 return fEmbedPolicy; 00482 } 00483 00484 bool IsLegalToEmbed () const 00485 { 00486 return WasReadFromDNG () || 00487 EmbedPolicy () == pepAllowCopying || 00488 EmbedPolicy () == pepEmbedIfUsed || 00489 EmbedPolicy () == pepNoRestrictions; 00490 } 00491 00492 // Accessors for hue sat maps. 00493 00494 bool HasHueSatDeltas () const 00495 { 00496 return fHueSatDeltas1.IsValid (); 00497 } 00498 00499 const dng_hue_sat_map & HueSatDeltas1 () const 00500 { 00501 return fHueSatDeltas1; 00502 } 00503 00504 void SetHueSatDeltas1 (const dng_hue_sat_map &deltas1); 00505 00506 const dng_hue_sat_map & HueSatDeltas2 () const 00507 { 00508 return fHueSatDeltas2; 00509 } 00510 00511 void SetHueSatDeltas2 (const dng_hue_sat_map &deltas2); 00512 00513 // Accessors for look table. 00514 00515 bool HasLookTable () const 00516 { 00517 return fLookTable.IsValid (); 00518 } 00519 00520 const dng_hue_sat_map & LookTable () const 00521 { 00522 return fLookTable; 00523 } 00524 00525 void SetLookTable (const dng_hue_sat_map &table); 00526 00527 // Accessors for tone curve. 00528 00529 const dng_tone_curve & ToneCurve () const 00530 { 00531 return fToneCurve; 00532 } 00533 00534 void SetToneCurve (const dng_tone_curve &curve) 00535 { 00536 fToneCurve = curve; 00537 ClearFingerprint (); 00538 } 00539 00540 // Accessors for profile calibration signature. 00541 00542 void SetProfileCalibrationSignature (const char *signature) 00543 { 00544 fProfileCalibrationSignature.Set (signature); 00545 } 00546 00547 const dng_string & ProfileCalibrationSignature () const 00548 { 00549 return fProfileCalibrationSignature; 00550 } 00551 00555 00556 void SetUniqueCameraModelRestriction (const char *camera) 00557 { 00558 fUniqueCameraModelRestriction.Set (camera); 00559 // Not included in fingerprint, so don't need ClearFingerprint (). 00560 } 00561 00565 00566 const dng_string & UniqueCameraModelRestriction () const 00567 { 00568 return fUniqueCameraModelRestriction; 00569 } 00570 00571 // Accessors for was read from DNG flag. 00572 00573 void SetWasReadFromDNG (bool state = true) 00574 { 00575 fWasReadFromDNG = state; 00576 } 00577 00578 bool WasReadFromDNG () const 00579 { 00580 return fWasReadFromDNG; 00581 } 00582 00585 00586 bool IsValid (uint32 channels) const; 00587 00591 00592 bool EqualData (const dng_camera_profile &profile) const; 00593 00595 00596 void Parse (dng_stream &stream, 00597 dng_camera_profile_info &profileInfo); 00598 00601 00602 bool ParseExtended (dng_stream &stream); 00603 00605 00606 virtual void SetFourColorBayer (); 00607 00610 00611 dng_hue_sat_map * HueSatMapForWhite (const dng_xy_coord &white) const; 00612 00614 00615 void Stub (); 00616 00618 00619 bool WasStubbed () const 00620 { 00621 return fWasStubbed; 00622 } 00623 00624 protected: 00625 00626 static real64 IlluminantToTemperature (uint32 light); 00627 00628 void ClearFingerprint () 00629 { 00630 fFingerprint.Clear (); 00631 } 00632 00633 void CalculateFingerprint () const; 00634 00635 static bool ValidForwardMatrix (const dng_matrix &m); 00636 00637 static void ReadHueSatMap (dng_stream &stream, 00638 dng_hue_sat_map &hueSatMap, 00639 uint32 hues, 00640 uint32 sats, 00641 uint32 vals, 00642 bool skipSat0); 00643 00644 }; 00645 00646 /******************************************************************************/ 00647 00648 void SplitCameraProfileName (const dng_string &name, 00649 dng_string &baseName, 00650 int32 &version); 00651 00652 /******************************************************************************/ 00653 00654 #endif 00655 00656 /******************************************************************************/ |