Beispiel #1
0
        public RGB ToRGB()
        {
            RGB rg  = new RGB();
            HSV hsx = new HSV(this.H, this.S, this.V);

            if (hsx.S == 0)
            {
                rg.R = rg.G = rg.B = Math.Round(hsx.V * 2.55); return(rg);
            }

            hsx.S  = hsx.S / 100;
            hsx.V  = hsx.V / 100;
            hsx.H /= 60;

            var i = Math.Floor(hsx.H);
            var f = hsx.H - i;
            var p = hsx.V * (1 - hsx.S);
            var q = hsx.V * (1 - hsx.S * f);
            var t = hsx.V * (1 - hsx.S * (1 - f));

            switch ((int)i)
            {
            case 0: rg.R = hsx.V; rg.G = t; rg.B = p; break;

            case 1: rg.R = q; rg.G = hsx.V; rg.B = p; break;

            case 2: rg.R = p; rg.G = hsx.V; rg.B = t; break;

            case 3: rg.R = p; rg.G = q; rg.B = hsx.V; break;

            case 4: rg.R = t; rg.G = p; rg.B = hsx.V; break;

            default: rg.R = hsx.V; rg.G = p; rg.B = q; break;
            }

            rg.R = Math.Round(rg.R * 255);
            rg.G = Math.Round(rg.G * 255);
            rg.B = Math.Round(rg.B * 255);

            return(rg);
        }
Beispiel #2
0
 private RGB HsvVariation(HSV hsv, double addsat, double addval)
 {
     return(new HSV(hsv.H, AddLimit(hsv.S, addsat, 0, 99), AddLimit(hsv.V, addval, 0, 99)).ToRGB());
 }
Beispiel #3
0
 public ColorMatch(HSV hsv) : this(hsv.H, hsv.S, hsv.V)
 {
 }
Beispiel #4
0
        public HSV ToHSV()
        {
            HSV hs = new HSV();
            RGB rg = new RGB(this.R, this.G, this.B);

            var m = rg.R;

            if (rg.G < m)
            {
                m = rg.G;
            }
            if (rg.B < m)
            {
                m = rg.B;
            }
            var v = rg.R;

            if (rg.G > v)
            {
                v = rg.G;
            }
            if (rg.B > v)
            {
                v = rg.B;
            }
            var value = 100 * v / 255;
            var delta = v - m;

            if (v == 0.0)
            {
                hs.S = 0;
            }
            else
            {
                hs.S = 100 * delta / v;
            }

            if (hs.S == 0)
            {
                hs.H = 0;
            }
            else
            {
                if (rg.R == v)
                {
                    hs.H = 60.0 * (rg.G - rg.B) / delta;
                }
                else if (rg.G == v)
                {
                    hs.H = 120.0 + 60.0 * (rg.B - rg.R) / delta;
                }
                else if (rg.B == v)
                {
                    hs.H = 240.0 + 60.0 * (rg.R - rg.G) / delta;
                }
                if (hs.H < 0.0)
                {
                    hs.H = hs.H + 360.0;
                }
            }

            hs.H = Math.Round(hs.H);
            hs.S = Math.Round(hs.S);
            hs.V = Math.Round(value);

            return(hs);
        }
Beispiel #5
0
 public HSV(HSV hs)
 {
     this.H = hs.H;
     this.S = hs.S;
     this.V = hs.V;
 }