mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 09:08:34 +00:00
Added gamma-value to brushes to allow a simple color correction
This commit is contained in:
parent
17d05d9527
commit
1b4af74b14
@ -2,6 +2,7 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
// ReSharper disable VirtualMemberNeverOverridden.Global
|
// ReSharper disable VirtualMemberNeverOverridden.Global
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -34,6 +35,12 @@ namespace CUE.NET.Brushes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public float Opacity { get; set; }
|
public float Opacity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
public float Gamma { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Rectangle used in the last render pass.
|
/// Gets the Rectangle used in the last render pass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -58,10 +65,12 @@ namespace CUE.NET.Brushes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="brightness">The overall percentage brightness of the brush. (default: 1f)</param>
|
/// <param name="brightness">The overall percentage brightness of the brush. (default: 1f)</param>
|
||||||
/// <param name="opacity">The overall percentage opacity of the brush. (default: 1f)</param>
|
/// <param name="opacity">The overall percentage opacity of the brush. (default: 1f)</param>
|
||||||
protected AbstractBrush(float brightness = 1f, float opacity = 1f)
|
/// <param name="gamma">The gamma-value used to correct the colors calculated by the brush. (default: 1f)</param>
|
||||||
|
protected AbstractBrush(float brightness = 1f, float opacity = 1f, float gamma = 1f)
|
||||||
{
|
{
|
||||||
this.Brightness = brightness;
|
this.Brightness = brightness;
|
||||||
this.Opacity = opacity;
|
this.Opacity = opacity;
|
||||||
|
this.Gamma = gamma;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -113,6 +122,10 @@ namespace CUE.NET.Brushes
|
|||||||
// THIS IS NOT A HSB CALCULATION!!!
|
// THIS IS NOT A HSB CALCULATION!!!
|
||||||
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
|
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
|
||||||
byte finalAlpha = (byte)(color.A * (Opacity < 0 ? 0 : (Opacity > 1f ? 1f : Opacity)));
|
byte finalAlpha = (byte)(color.A * (Opacity < 0 ? 0 : (Opacity > 1f ? 1f : Opacity)));
|
||||||
|
|
||||||
|
if (Math.Abs(Gamma - 1f) > float.Epsilon)
|
||||||
|
ColorHelper.CorrectGamma(color, Gamma);
|
||||||
|
|
||||||
return ColorHelper.ColorFromHSV(color.GetHSVHue(), color.GetHSVSaturation(), finalBrightness, finalAlpha);
|
return ColorHelper.ColorFromHSV(color.GetHSVHue(), color.GetHSVSaturation(), finalBrightness, finalAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,12 @@ namespace CUE.NET.Brushes
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
float Opacity { get; set; }
|
float Opacity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
float Gamma { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the Rectangle used in the last render pass.
|
/// Gets the Rectangle used in the last render pass.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -99,6 +99,23 @@ namespace CUE.NET.Helper
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Color-Correction
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Corrects the color using the specified gamma.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="color">The color to correct.</param>
|
||||||
|
/// <param name="gamma">The gamma value to apply.</param>
|
||||||
|
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
|
#region RGB/HSV conversion
|
||||||
// https://en.wikipedia.org/wiki/HSL_and_HSV
|
// https://en.wikipedia.org/wiki/HSL_and_HSV
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user