public static CIEXYZColor FromRGB(RGBColor rgb, CIERGBDefinition primaries) { var mat = primaries.rgb2xyz; var rgbvec = DenseVector.OfArray(new double[] { rgb.r, rgb.g, rgb.b }); var xyz = mat * rgbvec; return(new CIEXYZColor(xyz[0], xyz[1], xyz[2])); }
public RGBColor ToRGB(CIERGBDefinition primaries, bool limitGamut = true) { // NOTE: Assumes linear RGB, not sRGB. var mat = primaries.xyz2rgb; var rgb = mat * this; if (limitGamut && (rgb.Maximum() > 1.0 || rgb.Minimum() < 0.0)) { // Outside the gamut return(new RGBColor(float.NaN, float.NaN, float.NaN)); } else { return(new RGBColor((float)rgb[0], (float)rgb[1], (float)rgb[2])); } }