public static ColorProfileFactory GetFactory() { if (Factory == null) { Factory = new ColorProfileFactory(); } return(Factory); }
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); }
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)); }
private void DestColorSpaceComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (IsWindowInitialized == true) { var cb = sender as ComboBox; int selected = cb.SelectedIndex; int from = SourceColorSpaceComboBox.SelectedIndex; DestImageColorProfile = new ColorProfileNotifyChange(ColorProfileFactory.GetFactory().GetColorProfile((ColorProfileEnum)selected)); ColorProfileConverter.ConvertImage(SourceImageColorArray, DestImageColorArray, (ColorProfileEnum)from, (ColorProfileEnum)selected); Paint.CopyToWriteableBitmap(DestImageWB, DestImageColorArray); } }
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)); }
private void SetVariables() { ColorSpaceList = new List <string> { "sRGB", "Adobe RGB", "Apple RGB", "CIE RGB", "Wide Gamut", "PAL/SECAM" }; SourceImageCP = new ColorProfileNotifyChange(ColorProfileFactory.GetFactory().sRBGcolorProfile); DestImageCP = new ColorProfileNotifyChange(ColorProfileFactory.GetFactory().WideGamutcolorProfile); GrayscaleButtonClicked = false; KMeansParam = Globals.k_means; MaxIter = Globals.max_iter; worker.DoWork += worker_DoWork; worker.RunWorkerCompleted += worker_RunWorkerCompleted; }
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); }