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/effectors/Boxblur.cs

59 lines
1.8 KiB
C#
Raw Normal View History

2021-06-09 16:43:27 +00:00
using System;
using System.Windows.Forms;
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-09 19:19:30 +00:00
public sealed class Boxblur : MatrixGifGenerator
2021-06-09 16:43:27 +00:00
{
2021-06-11 11:36:55 +00:00
[UiWidget]
[UiDescription(title: "Blur size", description: "The side length of the bounding square used to blur in pixels")]
private int blurSize = 2;
2021-06-09 16:43:27 +00:00
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)
{
float avrR = 0;
float avrG = 0;
float avrB = 0;
if (blurSize > 0)
{
for (int i = -blurSize; i < blurSize; i++)
{
int s = Math.Clamp(x + i, 0, width - 1);
for (int j = -blurSize; j < blurSize; j++)
{
int t = Math.Clamp(y + j, 0, height - 1);
SampleFrame(actualStore, frame, s, t, width, out float tmpR, out float tmpG, out float tmpB);
avrR += tmpR;
avrG += tmpG;
avrB += tmpB;
}
}
float blurKernelArea = 1.0f / ((blurSize << 1) * (blurSize << 1));
r = avrR * blurKernelArea;
g = avrG * blurKernelArea;
b = avrB * blurKernelArea;
} else
{
SampleFrame(actualStore, frame, x, y, width, out float tmpR, out float tmpG, out float tmpB);
r = tmpR;
g = tmpG;
b = tmpB;
}
}
protected override void CreateUi(FlowLayoutPanel anchor, update invokeGenerator)
{
}
2021-06-09 16:43:27 +00:00
}
}