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

48 lines
1.9 KiB
C#
Raw Normal View History

2021-06-09 16:43:27 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using static Matrix_App.GifGeneratorUtils;
namespace Matrix_App.PregeneratedMods
{
public sealed class ColorAdjust : MatrixGifGenerator
{
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Tone offset", description: "Sets an additional offset to the pixels hue")]
2021-06-09 16:43:27 +00:00
public float hueOffset = 0.0f;
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Saturation boost", description: "Decreases or increases saturation")]
2021-06-09 16:43:27 +00:00
public float saturationBoost = 0.5f;
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Brightness boost", description: "Decreases or increases brightness")]
2021-06-09 16:43:27 +00:00
public float valueBoost = 0.5f;
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Red boost", description: "Decreases or increases Red")]
2021-06-09 16:43:27 +00:00
public float redBoost = 0.5f;
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Green boost", description: "Decreases or increases Green")]
2021-06-09 16:43:27 +00:00
public float greenBoost = 0.5f;
2021-06-09 19:19:30 +00:00
[UiDescriptionAttribute(title: "Blue boost", description: "Decreases or increases Blue")]
2021-06-09 16:43:27 +00:00
public float blueBoost = 0.5f;
private float boost(float x, float y)
{
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)
{
SampleFrame(actualStore, frame, x, y, width, out float tr, out float tg, out float tb);
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;
s = boost(s, saturationBoost);
value = boost(value, valueBoost);
RgbFromHsv(h, s, value, out tr, out tg, out tb);
r = boost(tr, redBoost);
g = boost(tg, greenBoost);
b = boost(tb, blueBoost);
}
}
}