mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Gamma ramp tweaks
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace GHelper.Display
|
||||
@@ -29,7 +30,7 @@ namespace GHelper.Display
|
||||
Blue = blue;
|
||||
}
|
||||
|
||||
public DisplayGammaRamp(double brightness = 0.5, double contrast = 0.5, double gamma = 1)
|
||||
public DisplayGammaRamp(double brightness = 1, double contrast = 1, double gamma = 1)
|
||||
: this(
|
||||
CalculateLUT(brightness, contrast, gamma),
|
||||
CalculateLUT(brightness, contrast, gamma),
|
||||
@@ -38,28 +39,60 @@ namespace GHelper.Display
|
||||
{
|
||||
}
|
||||
|
||||
public DisplayGammaRamp(
|
||||
double redBrightness,
|
||||
double redContrast,
|
||||
double redGamma,
|
||||
double greenBrightness,
|
||||
double greenContrast,
|
||||
double greenGamma,
|
||||
double blueBrightness,
|
||||
double blueContrast,
|
||||
double blueGamma
|
||||
)
|
||||
: this(
|
||||
CalculateLUT(redBrightness, redContrast, redGamma),
|
||||
CalculateLUT(greenBrightness, greenContrast, greenGamma),
|
||||
CalculateLUT(blueBrightness, blueContrast, blueGamma)
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
internal DisplayGammaRamp(GammaRamp ramp) :
|
||||
this(ramp.Red, ramp.Green, ramp.Blue)
|
||||
{
|
||||
}
|
||||
public ushort[] Blue { get; }
|
||||
public ushort[] Green { get; }
|
||||
public ushort[] Red { get; }
|
||||
private static ushort[] CalculateLUT(double brightness, double contrast, double gamma)
|
||||
{
|
||||
|
||||
// Fill the gamma curve
|
||||
var result = new ushort[GammaRamp.DataPoints];
|
||||
string bits = "";
|
||||
|
||||
for (var i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = (ushort)((0.5 + brightness / 2) * ushort.MaxValue * i / (float)(result.Length - 1));
|
||||
bits += result[i].ToString() + " ";
|
||||
}
|
||||
|
||||
//Debug.WriteLine(bits);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ushort[] Brightness(ushort[] data, double brightness)
|
||||
{
|
||||
var result = new ushort[GammaRamp.DataPoints];
|
||||
for (var i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = (ushort)(data[i]*brightness);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal GammaRamp AsBrightnessRamp(double brightness)
|
||||
{
|
||||
return new GammaRamp(
|
||||
Brightness(Red, brightness),
|
||||
Brightness(Green, brightness),
|
||||
Brightness(Blue, brightness)
|
||||
);
|
||||
}
|
||||
|
||||
internal GammaRamp AsRamp()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user