Exemple #1
0
        public DNGColorSpec(double[] colorMatrix1, double[] colorMatrix2,
                            IFDDNGCalibrationIlluminant.Illuminant illuminant1, IFDDNGCalibrationIlluminant.Illuminant illuminant2, float[] whiteBalance)
        {
            fChannels     = 3;
            fTemperature1 = ConvertIlluminantToTemperature(illuminant1);
            fTemperature2 = ConvertIlluminantToTemperature(illuminant2);


            if (colorMatrix1 == null)
            {
                fColorMatrix1 = DNGMatrix.Identity(fChannels); //best choice if nothing is given...
            }
            else
            {
                fColorMatrix1 = new DNGMatrix3x3(colorMatrix1);
            }

            if (colorMatrix2 == null)
            {
                fColorMatrix2 = new DNGMatrix();
            }
            else
            {
                fColorMatrix2 = new DNGMatrix3x3(colorMatrix2);
            }

            fForwardMatrix1 = new DNGMatrix();
            fForwardMatrix2 = new DNGMatrix();

            fReductionMatrix1 = new DNGMatrix();
            fReductionMatrix2 = new DNGMatrix();

            fCameraCalibration1 = DNGMatrix.Identity(fChannels);
            fCameraCalibration2 = DNGMatrix.Identity(fChannels);

            fAnalogBalance = DNGMatrix.Identity(fChannels);

            fForwardMatrix1 = NormalizeForwardMatrix(fForwardMatrix1);

            fColorMatrix1 = fAnalogBalance * fCameraCalibration1 * fColorMatrix1;

            if (fColorMatrix2.IsEmpty() ||
                fTemperature1 <= 0.0 ||
                fTemperature2 <= 0.0 ||
                fTemperature1 == fTemperature2)
            {
                fTemperature1 = 5000.0;
                fTemperature2 = 5000.0;

                fColorMatrix2       = fColorMatrix1;
                fForwardMatrix2     = fForwardMatrix1;
                fReductionMatrix2   = fReductionMatrix1;
                fCameraCalibration2 = fCameraCalibration1;
            }
            else
            {
                fForwardMatrix2 = NormalizeForwardMatrix(fForwardMatrix2);
                fColorMatrix2   = fAnalogBalance * fCameraCalibration2 * fColorMatrix2;

                // Swap values if temperatures are out of order.
                if (fTemperature1 > fTemperature2)
                {
                    double temp = fTemperature1;
                    fTemperature1 = fTemperature2;
                    fTemperature2 = temp;

                    DNGMatrix T = fColorMatrix1;
                    fColorMatrix1 = fColorMatrix2;
                    fColorMatrix2 = T;

                    T = fForwardMatrix1;
                    fForwardMatrix1 = fForwardMatrix2;
                    fForwardMatrix2 = T;

                    T = fReductionMatrix1;
                    fReductionMatrix1 = fReductionMatrix2;
                    fReductionMatrix2 = T;

                    T = fCameraCalibration1;
                    fCameraCalibration1 = fCameraCalibration2;
                    fCameraCalibration2 = T;
                }
            }

            DNGxyCoord white;
            DNGVector  vec = new DNGVector((uint)whiteBalance.Length);

            for (uint c = 0; c < whiteBalance.Length; c++)
            {
                //white point is given as a multiplicatice factor
                //actual white point is hence 1/value
                vec[c] = 1.0f / whiteBalance[c];
            }

            double unify = 1.0 / vec.MaxEntry();

            vec = unify * vec;

            white = NeutralToXY(vec);

            WhiteXY = white;
        }
Exemple #2
0
        public DNGColorSpec(uint aChannels, ImageFileDirectory ifd0, ImageFileDirectory raw)
        {
            fChannels = aChannels;
            if (GetTag <IFDDNGCalibrationIlluminant1>(ifd0, raw) != null)
            {
                fTemperature1 = ConvertIlluminantToTemperature(GetTag <IFDDNGCalibrationIlluminant1>(ifd0, raw).Value);
            }
            else
            {
                fTemperature1 = 0.0;
            }
            if (GetTag <IFDDNGCalibrationIlluminant2>(ifd0, raw) != null)
            {
                fTemperature2 = ConvertIlluminantToTemperature(GetTag <IFDDNGCalibrationIlluminant2>(ifd0, raw).Value);
            }
            else
            {
                fTemperature2 = 0.0;
            }

            fColorMatrix1 = GetTag <IFDDNGColorMatrix1>(ifd0, raw)?.Matrix;
            if (fColorMatrix1 == null)
            {
                fColorMatrix1 = DNGMatrix.Identity(fChannels); //best choice if nothing is given...
            }
            fColorMatrix2 = GetTag <IFDDNGColorMatrix2>(ifd0, raw)?.Matrix;
            if (fColorMatrix2 == null)
            {
                fColorMatrix2 = new DNGMatrix();
            }

            fForwardMatrix1 = GetTag <IFDDNGForwardMatrix1>(ifd0, raw)?.Matrix;
            if (fForwardMatrix1 == null)
            {
                fForwardMatrix1 = new DNGMatrix();
            }
            fForwardMatrix2 = GetTag <IFDDNGForwardMatrix2>(ifd0, raw)?.Matrix;
            if (fForwardMatrix2 == null)
            {
                fForwardMatrix2 = new DNGMatrix();
            }

            fReductionMatrix1 = GetTag <IFDDNGReductionMatrix1>(ifd0, raw)?.Matrix;
            if (fReductionMatrix1 == null)
            {
                fReductionMatrix1 = new DNGMatrix();
            }
            fReductionMatrix2 = GetTag <IFDDNGReductionMatrix2>(ifd0, raw)?.Matrix;
            if (fReductionMatrix2 == null)
            {
                fReductionMatrix2 = new DNGMatrix();
            }

            fCameraCalibration1 = GetTag <IFDDNGCameraCalibration1>(ifd0, raw)?.Matrix;
            fCameraCalibration2 = GetTag <IFDDNGCameraCalibration1>(ifd0, raw)?.Matrix;
            if (fCameraCalibration1 == null)
            {
                fCameraCalibration1 = DNGMatrix.Identity(fChannels);
            }
            if (fCameraCalibration2 == null)
            {
                fCameraCalibration2 = DNGMatrix.Identity(fChannels);
            }

            fAnalogBalance = GetTag <IFDDNGAnalogBalance>(ifd0, raw)?.Vector.AsDiagonal();
            if (fAnalogBalance == null)
            {
                fAnalogBalance = DNGMatrix.Identity(fChannels);
            }

            fForwardMatrix1 = NormalizeForwardMatrix(fForwardMatrix1);

            fColorMatrix1 = fAnalogBalance * fCameraCalibration1 * fColorMatrix1;

            if (fColorMatrix2.IsEmpty() ||
                fTemperature1 <= 0.0 ||
                fTemperature2 <= 0.0 ||
                fTemperature1 == fTemperature2)
            {
                fTemperature1 = 5000.0;
                fTemperature2 = 5000.0;

                fColorMatrix2       = fColorMatrix1;
                fForwardMatrix2     = fForwardMatrix1;
                fReductionMatrix2   = fReductionMatrix1;
                fCameraCalibration2 = fCameraCalibration1;
            }
            else
            {
                fForwardMatrix2 = NormalizeForwardMatrix(fForwardMatrix2);
                fColorMatrix2   = fAnalogBalance * fCameraCalibration2 * fColorMatrix2;

                // Swap values if temperatures are out of order.
                if (fTemperature1 > fTemperature2)
                {
                    double temp = fTemperature1;
                    fTemperature1 = fTemperature2;
                    fTemperature2 = temp;

                    DNGMatrix T = fColorMatrix1;
                    fColorMatrix1 = fColorMatrix2;
                    fColorMatrix2 = T;

                    T = fForwardMatrix1;
                    fForwardMatrix1 = fForwardMatrix2;
                    fForwardMatrix2 = T;

                    T = fReductionMatrix1;
                    fReductionMatrix1 = fReductionMatrix2;
                    fReductionMatrix2 = T;

                    T = fCameraCalibration1;
                    fCameraCalibration1 = fCameraCalibration2;
                    fCameraCalibration2 = T;
                }
            }

            IFDDNGAsShotNeutral neutral = GetTag <IFDDNGAsShotNeutral>(ifd0, raw);
            IFDDNGAsShotWhiteXY asShot  = GetTag <IFDDNGAsShotWhiteXY>(ifd0, raw);
            DNGxyCoord          white;

            if (asShot == null)
            {
                if (neutral == null)
                {
                    throw new ArgumentException("The DNG spec says that one of the As Shot White balance tags must be present.");
                }

                DNGVector vec = new DNGVector((uint)neutral.Value.Length);

                for (uint c = 0; c < neutral.Value.Length; c++)
                {
                    vec[c] = neutral.Value[c].Value;
                }

                double unify = 1.0 / vec.MaxEntry();
                vec = unify * vec;

                white = NeutralToXY(vec);
            }
            else
            {
                double x = asShot.Value[0].Value;
                double y = asShot.Value[1].Value;
                white = new DNGxyCoord(x, y);
            }
            WhiteXY = white;
        }
 public bool AlmostIdentity(double slop = 1.0e-8)
 {
     return(AlmostEqual(DNGMatrix.Identity(_rows), slop));
 }