Ejemplo n.º 1
0
        public RGB HSVToRGB(HSV hsv)
        {
            double r = 0, g = 0, b = 0;

            if (hsv.S == 0)
            {
                r = hsv.V;
                g = hsv.V;
                b = hsv.V;
            }
            else
            {
                int    i;
                double f, p, q, t;

                if (hsv.H == 360)
                {
                    hsv.H = 0;
                }
                else
                {
                    hsv.H = hsv.H / 60;
                }

                // while (hsv.H > 360.0) hsv.H -= 360.0;

                i = (int)Math.Truncate(hsv.H);
                f = hsv.H - i;

                p = hsv.V * (1.0 - hsv.S);
                q = hsv.V * (1.0 - (hsv.S * f));
                t = hsv.V * (1.0 - (hsv.S * (1.0 - f)));

                switch (i)
                {
                case 0:
                    r = hsv.V;
                    g = t;
                    b = p;
                    break;

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

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

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

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

                default:
                    r = hsv.V;
                    g = p;
                    b = q;
                    break;
                }
            }

            return(new RGB((byte)(r * 255), (byte)(g * 255), (byte)(b * 255)));
        }
Ejemplo n.º 2
0
 public bool Equals(HSV hsv)
 {
     return((this.H == hsv.H) && (this.S == hsv.S) && (this.V == hsv.V));
 }