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 data in dataSet) { int index = ((int)data.Key) * 3; - ColorData[index] = data.Value.R; - ColorData[index + 1] = data.Value.B; - ColorData[index + 2] = data.Value.G; + ColorData[index] = data.Value.GetR(); + ColorData[index + 1] = data.Value.GetB(); + ColorData[index + 2] = data.Value.GetG(); } _updateAction(_handle, ColorData); diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs index 045b6e4..ecc4cd6 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterUpdateQueue.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.CoolerMaster foreach (KeyValuePair data in dataSet) { (int row, int column) = ((int, int))data.Key; - _CoolerMasterSDK.SetLedColor(row, column, data.Value.R, data.Value.G, data.Value.B, _deviceIndex); + _CoolerMasterSDK.SetLedColor(row, column, data.Value.GetR(), data.Value.GetG(), data.Value.GetB(), _deviceIndex); } _CoolerMasterSDK.RefreshLed(false, _deviceIndex); diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs index 9540018..664a6e6 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairDeviceUpdateQueue.cs @@ -46,9 +46,9 @@ namespace RGB.NET.Devices.Corsair _CorsairLedColor color = new _CorsairLedColor { ledId = (int)data.Key, - r = data.Value.R, - g = data.Value.G, - b = data.Value.B + r = data.Value.GetR(), + g = data.Value.GetG(), + b = data.Value.GetB() }; Marshal.StructureToPtr(color, addPtr, false); diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs index 23e1b69..8ea4c6a 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceUpdateQueue.cs @@ -32,9 +32,9 @@ namespace RGB.NET.Devices.Logitech Color color = dataSet.Values.First(); _LogitechGSDK.LogiLedSetTargetDevice(LogitechDeviceCaps.DeviceRGB); - _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.RPercent * 100), - (int)Math.Round(color.GPercent * 100), - (int)Math.Round(color.BPercent * 100)); + _LogitechGSDK.LogiLedSetLighting((int)Math.Round(color.R * 100), + (int)Math.Round(color.G * 100), + (int)Math.Round(color.B * 100)); } #endregion diff --git a/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs b/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs index cfb5cd9..9bd9a6e 100644 --- a/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs +++ b/RGB.NET.Devices.Logitech/PerKey/BitmapMapping.cs @@ -158,10 +158,10 @@ namespace RGB.NET.Devices.Logitech [MethodImpl(MethodImplOptions.AggressiveInlining)] internal static void SetColor(byte[] bitmap, int offset, Color color) { - bitmap[offset] = color.B; - bitmap[offset + 1] = color.G; - bitmap[offset + 2] = color.R; - bitmap[offset + 3] = color.A; + bitmap[offset] = color.GetB(); + bitmap[offset + 1] = color.GetG(); + bitmap[offset + 2] = color.GetR(); + bitmap[offset + 3] = color.GetA(); } #endregion diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs index 02f7dd0..a166a3a 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyUpdateQueue.cs @@ -51,9 +51,9 @@ namespace RGB.NET.Devices.Logitech } else _LogitechGSDK.LogiLedSetLightingForKeyWithKeyName((int)customData, - (int)Math.Round(data.Value.RPercent * 100), - (int)Math.Round(data.Value.GPercent * 100), - (int)Math.Round(data.Value.BPercent * 100)); + (int)Math.Round(data.Value.R * 100), + (int)Math.Round(data.Value.G * 100), + (int)Math.Round(data.Value.B * 100)); } if (usesBitmap) diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs index ab0062c..a95ca98 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneUpdateQueue.cs @@ -56,9 +56,9 @@ namespace RGB.NET.Devices.Logitech { int zone = (int)data.Key; _LogitechGSDK.LogiLedSetLightingForTargetZone(_deviceType, zone, - (int)Math.Round(data.Value.RPercent * 100), - (int)Math.Round(data.Value.GPercent * 100), - (int)Math.Round(data.Value.BPercent * 100)); + (int)Math.Round(data.Value.R * 100), + (int)Math.Round(data.Value.G * 100), + (int)Math.Round(data.Value.B * 100)); } } diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs index 2387690..5fe18ab 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs @@ -66,7 +66,7 @@ namespace RGB.NET.Devices.Msi { string deviceType = DeviceInfo.MsiDeviceType; foreach (Led led in leds) - _MsiSDK.SetLedColor(deviceType, (int)led.CustomData, led.Color.R, led.Color.G, led.Color.B); + _MsiSDK.SetLedColor(deviceType, (int)led.CustomData, led.Color.GetR(), led.Color.GetG(), led.Color.GetB()); } } diff --git a/RGB.NET.Devices.Razer/Native/_Color.cs b/RGB.NET.Devices.Razer/Native/_Color.cs index 66b07ea..a36cc78 100644 --- a/RGB.NET.Devices.Razer/Native/_Color.cs +++ b/RGB.NET.Devices.Razer/Native/_Color.cs @@ -21,7 +21,7 @@ namespace RGB.NET.Devices.Razer.Native #region Constructors public _Color(Color color) - : this(color.R, color.G, color.B) { } + : this(color.GetR(), color.GetG(), color.GetB()) { } public _Color(byte red, byte green, byte blue) : this() diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs index 696f54e..e9fea46 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBUpdateQueue.cs @@ -62,7 +62,7 @@ namespace RGB.NET.Devices.WS281X.Arduino dataBuffer[0] = (byte)((channel << 4) | UPDATE_COMMAND[0]); int i = 1; foreach ((byte _, byte r, byte g, byte b) in channelData.OrderBy(x => x.Item1.key) - .Select(x => x.Value)) + .Select(x => x.Value.GetRGBBytes())) { dataBuffer[i++] = r; dataBuffer[i++] = g; diff --git a/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs b/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs index 8146006..20b17a1 100644 --- a/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs +++ b/Tests/RGB.NET.Core.Tests/Color/ColorTest.cs @@ -12,10 +12,10 @@ namespace RGB.NET.Core.Tests.Color { Core.Color transparent = Core.Color.Transparent; - Assert.AreEqual(0, transparent.A, "A is not 0"); - Assert.AreEqual(0, transparent.R, "R is not 0"); - Assert.AreEqual(0, transparent.G, "G is not 0"); - Assert.AreEqual(0, transparent.B, "B is not 0"); + Assert.AreEqual(0, transparent.GetA(), "A is not 0"); + Assert.AreEqual(0, transparent.GetR(), "R is not 0"); + Assert.AreEqual(0, transparent.GetG(), "G is not 0"); + Assert.AreEqual(0, transparent.GetB(), "B is not 0"); } [TestMethod] @@ -143,10 +143,10 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = new Core.Color((byte)10, (byte)120, (byte)255); - Assert.AreEqual(255, color.A, "A is not 255"); - Assert.AreEqual(10, color.R, "R is not 10"); - Assert.AreEqual(120, color.G, "G is not 120"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(255, color.GetA(), "A is not 255"); + Assert.AreEqual(10, color.GetR(), "R is not 10"); + Assert.AreEqual(120, color.GetG(), "G is not 120"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); } [TestMethod] @@ -154,10 +154,10 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = new Core.Color((byte)200, (byte)10, (byte)120, (byte)255); - Assert.AreEqual(200, color.A, "A is not 200"); - Assert.AreEqual(10, color.R, "R is not 10"); - Assert.AreEqual(120, color.G, "G is not 120"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(200, color.GetA(), "A is not 200"); + Assert.AreEqual(10, color.GetR(), "R is not 10"); + Assert.AreEqual(120, color.GetG(), "G is not 120"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); } [TestMethod] @@ -165,10 +165,10 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = new Core.Color(10, 120, 255); - Assert.AreEqual(255, color.A, "A is not 255"); - Assert.AreEqual(10, color.R, "R is not 10"); - Assert.AreEqual(120, color.G, "G is not 120"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(255, color.GetA(), "A is not 255"); + Assert.AreEqual(10, color.GetR(), "R is not 10"); + Assert.AreEqual(120, color.GetG(), "G is not 120"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); } [TestMethod] @@ -176,10 +176,10 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = new Core.Color(200, 10, 120, 255); - Assert.AreEqual(200, color.A, "A is not 200"); - Assert.AreEqual(10, color.R, "R is not 10"); - Assert.AreEqual(120, color.G, "G is not 120"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(200, color.GetA(), "A is not 200"); + Assert.AreEqual(10, color.GetR(), "R is not 10"); + Assert.AreEqual(120, color.GetG(), "G is not 120"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); } [TestMethod] @@ -187,17 +187,17 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color1 = new Core.Color(256, 256, 256); - Assert.AreEqual(255, color1.A, "A is not 255"); - Assert.AreEqual(255, color1.R, "R is not 255"); - Assert.AreEqual(255, color1.G, "G is not 255"); - Assert.AreEqual(255, color1.B, "B is not 255"); + Assert.AreEqual(255, color1.GetA(), "A is not 255"); + Assert.AreEqual(255, color1.GetR(), "R is not 255"); + Assert.AreEqual(255, color1.GetG(), "G is not 255"); + Assert.AreEqual(255, color1.GetB(), "B is not 255"); Core.Color color2 = new Core.Color(-1, -1, -1); - Assert.AreEqual(255, color2.A, "A is not 255"); - Assert.AreEqual(0, color2.R, "R is not 0"); - Assert.AreEqual(0, color2.G, "G is not 0"); - Assert.AreEqual(0, color2.B, "B is not 0"); + Assert.AreEqual(255, color2.GetA(), "A is not 255"); + Assert.AreEqual(0, color2.GetR(), "R is not 0"); + Assert.AreEqual(0, color2.GetG(), "G is not 0"); + Assert.AreEqual(0, color2.GetB(), "B is not 0"); } [TestMethod] @@ -205,87 +205,87 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = new Core.Color(256, 256, 256, 256); - Assert.AreEqual(255, color.A, "A is not 255"); - Assert.AreEqual(255, color.R, "R is not 255"); - Assert.AreEqual(255, color.G, "G is not 255"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(255, color.GetA(), "A is not 255"); + Assert.AreEqual(255, color.GetR(), "R is not 255"); + Assert.AreEqual(255, color.GetG(), "G is not 255"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); Core.Color color2 = new Core.Color(-1, -1, -1, -1); + Assert.AreEqual(0, color2.GetA(), "A is not 0"); + Assert.AreEqual(0, color2.GetR(), "R is not 0"); + Assert.AreEqual(0, color2.GetG(), "G is not 0"); + Assert.AreEqual(0, color2.GetB(), "B is not 0"); + } + + [TestMethod] + public void RGBPercentConstructorTest() + { + Core.Color color = new Core.Color(0.25341, 0.55367, 1); + + Assert.AreEqual(1, color.A, DoubleExtensions.TOLERANCE, "A is not 1"); + Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341"); + Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367"); + Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1"); + } + + [TestMethod] + public void ARGBPercentConstructorTest() + { + Core.Color color = new Core.Color(0.3315, 0.25341, 0.55367, 1); + + Assert.AreEqual(0.3315, color.A, DoubleExtensions.TOLERANCE, "A is not 0.3315"); + Assert.AreEqual(0.25341, color.R, DoubleExtensions.TOLERANCE, "R is not 0.25341"); + Assert.AreEqual(0.55367, color.G, DoubleExtensions.TOLERANCE, "G is not 0.55367"); + Assert.AreEqual(1, color.B, DoubleExtensions.TOLERANCE, "B is not 1"); + } + + [TestMethod] + public void RGBPercentConstructorClampTest() + { + Core.Color color1 = new Core.Color(1.1, 1.1, 1.1); + + Assert.AreEqual(1, color1.A, "A is not 1"); + Assert.AreEqual(1, color1.R, "R is not 1"); + Assert.AreEqual(1, color1.G, "G is not 1"); + Assert.AreEqual(1, color1.B, "B is not 1"); + + Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0); + + Assert.AreEqual(1, color2.A, "A is not 1"); + Assert.AreEqual(0, color2.R, "R is not 0"); + Assert.AreEqual(0, color2.G, "G is not 0"); + Assert.AreEqual(0, color2.B, "B is not 0"); + } + + [TestMethod] + public void ARGBPercentConstructorClampTest() + { + Core.Color color1 = new Core.Color(1.1, 1.1, 1.1, 1.1); + + Assert.AreEqual(1, color1.A, "A is not 1"); + Assert.AreEqual(1, color1.R, "R is not 1"); + Assert.AreEqual(1, color1.G, "G is not 1"); + Assert.AreEqual(1, color1.B, "B is not 1"); + + Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0, -1.0); + Assert.AreEqual(0, color2.A, "A is not 0"); Assert.AreEqual(0, color2.R, "R is not 0"); Assert.AreEqual(0, color2.G, "G is not 0"); Assert.AreEqual(0, color2.B, "B is not 0"); } - [TestMethod] - public void RGBPercentConstructorTest() - { - Core.Color color = new Core.Color(0.25341, 0.55367, 1); - - Assert.AreEqual(1, color.APercent, DoubleExtensions.TOLERANCE, "A is not 1"); - Assert.AreEqual(0.25341, color.RPercent, DoubleExtensions.TOLERANCE, "R is not 0.25341"); - Assert.AreEqual(0.55367, color.GPercent, DoubleExtensions.TOLERANCE, "G is not 0.55367"); - Assert.AreEqual(1, color.BPercent, DoubleExtensions.TOLERANCE, "B is not 1"); - } - - [TestMethod] - public void ARGBPercentConstructorTest() - { - Core.Color color = new Core.Color(0.3315, 0.25341, 0.55367, 1); - - Assert.AreEqual(0.3315, color.APercent, DoubleExtensions.TOLERANCE, "A is not 0.3315"); - Assert.AreEqual(0.25341, color.RPercent, DoubleExtensions.TOLERANCE, "R is not 0.25341"); - Assert.AreEqual(0.55367, color.GPercent, DoubleExtensions.TOLERANCE, "G is not 0.55367"); - Assert.AreEqual(1, color.BPercent, DoubleExtensions.TOLERANCE, "B is not 1"); - } - - [TestMethod] - public void RGBPercentConstructorClampTest() - { - Core.Color color1 = new Core.Color(1.1, 1.1, 1.1); - - Assert.AreEqual(1, color1.APercent, "A is not 1"); - Assert.AreEqual(1, color1.RPercent, "R is not 1"); - Assert.AreEqual(1, color1.GPercent, "G is not 1"); - Assert.AreEqual(1, color1.BPercent, "B is not 1"); - - Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0); - - Assert.AreEqual(1, color2.APercent, "A is not 1"); - Assert.AreEqual(0, color2.RPercent, "R is not 0"); - Assert.AreEqual(0, color2.GPercent, "G is not 0"); - Assert.AreEqual(0, color2.BPercent, "B is not 0"); - } - - [TestMethod] - public void ARGBPercentConstructorClampTest() - { - Core.Color color1 = new Core.Color(1.1, 1.1, 1.1, 1.1); - - Assert.AreEqual(1, color1.APercent, "A is not 1"); - Assert.AreEqual(1, color1.RPercent, "R is not 1"); - Assert.AreEqual(1, color1.GPercent, "G is not 1"); - Assert.AreEqual(1, color1.BPercent, "B is not 1"); - - Core.Color color2 = new Core.Color(-1.0, -1.0, -1.0, -1.0); - - Assert.AreEqual(0, color2.APercent, "A is not 0"); - Assert.AreEqual(0, color2.RPercent, "R is not 0"); - Assert.AreEqual(0, color2.GPercent, "G is not 0"); - Assert.AreEqual(0, color2.BPercent, "B is not 0"); - } - [TestMethod] public void CloneConstructorTest() { Core.Color referennceColor = new Core.Color(200, 10, 120, 255); Core.Color color = new Core.Color(referennceColor); - Assert.AreEqual(200, color.A, "A is not 200"); - Assert.AreEqual(10, color.R, "R is not 10"); - Assert.AreEqual(120, color.G, "G is not 120"); - Assert.AreEqual(255, color.B, "B is not 255"); + Assert.AreEqual(200, color.GetA(), "A is not 200"); + Assert.AreEqual(10, color.GetR(), "R is not 10"); + Assert.AreEqual(120, color.GetG(), "G is not 120"); + Assert.AreEqual(255, color.GetB(), "B is not 255"); } #endregion @@ -297,16 +297,16 @@ namespace RGB.NET.Core.Tests.Color { Core.Color color = (255, 120, 13, 1); - Assert.AreEqual(255, color.A, $"A doesn't equal the used component. ({color.A} != 255)"); - Assert.AreEqual(120, color.R, $"R doesn't equal the used component. ({color.R} != 120)"); - Assert.AreEqual(13, color.G, $"G doesn't equal the used component. ({color.G} != 13)"); - Assert.AreEqual(1, color.B, $"B doesn't equal the used component. ({color.B} != 1)"); + Assert.AreEqual(255, color.GetA(), $"A doesn't equal the used component. ({color.GetA()} != 255)"); + Assert.AreEqual(120, color.GetR(), $"R doesn't equal the used component. ({color.GetR()} != 120)"); + Assert.AreEqual(13, color.GetG(), $"G doesn't equal the used component. ({color.GetG()} != 13)"); + Assert.AreEqual(1, color.GetB(), $"B doesn't equal the used component. ({color.GetB()} != 1)"); } [TestMethod] public void DesconstructTest() { - (byte a, byte r, byte g, byte b) = new Core.Color(255, 120, 13, 1); + (byte a, byte r, byte g, byte b) = new Core.Color(255, 120, 13, 1).GetRGBBytes(); Assert.AreEqual(255, a, $"A doesn't equal the color. ({a} != 255)"); Assert.AreEqual(120, r, $"R doesn't equal the color. ({r} != 120)"); @@ -318,76 +318,76 @@ namespace RGB.NET.Core.Tests.Color public void AToPercentTest() { Core.Color color1 = new Core.Color(0, 0, 0, 0); - Assert.AreEqual(0, color1.APercent); + Assert.AreEqual(0, color1.A); Core.Color color2 = new Core.Color(255, 0, 0, 0); - Assert.AreEqual(1, color2.APercent); + Assert.AreEqual(1, color2.A); Core.Color color3 = new Core.Color(128, 0, 0, 0); - Assert.AreEqual(128 / 255.0, color3.APercent); + Assert.AreEqual(128 / 255.0, color3.A); Core.Color color4 = new Core.Color(30, 0, 0, 0); - Assert.AreEqual(30 / 255.0, color4.APercent); + Assert.AreEqual(30 / 255.0, color4.A); Core.Color color5 = new Core.Color(201, 0, 0, 0); - Assert.AreEqual(201 / 255.0, color5.APercent); + Assert.AreEqual(201 / 255.0, color5.A); } [TestMethod] public void RToPercentTest() { Core.Color color1 = new Core.Color(0, 0, 0, 0); - Assert.AreEqual(0, color1.RPercent); + Assert.AreEqual(0, color1.R); Core.Color color2 = new Core.Color(0, 255, 0, 0); - Assert.AreEqual(1, color2.RPercent); + Assert.AreEqual(1, color2.R); Core.Color color3 = new Core.Color(0, 128, 0, 0); - Assert.AreEqual(128 / 255.0, color3.RPercent); + Assert.AreEqual(128 / 255.0, color3.R); Core.Color color4 = new Core.Color(0, 30, 0, 0); - Assert.AreEqual(30 / 255.0, color4.RPercent); + Assert.AreEqual(30 / 255.0, color4.R); Core.Color color5 = new Core.Color(0, 201, 0, 0); - Assert.AreEqual(201 / 255.0, color5.RPercent); + Assert.AreEqual(201 / 255.0, color5.R); } [TestMethod] public void GToPercentTest() { Core.Color color1 = new Core.Color(0, 0, 0, 0); - Assert.AreEqual(0, color1.GPercent); + Assert.AreEqual(0, color1.G); Core.Color color2 = new Core.Color(0, 0, 255, 0); - Assert.AreEqual(1, color2.GPercent); + Assert.AreEqual(1, color2.G); Core.Color color3 = new Core.Color(0, 0, 128, 0); - Assert.AreEqual(128 / 255.0, color3.GPercent); + Assert.AreEqual(128 / 255.0, color3.G); Core.Color color4 = new Core.Color(0, 0, 30, 0); - Assert.AreEqual(30 / 255.0, color4.GPercent); + Assert.AreEqual(30 / 255.0, color4.G); Core.Color color5 = new Core.Color(0, 0, 201, 0); - Assert.AreEqual(201 / 255.0, color5.GPercent); + Assert.AreEqual(201 / 255.0, color5.G); } [TestMethod] public void BToPercentTest() { Core.Color color1 = new Core.Color(0, 0, 0, 0); - Assert.AreEqual(0, color1.BPercent); + Assert.AreEqual(0, color1.B); Core.Color color2 = new Core.Color(0, 0, 0, 255); - Assert.AreEqual(1, color2.BPercent); + Assert.AreEqual(1, color2.B); Core.Color color3 = new Core.Color(0, 0, 0, 128); - Assert.AreEqual(128 / 255.0, color3.BPercent); + Assert.AreEqual(128 / 255.0, color3.B); Core.Color color4 = new Core.Color(0, 0, 0, 30); - Assert.AreEqual(30 / 255.0, color4.BPercent); + Assert.AreEqual(30 / 255.0, color4.B); Core.Color color5 = new Core.Color(0, 0, 0, 201); - Assert.AreEqual(201 / 255.0, color5.BPercent); + Assert.AreEqual(201 / 255.0, color5.B); } #endregion