Browse Source

Refactored FilterProcessor<TPixel>

pull/1574/head
Sergio Pedri 6 years ago
parent
commit
f066dc0bbd
  1. 21
      src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs

21
src/ImageSharp/Processing/Processors/Filters/FilterProcessor{TPixel}.cs

@ -36,9 +36,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
protected override void OnFrameApply(ImageFrame<TPixel> source)
{
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
var operation = new RowIntervalOperation(interest.X, source, this.definition.Matrix, this.Configuration);
var operation = new RowOperation(interest.X, source, this.definition.Matrix, this.Configuration);
ParallelRowIterator.IterateRowIntervals<RowIntervalOperation, Vector4>(
ParallelRowIterator.IterateRows<RowOperation, Vector4>(
this.Configuration,
interest,
in operation);
@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <summary>
/// A <see langword="struct"/> implementing the convolution logic for <see cref="FilterProcessor{TPixel}"/>.
/// </summary>
private readonly struct RowIntervalOperation : IRowIntervalOperation<Vector4>
private readonly struct RowOperation : IRowOperation<Vector4>
{
private readonly int startX;
private readonly ImageFrame<TPixel> source;
@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
private readonly Configuration configuration;
[MethodImpl(InliningOptions.ShortMethod)]
public RowIntervalOperation(
public RowOperation(
int startX,
ImageFrame<TPixel> source,
ColorMatrix matrix,
@ -69,17 +69,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Filters
/// <inheritdoc/>
[MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows, Span<Vector4> span)
public void Invoke(int y, Span<Vector4> span)
{
for (int y = rows.Min; y < rows.Max; y++)
{
Span<TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
PixelOperations<TPixel>.Instance.ToVector4(this.configuration, rowSpan, span);
Span<TPixel> rowSpan = this.source.GetPixelRowSpan(y).Slice(this.startX, span.Length);
PixelOperations<TPixel>.Instance.ToVector4(this.configuration, rowSpan, span);
Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix));
Vector4Utils.Transform(span, ref Unsafe.AsRef(this.matrix));
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, span, rowSpan);
}
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, span, rowSpan);
}
}
}

Loading…
Cancel
Save