|
|
|
@ -34,12 +34,12 @@ namespace ImageSharp.Processing.Processors |
|
|
|
/// <summary>
|
|
|
|
/// The index in the destination buffer
|
|
|
|
/// </summary>
|
|
|
|
private readonly int destIndex; |
|
|
|
private readonly int flatStartIndex; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// The weights buffer <see cref="WeightsBuffer"/>.
|
|
|
|
/// The buffer containing the weights values.
|
|
|
|
/// </summary>
|
|
|
|
private readonly Buffer2D<float> buffer; |
|
|
|
private readonly Buffer<float> buffer; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="WeightsWindow"/> struct.
|
|
|
|
@ -51,22 +51,19 @@ namespace ImageSharp.Processing.Processors |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
internal WeightsWindow(int index, int left, Buffer2D<float> buffer, int length) |
|
|
|
{ |
|
|
|
this.destIndex = index; |
|
|
|
this.flatStartIndex = (index * buffer.Width) + left; |
|
|
|
this.Left = left; |
|
|
|
this.buffer = buffer; |
|
|
|
this.Length = length; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets an unsafe float* pointer to the beginning of <see cref="buffer"/>.
|
|
|
|
/// Gets a reference to the first item of the window.
|
|
|
|
/// </summary>
|
|
|
|
public ref float Ptr |
|
|
|
/// <returns>The reference to the first item of the window</returns>
|
|
|
|
public ref float GetStartReference() |
|
|
|
{ |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
get |
|
|
|
{ |
|
|
|
return ref this.GetWindowSpan().DangerousGetPinnableReference(); |
|
|
|
} |
|
|
|
return ref this.buffer[this.flatStartIndex]; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -74,7 +71,7 @@ namespace ImageSharp.Processing.Processors |
|
|
|
/// </summary>
|
|
|
|
/// <returns>The <see cref="Span{T}"/></returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public Span<float> GetWindowSpan() => this.buffer.GetRowSpan(this.destIndex).Slice(this.Left, this.Length); |
|
|
|
public Span<float> GetWindowSpan() => this.buffer.Slice(this.flatStartIndex, this.Length); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Computes the sum of vectors in 'rowSpan' weighted by weight values, pointed by this <see cref="WeightsWindow"/> instance.
|
|
|
|
@ -85,7 +82,7 @@ namespace ImageSharp.Processing.Processors |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public Vector4 ComputeWeightedRowSum(Span<Vector4> rowSpan, int sourceX) |
|
|
|
{ |
|
|
|
ref float horizontalValues = ref this.Ptr; |
|
|
|
ref float horizontalValues = ref this.GetStartReference(); |
|
|
|
int left = this.Left; |
|
|
|
ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX); |
|
|
|
|
|
|
|
@ -112,7 +109,7 @@ namespace ImageSharp.Processing.Processors |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public Vector4 ComputeExpandedWeightedRowSum(Span<Vector4> rowSpan, int sourceX) |
|
|
|
{ |
|
|
|
ref float horizontalValues = ref this.Ptr; |
|
|
|
ref float horizontalValues = ref this.GetStartReference(); |
|
|
|
int left = this.Left; |
|
|
|
ref Vector4 vecPtr = ref Unsafe.Add(ref rowSpan.DangerousGetPinnableReference(), left + sourceX); |
|
|
|
|
|
|
|
@ -140,7 +137,7 @@ namespace ImageSharp.Processing.Processors |
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public Vector4 ComputeWeightedColumnSum(Buffer2D<Vector4> firstPassPixels, int x, int sourceY) |
|
|
|
{ |
|
|
|
ref float verticalValues = ref this.Ptr; |
|
|
|
ref float verticalValues = ref this.GetStartReference(); |
|
|
|
int left = this.Left; |
|
|
|
|
|
|
|
// Destination color components
|
|
|
|
|