public static Color1931XYZ ToXYZ(this ColorRGB RGB, ColorTransformMatrix RGBtoXYZ) { Color1931XYZ XYZ = default(Color1931XYZ); RGBtoXYZ.Transform(RGB.R, RGB.G, RGB.B, out XYZ.X, out XYZ.Y, out XYZ.Z); return(XYZ); }
public static ColorRGB ToRGB(this Color1931XYZ XYZ, ColorTransformMatrix XYZtoRGB) { ColorRGB RGB = default(ColorRGB); XYZtoRGB.Transform(XYZ.X, XYZ.Y, XYZ.Z, out RGB.R, out RGB.G, out RGB.B); return(RGB); }
public static unsafe ImageSource RenderLinearGamutLuv(int width, int height, RGBPrimaries <Color1931xyY> primaries, Color1931XYZ white, float leftU, float rightU, float topV, float bottomV) { ColorTransformMatrix RGBtoXYZ = ColorTransformMatrix.GetRGBtoXYZ((Color1931XYZ)primaries.Red, (Color1931XYZ)primaries.Green, (Color1931XYZ)primaries.Blue, white); ColorTransformMatrix XYZtoRGB = RGBtoXYZ.Invert(); return(RenderLinearGamutLuv(width, height, XYZtoRGB, leftU, rightU, topV, bottomV)); }
internal static ColorLMS ToLMS(this Color1931XYZ XYZ, ref ColorTransformMatrix XYZtoLMS) { ColorLMS LMS; XYZtoLMS.Transform(XYZ.X, XYZ.Y, XYZ.Z, out LMS.L, out LMS.M, out LMS.S); return(LMS); }
internal static void XYZtoDKL(Color1931XYZ stimulus, ColorLMS backgroundLMS, ref ColorTransformMatrix XYZtoLMS, ref ColorTransformMatrix LMStoDKL, out ColorDKL dkl) { ColorLMS stimulusLMS; XYZtoLMS.Transform(stimulus.X, stimulus.Y, stimulus.Z, out stimulusLMS.L, out stimulusLMS.M, out stimulusLMS.S); ColorLMS deltaLMS = stimulusLMS - backgroundLMS; LMStoDKL.Transform(deltaLMS.L, deltaLMS.M, deltaLMS.S, out dkl.Isochromatic, out dkl.RGisoluminant, out dkl.Sisoluminant); }
internal static void DKLtoXYZ(ColorDKL dkl, ColorLMS backgroundLMS, ref ColorTransformMatrix DKLtoLMS, ref ColorTransformMatrix LMStoXYZ, out Color1931XYZ xyz) { ColorLMS diffLMS; DKLtoLMS.Transform(dkl.Isochromatic, dkl.RGisoluminant, dkl.Sisoluminant, out diffLMS.L, out diffLMS.M, out diffLMS.S); ColorLMS stimulusLMS = diffLMS + backgroundLMS; LMStoXYZ.Transform(stimulusLMS.L, stimulusLMS.M, stimulusLMS.S, out xyz.X, out xyz.Y, out xyz.Z); }
public ColorTransformMatrix Invert(int iterations) { ColorTransformMatrix inverse = Invert(); for (int i = 0; i < iterations; i++) { inverse = inverse * (2 * Identity - this * inverse); } return(inverse); }
public static ColorTransformMatrix GetRGBtoXYZ(Color1931XYZ red, Color1931XYZ green, Color1931XYZ blue, Color1931XYZ white) { ColorTransformMatrix XYZ = new ColorTransformMatrix(red, green, blue); ColorTransformMatrix XYZinv = XYZ.Invert(); float Sr, Sg, Sb; XYZinv.Transform(white.X, white.Y, white.Z, out Sr, out Sg, out Sb); ColorTransformMatrix M = XYZ; M.a *= Sr; M.b *= Sg; M.c *= Sb; M.d *= Sr; M.e *= Sg; M.f *= Sb; M.g *= Sr; M.h *= Sg; M.i *= Sb; return(M); }
// Kaiser, Bonton (1996). Human Color Vision (Second Edition), Appendix, Part IV public static ColorTransformMatrix GetScaledLMStoDKL(ColorLMS background) { ColorTransformMatrix LMStoDKL = new ColorTransformMatrix ( 1, 1, 0, 1, -background.L / background.M, 0, -1, -1, (background.L + background.M) / background.S ); ColorTransformMatrix DKLtoLMS = LMStoDKL.Invert(); ColorLMS isolatingIso = new ColorLMS(DKLtoLMS.a, DKLtoLMS.d, DKLtoLMS.g); float pooledConeContrastIso = (isolatingIso / background).Length; ColorLMS normalizedIso = isolatingIso / pooledConeContrastIso; ColorLMS isolatingRGiso = new ColorLMS(DKLtoLMS.b, DKLtoLMS.e, DKLtoLMS.h); float pooledConeCotnrastRGiso = (isolatingRGiso / background).Length; ColorLMS normalizedRGiso = isolatingRGiso / pooledConeCotnrastRGiso; ColorLMS isolatingSiso = new ColorLMS(DKLtoLMS.c, DKLtoLMS.f, DKLtoLMS.i); float pooledConeContrastSiso = (isolatingSiso / background).Length; ColorLMS normalizedSiso = isolatingSiso / pooledConeContrastSiso; ColorDKL unitResponse; LMStoDKL.Transform(normalizedIso.L, normalizedIso.M, normalizedIso.S, out unitResponse.Isochromatic, out _, out _); LMStoDKL.Transform(normalizedRGiso.L, normalizedRGiso.M, normalizedRGiso.S, out _, out unitResponse.RGisoluminant, out _); LMStoDKL.Transform(normalizedSiso.L, normalizedSiso.M, normalizedSiso.S, out _, out _, out unitResponse.Sisoluminant); ColorTransformMatrix rescaler = new ColorTransformMatrix ( 1 / unitResponse.Isochromatic, 0, 0, 0, 1 / unitResponse.RGisoluminant, 0, 0, 0, 1 / unitResponse.Sisoluminant ); return(rescaler * LMStoDKL); }
private static void Solve(float x1, float x2, float x3, ColorRGB rgb1, ColorRGB rgb2, ColorRGB rgb3, out float m1, out float m2, out float m3) { // Cramer's rule ColorTransformMatrix A = new ColorTransformMatrix ( rgb1.R, rgb1.G, rgb1.B, rgb2.R, rgb2.G, rgb2.B, rgb3.R, rgb3.G, rgb3.B ); ColorTransformMatrix A1 = new ColorTransformMatrix ( x1, rgb1.G, rgb1.B, x2, rgb2.G, rgb2.B, x3, rgb3.G, rgb3.B ); ColorTransformMatrix A2 = new ColorTransformMatrix ( rgb1.R, x1, rgb1.B, rgb2.R, x2, rgb2.B, rgb3.R, x3, rgb3.B ); ColorTransformMatrix A3 = new ColorTransformMatrix ( rgb1.R, rgb1.G, x1, rgb2.R, rgb2.G, x2, rgb3.R, rgb3.G, x3 ); float det = A.Determinant; m1 = A1.Determinant / det; m2 = A2.Determinant / det; m3 = A3.Determinant / det; }
public static Color1931XYZ ToXYZ(this ColorHSV HSV, ColorTransformMatrix RGBtoXYZ) { ColorRGB RGB = ToRGB(HSV); return(ToXYZ(HSV, RGBtoXYZ)); }
public static unsafe ImageSource RenderLinearGamutLuv(int width, int height, ColorTransformMatrix XYZtoRGB, float leftU, float rightU, float topV, float bottomV) { if (width == 0 || height == 0) { return(null); } const float minVisibleU = 0.001423f; const float maxVisibleU = 0.6234f; const float minVisibleV = 0.01592f; const float maxVisibleV = 0.5868f; float widthU = rightU - leftU; float heightV = bottomV - topV; float uPerPixel = widthU / width; float vPerPixel = heightV / height; int pxMinVisibleU = 0; if (uPerPixel != 0) { pxMinVisibleU = Math.Max(0, (int)((minVisibleU - leftU) / uPerPixel)); } int pxMaxVisibleU = width; if (uPerPixel != 0) { pxMaxVisibleU = Math.Min(width, (int)((maxVisibleU - leftU) / uPerPixel)); } int pxMinVisibleV = height; if (vPerPixel != 0) { pxMinVisibleV = Math.Min(height, (int)((minVisibleV - topV) / vPerPixel)); } int pxMaxVisibleV = 0; if (uPerPixel != 0) { pxMaxVisibleV = Math.Max(0, (int)((maxVisibleV - topV) / vPerPixel)); } byte[] data = new byte[width * height * 4]; float R, G, B; float u, v, x, y; float X, Y = 1f, Z; fixed(byte *pData = data) { for (int pxV = pxMaxVisibleV; pxV <= pxMinVisibleV; pxV++) { for (int pxU = pxMinVisibleU; pxU <= pxMaxVisibleU; pxU++) { u = leftU + pxU * uPerPixel; v = topV + pxV * vPerPixel; ConvertColor.Fastuv2xy(u, v, out x, out y); ConvertColor.FastxyY2XYZ(x, y, Y, out X, out Z); XYZtoRGB.Transform(X, Y, Z, out R, out G, out B); if (R >= 0 && G >= 0 && B >= 0) { byte *pBGR = pData + (pxV * width + pxU) * 4; pBGR[0] = (byte)Math.Min(255, ConvertColor.scRGBtosRGB(B) * 255); // TODO: handle negative pBGR[1] = (byte)Math.Min(255, ConvertColor.scRGBtosRGB(G) * 255); pBGR[2] = (byte)Math.Min(255, ConvertColor.scRGBtosRGB(R) * 255); pBGR[3] = 255; } } } } return(BitmapSource.Create(width, height, 96, 96, PixelFormats.Pbgra32, null, data, width * 4)); }
public static ColorRGB ToRGB(this Chromaticity1976uv uv, ColorTransformMatrix XYZtoRGB) { Chromaticity1931xy xy = Toxy(uv); return(ToRGB(xy, XYZtoRGB)); }
public static ColorRGB ToRGB(this Chromaticity1931xy xy, ColorTransformMatrix XYZtoRGB) { Color1931XYZ XYZ = ToXYZ(xy, 1f); return(ToRGB(XYZ, XYZtoRGB)); }
public static ColorRGB ToRGB(this Color1976LCh LCh, ColorTransformMatrix XYZtoRGB, Color1931XYZ white) { return(ToRGB((Color1976Lab)LCh, XYZtoRGB, white)); }
public static ColorRGB ToRGB(this Color1976Lab Lab, ColorTransformMatrix XYZtoRGB, Color1931XYZ white) { Color1931XYZ XYZ = ToXYZ(Lab, white); return(ToRGB(XYZ, XYZtoRGB)); }
public static Color1976Luv ToLuv(this ColorRGB RGB, ColorTransformMatrix RGBtoXYZ, Color1931XYZ whiteLuv) { Color1931XYZ XYZ = ToXYZ(RGB, RGBtoXYZ); return(ToLuv(XYZ, whiteLuv)); }
public static Color1931xyY ToxyY(this ColorRGB RGB, ColorTransformMatrix RGBtoXYZ) { Color1931XYZ XYZ = ToXYZ(RGB, RGBtoXYZ); return(ToxyY(XYZ)); }
public static ColorRGB ToRGB(int nm, ColorTransformMatrix XYZtoRGB) { Color1931XYZ XYZ = ToXYZ(nm); return(ToRGB(XYZ, XYZtoRGB)); }
public static Chromaticity1976uv Touv(this ColorHSV HSV, ColorTransformMatrix RGBtoXYZ) { Color1931XYZ XYZ = ToXYZ(HSV, RGBtoXYZ); return(Touv(XYZ)); }
public static Chromaticity1931xy Toxy(this ColorRGB RGB, ColorTransformMatrix RGBtoXYZ) { Color1931XYZ XYZ = ToXYZ(RGB, RGBtoXYZ); return(Toxy(XYZ)); }
internal static ColorLMS ToLMS(this Color1931xyY xyY, ref ColorTransformMatrix XYZtoLMS) => xyY.ToXYZ().ToLMS(ref XYZtoLMS);
public static ColorRGB ToRGB(this Color1931xyY xyY, ColorTransformMatrix XYZtoRGB) { Color1931XYZ XYZ = ToXYZ(xyY); return(ToRGB(XYZ, XYZtoRGB)); }
public static Chromaticity1931xy Toxy(this ColorHSV HSV, ColorTransformMatrix RGBtoXYZ) { ColorRGB RGB = ToRGB(HSV); return(Toxy(RGB, RGBtoXYZ)); }
public static Color1976Lab ToLab(this ColorHSV HSV, ColorTransformMatrix RGBtoXYZ, Color1931XYZ whiteLab) { Color1931XYZ XYZ = ToXYZ(HSV, RGBtoXYZ); return(ToLab(XYZ, whiteLab)); }