diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index d2c547bac2..834120f84a 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -336,6 +336,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution private readonly Buffer2D targetValues; private readonly Buffer2D sourcePixels; private readonly Complex64[] kernel; + private readonly int maxY; + private readonly int maxX; [MethodImpl(InliningOptions.ShortMethod)] public ApplyVerticalConvolutionRowIntervalAction( @@ -345,6 +347,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution Complex64[] kernel) { this.bounds = bounds; + this.maxY = this.bounds.Bottom - 1; + this.maxX = this.bounds.Right - 1; this.targetValues = targetValues; this.sourcePixels = sourcePixels; this.kernel = kernel; @@ -354,16 +358,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution [MethodImpl(InliningOptions.ShortMethod)] public void Invoke(in RowInterval rows) { - int maxY = this.bounds.Bottom - 1; - int maxX = this.bounds.Right - 1; - for (int y = rows.Min; y < rows.Max; y++) { Span targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); for (int x = 0; x < this.bounds.Width; x++) { - Buffer2DUtils.Convolve4(this.kernel, this.sourcePixels, targetRowSpan, y, x, this.bounds.Y, maxY, this.bounds.X, maxX); + Buffer2DUtils.Convolve4(this.kernel, this.sourcePixels, targetRowSpan, y, x, this.bounds.Y, this.maxY, this.bounds.X, this.maxX); } } } @@ -380,6 +381,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution private readonly Complex64[] kernel; private readonly float z; private readonly float w; + private readonly int maxY; + private readonly int maxX; [MethodImpl(InliningOptions.ShortMethod)] public ApplyHorizontalConvolutionRowIntervalAction( @@ -391,6 +394,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution float w) { this.bounds = bounds; + this.maxY = this.bounds.Bottom - 1; + this.maxX = this.bounds.Right - 1; this.targetValues = targetValues; this.sourceValues = sourceValues; this.kernel = kernel; @@ -402,16 +407,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution [MethodImpl(InliningOptions.ShortMethod)] public void Invoke(in RowInterval rows) { - int maxY = this.bounds.Bottom - 1; - int maxX = this.bounds.Right - 1; - for (int y = rows.Min; y < rows.Max; y++) { Span targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); for (int x = 0; x < this.bounds.Width; x++) { - Buffer2DUtils.Convolve4AndAccumulatePartials(this.kernel, this.sourceValues, targetRowSpan, y, x, this.bounds.Y, maxY, this.bounds.X, maxX, this.z, this.w); + Buffer2DUtils.Convolve4AndAccumulatePartials(this.kernel, this.sourceValues, targetRowSpan, y, x, this.bounds.Y, this.maxY, this.bounds.X, this.maxX, this.z, this.w); } } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs index 410b7405cf..cd550a3355 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs @@ -80,6 +80,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution private readonly struct RowIntervalAction : IRowIntervalAction { private readonly Rectangle bounds; + private readonly int maxY; + private readonly int maxX; private readonly Buffer2D targetPixels; private readonly Buffer2D sourcePixels; private readonly DenseMatrix kernelY; @@ -98,6 +100,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution bool preserveAlpha) { this.bounds = bounds; + this.maxY = this.bounds.Bottom - 1; + this.maxX = this.bounds.Right - 1; this.targetPixels = targetPixels; this.sourcePixels = sourcePixels; this.kernelY = kernelY; @@ -114,9 +118,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution int length = vectorSpan.Length; ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan); - int maxY = this.bounds.Bottom - 1; - int maxX = this.bounds.Right - 1; - for (int y = rows.Min; y < rows.Max; y++) { Span targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X); @@ -134,9 +135,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution y, x, this.bounds.Y, - maxY, + this.maxY, this.bounds.X, - maxX); + this.maxX); } } else @@ -151,9 +152,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution y, x, this.bounds.Y, - maxY, + this.maxY, this.bounds.X, - maxX); + this.maxX); } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs index db7bc51888..b68dc56e05 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs @@ -71,6 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution private readonly struct RowIntervalAction : IRowIntervalAction { private readonly Rectangle bounds; + private readonly int maxY; + private readonly int maxX; private readonly Buffer2D targetPixels; private readonly Buffer2D sourcePixels; private readonly DenseMatrix kernel; @@ -87,6 +89,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution bool preserveAlpha) { this.bounds = bounds; + this.maxY = this.bounds.Bottom - 1; + this.maxX = this.bounds.Right - 1; this.targetPixels = targetPixels; this.sourcePixels = sourcePixels; this.kernel = kernel; @@ -102,9 +106,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution int length = vectorSpan.Length; ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan); - int maxY = this.bounds.Bottom - 1; - int maxX = this.bounds.Right - 1; - for (int y = rows.Min; y < rows.Max; y++) { Span targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X); @@ -121,9 +122,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution y, x, this.bounds.Y, - maxY, + this.maxY, this.bounds.X, - maxX); + this.maxX); } } else @@ -137,9 +138,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution y, x, this.bounds.Y, - maxY, + this.maxY, this.bounds.X, - maxX); + this.maxX); } }