diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 76abc64996..9b757f6e1b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -162,7 +162,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms IResampler sampler = this.Sampler; float radius = MathF.Ceiling(scale * sampler.Radius); - var result = new WeightsBuffer(memoryAllocator, sourceSize, destinationSize); + var result = new WeightsBuffer(memoryAllocator, destinationSize, radius); for (int i = 0; i < destinationSize; i++) { diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs index 68133a5489..6acf38d119 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsBuffer.cs @@ -19,11 +19,12 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// Initializes a new instance of the class. /// /// The to use for allocations. - /// The size of the source window /// The size of the destination window - public WeightsBuffer(MemoryAllocator memoryAllocator, int sourceSize, int destinationSize) + /// The radius of the kernel + public WeightsBuffer(MemoryAllocator memoryAllocator, int destinationSize, float kernelRadius) { - this.dataBuffer = memoryAllocator.Allocate2D(sourceSize, destinationSize, AllocationOptions.Clean); + int width = (int)Math.Ceiling(kernelRadius * 2); + this.dataBuffer = memoryAllocator.Allocate2D(width, destinationSize, AllocationOptions.Clean); this.Weights = new WeightsWindow[destinationSize]; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs index 01cf97e591..56c665c30d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/WeightsWindow.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The buffer containing the weights values. /// - private readonly MemorySource buffer; + private readonly Memory buffer; /// /// Initializes a new instance of the struct. @@ -47,9 +47,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms [MethodImpl(MethodImplOptions.AggressiveInlining)] internal WeightsWindow(int index, int left, Buffer2D buffer, int length) { - this.flatStartIndex = (index * buffer.Width) + left; + this.flatStartIndex = index * buffer.Width; this.Left = left; - this.buffer = buffer.MemorySource; + this.buffer = buffer.MemorySource.Memory; this.Length = length; } @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref float GetStartReference() { - Span span = this.buffer.GetSpan(); + Span span = this.buffer.Span; return ref span[this.flatStartIndex]; } @@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// /// The [MethodImpl(MethodImplOptions.AggressiveInlining)] - public Span GetWindowSpan() => this.buffer.GetSpan().Slice(this.flatStartIndex, this.Length); + public Span GetWindowSpan() => this.buffer.Span.Slice(this.flatStartIndex, this.Length); /// /// Computes the sum of vectors in 'rowSpan' weighted by weight values, pointed by this instance.