From 525153834a3f8b6b2d2582bb18330c72ed20d5fa Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 4 Apr 2018 18:11:17 +1000 Subject: [PATCH] Use PixelOperations --- src/ImageSharp/ImageFrame{TPixel}.cs | 18 +++++++++--------- .../PixelFormats/Rgba32.PixelOperations.cs | 13 +++++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 1d9622aa49..cf7a1ae4fc 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -248,20 +248,20 @@ namespace SixLabors.ImageSharp var target = new ImageFrame(this.MemoryManager, this.Width, this.Height, this.MetaData.Clone()); - Parallel.For( + // TODO: ImageFrame has no visibility of the current configuration. It should have. + ParallelFor.WithTemporaryBuffer( 0, - target.Height, - Configuration.Default.ParallelOptions, - y => + this.Height, + Configuration.Default, + this.Width, + (int y, IBuffer tempRowBuffer) => { Span sourceRow = this.GetPixelRowSpan(y); Span targetRow = target.GetPixelRowSpan(y); + Span tempRowSpan = tempRowBuffer.Span; - for (int x = 0; x < target.Width; x++) - { - ref var pixel = ref targetRow[x]; - pixel.PackFromScaledVector4(sourceRow[x].ToScaledVector4()); - } + PixelOperations.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length); + PixelOperations.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length); }); return target; diff --git a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs index 7d5d632411..beb0bd3abe 100644 --- a/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs +++ b/src/ImageSharp/PixelFormats/Rgba32.PixelOperations.cs @@ -115,6 +115,7 @@ namespace SixLabors.ImageSharp.PixelFormats } } + /// internal override void PackFromVector4(ReadOnlySpan sourceVectors, Span destColors, int count) { GuardSpans(sourceVectors, nameof(sourceVectors), destColors, nameof(destColors), count); @@ -144,6 +145,18 @@ namespace SixLabors.ImageSharp.PixelFormats } } + /// + internal override void ToScaledVector4(ReadOnlySpan sourceColors, Span destinationVectors, int count) + { + this.ToVector4(sourceColors, destinationVectors, count); + } + + /// + internal override void PackFromScaledVector4(ReadOnlySpan sourceVectors, Span destinationColors, int count) + { + this.PackFromVector4(sourceVectors, destinationColors, count); + } + /// internal override void PackFromRgba32(ReadOnlySpan source, Span destPixels, int count) {