Exemple #1
0
 public static ColorHSV ToHSV(ColorHSVFull hsv)
 {
     var hue = Math.Round(hsv.Hue);
     var saturation = Math.Round(Clamp(hsv.Saturation) * ColorHSVFull.MaxValue);
     var value = Math.Round(Clamp(hsv.Value) * ColorHSVFull.MaxValue);
     return new ColorHSV((int)hue, (int)saturation, (int)value);
 }
Exemple #2
0
        public static ColorRGBFull ToRGB(ColorHSVFull hsv)
        {
            double r = 0.0, g = 0.0, b = 0.0;

            if (hsv.Saturation == 0.0)
            {
                r = g = b = hsv.Value;
            }
            else
            {
                double h = (hsv.Hue == 360 ? 0 : hsv.Hue) / 60;

                int i = (int)h;
                double f = h - i,
                    p = hsv.Value * (1.0 - hsv.Saturation),
                    q = hsv.Value * (1.0 - hsv.Saturation * f),
                    t = hsv.Value * (1.0 - hsv.Saturation * (1.0 - f));
                switch (i)
                {
                    case 0:
                        r = hsv.Value;
                        g = t;
                        b = p;
                        break;

                    case 1:
                        r = q;
                        g = hsv.Value;
                        b = p;
                        break;

                    case 2:
                        r = p;
                        g = hsv.Value;
                        b = t;
                        break;

                    case 3:
                        r = p;
                        g = q;
                        b = hsv.Value;
                        break;

                    case 4:
                        r = t;
                        g = p;
                        b = hsv.Value;
                        break;

                    default:
                        r = hsv.Value;
                        g = p;
                        b = q;
                        break;
                }
            }
            return new ColorRGBFull(r, g, b);
        }
Exemple #3
0
 public static ColorHSVFull Clamp(ColorHSVFull hsv)
 {
     var hue = Math.Min(ColorHSVFull.MaxHueValue, Math.Max(0.0, hsv.Hue));
     var value = Clamp(hsv.Value);
     var saturation = Clamp(hsv.Saturation);
     return new ColorHSVFull(hue, saturation, value);
 }