diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs
index b5266c9bd..9c37b69e6 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs
+++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.Weights.cs
@@ -27,31 +27,54 @@ namespace ImageSharp.Processing.Processors
public int Left;
///
- /// The span of weights pointing to .
+ /// The length of the weights window
///
- public Span Span;
+ public int Length;
+
+ ///
+ /// The index in the destination buffer
+ ///
+ private readonly int destIndex;
+
+ ///
+ /// The weights buffer .
+ ///
+ private readonly Buffer2D buffer;
///
/// Initializes a new instance of the struct.
///
+ /// The destination index in the buffer
/// The local left index
- /// The span
+ /// The span
+ /// The length of the window
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal WeightsWindow(int left, Span span)
+ internal WeightsWindow(int index, int left, Buffer2D buffer, int length)
{
+ this.destIndex = index;
this.Left = left;
- this.Span = span;
+ this.buffer = buffer;
+ this.Length = length;
}
///
- /// Gets an unsafe float* pointer to the beginning of .
+ /// Gets an unsafe float* pointer to the beginning of .
///
- public ref float Ptr => ref this.Span.DangerousGetPinnableReference();
+ public ref float Ptr
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ return ref this.GetWindowSpan().DangerousGetPinnableReference();
+ }
+ }
///
- /// Gets the lenghth of the weights window
+ /// Gets the span representing the portion of the that this window covers
///
- public int Length => this.Span.Length;
+ /// The
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public Span GetWindowSpan() => this.buffer.GetRowSpan(this.destIndex).Slice(this.Left, this.Length);
///
/// Computes the sum of vectors in 'rowSpan' weighted by weight values, pointed by this instance.
@@ -139,7 +162,7 @@ namespace ImageSharp.Processing.Processors
///
internal class WeightsBuffer : IDisposable
{
- private Buffer2D dataBuffer;
+ private readonly Buffer2D dataBuffer;
///
/// Initializes a new instance of the class.
@@ -174,8 +197,7 @@ namespace ImageSharp.Processing.Processors
/// The weights
public WeightsWindow GetWeightsWindow(int destIdx, int leftIdx, int rightIdx)
{
- Span span = this.dataBuffer.GetRowSpan(destIdx).Slice(leftIdx, rightIdx - leftIdx + 1);
- return new WeightsWindow(leftIdx, span);
+ return new WeightsWindow(destIdx, leftIdx, this.dataBuffer, rightIdx - leftIdx + 1);
}
}
}
diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs
index 3f8a75b92..8b57586f4 100644
--- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs
+++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs
@@ -5,6 +5,7 @@
namespace ImageSharp.Tests.Processing.Transforms
{
+ using System;
using System.IO;
using System.Text;
@@ -49,9 +50,10 @@ namespace ImageSharp.Tests.Processing.Transforms
foreach (ResamplingWeightedProcessor.WeightsWindow window in weights.Weights)
{
+ Span span = window.GetWindowSpan();
for (int i = 0; i < window.Length; i++)
{
- float value = window.Span[i];
+ float value = span[i];
bld.Append(value);
bld.Append("| ");
}