Browse Source

Switch to shared sampling map for convolution passes

js/color-alpha-handling
Sergio Pedri 6 years ago
parent
commit
82d0ba44cf
  1. 74
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs

74
src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs

@ -67,45 +67,41 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution
// for source and target bulk pixel conversion. // for source and target bulk pixel conversion.
var operationBounds = new Rectangle(interest.X, interest.Y, interest.Width * 2, interest.Height); var operationBounds = new Rectangle(interest.X, interest.Y, interest.Width * 2, interest.Height);
using (var mapX = new KernelSamplingMap(this.Configuration.MemoryAllocator)) // We can create a single sampling map with the size as if we were using the non separated 2D kernel
{ // the two 1D kernels represent, and reuse it across both convolution steps, like in the bokeh blur.
mapX.BuildSamplingOffsetMap(this.KernelX, interest); using var mapXY = new KernelSamplingMap(this.Configuration.MemoryAllocator);
// Horizontal convolution mapXY.BuildSamplingOffsetMap(this.KernelY.Rows, this.KernelX.Columns, interest);
var horizontalOperation = new HorizontalConvolutionRowOperation(
interest, // Horizontal convolution
firstPassPixels, var horizontalOperation = new HorizontalConvolutionRowOperation(
source.PixelBuffer, interest,
mapX, firstPassPixels,
this.KernelX, source.PixelBuffer,
this.Configuration, mapXY,
this.PreserveAlpha); this.KernelX,
this.Configuration,
ParallelRowIterator.IterateRows<HorizontalConvolutionRowOperation, Vector4>( this.PreserveAlpha);
this.Configuration,
operationBounds, ParallelRowIterator.IterateRows<HorizontalConvolutionRowOperation, Vector4>(
in horizontalOperation); this.Configuration,
} operationBounds,
in horizontalOperation);
using (var mapY = new KernelSamplingMap(this.Configuration.MemoryAllocator))
{ // Vertical convolution
mapY.BuildSamplingOffsetMap(this.KernelY, interest); var verticalOperation = new VerticalConvolutionRowOperation(
interest,
// Vertical convolution source.PixelBuffer,
var verticalOperation = new VerticalConvolutionRowOperation( firstPassPixels,
interest, mapXY,
source.PixelBuffer, this.KernelY,
firstPassPixels, this.Configuration,
mapY, this.PreserveAlpha);
this.KernelY,
this.Configuration, ParallelRowIterator.IterateRows<VerticalConvolutionRowOperation, Vector4>(
this.PreserveAlpha); this.Configuration,
operationBounds,
ParallelRowIterator.IterateRows<VerticalConvolutionRowOperation, Vector4>( in verticalOperation);
this.Configuration,
operationBounds,
in verticalOperation);
}
} }
/// <summary> /// <summary>

Loading…
Cancel
Save