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 Rgb ToRgb() { var cmy = new Cmy { C = C * (1 - K) + K, M = M * (1 - K) + K, Y = Y * (1 - K) + K }; return(cmy.ToColorSpace <Rgb>()); }
public static ColorSpace FromXElement(XElement element) { if (element.Name != "ColorSpace") { throw new XmlException("XElement name must be \"ColorSpace\""); } switch (element.Attribute("Type").Value) { case "CMY": { var result = new Cmy(); result.FromXNode(element); return(result); } case "CMYK": { var result = new Cmyk(); result.FromXNode(element); return(result); } case "HSL": { var result = new Hsl(); result.FromXNode(element); return(result); } case "HSV": { var result = new Hsv(); result.FromXNode(element); return(result); } case "HunterLAB": { var result = new HunterLab(); result.FromXNode(element); return(result); } case "LAB": { var result = new Lab(); result.FromXNode(element); return(result); } case "LCH": { var result = new Lch(); result.FromXNode(element); return(result); } case "LUV": { var result = new Luv(); result.FromXNode(element); return(result); } case "RGB": { var result = new Rgb(); result.FromXNode(element); return(result); } case "RGBA": { var result = new Rgba(); result.FromXNode(element); return(result); } case "XYZ": { var result = new Xyz(); result.FromXNode(element); return(result); } case "YXY": { var result = new Yxy(); result.FromXNode(element); return(result); } default: throw new ArgumentException("Unrecognized ColorSpace type"); } }