mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Removed byte-component from color
This commit is contained in:
parent
558eb3eb5a
commit
fa396127ea
@ -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);
|
||||
}
|
||||
|
||||
@ -25,45 +25,25 @@ namespace RGB.NET.Core
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
/// <summary>
|
||||
/// Gets the alpha component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
public byte A { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the alpha component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double APercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the red component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
public byte R { get; }
|
||||
public double A { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the red component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double RPercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the green component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
public byte G { get; }
|
||||
public double R { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the green component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double GPercent { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blue component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
public byte B { get; }
|
||||
public double G { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blue component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public double BPercent { get; }
|
||||
public double B { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
@ -101,7 +81,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green component value of this <see cref="Color"/>.</param>
|
||||
/// <param name="b">The blue component value of this <see cref="Color"/>.</param>
|
||||
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())
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@ -134,8 +114,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green component value of this <see cref="Color"/>.</param>
|
||||
/// <param name="b">The blue component value of this <see cref="Color"/>.</param>
|
||||
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())
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@ -168,8 +147,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green component value of this <see cref="Color"/>.</param>
|
||||
/// <param name="b">The blue component value of this <see cref="Color"/>.</param>
|
||||
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)
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
@ -180,9 +158,12 @@ namespace RGB.NET.Core
|
||||
/// <param name="g">The green component value of this <see cref="Color"/>.</param>
|
||||
/// <param name="b">The blue component value of this <see cref="Color"/>.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
@ -190,22 +171,9 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="color">The <see cref="T:RGB.NET.Core.Color" /> the values are copied from.</param>
|
||||
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 <see cref="Color"/> to a human-readable string.
|
||||
/// </summary>
|
||||
/// <returns>A string that contains the individual byte values of this <see cref="Color"/>. For example "[A: 255, R: 255, G: 0, B: 0]".</returns>
|
||||
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()}]";
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Color" /> and is equivalent to this <see cref="Color" />.
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Deconstructs the Color into it's ARGB-components.
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha component of this color.</param>
|
||||
/// <param name="r">The red component of this color.</param>
|
||||
/// <param name="g">The green component of this color.</param>
|
||||
/// <param name="b">The blue component of this color.</param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
@ -272,15 +221,15 @@ namespace RGB.NET.Core
|
||||
/// <param name="color">The <see cref="Color"/> to blend.</param>
|
||||
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);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -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);
|
||||
|
||||
@ -6,13 +6,49 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Getter
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static byte GetA(this Color color) => color.A.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the R component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static byte GetR(this Color color) => color.R.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the G component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static byte GetG(this Color color) => color.G.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static byte GetB(this Color color) => color.B.GetByteValueFromPercentage();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A, R, G and B component value of this <see cref="Color"/> as byte in the range [0..255].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
public static (byte a, byte r, byte g, byte b) GetRGBBytes(this Color color)
|
||||
=> (color.GetA(), color.GetR(), color.GetG(), color.GetB());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the A, R, G and B component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
/// <param name="color"></param>
|
||||
/// <returns></returns>
|
||||
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
|
||||
/// <param name="b">The blue value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given RGB-percent values to this color.
|
||||
@ -38,7 +74,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="b">The blue value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given alpha value to this color.
|
||||
@ -46,7 +82,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given alpha-percent value to this color.
|
||||
@ -54,7 +90,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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
|
||||
/// <param name="b">The blue value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given RGB values to this color.
|
||||
@ -78,7 +114,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="b">The blue value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given alpha value to this color.
|
||||
@ -86,7 +122,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Subtracts the given alpha-percent value to this color.
|
||||
@ -94,7 +130,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to subtract.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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
|
||||
/// <param name="b">The blue value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Multiplies the given alpha value to this color.
|
||||
@ -116,7 +152,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to multiply.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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
|
||||
/// <param name="b">The blue value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Divides the given alpha value to this color.
|
||||
@ -138,7 +174,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="a">The alpha value to divide.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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());
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given RGB value of this color.
|
||||
@ -162,7 +198,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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());
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given RGB value of this color.
|
||||
@ -172,21 +208,21 @@ namespace RGB.NET.Core
|
||||
/// <param name="b">The blue value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given alpha value of this color.
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// Sets the given alpha value of this color.
|
||||
/// </summary>
|
||||
/// <param name="a">The alpha value to set.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
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.
|
||||
/// </summary>
|
||||
/// <returns>The RGB-HEX-string.</returns>
|
||||
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());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current color as a ARGB-HEX-string.
|
||||
/// </summary>
|
||||
/// <returns>The ARGB-HEX-string.</returns>
|
||||
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
|
||||
|
||||
|
||||
@ -57,9 +57,9 @@ namespace RGB.NET.Devices.Asus
|
||||
foreach (KeyValuePair<object, Color> 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);
|
||||
|
||||
@ -39,7 +39,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
foreach (KeyValuePair<object, Color> 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);
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user