mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +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 VirtualMemberNeverOverridden.Global
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
@ -34,6 +35,12 @@ namespace CUE.NET.Brushes
|
||||
/// </summary>
|
||||
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>
|
||||
/// Gets the Rectangle used in the last render pass.
|
||||
/// </summary>
|
||||
@ -58,10 +65,12 @@ namespace CUE.NET.Brushes
|
||||
/// </summary>
|
||||
/// <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>
|
||||
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.Opacity = opacity;
|
||||
this.Gamma = gamma;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -113,6 +122,10 @@ namespace CUE.NET.Brushes
|
||||
// THIS IS NOT A HSB CALCULATION!!!
|
||||
float finalBrightness = color.GetHSVValue() * (Brightness < 0 ? 0 : (Brightness > 1f ? 1f : Brightness));
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -29,6 +29,12 @@ namespace CUE.NET.Brushes
|
||||
/// </summary>
|
||||
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>
|
||||
/// Gets the Rectangle used in the last render pass.
|
||||
/// </summary>
|
||||
|
||||
@ -99,6 +99,23 @@ namespace CUE.NET.Helper
|
||||
|
||||
#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
|
||||
// https://en.wikipedia.org/wiki/HSL_and_HSV
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user