Ejemplo n.º 1
0
        void Convert(HSVComponent hsv, RGBComponent rgb)
        {
            double rs = hsv.S / 100.0;
            double rv = hsv.V / 100.0;

            double c = rv * rs;


            double x = c * (1 - Math.Abs(((hsv.H / 60.0) % 2) - 1));
            double m = rv - c;

            Tuple <double, double, double> rrgb;

            if (hsv.H < 60)
            {
                rrgb = new Tuple <double, double, double>(c, x, 0);
            }
            else if (hsv.H < 120)
            {
                rrgb = new Tuple <double, double, double>(x, c, 0);
            }
            else if (hsv.H < 180)
            {
                rrgb = new Tuple <double, double, double>(0, c, x);
            }
            else if (hsv.H < 240)
            {
                rrgb = new Tuple <double, double, double>(0, x, c);
            }
            else if (hsv.H < 300)
            {
                rrgb = new Tuple <double, double, double>(x, 0, c);
            }
            else
            {
                rrgb = new Tuple <double, double, double>(c, 0, x);
            }

            rgb.R = (byte)((rrgb.Item1 + m) * 255.0);
            rgb.G = (byte)((rrgb.Item2 + m) * 255.0);
            rgb.B = (byte)((rrgb.Item3 + m) * 255.0);
        }
Ejemplo n.º 2
0
        void Convert(RGBComponent rgb, HSVComponent hsv)
        {
            double rr = rgb.R / 255.0;
            double rg = rgb.G / 255.0;
            double rb = rgb.B / 255.0;

            double cmax  = Math.Max(rr, Math.Max(rg, rb));
            double cmin  = Math.Min(rr, Math.Min(rg, rb));
            double delta = cmax - cmin;

            if (delta == 0.0)
            {
                hsv.H = 0;
            }
            else if (cmax == rr)
            {
                hsv.H = (ushort)(60 * ((int)((rg - rb) / delta) % 6));
            }
            else if (cmax == rg)
            {
                hsv.H = (ushort)(60 * ((rb - rr) / delta + 2));
            }
            else
            {
                hsv.H = (ushort)(60 * ((rr - rg) / delta + 4));
            }

            if (cmax == 0.0)
            {
                hsv.S = 0;
            }
            else
            {
                hsv.S = (byte)((delta / cmax) * 100.0);
            }

            hsv.V = (byte)(cmax * 100.0);
        }