Browse Source

Minor perf update

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
d07e754259
  1. 18
      src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
  2. 15
      src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
  3. 15
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs

18
src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs

@ -336,6 +336,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
private readonly Buffer2D<ComplexVector4> targetValues; private readonly Buffer2D<ComplexVector4> targetValues;
private readonly Buffer2D<TPixel> sourcePixels; private readonly Buffer2D<TPixel> sourcePixels;
private readonly Complex64[] kernel; private readonly Complex64[] kernel;
private readonly int maxY;
private readonly int maxX;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public ApplyVerticalConvolutionRowIntervalAction( public ApplyVerticalConvolutionRowIntervalAction(
@ -345,6 +347,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
Complex64[] kernel) Complex64[] kernel)
{ {
this.bounds = bounds; this.bounds = bounds;
this.maxY = this.bounds.Bottom - 1;
this.maxX = this.bounds.Right - 1;
this.targetValues = targetValues; this.targetValues = targetValues;
this.sourcePixels = sourcePixels; this.sourcePixels = sourcePixels;
this.kernel = kernel; this.kernel = kernel;
@ -354,16 +358,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) 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++) for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<ComplexVector4> targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); Span<ComplexVector4> targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X);
for (int x = 0; x < this.bounds.Width; 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 Complex64[] kernel;
private readonly float z; private readonly float z;
private readonly float w; private readonly float w;
private readonly int maxY;
private readonly int maxX;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public ApplyHorizontalConvolutionRowIntervalAction( public ApplyHorizontalConvolutionRowIntervalAction(
@ -391,6 +394,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
float w) float w)
{ {
this.bounds = bounds; this.bounds = bounds;
this.maxY = this.bounds.Bottom - 1;
this.maxX = this.bounds.Right - 1;
this.targetValues = targetValues; this.targetValues = targetValues;
this.sourceValues = sourceValues; this.sourceValues = sourceValues;
this.kernel = kernel; this.kernel = kernel;
@ -402,16 +407,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) 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++) for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<Vector4> targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X); Span<Vector4> targetRowSpan = this.targetValues.GetRowSpan(y).Slice(this.bounds.X);
for (int x = 0; x < this.bounds.Width; 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);
} }
} }
} }

15
src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs

@ -80,6 +80,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
private readonly struct RowIntervalAction : IRowIntervalAction<Vector4> private readonly struct RowIntervalAction : IRowIntervalAction<Vector4>
{ {
private readonly Rectangle bounds; private readonly Rectangle bounds;
private readonly int maxY;
private readonly int maxX;
private readonly Buffer2D<TPixel> targetPixels; private readonly Buffer2D<TPixel> targetPixels;
private readonly Buffer2D<TPixel> sourcePixels; private readonly Buffer2D<TPixel> sourcePixels;
private readonly DenseMatrix<float> kernelY; private readonly DenseMatrix<float> kernelY;
@ -98,6 +100,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
bool preserveAlpha) bool preserveAlpha)
{ {
this.bounds = bounds; this.bounds = bounds;
this.maxY = this.bounds.Bottom - 1;
this.maxX = this.bounds.Right - 1;
this.targetPixels = targetPixels; this.targetPixels = targetPixels;
this.sourcePixels = sourcePixels; this.sourcePixels = sourcePixels;
this.kernelY = kernelY; this.kernelY = kernelY;
@ -114,9 +118,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
int length = vectorSpan.Length; int length = vectorSpan.Length;
ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan); 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++) for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<TPixel> targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X); Span<TPixel> targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X);
@ -134,9 +135,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
y, y,
x, x,
this.bounds.Y, this.bounds.Y,
maxY, this.maxY,
this.bounds.X, this.bounds.X,
maxX); this.maxX);
} }
} }
else else
@ -151,9 +152,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
y, y,
x, x,
this.bounds.Y, this.bounds.Y,
maxY, this.maxY,
this.bounds.X, this.bounds.X,
maxX); this.maxX);
} }
} }

15
src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs

@ -71,6 +71,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
private readonly struct RowIntervalAction : IRowIntervalAction<Vector4> private readonly struct RowIntervalAction : IRowIntervalAction<Vector4>
{ {
private readonly Rectangle bounds; private readonly Rectangle bounds;
private readonly int maxY;
private readonly int maxX;
private readonly Buffer2D<TPixel> targetPixels; private readonly Buffer2D<TPixel> targetPixels;
private readonly Buffer2D<TPixel> sourcePixels; private readonly Buffer2D<TPixel> sourcePixels;
private readonly DenseMatrix<float> kernel; private readonly DenseMatrix<float> kernel;
@ -87,6 +89,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
bool preserveAlpha) bool preserveAlpha)
{ {
this.bounds = bounds; this.bounds = bounds;
this.maxY = this.bounds.Bottom - 1;
this.maxX = this.bounds.Right - 1;
this.targetPixels = targetPixels; this.targetPixels = targetPixels;
this.sourcePixels = sourcePixels; this.sourcePixels = sourcePixels;
this.kernel = kernel; this.kernel = kernel;
@ -102,9 +106,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
int length = vectorSpan.Length; int length = vectorSpan.Length;
ref Vector4 vectorSpanRef = ref MemoryMarshal.GetReference(vectorSpan); 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++) for (int y = rows.Min; y < rows.Max; y++)
{ {
Span<TPixel> targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X); Span<TPixel> targetRowSpan = this.targetPixels.GetRowSpan(y).Slice(this.bounds.X);
@ -121,9 +122,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
y, y,
x, x,
this.bounds.Y, this.bounds.Y,
maxY, this.maxY,
this.bounds.X, this.bounds.X,
maxX); this.maxX);
} }
} }
else else
@ -137,9 +138,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
y, y,
x, x,
this.bounds.Y, this.bounds.Y,
maxY, this.maxY,
this.bounds.X, this.bounds.X,
maxX); this.maxX);
} }
} }

Loading…
Cancel
Save