コード例 #1
0
        //I found this useful little snippet here: http://www.splinter.com.au/converting-hsv-to-rgb-colour-using-c/
        //This takes a color's hue and saturation and converts it to the maximum brightness using an HSV color
        public static Color maxBright(this Color c)
        {
            Color maxC = c;
            float sat = c.Saturation();
            float hue = c.Hue();
            float r, g, b;

            if (sat <= 0)
            {
                r = g = b = 0;
            }
            else
            {
                float h  = hue * 6;
                int   i  = (int)Math.Floor(h);
                float f  = h - i;
                float pv = 1 - sat;
                float qv = 1 - sat * f;
                float tv = 1 - sat * (1 - f);

                switch (i)
                {
                case 0:
                    r = 1;
                    g = tv;
                    b = pv;
                    break;

                case 1:
                    r = qv;
                    g = 1;
                    b = pv;
                    break;

                case 2:
                    r = pv;
                    g = 1;
                    b = tv;
                    break;

                case 3:
                    r = pv;
                    g = qv;
                    b = 1;
                    break;

                case 4:
                    r = tv;
                    g = pv;
                    b = 1;
                    break;

                case 5:
                    r = 1;
                    g = pv;
                    b = qv;
                    break;

                default:
                    r = g = b = 1;
                    break;
                }
            }

            r = clamp(r);
            g = clamp(g);
            b = clamp(b);

            maxC = new Color(r, g, b);

            return(maxC);
        }