private DNGMatrix NormalizeForwardMatrix(DNGMatrix m) { if (m == null) { return(new DNGMatrix()); } if (m.NotEmpty()) { DNGVector cameraOne = DNGVector.Identity(m.Cols); DNGVector xyz = m * cameraOne; m = DNGxyCoord.PCStoXYZ.AsDiagonal() * (xyz.AsDiagonal().Invert()) * m; } return(m); }
private DNGMatrix FindXYZtoCamera(DNGxyCoord white, ref DNGMatrix forwardMatrix, ref DNGMatrix reductionMatrix, ref DNGMatrix cameraCalibration) { // Convert to temperature/offset space. DNGTemperature td = new DNGTemperature(white); // Find fraction to weight the first calibration. double g; if (td.Temperature <= fTemperature1) { g = 1.0; } else if (td.Temperature >= fTemperature2) { g = 0.0; } else { double invT = 1.0 / td.Temperature; g = (invT - (1.0 / fTemperature2)) / ((1.0 / fTemperature1) - (1.0 / fTemperature2)); } // Interpolate the color matrix. DNGMatrix colorMatrix; if (g >= 1.0) { colorMatrix = fColorMatrix1; } else if (g <= 0.0) { colorMatrix = fColorMatrix2; } else { colorMatrix = (g) * fColorMatrix1 + (1.0 - g) * fColorMatrix2; } // Interpolate forward matrix, if any. if (forwardMatrix != null) { bool has1 = fForwardMatrix1.NotEmpty(); bool has2 = fForwardMatrix2.NotEmpty(); if (has1 && has2) { if (g >= 1.0) { forwardMatrix = fForwardMatrix1; } else if (g <= 0.0) { forwardMatrix = fForwardMatrix2; } else { forwardMatrix = (g) * fForwardMatrix1 + (1.0 - g) * fForwardMatrix2; } } else if (has1) { forwardMatrix = fForwardMatrix1; } else if (has2) { forwardMatrix = fForwardMatrix2; } else { forwardMatrix.Clear(); } } // Interpolate reduction matrix, if any. if (reductionMatrix != null) { bool has1 = fReductionMatrix1.NotEmpty(); bool has2 = fReductionMatrix2.NotEmpty(); if (has1 && has2) { if (g >= 1.0) { reductionMatrix = fReductionMatrix1; } else if (g <= 0.0) { reductionMatrix = fReductionMatrix2; } else { reductionMatrix = (g) * fReductionMatrix1 + (1.0 - g) * fReductionMatrix2; } } else if (has1) { reductionMatrix = fReductionMatrix1; } else if (has2) { reductionMatrix = fReductionMatrix2; } else { reductionMatrix.Clear(); } } // Interpolate camera calibration matrix. if (cameraCalibration != null) { if (g >= 1.0) { cameraCalibration = fCameraCalibration1; } else if (g <= 0.0) { cameraCalibration = fCameraCalibration2; } else { cameraCalibration = (g) * fCameraCalibration1 + (1.0 - g) * fCameraCalibration2; } } // Return the interpolated color matrix. return(colorMatrix); }