Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Switch to shared sampling map for convolution passes
  • Loading branch information
Sergio0694 committed Dec 15, 2020
commit a9c165294e3424862b299cf12a1eedaef7d138b9
Original file line number Diff line number Diff line change
Expand Up @@ -67,45 +67,41 @@ protected override void OnFrameApply(ImageFrame<TPixel> source)
// for source and target bulk pixel conversion.
var operationBounds = new Rectangle(interest.X, interest.Y, interest.Width * 2, interest.Height);

using (var mapX = new KernelSamplingMap(this.Configuration.MemoryAllocator))
{
mapX.BuildSamplingOffsetMap(this.KernelX, interest);

// Horizontal convolution
var horizontalOperation = new HorizontalConvolutionRowOperation(
interest,
firstPassPixels,
source.PixelBuffer,
mapX,
this.KernelX,
this.Configuration,
this.PreserveAlpha);

ParallelRowIterator.IterateRows<HorizontalConvolutionRowOperation, Vector4>(
this.Configuration,
operationBounds,
in horizontalOperation);
}

using (var mapY = new KernelSamplingMap(this.Configuration.MemoryAllocator))
{
mapY.BuildSamplingOffsetMap(this.KernelY, interest);

// Vertical convolution
var verticalOperation = new VerticalConvolutionRowOperation(
interest,
source.PixelBuffer,
firstPassPixels,
mapY,
this.KernelY,
this.Configuration,
this.PreserveAlpha);

ParallelRowIterator.IterateRows<VerticalConvolutionRowOperation, Vector4>(
this.Configuration,
operationBounds,
in verticalOperation);
}
// 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.
using var mapXY = new KernelSamplingMap(this.Configuration.MemoryAllocator);

mapXY.BuildSamplingOffsetMap(this.KernelY.Rows, this.KernelX.Columns, interest);

// Horizontal convolution
var horizontalOperation = new HorizontalConvolutionRowOperation(
interest,
firstPassPixels,
source.PixelBuffer,
mapXY,
this.KernelX,
this.Configuration,
this.PreserveAlpha);

ParallelRowIterator.IterateRows<HorizontalConvolutionRowOperation, Vector4>(
this.Configuration,
operationBounds,
in horizontalOperation);

// Vertical convolution
var verticalOperation = new VerticalConvolutionRowOperation(
interest,
source.PixelBuffer,
firstPassPixels,
mapXY,
this.KernelY,
this.Configuration,
this.PreserveAlpha);

ParallelRowIterator.IterateRows<VerticalConvolutionRowOperation, Vector4>(
this.Configuration,
operationBounds,
in verticalOperation);
}

/// <summary>
Expand Down