Beispiel #1
0
        public static HsbColor FromRgb(Color rgb)
        {
            var hsb = new HsbColor();
            
            var r = (int)rgb.R;
            var g = (int)rgb.G;
            var b = (int)rgb.B;

            hsb.A = rgb.A / 255.0f;

            float min = Math.Min(Math.Min(r, g), b);
            float max = Math.Max(Math.Max(r, g), b);
            float delta = max - min;
            
            if (max == 0.0)
            {
                hsb.H = 0.0f;
                hsb.S = 0.0f;
                hsb.B = 0.0f;
                return hsb;
            }

            if (delta == 0.0) hsb.H = 0;
            else if (r == max) hsb.H = (g - b) / delta;
            else if (g == max) hsb.H = 2 + (b - r) / delta;
            else if (b == max) hsb.H = 4 + (r - g) / delta;
            hsb.H *= 60;
            if (hsb.H < 0.0) hsb.H += 360;
            
            hsb.S = delta / max;
            hsb.B = max / 255;
            
            return hsb;
        }
Beispiel #2
0
        public static HsbColor FromRgb(Color rgb)
        {
            var hsb = new HsbColor();

            var r = (int)rgb.R;
            var g = (int)rgb.G;
            var b = (int)rgb.B;

            hsb.A = rgb.A / 255.0f;

            float min   = Math.Min(Math.Min(r, g), b);
            float max   = Math.Max(Math.Max(r, g), b);
            float delta = max - min;

            if (max == 0.0)
            {
                hsb.H = 0.0f;
                hsb.S = 0.0f;
                hsb.B = 0.0f;
                return(hsb);
            }

            if (delta == 0.0)
            {
                hsb.H = 0;
            }
            else if (r == max)
            {
                hsb.H = (g - b) / delta;
            }
            else if (g == max)
            {
                hsb.H = 2 + (b - r) / delta;
            }
            else if (b == max)
            {
                hsb.H = 4 + (r - g) / delta;
            }
            hsb.H *= 60;
            if (hsb.H < 0.0)
            {
                hsb.H += 360;
            }

            hsb.S = delta / max;
            hsb.B = max / 255;

            return(hsb);
        }
Beispiel #3
0
 public static Color FromHsb(HsbColor hsb) => hsb.ToRgb();
Beispiel #4
0
 public HsbColor ToHsb() => HsbColor.FromRgb(this);
Beispiel #5
0
 public bool Equals(HsbColor other)
 {
     return(A == other.A && H == other.H && S == other.S && B == other.B);
 }
Beispiel #6
0
 public bool Equals(HsbColor other)
 {
     return A == other.A && H == other.H && S == other.S && B == other.B;
 }