protected static Matrix GetRGBToXYZMatrix(IRGBWorkingSpace workingSpace)
        {
            if (workingSpace == null)
            {
                throw new ArgumentNullException("workingSpace");
            }

            // for more info, see: http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

            RGBPrimariesChromaticityCoordinates chromaticity = workingSpace.ChromaticityCoordinates;
            double xr = chromaticity.R.x, xg = chromaticity.G.x, xb = chromaticity.B.x,
                   yr = chromaticity.R.y, yg = chromaticity.G.y, yb = chromaticity.B.y;

            double Sr, Sg, Sb;

            double       Xr = xr / yr;
            const double Yr = 1;
            double       Zr = (1 - xr - yr) / yr;

            double       Xg = xg / yg;
            const double Yg = 1;
            double       Zg = (1 - xg - yg) / yg;

            double       Xb = xb / yb;
            const double Yb = 1;
            double       Zb = (1 - xb - yb) / yb;

            var S = new []
            {
                new[] { Xr, Xg, Xb },
                new[] { Yr, Yg, Yb },
                new[] { Zr, Zg, Zb },
            }.Inverse();

            Vector W = workingSpace.WhitePoint.Vector;

            (S.MultiplyBy(W)).AssignVariables(out Sr, out Sg, out Sb);

            var M = new []
            {
                new[] { Sr *Xr, Sg *Xg, Sb *Xb },
                new[] { Sr *Yr, Sg *Yg, Sb *Yb },
                new[] { Sr *Zr, Sg *Zg, Sb *Zb },
            };

            return(M);
        }
Beispiel #2
0
 /// <summary>
 /// Constructs RGB working space using a reference white, companding, and chromacity coordinates.
 /// </summary>
 public RGBWorkingSpace(XYZColor referenceWhite, ICompanding companding, RGBPrimariesChromaticityCoordinates chromaticityCoordinates)
 {
     WhitePoint = referenceWhite;
     Companding = companding;
     ChromaticityCoordinates = chromaticityCoordinates;
 }
Beispiel #3
0
 /// <inheritdoc cref="object" />
 public bool Equals(RGBPrimariesChromaticityCoordinates other) =>
 R.Equals(other.R) &&
 G.Equals(other.G) &&
 B.Equals(other.B);