public static CMYK FromRGB(RGBdouble value) { double c = 1.0 - value.R, m = 1.0 - value.G, y = 1.0 - value.B, k = 1.0; if (c < k) { k = c; } if (m < k) { k = m; } if (y < k) { k = y; } if (k == 1.0)//black { c = m = y = 0.0; } else { c = (c - k) / (1.0 - k); m = (m - k) / (1.0 - k); y = (y - k) / (1.0 - k); } return(new CMYK(c, m, y, k)); }
public static XYZ FromRGB(RGBdouble value) { double r = GammaCorrection(value.R), g = GammaCorrection(value.G), b = GammaCorrection(value.B); //Observer. = 2°, Illuminant = D65 return(new XYZ( r * 41.24 + g * 35.76 + b * 18.05,//multiplicated by 100 r * 21.26 + g * 71.52 + b * 7.22, r * 1.93 + g * 11.92 + b * 95.05)); }
public static HSV FromRGB(RGBdouble col) { double min = Math.Min(Math.Min(col.R, col.G), col.B), max = Math.Max(Math.Max(col.R, col.G), col.B), delta_max = max - min; HSV ret = new HSV(0, 0, 0); ret._v = max; if (delta_max == 0.0) { ret._h = 0.0; ret._s = 0.0; } else { ret._s = delta_max / max; double del_R = (((max - col.R) / 6.0) + (delta_max / 2.0)) / delta_max; double del_G = (((max - col.G) / 6.0) + (delta_max / 2.0)) / delta_max; double del_B = (((max - col.B) / 6.0) + (delta_max / 2.0)) / delta_max; if (col.R == max) { ret._h = del_B - del_G; } else if (col.G == max) { ret._h = (1.0 / 3.0) + del_R - del_B; } else if (col.B == max) { ret._h = (2.0 / 3.0) + del_G - del_R; } if (ret._h < 0.0) { ret._h += 1.0; } if (ret._h > 1.0) { ret._h -= 1.0; } } return(ret); }