public static HsvColor FromRGB(int r, int g, int b)
{
double h;
double min = Math.Min(Math.Min(r, g), b);
double v = Math.Max(Math.Max(r, g), b);
double delta = v - min;
double s = (v == 0.0) ? 0.0 : (delta / v);
if (s == 0.0)
{
h = 0.0;
}
else
{
if (r == v)
{
h = ((double)(g - b)) / delta;
}
else if (g == v)
{
h = 2.0 + (((double)(b - r)) / delta);
}
else
{
h = 4.0 + (((double)(r - g)) / delta);
}
h *= 60.0;
if (h < 0.0)
{
h += 360.0;
}
}
return new HsvColor(h, s, v / 255.0);
}