public static LinearRgbColor ToLinearRgb(this CieXyzColor source) { Vector4 xyz = new Vector4((float)source.X, (float)source.Y, (float)source.Z, 1.0f); Vector4 rgb = Vector4.Transform(xyz, cieToLinearRgbTransform); return(new LinearRgbColor { R = rgb.X, G = rgb.Y, B = rgb.Z }); }
public static CieLabColor ToCieLab(this CieXyzColor source) { float L = 116.0f * f(source.Y / CieConstants.Yn) - 16.0f; float a = 500.0f * (f(source.X / CieConstants.Xn) - f(source.Y / CieConstants.Yn)); float b = 200.0f * (f(source.Y / CieConstants.Yn) - f(source.Z / CieConstants.Zn)); return(new CieLabColor { L = L, a = a, b = b }); float f(float t) { return(t > CieConstants.delta * CieConstants.delta * CieConstants.delta ? (float)Math.Pow(t, 1.0 / 3.0) : t / (3 * CieConstants.delta * CieConstants.delta) + 4.0f / 29.0f); } }
public static CieLuvColor ToCieLuv(this CieXyzColor source) { const float inflectionPoint = (6.0f / 29.0f) * (6.0f / 29.0f) * (6.0f / 29.0f); float inflectionTest = source.Y / CieConstants.Yn; float denominator = (source.X + 15.0f * source.Y + 3.0f * source.Z); float uPrime = denominator == 0.0f ? 0.0f : (4.0f * source.X) / denominator; float vPrime = denominator == 0.0f ? 0.0f : (9.0f * source.Y) / denominator; float L = inflectionTest <= inflectionPoint ? (29.0f / 3.0f) * (29.0f / 3.0f) * (29.0f / 3.0f) * source.Y / CieConstants.Yn : 116.0f * (float)Math.Pow(source.Y / CieConstants.Yn, 1.0f / 3.0f) - 16.0f; float u = 13.0f * L * (uPrime - CieConstants.uN); float v = 13.0f * L * (vPrime - CieConstants.vN); return(new CieLuvColor { L = L, u = u, v = v }); }
public static StandardRgbColor ToStandardRgb(this CieXyzColor source) { return(source.ToLinearRgb().ToStandardRgb()); }