Ejemplo n.º 1
0
        public ColorProfile GetColorProfile(ColorProfileEnum cp)
        {
            switch (cp)
            {
            case ColorProfileEnum.sRGB:
                return(sRBGcolorProfile);

            case ColorProfileEnum.adobeRGB:
                return(adobeRBGcolorProfile);

            case ColorProfileEnum.appleRGB:
                return(appleRBGcolorProfile);

            case ColorProfileEnum.CIE_RGB:
                return(CIE_RBGcolorProfile);

            case ColorProfileEnum.WideGamut:
                return(WideGamutcolorProfile);

            case ColorProfileEnum.PAL:
                return(PALcolorProfile);

            default:
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static DoubleColor ConvertColorToXYZ(DoubleColor color, ColorProfileEnum from)
        {
            ColorProfile cp = null;

            switch (from)
            {
            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);
            var         v   = cp.RGBtoXYZ.MultiplyByVectorRight(color.R, color.G, color.B);
            DoubleColor XYZ = new DoubleColor(v.X, v.Y, v.Z);

            //XYZ.ToXYZ();
            return(XYZ);



            //return new DoubleColor(-1, -1, -1);
        }
Ejemplo n.º 3
0
        public static DoubleColor ConvertColorFromXYZToLAB(DoubleColor color, ColorProfileEnum from)
        {
            var    cp = ColorProfileFactory.GetFactory().GetColorProfile(from);
            double YR = 100d;
            double XR = cp.White_X * YR / cp.White_Y;
            double ZR = cp.White_Z * YR / cp.White_Y;

            double xr = color.R / XR;
            double yr = color.G / YR;
            double zr = color.B / ZR;

            double k_modifier   = 903.3;
            double eps_modifier = 0.008856;

            double fx;
            double fy;
            double fz;

            if (xr > eps_modifier)
            {
                fx = Math.Pow(xr, 1d / 3d);
            }
            else
            {
                fx = (k_modifier * xr + 16d) / 116d;
            }

            if (yr > eps_modifier)
            {
                fy = Math.Pow(yr, 1d / 3d);
            }
            else
            {
                fy = (k_modifier * yr + 16d) / 116d;
            }

            if (zr > eps_modifier)
            {
                fz = Math.Pow(zr, 1d / 3d);
            }
            else
            {
                fz = (k_modifier * zr + 16d) / 116d;
            }

            double L = 116 * fy - 16;
            double a = 500 * (fx - fy);
            double b = 200 * (fy - fz);

            return(new DoubleColor(L, a, b));
        }
Ejemplo n.º 4
0
        public static DoubleColor ConvertColorFromLABToXYZ(DoubleColor color, ColorProfileEnum from)
        {
            var    cp = ColorProfileFactory.GetFactory().GetColorProfile(from);
            double YR = 100d;
            double XR = cp.White_X * YR / cp.White_Y;
            double ZR = cp.White_Z * YR / cp.White_Y;

            double xr;
            double yr;
            double zr;

            double k_modifier   = 903.3;
            double eps_modifier = 0.008856;


            double fy = (color.R + 16d) / 116d;
            double fx = color.G / 500d + fy;
            double fz = fy - color.B / 200d;

            xr = Math.Pow(fx, 3);
            if (xr <= eps_modifier)
            {
                xr = (116d * fx - 16d) / k_modifier;
            }

            if (color.R > k_modifier * eps_modifier)
            {
                yr = Math.Pow((color.R + 16d) / 116d, 3);
            }
            else
            {
                yr = color.R / k_modifier;
            }

            zr = Math.Pow(fz, 3);
            if (zr <= eps_modifier)
            {
                zr = (116d * fz - 16d) / k_modifier;
            }


            double X = xr * XR;
            double Y = yr * YR;
            double Z = zr * ZR;

            return(new DoubleColor(X, Y, Z));
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 public static void ConvertImageFromLAB(DoubleColor[,] imageSource, SimpleColor[,] imageDest, ColorProfileEnum from)
 {
     Parallel.For(0, imageSource.GetLength(0), i =>
     {
         for (int j = 0; j < imageSource.GetLength(1); j++)
         {
             //DoubleColor color = new DoubleColor(imageSource[i, j]);
             var c1          = ConvertColorFromLABToXYZ(imageSource[i, j], from);
             var c2          = ConvertColorFromXYZ(c1, from, from);
             imageDest[i, j] = c2.ToSimpleColor();
         }
     });
 }
Ejemplo n.º 7
0
 public static MyMatrix GenerateBradfordMatrix(ColorProfileEnum from, ColorProfileEnum to)
 {
     //from is D65
     if (from == ColorProfileEnum.sRGB || from == ColorProfileEnum.adobeRGB || from == ColorProfileEnum.appleRGB || from == ColorProfileEnum.PAL)
     {
         //to is D65
         if (to == ColorProfileEnum.sRGB || to == ColorProfileEnum.adobeRGB || to == ColorProfileEnum.appleRGB || to == ColorProfileEnum.PAL)
         {
             return(null);
         }
         //to is D50
         else if (to == ColorProfileEnum.WideGamut)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 1.0478;
             bm[0, 1] = 0.0229;
             bm[0, 2] = -0.0501;
             bm[1, 0] = 0.0295;
             bm[1, 1] = 0.9905;
             bm[1, 2] = -0.0171;
             bm[2, 0] = -0.0092;
             bm[2, 1] = 0.0150;
             bm[2, 2] = 0.7521;
             return(bm);
         }
         //to is E
         else if (to == ColorProfileEnum.CIE_RGB)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 1.0503;
             bm[0, 1] = 0.0271;
             bm[0, 2] = -0.0233;
             bm[1, 0] = 0.0391;
             bm[1, 1] = 0.9730;
             bm[1, 2] = -0.0093;
             bm[2, 0] = -0.0024;
             bm[2, 1] = 0.0026;
             bm[2, 2] = 0.9181;
             return(bm);
         }
     }
     //from is D50
     else if (from == ColorProfileEnum.WideGamut)
     {
         //to is D65
         if (to == ColorProfileEnum.sRGB || to == ColorProfileEnum.adobeRGB || to == ColorProfileEnum.appleRGB || to == ColorProfileEnum.PAL)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 0.9556;
             bm[0, 1] = -0.0230;
             bm[0, 2] = 0.0632;
             bm[1, 0] = -0.0283;
             bm[1, 1] = 1.0099;
             bm[1, 2] = 0.0210;
             bm[2, 0] = 0.0123;
             bm[2, 1] = -0.0205;
             bm[2, 2] = 1.3299;
             return(bm);
         }
         //to is D50
         else if (to == ColorProfileEnum.WideGamut)
         {
             return(null);
         }
         //to is E
         else if (to == ColorProfileEnum.CIE_RGB)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 1.0026;
             bm[0, 1] = 0.0036;
             bm[0, 2] = 0.0360;
             bm[1, 0] = 0.0097;
             bm[1, 1] = 0.9819;
             bm[1, 2] = 0.0106;
             bm[2, 0] = 0.0089;
             bm[2, 1] = -0.0161;
             bm[2, 2] = 1.2209;
             return(bm);
         }
     }
     //from is E
     else if (from == ColorProfileEnum.CIE_RGB)
     {
         //to is D65
         if (to == ColorProfileEnum.sRGB || to == ColorProfileEnum.adobeRGB || to == ColorProfileEnum.appleRGB || to == ColorProfileEnum.PAL)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 0.9532;
             bm[0, 1] = -0.0266;
             bm[0, 2] = 0.0239;
             bm[1, 0] = -0.0382;
             bm[1, 1] = 1.0288;
             bm[1, 2] = 0.0094;
             bm[2, 0] = 0.0026;
             bm[2, 1] = -0.0030;
             bm[2, 2] = 1.0893;
             return(bm);
         }
         //to is D50
         else if (to == ColorProfileEnum.WideGamut)
         {
             var bm = new MyMatrix();
             bm[0, 0] = 0.9978;
             bm[0, 1] = -0.0042;
             bm[0, 2] = -0.0294;
             bm[1, 0] = -0.0098;
             bm[1, 1] = 1.0183;
             bm[1, 2] = -0.0085;
             bm[2, 0] = -0.0074;
             bm[2, 1] = 0.0134;
             bm[2, 2] = 0.8192;
             return(bm);
         }
         //to is E
         else if (to == ColorProfileEnum.CIE_RGB)
         {
             return(null);
         }
     }
     return(null);
 }