diff --git a/LuaScript.Gpu/Buffer/GpuConvolveOperation.cs b/LuaScript.Gpu/Buffer/GpuConvolveOperation.cs index fe6d937..9ace253 100644 --- a/LuaScript.Gpu/Buffer/GpuConvolveOperation.cs +++ b/LuaScript.Gpu/Buffer/GpuConvolveOperation.cs @@ -15,13 +15,13 @@ namespace LuaScript.Engine.Processing private readonly float[] _constants = new float[1024]; private readonly List _validations = []; - public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset) + public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false) { if (!IsTextureSupported(target, width, height) || !IsSupported(kernel, size, divisor, offset)) return false; long work = (long)width * height * size * size; - if (work < ConvolveWorkThreshold || !EnsureValidated(target, width, height, kernel, size, divisor, offset)) + if (!force && work < ConvolveWorkThreshold || !EnsureValidated(target, width, height, kernel, size, divisor, offset)) return false; SetConstants(width, height, kernel, size, divisor, offset); diff --git a/LuaScript.Gpu/Buffer/GpuFillOperation.cs b/LuaScript.Gpu/Buffer/GpuFillOperation.cs index 36476d3..c1d2291 100644 --- a/LuaScript.Gpu/Buffer/GpuFillOperation.cs +++ b/LuaScript.Gpu/Buffer/GpuFillOperation.cs @@ -16,7 +16,7 @@ namespace LuaScript.Engine.Processing private bool? _fullValidated; private bool? _partialValidated; - public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight) + public 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 force = false) { if (!IsTextureSupported(target, width, height) || !AreFinite(r, g, b, a)) return false; @@ -25,14 +25,14 @@ namespace LuaScript.Engine.Processing bool full = x == 0 && y == 0 && fillWidth == width && fillHeight == height; if (full) { - if (pixels < FillFullThreshold || !EnsureFullValidated()) + if (!force && pixels < FillFullThreshold || !EnsureFullValidated()) return false; SetConstants(r, g, b, a); return RunFillFull(_constants.AsSpan(0, 4), target, width, height); } long area = (long)fillWidth * fillHeight; - if (pixels < FillPartialThreshold || area * 4L < pixels * 3L || !EnsurePartialValidated()) + if (!force && (pixels < FillPartialThreshold || area * 4L < pixels * 3L) || !EnsurePartialValidated()) return false; SetConstants(r, g, b, a); diff --git a/LuaScript.Gpu/Buffer/GpuPixelBufferProcessor.cs b/LuaScript.Gpu/Buffer/GpuPixelBufferProcessor.cs index 1fe0c7d..0fcaf16 100644 --- a/LuaScript.Gpu/Buffer/GpuPixelBufferProcessor.cs +++ b/LuaScript.Gpu/Buffer/GpuPixelBufferProcessor.cs @@ -9,22 +9,22 @@ namespace LuaScript.Engine.Processing private readonly GpuConvolveOperation _convolve = new(runner); private readonly GpuResizeOperation _resize = new(runner); - public bool TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight) + public 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 force = false) { lock (_gate) - return _fill.TryFill(target, width, height, r, g, b, a, x, y, fillWidth, fillHeight); + return _fill.TryFill(target, width, height, r, g, b, a, x, y, fillWidth, fillHeight, force); } - public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset) + public bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false) { lock (_gate) - return _convolve.TryConvolve(target, width, height, kernel, size, divisor, offset); + return _convolve.TryConvolve(target, width, height, kernel, size, divisor, offset, force); } - public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target) + public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false) { lock (_gate) - return _resize.TryResize(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target); + return _resize.TryResize(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target, force); } } } diff --git a/LuaScript.Gpu/Buffer/GpuResizeOperation.cs b/LuaScript.Gpu/Buffer/GpuResizeOperation.cs index 683595d..3338110 100644 --- a/LuaScript.Gpu/Buffer/GpuResizeOperation.cs +++ b/LuaScript.Gpu/Buffer/GpuResizeOperation.cs @@ -16,14 +16,14 @@ namespace LuaScript.Engine.Processing private bool? _nearestValidated; private bool? _linearValidated; - public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target) + public bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false) { target = null; if (!IsTextureSupported(source, sourceWidth, sourceHeight) || !IsTextureSizeSupported(targetWidth, targetHeight)) return false; long pixels = (long)targetWidth * targetHeight; - if (pixels < ResizeThreshold || !(linear ? EnsureLinearValidated(source, sourceWidth, sourceHeight) : EnsureNearestValidated(source, sourceWidth, sourceHeight))) + if (!force && pixels < ResizeThreshold || !(linear ? EnsureLinearValidated(source, sourceWidth, sourceHeight) : EnsureNearestValidated(source, sourceWidth, sourceHeight))) return false; return RunShader(source, sourceWidth, sourceHeight, targetWidth, targetHeight, linear, out target); diff --git a/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs b/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs index 215f5d9..ffb0d59 100644 --- a/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs +++ b/LuaScript.Runtime/Engine/IPixelBufferProcessor.cs @@ -2,10 +2,10 @@ 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 TryFill(byte[] target, int width, int height, double r, double g, double b, double a, int x, int y, int fillWidth, int fillHeight, bool force = false); - bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset); + bool TryConvolve(byte[] target, int width, int height, double[] kernel, int size, double divisor, double offset, bool force = false); - bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target); + bool TryResize(byte[] source, int sourceWidth, int sourceHeight, int targetWidth, int targetHeight, bool linear, out byte[]? target, bool force = false); } }