From a8650aa5f10e785c54c3ccd3cba9adead7f6eff2 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 26 Jan 2020 21:47:41 +0100 Subject: [PATCH] Reintroduced bulk ToVector4 source conversion --- .../Effects/OilPaintingProcessor{TPixel}.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index d8e2eec166..887ae6c8c7 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -54,6 +54,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects int radius = brushSize >> 1; int levels = this.definition.Levels; + int width = this.SourceRectangle.Width; Configuration configuration = this.Configuration; @@ -66,6 +67,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects this.Configuration, (rows) => { + // Allocate the reusable source buffer, to enable vectorized bulk conversion + using IMemoryOwner sourceRowBuffer = configuration.MemoryAllocator.Allocate(width); + + Span sourceRow = sourceRowBuffer.Memory.Span; + // Rent the shared buffer only once per parallel item. using IMemoryOwner bins = configuration.MemoryAllocator.Allocate(levels * 4); @@ -77,7 +83,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects for (int y = rows.Min; y < rows.Max; y++) { - Span sourceRow = source.GetPixelRowSpan(y); + PixelOperations.Instance.ToVector4(configuration, source.GetPixelRowSpan(y), sourceRow); + Span targetRow = targetPixels.GetRowSpan(y); for (int x = startX; x < endX; x++) @@ -126,7 +133,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects float red = MathF.Abs(Unsafe.Add(ref redBinRef, maxIndex) / maxIntensity); float blue = MathF.Abs(Unsafe.Add(ref blueBinRef, maxIndex) / maxIntensity); float green = MathF.Abs(Unsafe.Add(ref greenBinRef, maxIndex) / maxIntensity); - float alpha = sourceRow[x].ToVector4().W; + float alpha = sourceRow[x].W; ref TPixel pixel = ref targetRow[x]; pixel.FromVector4(new Vector4(red, green, blue, alpha));