diff --git a/RGB.NET.Brushes/Gradients/LinearGradient.cs b/RGB.NET.Brushes/Gradients/LinearGradient.cs
index c8f9227..535fe5d 100644
--- a/RGB.NET.Brushes/Gradients/LinearGradient.cs
+++ b/RGB.NET.Brushes/Gradients/LinearGradient.cs
@@ -97,10 +97,10 @@ namespace RGB.NET.Brushes.Gradients
if (!gsBefore.Offset.Equals(gsAfter.Offset))
blendFactor = ((offset - gsBefore.Offset) / (gsAfter.Offset - gsBefore.Offset));
- byte colA = (byte)(((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A);
- byte colR = (byte)(((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R);
- byte colG = (byte)(((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G);
- byte colB = (byte)(((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B);
+ double colA = ((gsAfter.Color.A - gsBefore.Color.A) * blendFactor) + gsBefore.Color.A;
+ double colR = ((gsAfter.Color.R - gsBefore.Color.R) * blendFactor) + gsBefore.Color.R;
+ double colG = ((gsAfter.Color.G - gsBefore.Color.G) * blendFactor) + gsBefore.Color.G;
+ double colB = ((gsAfter.Color.B - gsBefore.Color.B) * blendFactor) + gsBefore.Color.B;
return new Color(colA, colR, colG, colB);
}
diff --git a/RGB.NET.Core/Color/Color.cs b/RGB.NET.Core/Color/Color.cs
index 20d7f9c..0d5a028 100644
--- a/RGB.NET.Core/Color/Color.cs
+++ b/RGB.NET.Core/Color/Color.cs
@@ -25,45 +25,25 @@ namespace RGB.NET.Core
#region Properties & Fields
- ///
- /// Gets the alpha component value of this as byte in the range [0..255].
- ///
- public byte A { get; }
-
///
/// Gets the alpha component value of this as percentage in the range [0..1].
///
- public double APercent { get; }
-
- ///
- /// Gets the red component value of this as byte in the range [0..255].
- ///
- public byte R { get; }
+ public double A { get; }
///
/// Gets the red component value of this as percentage in the range [0..1].
///
- public double RPercent { get; }
-
- ///
- /// Gets the green component value of this as byte in the range [0..255].
- ///
- public byte G { get; }
+ public double R { get; }
///
/// Gets the green component value of this as percentage in the range [0..1].
///
- public double GPercent { get; }
-
- ///
- /// Gets the blue component value of this as byte in the range [0..255].
- ///
- public byte B { get; }
+ public double G { get; }
///
/// Gets the blue component value of this as percentage in the range [0..1].
///
- public double BPercent { get; }
+ public double B { get; }
#endregion
@@ -101,7 +81,7 @@ namespace RGB.NET.Core
/// The green component value of this .
/// The blue component value of this .
public Color(byte a, byte r, byte g, byte b)
- : this(a, r, g, b, a.GetPercentageFromByteValue(), r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue())
+ : this(a.GetPercentageFromByteValue(), r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue())
{ }
///
@@ -134,8 +114,7 @@ namespace RGB.NET.Core
/// The green component value of this .
/// The blue component value of this .
public Color(double a, byte r, byte g, byte b)
- : this(a.GetByteValueFromPercentage(), r, g, b,
- a.Clamp(0, 1), r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue())
+ : this(a, r.GetPercentageFromByteValue(), g.GetPercentageFromByteValue(), b.GetPercentageFromByteValue())
{ }
///
@@ -168,8 +147,7 @@ namespace RGB.NET.Core
/// The green component value of this .
/// The blue component value of this .
public Color(byte a, double r, double g, double b)
- : this(a, r.GetByteValueFromPercentage(), g.GetByteValueFromPercentage(), b.GetByteValueFromPercentage(),
- a.GetPercentageFromByteValue(), r.Clamp(0, 1), g.Clamp(0, 1), b.Clamp(0, 1))
+ : this(a.GetPercentageFromByteValue(), r, g, b)
{ }
///
@@ -180,9 +158,12 @@ namespace RGB.NET.Core
/// The green component value of this .
/// The blue component value of this .
public Color(double a, double r, double g, double b)
- : this(a.GetByteValueFromPercentage(), r.GetByteValueFromPercentage(), g.GetByteValueFromPercentage(), b.GetByteValueFromPercentage(),
- a.Clamp(0, 1), r.Clamp(0, 1), g.Clamp(0, 1), b.Clamp(0, 1))
- { }
+ {
+ A = a.Clamp(0, 1);
+ R = r.Clamp(0, 1);
+ G = g.Clamp(0, 1);
+ B = b.Clamp(0, 1);
+ }
///
///
@@ -190,22 +171,9 @@ namespace RGB.NET.Core
///
/// The the values are copied from.
public Color(Color color)
- : this(color.APercent, color.RPercent, color.GPercent, color.BPercent)
+ : this(color.A, color.R, color.G, color.B)
{ }
- private Color(byte a, byte r, byte g, byte b, double aP, double rP, double gP, double bP)
- {
- this.A = a;
- this.R = r;
- this.G = g;
- this.B = b;
-
- this.APercent = aP;
- this.RPercent = rP;
- this.GPercent = gP;
- this.BPercent = bP;
- }
-
#endregion
#region Methods
@@ -214,7 +182,7 @@ namespace RGB.NET.Core
/// Converts the individual byte values of this to a human-readable string.
///
/// A string that contains the individual byte values of this . For example "[A: 255, R: 255, G: 0, B: 0]".
- public override string ToString() => $"[A: {A}, R: {R}, G: {G}, B: {B}]";
+ public override string ToString() => $"[A: {this.GetA()}, R: {this.GetR()}, G: {this.GetG()}, B: {this.GetB()}]";
///
/// Tests whether the specified object is a and is equivalent to this .
@@ -225,8 +193,8 @@ namespace RGB.NET.Core
{
if (!(obj is Color)) return false;
- (byte a, byte r, byte g, byte b) = (Color)obj;
- return (a == A) && (r == R) && (g == G) && (b == B);
+ (double a, double r, double g, double b) = ((Color)obj).GetRGB();
+ return A.EqualsInTolerance(a) && R.EqualsInTolerance(r) && G.EqualsInTolerance(g) && B.EqualsInTolerance(b);
}
///
@@ -237,33 +205,14 @@ namespace RGB.NET.Core
{
unchecked
{
- int hashCode = APercent.GetHashCode();
- hashCode = (hashCode * 397) ^ RPercent.GetHashCode();
- hashCode = (hashCode * 397) ^ GPercent.GetHashCode();
- hashCode = (hashCode * 397) ^ BPercent.GetHashCode();
+ int hashCode = A.GetHashCode();
+ hashCode = (hashCode * 397) ^ R.GetHashCode();
+ hashCode = (hashCode * 397) ^ G.GetHashCode();
+ hashCode = (hashCode * 397) ^ B.GetHashCode();
return hashCode;
}
}
- #region Deconstruction
-
- ///
- /// Deconstructs the Color into it's ARGB-components.
- ///
- /// The alpha component of this color.
- /// The red component of this color.
- /// The green component of this color.
- /// The blue component of this color.
- public void Deconstruct(out byte a, out byte r, out byte g, out byte b)
- {
- a = A;
- r = R;
- g = G;
- b = B;
- }
-
- #endregion
-
#region Manipulation
///
@@ -272,15 +221,15 @@ namespace RGB.NET.Core
/// The to blend.
public Color Blend(Color color)
{
- if (color.A == 0) return this;
+ if (color.A.EqualsInTolerance(0)) return this;
- if (color.A == 255)
+ if (color.A.EqualsInTolerance(1))
return color;
- double resultA = (1.0 - ((1.0 - color.APercent) * (1.0 - APercent)));
- double resultR = (((color.RPercent * color.APercent) / resultA) + ((RPercent * APercent * (1.0 - color.APercent)) / resultA));
- double resultG = (((color.GPercent * color.APercent) / resultA) + ((GPercent * APercent * (1.0 - color.APercent)) / resultA));
- double resultB = (((color.BPercent * color.APercent) / resultA) + ((BPercent * APercent * (1.0 - color.APercent)) / resultA));
+ double resultA = (1.0 - ((1.0 - color.A) * (1.0 - A)));
+ double resultR = (((color.R * color.A) / resultA) + ((R * A * (1.0 - color.A)) / resultA));
+ double resultG = (((color.G * color.A) / resultA) + ((G * A * (1.0 - color.A)) / resultA));
+ double resultB = (((color.B * color.A) / resultA) + ((B * A * (1.0 - color.A)) / resultA));
return new Color(resultA, resultR, resultG, resultB);
}
diff --git a/RGB.NET.Core/Color/HSVColor.cs b/RGB.NET.Core/Color/HSVColor.cs
index e1562b1..21bb5b1 100644
--- a/RGB.NET.Core/Color/HSVColor.cs
+++ b/RGB.NET.Core/Color/HSVColor.cs
@@ -36,7 +36,7 @@ namespace RGB.NET.Core
///
///
public static (double hue, double saturation, double value) GetHSV(this Color color)
- => CaclulateHSVFromRGB(color.RPercent, color.GPercent, color.BPercent);
+ => CaclulateHSVFromRGB(color.R, color.G, color.B);
#endregion
@@ -52,7 +52,7 @@ namespace RGB.NET.Core
public static Color AddHSV(this Color color, double hue = 0, double saturation = 0, double value = 0)
{
(double cHue, double cSaturation, double cValue) = color.GetHSV();
- return Create(color.APercent, cHue + hue, cSaturation + saturation, cValue + value);
+ return Create(color.A, cHue + hue, cSaturation + saturation, cValue + value);
}
///
@@ -65,7 +65,7 @@ namespace RGB.NET.Core
public static Color SubtractHSV(this Color color, double hue = 0, double saturation = 0, double value = 0)
{
(double cHue, double cSaturation, double cValue) = color.GetHSV();
- return Create(color.APercent, cHue - hue, cSaturation - saturation, cValue - value);
+ return Create(color.A, cHue - hue, cSaturation - saturation, cValue - value);
}
///
@@ -78,7 +78,7 @@ namespace RGB.NET.Core
public static Color MultiplyHSV(this Color color, double hue = 1, double saturation = 1, double value = 1)
{
(double cHue, double cSaturation, double cValue) = color.GetHSV();
- return Create(color.APercent, cHue * hue, cSaturation * saturation, cValue * value);
+ return Create(color.A, cHue * hue, cSaturation * saturation, cValue * value);
}
@@ -92,7 +92,7 @@ namespace RGB.NET.Core
public static Color DivideHSV(this Color color, double hue = 1, double saturation = 1, double value = 1)
{
(double cHue, double cSaturation, double cValue) = color.GetHSV();
- return Create(color.APercent, cHue / hue, cSaturation / saturation, cValue / value);
+ return Create(color.A, cHue / hue, cSaturation / saturation, cValue / value);
}
///
@@ -105,7 +105,7 @@ namespace RGB.NET.Core
public static Color SetHSV(this Color color, double? hue = null, double? saturation = null, double? value = null)
{
(double cHue, double cSaturation, double cValue) = color.GetHSV();
- return Create(color.APercent, hue ?? cHue, saturation ?? cSaturation, value ?? cValue);
+ return Create(color.A, hue ?? cHue, saturation ?? cSaturation, value ?? cValue);
}
#endregion
@@ -164,17 +164,17 @@ namespace RGB.NET.Core
private static (double h, double s, double v) CaclulateHSVFromRGB(double r, double g, double b)
{
- if ((r == g) && (g == b)) return (0, 0, r);
+ if (r.EqualsInTolerance(g) && g.EqualsInTolerance(b)) return (0, 0, r);
double min = Math.Min(Math.Min(r, g), b);
double max = Math.Max(Math.Max(r, g), b);
double hue;
- if (max == min)
+ if (max.EqualsInTolerance(min))
hue = 0;
- else if (max == r) // r is max
+ else if (max.EqualsInTolerance(r)) // r is max
hue = (g - b) / (max - min);
- else if (max == g) // g is max
+ else if (max.EqualsInTolerance(g)) // g is max
hue = 2.0 + ((b - r) / (max - min));
else // b is max
hue = 4.0 + ((r - g) / (max - min));
@@ -182,7 +182,7 @@ namespace RGB.NET.Core
hue = hue * 60.0;
hue = hue.Wrap(0, 360);
- double saturation = (max == 0) ? 0 : 1.0 - (min / max);
+ double saturation = max.EqualsInTolerance(0) ? 0 : 1.0 - (min / max);
double value = Math.Max(r, Math.Max(g, b));
return (hue, saturation, value);
diff --git a/RGB.NET.Core/Color/RGBColor.cs b/RGB.NET.Core/Color/RGBColor.cs
index 2aa3b74..bacc9c0 100644
--- a/RGB.NET.Core/Color/RGBColor.cs
+++ b/RGB.NET.Core/Color/RGBColor.cs
@@ -6,13 +6,49 @@ namespace RGB.NET.Core
{
#region Getter
+ ///
+ /// Gets the A component value of this as byte in the range [0..255].
+ ///
+ ///
+ ///
+ public static byte GetA(this Color color) => color.A.GetByteValueFromPercentage();
+
+ ///
+ /// Gets the R component value of this as byte in the range [0..255].
+ ///
+ ///
+ ///
+ public static byte GetR(this Color color) => color.R.GetByteValueFromPercentage();
+
+ ///
+ /// Gets the G component value of this as byte in the range [0..255].
+ ///
+ ///
+ ///
+ public static byte GetG(this Color color) => color.G.GetByteValueFromPercentage();
+
+ ///
+ /// Gets the B component value of this as byte in the range [0..255].
+ ///
+ ///
+ ///
+ public static byte GetB(this Color color) => color.B.GetByteValueFromPercentage();
+
+ ///
+ /// Gets the A, R, G and B component value of this as byte in the range [0..255].
+ ///
+ ///
+ ///
+ public static (byte a, byte r, byte g, byte b) GetRGBBytes(this Color color)
+ => (color.GetA(), color.GetR(), color.GetG(), color.GetB());
+
///
/// Gets the A, R, G and B component value of this as percentage in the range [0..1].
///
///
///
- public static (double a, double r, double g, double b) GetRGBPercent(this Color color)
- => (color.APercent, color.RPercent, color.GPercent, color.BPercent);
+ public static (double a, double r, double g, double b) GetRGB(this Color color)
+ => (color.A, color.R, color.G, color.B);
#endregion
@@ -28,7 +64,7 @@ namespace RGB.NET.Core
/// The blue value to add.
/// The new color after the modification.
public static Color AddRGB(this Color color, int r = 0, int g = 0, int b = 0)
- => new Color(color.APercent, color.R + r, color.G + g, color.B + b);
+ => new Color(color.A, color.GetR() + r, color.GetG() + g, color.GetB() + b);
///
/// Adds the given RGB-percent values to this color.
@@ -38,7 +74,7 @@ namespace RGB.NET.Core
/// The blue value to add.
/// The new color after the modification.
public static Color AddRGB(this Color color, double r = 0, double g = 0, double b = 0)
- => new Color(color.APercent, color.RPercent + r, color.GPercent + g, color.BPercent + b);
+ => new Color(color.A, color.R + r, color.G + g, color.B + b);
///
/// Adds the given alpha value to this color.
@@ -46,7 +82,7 @@ namespace RGB.NET.Core
/// The alpha value to add.
/// The new color after the modification.
public static Color AddA(this Color color, int a)
- => new Color(color.A + a, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.GetA() + a, color.R, color.G, color.B);
///
/// Adds the given alpha-percent value to this color.
@@ -54,7 +90,7 @@ namespace RGB.NET.Core
/// The alpha value to add.
/// The new color after the modification.
public static Color AddA(this Color color, double a)
- => new Color(color.APercent + a, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.A + a, color.R, color.G, color.B);
#endregion
@@ -68,7 +104,7 @@ namespace RGB.NET.Core
/// The blue value to subtract.
/// The new color after the modification.
public static Color SubtractRGB(this Color color, int r = 0, int g = 0, int b = 0)
- => new Color(color.APercent, color.R - r, color.G - g, color.B - b);
+ => new Color(color.A, color.GetR() - r, color.GetG() - g, color.GetB() - b);
///
/// Subtracts the given RGB values to this color.
@@ -78,7 +114,7 @@ namespace RGB.NET.Core
/// The blue value to subtract.
/// The new color after the modification.
public static Color SubtractRGB(this Color color, double r = 0, double g = 0, double b = 0)
- => new Color(color.APercent, color.RPercent - r, color.GPercent - g, color.BPercent - b);
+ => new Color(color.A, color.R - r, color.G - g, color.B - b);
///
/// Subtracts the given alpha value to this color.
@@ -86,7 +122,7 @@ namespace RGB.NET.Core
/// The alpha value to subtract.
/// The new color after the modification.
public static Color SubtractA(this Color color, int a)
- => new Color(color.A - a, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.GetA() - a, color.R, color.G, color.B);
///
/// Subtracts the given alpha-percent value to this color.
@@ -94,7 +130,7 @@ namespace RGB.NET.Core
/// The alpha value to subtract.
/// The new color after the modification.
public static Color SubtractA(this Color color, double aPercent)
- => new Color(color.APercent - aPercent, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.A - aPercent, color.R, color.G, color.B);
#endregion
@@ -108,7 +144,7 @@ namespace RGB.NET.Core
/// The blue value to multiply.
/// The new color after the modification.
public static Color MultiplyRGB(this Color color, double r = 1, double g = 1, double b = 1)
- => new Color(color.APercent, color.RPercent * r, color.GPercent * g, color.BPercent * b);
+ => new Color(color.A, color.R * r, color.G * g, color.B * b);
///
/// Multiplies the given alpha value to this color.
@@ -116,7 +152,7 @@ namespace RGB.NET.Core
/// The alpha value to multiply.
/// The new color after the modification.
public static Color MultiplyA(this Color color, double a)
- => new Color(color.APercent * a, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.A * a, color.R, color.G, color.B);
#endregion
@@ -130,7 +166,7 @@ namespace RGB.NET.Core
/// The blue value to divide.
/// The new color after the modification.
public static Color DivideRGB(this Color color, double r = 1, double g = 1, double b = 1)
- => new Color(color.APercent, color.RPercent / r, color.GPercent / g, color.BPercent / b);
+ => new Color(color.A, color.R / r, color.G / g, color.B / b);
///
/// Divides the given alpha value to this color.
@@ -138,7 +174,7 @@ namespace RGB.NET.Core
/// The alpha value to divide.
/// The new color after the modification.
public static Color DivideA(this Color color, double a)
- => new Color(color.APercent / a, color.RPercent, color.GPercent, color.BPercent);
+ => new Color(color.A / a, color.R, color.G, color.B);
#endregion
@@ -152,7 +188,7 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, byte? r = null, byte? g = null, byte? b = null)
- => new Color(color.APercent, r ?? color.R, g ?? color.G, b ?? color.B);
+ => new Color(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
///
/// Sets the given RGB value of this color.
@@ -162,7 +198,7 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, int? r = null, int? g = null, int? b = null)
- => new Color(color.APercent, r ?? color.R, g ?? color.G, b ?? color.B);
+ => new Color(color.A, r ?? color.GetR(), g ?? color.GetG(), b ?? color.GetB());
///
/// Sets the given RGB value of this color.
@@ -172,21 +208,21 @@ namespace RGB.NET.Core
/// The blue value to set.
/// The new color after the modification.
public static Color SetRGB(this Color color, double? r = null, double? g = null, double? b = null)
- => new Color(color.APercent, r ?? color.RPercent, g ?? color.GPercent, b ?? color.BPercent);
+ => new Color(color.A, r ?? color.R, g ?? color.G, b ?? color.B);
///
/// Sets the given alpha value of this color.
///
/// The alpha value to set.
/// The new color after the modification.
- public static Color SetA(this Color color, int a) => new Color(a, color.RPercent, color.GPercent, color.BPercent);
+ public static Color SetA(this Color color, int a) => new Color(a, color.R, color.G, color.B);
///
/// Sets the given alpha value of this color.
///
/// The alpha value to set.
/// The new color after the modification.
- public static Color SetA(this Color color, double a) => new Color(a, color.RPercent, color.GPercent, color.BPercent);
+ public static Color SetA(this Color color, double a) => new Color(a, color.R, color.G, color.B);
#endregion
@@ -198,13 +234,13 @@ namespace RGB.NET.Core
/// Gets the current color as a RGB-HEX-string.
///
/// The RGB-HEX-string.
- public static string AsRGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.R, color.G, color.B);
+ public static string AsRGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetR(), color.GetG(), color.GetB());
///
/// Gets the current color as a ARGB-HEX-string.
///
/// The ARGB-HEX-string.
- public static string AsARGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.A, color.R, color.G, color.B);
+ public static string AsARGBHexString(this Color color, bool leadingHash = true) => (leadingHash ? "#" : "") + ConversionHelper.ToHex(color.GetA(), color.GetR(), color.GetG(), color.GetB());
#endregion
diff --git a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
index e6d4a6a..28fa936 100644
--- a/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
+++ b/RGB.NET.Devices.Asus/Generic/AsusUpdateQueue.cs
@@ -57,9 +57,9 @@ namespace RGB.NET.Devices.Asus
foreach (KeyValuePair