private XYZColor rgb_to_xyz(Color rgb_col) { var red = (double)rgb_col.R; var green = (double)rgb_col.G; var blue = (double)rgb_col.B; var _red = red / 255; var _green = green / 255; var _blue = blue / 255; if (_red > 0.04045) { _red = (_red + 0.055) / 1.055; _red = Math.Pow(_red, 2.4); } else { _red = _red / 12.92; } if (_green > 0.04045) { _green = (_green + 0.055) / 1.055; _green = Math.Pow(_green, 2.4); } else { _green = _green / 12.92; } if (_blue > 0.04045) { _blue = (_blue + 0.055) / 1.055; _blue = Math.Pow(_blue, 2.4); } else { _blue = _blue / 12.92; } _red *= 100; _green *= 100; _blue *= 100; XYZColor converted = new XYZColor(); converted.x = _red * 0.4124 + _green * 0.3576 + _blue * 0.1805; converted.y = _red * 0.2126 + _green * 0.7152 + _blue * 0.0722; converted.x = _red * 0.0193 + _green * 0.1192 + _blue * 0.9505; return(converted); }
private LABColor xyz_to_lab(XYZColor xyz_col) { var x = xyz_col.x; var y = xyz_col.y; var z = xyz_col.z; var _x = x / 95.047; var _y = y / 100; var _z = z / 108.883; if (_x > 0.008856) { _x = Math.Pow(_x, 1.0d / 3.0d); } else { _x = 7.787 * _x + 16.0d / 116.0d; } if (_y > 0.008856) { _y = Math.Pow(_y, 1.0d / 3.0d); } else { _y = 7.787 * _y + 16.0d / 116.0d; } if (_z > 0.008856) { _z = Math.Pow(_z, 1.0d / 3.0d); } else { _z = 7.787 * _z + 16.0d / 116.0d; } var l = 116 * _y - 16.0d; var a = 500 * (_x - _y); var b = 200 * (_y - _z); return(new LABColor { L = l, A = a, B = b }); }