Browse Source

Refactored BackgroundColorProcessor<TPixel>

pull/1132/head
Sergio Pedri 6 years ago
parent
commit
7c1d297f5c
  1. 35
      src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs

35
src/ImageSharp/Processing/Processors/Overlays/BackgroundColorProcessor{TPixel}.cs

@ -49,14 +49,14 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(graphicsOptions); PixelBlender<TPixel> blender = PixelOperations<TPixel>.Instance.GetPixelBlender(graphicsOptions);
var operation = new RowIntervalOperation(configuration, interest, blender, amount, colors, source); var operation = new RowOperation(configuration, interest, blender, amount, colors, source);
ParallelRowIterator.IterateRowIntervals( ParallelRowIterator.IterateRows(
configuration, configuration,
interest, interest,
in operation); in operation);
} }
private readonly struct RowIntervalOperation : IRowIntervalOperation private readonly struct RowOperation : IRowOperation
{ {
private readonly Configuration configuration; private readonly Configuration configuration;
private readonly Rectangle bounds; private readonly Rectangle bounds;
@ -66,7 +66,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
private readonly ImageFrame<TPixel> source; private readonly ImageFrame<TPixel> source;
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public RowIntervalOperation( public RowOperation(
Configuration configuration, Configuration configuration,
Rectangle bounds, Rectangle bounds,
PixelBlender<TPixel> blender, PixelBlender<TPixel> blender,
@ -83,23 +83,20 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays
} }
[MethodImpl(InliningOptions.ShortMethod)] [MethodImpl(InliningOptions.ShortMethod)]
public void Invoke(in RowInterval rows) public void Invoke(int y)
{ {
for (int y = rows.Min; y < rows.Max; y++) Span<TPixel> destination =
{ this.source.GetPixelRowSpan(y)
Span<TPixel> destination = .Slice(this.bounds.X, this.bounds.Width);
this.source.GetPixelRowSpan(y)
.Slice(this.bounds.X, this.bounds.Width);
// Switch color & destination in the 2nd and 3rd places because we are // Switch color & destination in the 2nd and 3rd places because we are
// applying the target color under the current one. // applying the target color under the current one.
this.blender.Blend( this.blender.Blend(
this.configuration, this.configuration,
destination, destination,
this.colors.GetSpan(), this.colors.GetSpan(),
destination, destination,
this.amount.GetSpan()); this.amount.GetSpan());
}
} }
} }
} }

Loading…
Cancel
Save