Beispiel #1
0
        public void SetColorMatrix()
        {
            double X_W;
            double Y_W;
            double Z_W;

            if (White_Y < 1e-5)
            {
                X_W = 0;
                Y_W = 0;
                Z_W = 0;
            }
            else
            {
                X_W = White_X / White_Y;
                Y_W = 1d;
                Z_W = White_Z / White_Y;
            }
            MyMatrix matrix = new MyMatrix(this);

            MyMatrix inv = matrix.Invert();

            if (inv == null)
            {
                throw new Exception();
            }

            (double S_R, double S_G, double S_B) = inv.MultiplyByVectorRight(X_W, Y_W, Z_W);

            matrix.MultiplyBySRSGSB(S_R, S_G, S_B);
            RGBtoXYZ = matrix;
            XYZtoRGB = matrix.Invert();
        }
        public static DoubleColor ConvertColorFromXYZ(DoubleColor color, ColorProfile dest, MyMatrix bradfordMatrix = null)
        {
            if (bradfordMatrix != null)
            {
                (color.R, color.G, color.B) = bradfordMatrix.MultiplyByVectorRight(color.R, color.G, color.B);
            }
            var         v   = dest.XYZtoRGB.MultiplyByVectorRight(color.R, color.G, color.B);
            DoubleColor XYZ = new DoubleColor(v.X, v.Y, v.Z);

            XYZ.GammaCorrection(dest.Gamma);
            return(XYZ);
        }
        public static DoubleColor ConvertColorFromXYZ(DoubleColor color, ColorProfileEnum from, ColorProfileEnum to)
        {
            ColorProfile cp = null;

            switch (to)
            {
            case ColorProfileEnum.sRGB:
            {
                cp = ColorProfileFactory.GetFactory().sRBGcolorProfile;
            }
            break;

            case ColorProfileEnum.adobeRGB:
            {
                cp = ColorProfileFactory.GetFactory().adobeRBGcolorProfile;
            }
            break;

            case ColorProfileEnum.appleRGB:
            {
                cp = ColorProfileFactory.GetFactory().appleRBGcolorProfile;
            }
            break;

            case ColorProfileEnum.CIE_RGB:
            {
                cp = ColorProfileFactory.GetFactory().CIE_RBGcolorProfile;
            }
            break;

            case ColorProfileEnum.WideGamut:
            {
                cp = ColorProfileFactory.GetFactory().WideGamutcolorProfile;
            }
            break;

            case ColorProfileEnum.PAL:
            {
                cp = ColorProfileFactory.GetFactory().PALcolorProfile;
            }
            break;

            default:
                break;
            }


            //color.InverseGammaCorrection(cp.Gamma);
            MyMatrix bradford = MyMatrix.GenerateBradfordMatrix(from, to);

            if (bradford != null)
            {
                (color.R, color.G, color.B) = bradford.MultiplyByVectorRight(color.R, color.G, color.B);
            }
            var         v   = cp.XYZtoRGB.MultiplyByVectorRight(color.R, color.G, color.B);
            DoubleColor XYZ = new DoubleColor(v.X, v.Y, v.Z);

            XYZ.GammaCorrection(cp.Gamma);
            return(XYZ);


            //return new DoubleColor(-1, -1, -1);
        }