diff --git a/LuaScript.Runtime/Engine/AviUtlScriptContext.cs b/LuaScript.Runtime/Engine/AviUtlScriptContext.cs index d47d7dd..3a8d3b3 100644 --- a/LuaScript.Runtime/Engine/AviUtlScriptContext.cs +++ b/LuaScript.Runtime/Engine/AviUtlScriptContext.cs @@ -169,6 +169,8 @@ namespace LuaScript internal IPixelShaderRunner? ShaderRunner { get; set; } + internal IPixelBufferProcessor? PixelProcessor { get; set; } + internal AviUtlPixelShaderLibrary PixelShaders { get; set; } = AviUtlPixelShaderLibrary.Empty; internal bool TryGetShaderResource(string id, out byte[] data, out int width, out int height) => @@ -524,6 +526,12 @@ namespace LuaScript if (x1 <= x0 || y1 <= y0) return; + if (PixelProcessor?.TryFill(_pixelBuffer, cw, ch, r, g, b, a, x0, y0, x1 - x0, y1 - y0) == true) + { + _isPixelsDirty = true; + return; + } + _isPixelsDirty = true; double aK = Math.Clamp(a, 0d, 255d) / 255d; byte pb = (byte)Math.Clamp(b * aK, 0d, 255d); @@ -641,6 +649,12 @@ namespace LuaScript int cw = ImageWidth; int ch = ImageHeight; + if (PixelProcessor?.TryConvolve(_pixelBuffer, cw, ch, kernel, size, divisor, offset) == true) + { + _isPixelsDirty = true; + return; + } + int count = cw * ch * 4; if (_convolveSource is null || _convolveSource.Length < count) _convolveSource = new double[count]; @@ -720,6 +734,12 @@ namespace LuaScript int cw = ImageWidth; int ch = ImageHeight; + if (PixelProcessor?.TryResize(_pixelBuffer, cw, ch, newWidth, newHeight, linear, out var processed) == true && processed is not null) + { + ReplaceBuffer(processed, newWidth, newHeight); + return; + } + int srcCount = cw * ch * 4; if (_resizeSource is null || _resizeSource.Length < srcCount) _resizeSource = new byte[srcCount]; diff --git a/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs b/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs new file mode 100644 index 0000000..215f5d9 --- /dev/null +++ b/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs @@ -0,0 +1,11 @@ +namespace LuaScript +{ + internal interface IPixelBufferProcessor + { + bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight); + + bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset); + + bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target); + } +}