diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs index ee52d72cb..11887433c 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor{TPixel}.cs @@ -60,15 +60,13 @@ namespace SixLabors.ImageSharp.Processing.Processors.Overlays Configuration configuration = this.Configuration; MemoryAllocator allocator = configuration.MemoryAllocator; - using (IMemoryOwner rowColors = allocator.Allocate(interest.Width)) - { - rowColors.GetSpan().Fill(vignetteColor); + using IMemoryOwner rowColors = allocator.Allocate(interest.Width); + rowColors.GetSpan().Fill(vignetteColor); - ParallelRowIterator.IterateRows( - interest, - configuration, - new RowIntervalAction(configuration, interest, rowColors, this.blender, center, maxDistance, blendPercent, source)); - } + ParallelRowIterator.IterateRows( + interest, + configuration, + new RowIntervalAction(configuration, interest, rowColors, this.blender, center, maxDistance, blendPercent, source)); } private readonly struct RowIntervalAction : IRowIntervalAction diff --git a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs index c01cdd8ef..041f602a5 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/FlipProcessor{TPixel}.cs @@ -3,7 +3,9 @@ using System; using System.Buffers; +using System.Runtime.CompilerServices; using SixLabors.ImageSharp.Advanced; +using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.PixelFormats; namespace SixLabors.ImageSharp.Processing.Processors.Transforms @@ -53,20 +55,17 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms private void FlipX(ImageFrame source, Configuration configuration) { int height = source.Height; + using IMemoryOwner tempBuffer = configuration.MemoryAllocator.Allocate(source.Width); + Span temp = tempBuffer.Memory.Span; - using (IMemoryOwner tempBuffer = configuration.MemoryAllocator.Allocate(source.Width)) + for (int yTop = 0; yTop < height / 2; yTop++) { - Span temp = tempBuffer.Memory.Span; - - for (int yTop = 0; yTop < height / 2; yTop++) - { - int yBottom = height - yTop - 1; - Span topRow = source.GetPixelRowSpan(yBottom); - Span bottomRow = source.GetPixelRowSpan(yTop); - topRow.CopyTo(temp); - bottomRow.CopyTo(topRow); - temp.CopyTo(bottomRow); - } + int yBottom = height - yTop - 1; + Span topRow = source.GetPixelRowSpan(yBottom); + Span bottomRow = source.GetPixelRowSpan(yTop); + topRow.CopyTo(temp); + bottomRow.CopyTo(topRow); + temp.CopyTo(bottomRow); } } @@ -80,13 +79,24 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms ParallelRowIterator.IterateRows( source.Bounds(), configuration, - rows => - { - for (int y = rows.Min; y < rows.Max; y++) - { - source.GetPixelRowSpan(y).Reverse(); - } - }); + new RowIntervalAction(source)); + } + + private readonly struct RowIntervalAction : IRowIntervalAction + { + private readonly ImageFrame source; + + [MethodImpl(InliningOptions.ShortMethod)] + public RowIntervalAction(ImageFrame source) => this.source = source; + + [MethodImpl(InliningOptions.ShortMethod)] + public void Invoke(in RowInterval rows) + { + for (int y = rows.Min; y < rows.Max; y++) + { + this.source.GetPixelRowSpan(y).Reverse(); + } + } } } }