void dng_matrix::SetIdentity (uint32 count) { *this = dng_matrix (count, count); for (uint32 j = 0; j < count; j++) { fData [j] [j] = 1.0; } }
void dng_shared::PostParse (dng_host & /* host */, dng_exif & /* exif */) { // Fill in default values for DNG images. if (fDNGVersion != 0) { // Support for DNG versions before 1.0.0.0. if (fDNGVersion < dngVersion_1_0_0_0) { #if qDNGValidate ReportWarning ("DNGVersion less than 1.0.0.0"); #endif // The CalibrationIlluminant tags were added just before // DNG version 1.0.0.0, and were hardcoded before that. fCameraProfile.fCalibrationIlluminant1 = lsStandardLightA; fCameraProfile.fCalibrationIlluminant2 = lsD65; fDNGVersion = dngVersion_1_0_0_0; } // Default value for DNGBackwardVersion tag. if (fDNGBackwardVersion == 0) { fDNGBackwardVersion = fDNGVersion & 0xFFFF0000; } // Check DNGBackwardVersion value. if (fDNGBackwardVersion < dngVersion_1_0_0_0) { #if qDNGValidate ReportWarning ("DNGBackwardVersion less than 1.0.0.0"); #endif fDNGBackwardVersion = dngVersion_1_0_0_0; } if (fDNGBackwardVersion > fDNGVersion) { #if qDNGValidate ReportWarning ("DNGBackwardVersion > DNGVersion"); #endif fDNGBackwardVersion = fDNGVersion; } // Check UniqueCameraModel. if (fUniqueCameraModel.IsEmpty ()) { #if qDNGValidate ReportWarning ("Missing or invalid UniqueCameraModel"); #endif fUniqueCameraModel.Set ("Digital Negative"); } // If we don't know the color depth yet, it must be a monochrome DNG. if (fCameraProfile.fColorPlanes == 0) { fCameraProfile.fColorPlanes = 1; } // Check color info. if (fCameraProfile.fColorPlanes > 1) { // Check illuminant pair. if (fCameraProfile.fColorMatrix2.NotEmpty ()) { if (fCameraProfile.fCalibrationIlluminant1 == lsUnknown || (fCameraProfile.fCalibrationIlluminant2 == lsUnknown || (fCameraProfile.fCalibrationIlluminant1 == fCameraProfile.fCalibrationIlluminant2))) { #if qDNGValidate ReportWarning ("Invalid CalibrationIlluminant pair"); #endif fCameraProfile.fColorMatrix2 = dng_matrix (); } } // If the colorimetric reference is the ICC profile PCS, then the // data must already be white balanced. The "AsShotWhiteXY" is required // to be the ICC Profile PCS white point. if (fColorimetricReference == crICCProfilePCS) { if (fAsShotNeutral.NotEmpty ()) { #if qDNGValidate ReportWarning ("AsShotNeutral not allowed for this " "ColorimetricReference value"); #endif fAsShotNeutral.Clear (); } dng_xy_coord pcs = PCStoXY (); #if qDNGValidate if (fAsShotWhiteXY.IsValid ()) { if (Abs_real64 (fAsShotWhiteXY.x - pcs.x) > 0.01 || Abs_real64 (fAsShotWhiteXY.y - pcs.y) > 0.01) { ReportWarning ("AsShotWhiteXY does not match the ICC Profile PCS"); } } #endif fAsShotWhiteXY = pcs; } else { // Warn if both AsShotNeutral and AsShotWhiteXY are specified. if (fAsShotNeutral.NotEmpty () && fAsShotWhiteXY.IsValid ()) { #if qDNGValidate ReportWarning ("Both AsShotNeutral and AsShotWhiteXY included"); #endif fAsShotWhiteXY = dng_xy_coord (); } // Warn if neither AsShotNeutral nor AsShotWhiteXY are specified. #if qDNGValidate if (fAsShotNeutral.IsEmpty () && !fAsShotWhiteXY.IsValid ()) { ReportWarning ("Neither AsShotNeutral nor AsShotWhiteXY included", "legal but not recommended"); } #endif } // Default values of calibration signatures are required for legacy // compatiblity. if (fCameraProfile.fCalibrationIlluminant1 == lsStandardLightA && fCameraProfile.fCalibrationIlluminant2 == lsD65 && fCameraCalibration1.Rows () == fCameraProfile.fColorPlanes && fCameraCalibration1.Cols () == fCameraProfile.fColorPlanes && fCameraCalibration2.Rows () == fCameraProfile.fColorPlanes && fCameraCalibration2.Cols () == fCameraProfile.fColorPlanes && fCameraCalibrationSignature.IsEmpty () && fCameraProfile.fProfileCalibrationSignature.IsEmpty () ) { fCameraCalibrationSignature.Set (kAdobeCalibrationSignature); fCameraProfile.fProfileCalibrationSignature.Set (kAdobeCalibrationSignature); } } // Check BaselineNoise. if (fBaselineNoise.As_real64 () <= 0.0) { #if qDNGValidate ReportWarning ("Invalid BaselineNoise"); #endif fBaselineNoise = dng_urational (1, 1); } // Check BaselineSharpness. if (fBaselineSharpness.As_real64 () <= 0.0) { #if qDNGValidate ReportWarning ("Invalid BaselineSharpness"); #endif fBaselineSharpness = dng_urational (1, 1); } // Check NoiseProfile. if (!fNoiseProfile.IsValid () && fNoiseProfile.NumFunctions () != 0) { #if qDNGValidate ReportWarning ("Invalid NoiseProfile"); #endif fNoiseProfile = dng_noise_profile (); } // Check LinearResponseLimit. if (fLinearResponseLimit.As_real64 () < 0.5 || fLinearResponseLimit.As_real64 () > 1.0) { #if qDNGValidate ReportWarning ("Invalid LinearResponseLimit"); #endif fLinearResponseLimit = dng_urational (1, 1); } // Check ShadowScale. if (fShadowScale.As_real64 () <= 0.0) { #if qDNGValidate ReportWarning ("Invalid ShadowScale"); #endif fShadowScale = dng_urational (1, 1); } } }
dng_color_spec::dng_color_spec (const dng_negative &negative, const dng_camera_profile *profile) : fChannels (negative.ColorChannels ()) , fTemperature1 (0.0) , fTemperature2 (0.0) , fColorMatrix1 () , fColorMatrix2 () , fForwardMatrix1 () , fForwardMatrix2 () , fReductionMatrix1 () , fReductionMatrix2 () , fCameraCalibration1 () , fCameraCalibration2 () , fAnalogBalance () , fWhiteXY () , fCameraWhite () , fCameraToPCS () , fPCStoCamera () { if (fChannels > 1) { if (!profile || !profile->IsValid (fChannels)) { ThrowBadFormat (); } if (profile->WasStubbed ()) { ThrowProgramError ("Using stubbed profile"); } fTemperature1 = profile->CalibrationTemperature1 (); fTemperature2 = profile->CalibrationTemperature2 (); fColorMatrix1 = profile->ColorMatrix1 (); fColorMatrix2 = profile->ColorMatrix2 (); fForwardMatrix1 = profile->ForwardMatrix1 (); fForwardMatrix2 = profile->ForwardMatrix2 (); fReductionMatrix1 = profile->ReductionMatrix1 (); fReductionMatrix2 = profile->ReductionMatrix2 (); fCameraCalibration1.SetIdentity (fChannels); fCameraCalibration2.SetIdentity (fChannels); if (negative. CameraCalibrationSignature () == profile->ProfileCalibrationSignature ()) { if (negative.CameraCalibration1 ().Rows () == fChannels && negative.CameraCalibration1 ().Cols () == fChannels) { fCameraCalibration1 = negative.CameraCalibration1 (); } if (negative.CameraCalibration2 ().Rows () == fChannels && negative.CameraCalibration2 ().Cols () == fChannels) { fCameraCalibration2 = negative.CameraCalibration2 (); } } fAnalogBalance = dng_matrix (fChannels, fChannels); for (uint32 j = 0; j < fChannels; j++) { fAnalogBalance [j] [j] = negative.AnalogBalance (j); } dng_camera_profile::NormalizeForwardMatrix (fForwardMatrix1); fColorMatrix1 = fAnalogBalance * fCameraCalibration1 * fColorMatrix1; if (!profile->HasColorMatrix2 () || fTemperature1 <= 0.0 || fTemperature2 <= 0.0 || fTemperature1 == fTemperature2) { fTemperature1 = 5000.0; fTemperature2 = 5000.0; fColorMatrix2 = fColorMatrix1; fForwardMatrix2 = fForwardMatrix1; fReductionMatrix2 = fReductionMatrix1; fCameraCalibration2 = fCameraCalibration1; } else { dng_camera_profile::NormalizeForwardMatrix (fForwardMatrix2); fColorMatrix2 = fAnalogBalance * fCameraCalibration2 * fColorMatrix2; // Swap values if temperatures are out of order. if (fTemperature1 > fTemperature2) { real64 temp = fTemperature1; fTemperature1 = fTemperature2; fTemperature2 = temp; dng_matrix T = fColorMatrix1; fColorMatrix1 = fColorMatrix2; fColorMatrix2 = T; T = fForwardMatrix1; fForwardMatrix1 = fForwardMatrix2; fForwardMatrix2 = T; T = fReductionMatrix1; fReductionMatrix1 = fReductionMatrix2; fReductionMatrix2 = T; T = fCameraCalibration1; fCameraCalibration1 = fCameraCalibration2; fCameraCalibration2 = T; } } } }