This repository has been archived on 2023-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
PainterlyUNO/Matrix App/PregeneratedMods/ColorAdjust.cs

59 lines
2.0 KiB
C#
Raw Normal View History

2021-06-09 16:43:27 +00:00
using System;
2021-06-11 11:36:55 +00:00
using Matrix_App.PregeneratedMods.reflection;
2021-06-09 16:43:27 +00:00
using static Matrix_App.GifGeneratorUtils;
namespace Matrix_App.PregeneratedMods
{
2021-06-11 11:36:55 +00:00
public class ColorAdjust : MatrixGifGenerator
2021-06-09 16:43:27 +00:00
{
2021-06-11 11:36:55 +00:00
[UiWidget]
[UiDescription(title: "Tone offset", description: "Sets an additional offset to the pixels hue")]
private float hueOffset = 0.0f;
[UiWidget]
[UiDescription(title: "Saturation boost", description: "Decreases or increases saturation")]
private float saturationBoost = 0.5f;
[UiWidget]
[UiDescription(title: "Brightness boost", description: "Decreases or increases brightness")]
private float valueBoost = 0.5f;
[UiWidget]
[UiDescription(title: "Red boost", description: "Decreases or increases Red")]
private float redBoost = 0.5f;
[UiWidget]
[UiDescription(title: "Green boost", description: "Decreases or increases Green")]
private float greenBoost = 0.5f;
[UiWidget]
[UiDescription(title: "Blue boost", description: "Decreases or increases Blue")]
private float blueBoost = 0.5f;
private static float Boost(float x, float y)
2021-06-09 16:43:27 +00:00
{
return Math.Clamp(x + (y - 0.5f) * 2.0f, 0.0f, 1.0f);
}
protected override void ColorFragment(in int x, in int y, in float u, in float v, in int frame, out float r, out float g, out float b)
{
2021-06-11 11:36:55 +00:00
SampleFrame(actualStore!, frame, x, y, width, out float tr, out float tg, out float tb);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
// Adjust HSV
2021-06-09 16:43:27 +00:00
HsvFromRgb(tr, tg, tb, out float h, out float s, out float value);
h = h / 360.0f + hueOffset;
h = (h - MathF.Floor(h)) * 360.0f;
2021-06-11 11:36:55 +00:00
s = Boost(s, saturationBoost);
value = Boost(value, valueBoost);
2021-06-09 16:43:27 +00:00
2021-06-11 11:36:55 +00:00
// Adjust RGB
2021-06-09 16:43:27 +00:00
RgbFromHsv(h, s, value, out tr, out tg, out tb);
2021-06-11 11:36:55 +00:00
r = Boost(tr, redBoost);
g = Boost(tg, greenBoost);
b = Boost(tb, blueBoost);
2021-06-09 16:43:27 +00:00
}
}
}