protected override void FromRgb(Rgb color) { var xyz = color.ToColorSpace<Xyz>(); var dividend = xyz.X + xyz.Y + xyz.Z; Y1 = xyz.Y; X = dividend.ApproximatelyEquals(0) ? 0 : xyz.X / dividend; Y2 = dividend.ApproximatelyEquals(0) ? 0 : xyz.Y / dividend; }
public Yxy(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { var r1 = color.R / 255.0; var g1 = color.G / 255.0; var b1 = color.B / 255.0; var cMin = r1; var cMax = r1; if (g1 > cMax) cMax = g1; if (b1 > cMax) cMax = b1; if (g1 < cMin) cMin = g1; if (b1 < cMin) cMin = b1; var delta = cMax - cMin; H = 0; S = 0; L = (cMax + cMin) / 2.0; if (!color.R.Equals(color.G) || !color.G.Equals(color.B)) { if (r1.Equals(cMax)) H = (g1 - b1) / delta; else if (g1.Equals(cMax)) H = 2.0 + (b1 - r1) / delta; else if (b1.Equals(cMax)) H = 4.0 + (r1 - g1) / delta; H *= 60.0; if (H < 0) H += 360.0; } if (!delta.Equals(0)) { S = delta / (1.0 - System.Math.Abs(2.0 * L - 1.0)); } }
public Hsl(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { var xyz = color.ToColorSpace<Xyz>(); var x = xyz.X / Xyz.WhiteReference[0]; var y = xyz.Y / Xyz.WhiteReference[1]; var z = xyz.Z / Xyz.WhiteReference[2]; x = x > Xyz.Epsilon ? CubicRoot(x) : (Xyz.Kappa * x + 16) / 116; y = y > Xyz.Epsilon ? CubicRoot(y) : (Xyz.Kappa * y + 16) / 116; z = z > Xyz.Epsilon ? CubicRoot(z) : (Xyz.Kappa * z + 16) / 116; L = System.Math.Max(0, 116 * y - 16); A = 500 * (x - y); B = 200 * (y - z); }
public Lab(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { var r = color.R / 255.0; var g = color.G / 255.0; var b = color.B / 255.0; r = (r > 0.04045 ? System.Math.Pow((r + 0.055) / 1.055, 2.4) : r / 12.92) * 100.0; g = (g > 0.04045 ? System.Math.Pow((g + 0.055) / 1.055, 2.4) : g / 12.92) * 100.0; b = (b > 0.04045 ? System.Math.Pow((b + 0.055) / 1.055, 2.4) : b / 12.92) * 100.0; // TODO: Hard-coded to use sRGB. Update to allow multiple working spaces X = r * RgbXyzMatrix.SRgb[0, 0] + g * RgbXyzMatrix.SRgb[0, 1] + b * RgbXyzMatrix.SRgb[0, 2]; Y = r * RgbXyzMatrix.SRgb[1, 0] + g * RgbXyzMatrix.SRgb[1, 1] + b * RgbXyzMatrix.SRgb[1, 2]; Z = r * RgbXyzMatrix.SRgb[2, 0] + g * RgbXyzMatrix.SRgb[2, 1] + b * RgbXyzMatrix.SRgb[2, 2]; }
public Lch(Rgb color) { FromRgb(color); }
public Luv(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { R = color.R; G = color.G; B = color.B; }
protected override void FromRgb(Rgb color) { var xyz = color.ToColorSpace<Xyz>(); var y = xyz.Y / Xyz.WhiteReference[1]; L = y > Xyz.Epsilon ? 116.0 * System.Math.Pow(y, 1.0 / 3.0) - 16.0 : Xyz.Kappa * y; var targetDenominator = xyz.X + 15.0 * xyz.Y + 3.0 * xyz.Z; var referenceDenominator = Xyz.WhiteReference[0] + 15.0 * Xyz.WhiteReference[1] + 3.0 * Xyz.WhiteReference[2]; var xTarget = targetDenominator.Equals(0) ? 0 : 4.0 * xyz.X / targetDenominator - 4.0 * Xyz.WhiteReference[0] / referenceDenominator; var yTarget = targetDenominator.Equals(0) ? 0 : 9.0 * xyz.Y / targetDenominator - 9.0 * Xyz.WhiteReference[1] / referenceDenominator; U = 13.0 * L * xTarget; V = 13.0 * L * yTarget; }
public HunterLab(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { var xyz = color.ToColorSpace<Xyz>(); L = 10.0 * System.Math.Sqrt(xyz.Y); A = !xyz.Y.Equals(0) ? 17.5 * ((1.02 * xyz.X - xyz.Y) / System.Math.Sqrt(xyz.Y)) : 0; B = !xyz.Y.Equals(0) ? 7.0 * ((xyz.Y - 0.847 * xyz.Z) / System.Math.Sqrt(xyz.Y)) : 0; }
protected override void FromRgb(Rgb color) { var cmy = new Cmy(color); var k = 1.0; if (cmy.C < k) k = cmy.C; if (cmy.M < k) k = cmy.M; if (cmy.Y < k) k = cmy.Y; K = k; if (k.ApproximatelyEquals(1.0)) { C = 0; M = 0; Y = 0; } else { C = (cmy.C - k) / (1 - k); M = (cmy.M - k) / (1 - k); Y = (cmy.Y - k) / (1 - k); } }
protected override void FromRgb(Rgb color) { base.FromRgb(color); var rgba = color as Rgba; if (rgba != null) A = rgba.A; }
public Cmyk(Rgb color) { FromRgb(color); }
protected override void FromRgb(Rgb color) { var lab = new Lab(color); var hDeg = System.Math.Atan2(lab.B, lab.A); if (hDeg > 0) { hDeg = hDeg / System.Math.PI * 180.0; } else { hDeg = 360.0 - System.Math.Abs(hDeg) / System.Math.PI * 180.0; } if (hDeg < 0) hDeg += 360.0; else if (hDeg >= 360) hDeg -= 360.0; L = lab.L; C = System.Math.Sqrt(lab.A * lab.A + lab.B * lab.B); H = hDeg; }