diff --git a/Brushes/AbstractBrush.cs b/Brushes/AbstractBrush.cs
index 0341ec3..0a5968c 100644
--- a/Brushes/AbstractBrush.cs
+++ b/Brushes/AbstractBrush.cs
@@ -2,10 +2,10 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable VirtualMemberNeverOverridden.Global
-using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
+using CUE.NET.ColorCorrection;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Effects;
@@ -36,10 +36,9 @@ namespace CUE.NET.Brushes
public float Opacity { get; set; }
///
- /// Gets or sets the gamma-value used to correct the colors calculated by the brush.
- /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ /// Gets a list of color-corrections used to correct the colors of the brush.
///
- public float Gamma { get; set; }
+ public List ColorCorrections { get; } = new List();
///
/// Gets the Rectangle used in the last render pass.
@@ -65,12 +64,10 @@ namespace CUE.NET.Brushes
///
/// The overall percentage brightness of the brush. (default: 1f)
/// The overall percentage opacity of the brush. (default: 1f)
- /// The gamma-value used to correct the colors calculated by the brush. (default: 1f)
- protected AbstractBrush(float brightness = 1f, float opacity = 1f, float gamma = 1f)
+ protected AbstractBrush(float brightness = 1f, float opacity = 1f)
{
this.Brightness = brightness;
this.Opacity = opacity;
- this.Gamma = gamma;
}
#endregion
@@ -117,8 +114,8 @@ namespace CUE.NET.Brushes
/// The finalized color.
protected virtual CorsairColor FinalizeColor(CorsairColor color)
{
- if (Math.Abs(Gamma - 1f) > float.Epsilon)
- ColorHelper.CorrectGamma(color, Gamma);
+ foreach (IColorCorrection colorCorrection in ColorCorrections)
+ colorCorrection.ApplyTo(color);
// Since we use HSV to calculate there is no way to make a color 'brighter' than 100%
// Be carefull with the naming: Since we use HSV the correct term is 'value' but outside we call it 'brightness'
diff --git a/Brushes/IBrush.cs b/Brushes/IBrush.cs
index 1be96ab..0e00dab 100644
--- a/Brushes/IBrush.cs
+++ b/Brushes/IBrush.cs
@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Drawing;
+using CUE.NET.ColorCorrection;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Effects;
@@ -30,10 +31,9 @@ namespace CUE.NET.Brushes
float Opacity { get; set; }
///
- /// Gets or sets the gamma-value used to correct the colors calculated by the brush.
- /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ /// Gets a list of color-corrections used to correct the colors of the brush.
///
- float Gamma { get; set; }
+ List ColorCorrections { get; }
///
/// Gets the Rectangle used in the last render pass.
diff --git a/CUE.NET.csproj b/CUE.NET.csproj
index db428ba..65c71c0 100644
--- a/CUE.NET.csproj
+++ b/CUE.NET.csproj
@@ -51,6 +51,8 @@
+
+
diff --git a/ColorCorrection/GammaCorrection.cs b/ColorCorrection/GammaCorrection.cs
new file mode 100644
index 0000000..153ed6a
--- /dev/null
+++ b/ColorCorrection/GammaCorrection.cs
@@ -0,0 +1,104 @@
+using System;
+using CUE.NET.Devices.Generic;
+using CUE.NET.Helper;
+
+namespace CUE.NET.ColorCorrection
+{
+ ///
+ /// Represents a gamma-color-correction.
+ ///
+ public class GammaCorrection : IColorCorrection
+ {
+ #region Properties & Fields
+
+ ///
+ /// Gets or sets the gamma-value of the color 'red' used for color-correction.
+ /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ ///
+ public float R { get; set; }
+
+ ///
+ /// Gets or sets the gamma-value of the color 'green' used for color-correction.
+ /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ ///
+ public float G { get; set; }
+
+ ///
+ /// Gets or sets the gamma-value of the color 'blue' used for color-correction.
+ /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ ///
+ public float B { get; set; }
+
+ #endregion
+
+ #region Constructors
+
+ ///
+ /// Initializes a new instance of the class using the default-value 1f (no correction) for all colors.
+ ///
+ public GammaCorrection() : this(1f) { }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The gamma-value for all colors used for color-correction.
+ /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ public GammaCorrection(float gamma)
+ {
+ this.R = gamma;
+ this.G = gamma;
+ this.B = gamma;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The gamma-value for the color 'red' used for color-correction.
+ /// Values greater than one will make colors brighter, values less than one will make colors darker.
+ /// The gamma-value for the color 'green' used for color-correction. Values
+ /// greater than one will make colors brighter, values less than one will make colors darker.
+ /// The gamma-value for the color 'blue' used for color-correction. Values
+ /// greater than one will make colors brighter, values less than one will make colors darker.
+ public GammaCorrection(float r, float g, float b)
+ {
+ this.R = r;
+ this.G = g;
+ this.B = b;
+ }
+
+ #endregion
+
+ #region Methods
+
+ ///
+ /// Applies the gamma-correction to the given color.
+ ///
+ /// The color to correct.
+ public void ApplyTo(CorsairColor color)
+ {
+ if (Math.Abs(R - 1f) > float.Epsilon)
+ color.R = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatR(), 1.0 / R));
+
+ if (Math.Abs(G - 1f) > float.Epsilon)
+ color.G = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatG(), 1.0 / G));
+
+ if (Math.Abs(B - 1f) > float.Epsilon)
+ color.B = ColorHelper.GetIntColorFromFloat((float)Math.Pow(color.GetFloatB(), 1.0 / B));
+ }
+
+ #endregion
+
+ #region Operators
+
+ ///
+ /// Converts a to a using the same value for all colors.
+ ///
+ /// The float-value to convert.
+ public static implicit operator GammaCorrection(float gamma)
+ {
+ return new GammaCorrection(gamma);
+ }
+
+ #endregion
+ }
+}
diff --git a/ColorCorrection/IColorCorrection.cs b/ColorCorrection/IColorCorrection.cs
new file mode 100644
index 0000000..9c698aa
--- /dev/null
+++ b/ColorCorrection/IColorCorrection.cs
@@ -0,0 +1,16 @@
+using CUE.NET.Devices.Generic;
+
+namespace CUE.NET.ColorCorrection
+{
+ ///
+ /// Represents generic color-correction.
+ ///
+ public interface IColorCorrection
+ {
+ ///
+ /// Applies the color-correction to the given color.
+ ///
+ /// The color to correct.
+ void ApplyTo(CorsairColor color);
+ }
+}
diff --git a/Helper/ColorHelper.cs b/Helper/ColorHelper.cs
index 8a6e842..daf06f1 100644
--- a/Helper/ColorHelper.cs
+++ b/Helper/ColorHelper.cs
@@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
using System;
+using CUE.NET.ColorCorrection;
using CUE.NET.Devices.Generic;
namespace CUE.NET.Helper
@@ -13,7 +14,7 @@ namespace CUE.NET.Helper
#region byte/float conversion
///
- /// Converts the alpha-value of the to an float value int the range [0..1].
+ /// Converts the alpha-value of the to a float value in the range [0..1].
///
/// The color to take the alpha-value from.
/// The float-value in the range of [0..1]
@@ -23,7 +24,7 @@ namespace CUE.NET.Helper
}
///
- /// Converts the red-value of the to an float value int the range [0..1].
+ /// Converts the red-value of the to a float value in the range [0..1].
///
/// The color to take the red-value from.
/// The float-value in the range of [0..1]
@@ -33,7 +34,7 @@ namespace CUE.NET.Helper
}
///
- /// Converts the green-value of the to an float value int the range [0..1].
+ /// Converts the green-value of the to a float value in the range [0..1].
///
/// The color to take the green-value from.
/// The float-value in the range of [0..1]
@@ -43,7 +44,7 @@ namespace CUE.NET.Helper
}
///
- /// Converts the blue-value of the to an float value int the range [0..1].
+ /// Converts the blue-value of the to a float value in the range [0..1].
///
/// The color to take the blue-value from.
/// The float-value in the range of [0..1]
@@ -65,7 +66,12 @@ namespace CUE.NET.Helper
return new CorsairColor(GetIntColorFromFloat(a), GetIntColorFromFloat(r), GetIntColorFromFloat(g), GetIntColorFromFloat(b));
}
- private static byte GetIntColorFromFloat(float f)
+ ///
+ /// Converts the given float-value to a integer-color in the range [0..255].
+ ///
+ /// The float color-value
+ /// The integer-value int the range [0..255].
+ public static byte GetIntColorFromFloat(float f)
{
// ReSharper disable once RedundantCast - never trust this ...
float calcF = (float)Math.Max(0f, Math.Min(1f, f));
@@ -99,23 +105,6 @@ namespace CUE.NET.Helper
#endregion
- #region Color-Correction
-
- ///
- /// Corrects the color using the specified gamma.
- ///
- /// The color to correct.
- /// The gamma value to apply.
- public static void CorrectGamma(CorsairColor color, float gamma)
- {
- double value = 1.0 / gamma;
- color.R = GetIntColorFromFloat((float)Math.Pow(color.GetFloatR(), value));
- color.G = GetIntColorFromFloat((float)Math.Pow(color.GetFloatG(), value));
- color.B = GetIntColorFromFloat((float)Math.Pow(color.GetFloatB(), value));
- }
-
- #endregion
-
#region RGB/HSV conversion
// https://en.wikipedia.org/wiki/HSL_and_HSV