public ColorRgb(ColorXyz xyz, RgbWorkingSpace ws) { var m = ws.XyztoRgbMatrix; double x = xyz.X / 100; double y = xyz.Y / 100; double z = xyz.Z / 100; double lin_r = (x * m[0, 0]) + (y * m[0, 1]) + (z * m[0, 2]); // red double lin_g = (x * m[1, 0]) + (y * m[1, 1]) + (z * m[1, 2]); // green double lin_b = (x * m[2, 0]) + (y * m[2, 1]) + (z * m[2, 2]); // blue double r = (lin_r <= 0.0031308) ? 12.92 * lin_r : (1.055) * System.Math.Pow(lin_r, (1.0 / 2.4)) - 0.055; double g = (lin_g <= 0.0031308) ? 12.92 * lin_g : (1.055) * System.Math.Pow(lin_g, (1.0 / 2.4)) - 0.055; double b = (lin_b <= 0.0031308) ? 12.92 * lin_b : (1.055) * System.Math.Pow(lin_b, (1.0 / 2.4)) - 0.055; r = ClampToRange_0_1(r); g = ClampToRange_0_1(g); b = ClampToRange_0_1(b); this._alpha = xyz.Alpha; this._r = r; this._g = g; this._b = b; }
public ColorXyz(double alpha, double x, double y, double z) { ColorXyz.check_xyz(alpha, x, y, z); this._alpha = alpha; this._x = x; this._y = y; this._z = z; }
public static ColorLab ToLab(ColorRgb rgb) { ColorXyz xyz = XyzConverter.ToXyz(rgb); ColorXyz white = XyzConverter.WhiteReference; double x = PivotXyz(xyz.X / white.X); double y = PivotXyz(xyz.Y / white.Y); double z = PivotXyz(xyz.Z / white.Z); return(new ColorLab( Math.Max(0, 116 * y - 16), 500 * (x - y), 200 * (y - z))); }
public void Colors_ShouldRoundtripFromRgbToCielab() { // Arrange var color = Color.Red; // Act var colorRgb = new RgbVector(color); var colorXyz = ColorXyz.FromRgb(colorRgb); var colorCielab = ColorCielab.FromRgb(colorRgb); var colorXyzBack = colorCielab.AsColorXyz(); var colorRgbBack = colorXyzBack.AsColorRgb(); // Assert Assert.Fail(); }
public static ColorRgb ToColor(ColorLab lab) { double y = (lab.L + 16.0) / 116.0; double x = lab.A / 500.0 + y; double z = y - lab.B / 200.0; ColorXyz white = XyzConverter.WhiteReference; double x3 = x * x * x; double z3 = z * z * z; ColorXyz xyz = new ColorXyz( white.X * (x3 > XyzConverter.Epsilon ? x3 : (x - 16.0 / 116.0) / 7.787), white.Y * (lab.L > (XyzConverter.Kappa * XyzConverter.Epsilon) ? Math.Pow(((lab.L + 16.0) / 116.0), 3) : lab.L / XyzConverter.Kappa), white.Z * (z3 > XyzConverter.Epsilon ? z3 : (z - 16.0 / 116.0) / 7.787)); return(XyzConverter.ToColor(xyz)); }
public static ColorRgb ToColor(ColorXyz xyz) { // (Observer = 2°, Illuminant = D65) double x = xyz.X / 100.0; double y = xyz.Y / 100.0; double z = xyz.Z / 100.0; double r = x * 3.2406 + y * -1.5372 + z * -0.4986; double g = x * -0.9689 + y * 1.8758 + z * 0.0415; double b = x * 0.0557 + y * -0.2040 + z * 1.0570; r = r > 0.0031308 ? 1.055 * Math.Pow(r, 1 / 2.4) - 0.055 : 12.92 * r; g = g > 0.0031308 ? 1.055 * Math.Pow(g, 1 / 2.4) - 0.055 : 12.92 * g; b = b > 0.0031308 ? 1.055 * Math.Pow(b, 1 / 2.4) - 0.055 : 12.92 * b; return(new ColorRgb(ToRgb(r), ToRgb(g), ToRgb(b))); }
public ColorXyz(ColorLab lab, RgbWorkingSpace ws) { ColorXyz i = ws.ReferenceWhite.ColorXyz; double delta = 6.0 / 29.0; double fy = (lab.L + 16) / 116.0; double fx = fy + (lab.A / 500.0); double fz = fy - (lab.B / 200.0); double x = (fx > delta) ? i.X * (fx * fx * fx) : (fx - 16.0 / 116.0) * 3 * (delta * delta) * i.X; double y = (fy > delta) ? i.Y * (fy * fy * fy) : (fy - 16.0 / 116.0) * 3 * (delta * delta) * i.Y; double z = (fz > delta) ? i.Z * (fz * fz * fz) : (fz - 16.0 / 116.0) * 3 * (delta * delta) * i.Z; this._alpha = lab.Alpha; this._x = x; this._y = y; this._z = z; }
public Illuminant(string name, int degree, ColorXyz xyz) { this.Name = name; this.Degree = degree; this.ColorXyz = xyz; }