From d2741422fc31c08dbd3c1becc8fe709d842669cd Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Fri, 7 Feb 2020 16:11:56 +0100 Subject: [PATCH] Refactor ImageFrame --- src/ImageSharp/ImageFrame{TPixel}.cs | 44 +++++++++++++++---- .../Resize/ResizeProcessor{TPixel}.cs | 2 +- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 88591af69..c3bab8e65 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -263,15 +263,7 @@ namespace SixLabors.ImageSharp ParallelRowIterator.IterateRows( this.Bounds(), configuration, - rows => - { - for (int y = rows.Min; y < rows.Max; y++) - { - Span sourceRow = this.GetPixelRowSpan(y); - Span targetRow = target.GetPixelRowSpan(y); - PixelOperations.Instance.To(configuration, sourceRow, targetRow); - } - }); + new RowIntervalAction(this, target, configuration)); return target; } @@ -293,5 +285,39 @@ namespace SixLabors.ImageSharp span.Fill(value); } } + + /// + /// A implementing the clone logic for . + /// + private readonly struct RowIntervalAction : IRowIntervalAction + where TPixel2 : struct, IPixel + { + private readonly ImageFrame source; + private readonly ImageFrame target; + private readonly Configuration configuration; + + [MethodImpl(InliningOptions.ShortMethod)] + public RowIntervalAction( + ImageFrame source, + ImageFrame target, + Configuration configuration) + { + this.source = source; + this.target = target; + this.configuration = configuration; + } + + /// + [MethodImpl(InliningOptions.ShortMethod)] + public void Invoke(in RowInterval rows) + { + for (int y = rows.Min; y < rows.Max; y++) + { + Span sourceRow = this.source.GetPixelRowSpan(y); + Span targetRow = this.target.GetPixelRowSpan(y); + PixelOperations.Instance.To(this.configuration, sourceRow, targetRow); + } + } + } } } diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs index 4a986adb0..02622622d 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeProcessor{TPixel}.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms private readonly int targetWidth; private readonly int targetHeight; private readonly IResampler resampler; - private Rectangle targetRectangle; + private readonly Rectangle targetRectangle; private readonly bool compand; // The following fields are not immutable but are optionally created on demand.