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; }
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); }
public static Color FromHsb(HsbColor hsb) => hsb.ToRgb();
public HsbColor ToHsb() => HsbColor.FromRgb(this);
public bool Equals(HsbColor other) { return(A == other.A && H == other.H && S == other.S && B == other.B); }
public bool Equals(HsbColor other) { return A == other.A && H == other.H && S == other.S && B == other.B; }