From c09a25426e111dac7c4055bce50dcd983decad39 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Sun, 26 Jan 2020 22:04:52 +0100 Subject: [PATCH] Fixed indexing of source row span --- .../Effects/OilPaintingProcessor{TPixel}.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 887ae6c8c..5d9010198 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -54,7 +54,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects int radius = brushSize >> 1; int levels = this.definition.Levels; - int width = this.SourceRectangle.Width; + int rowWidth = source.Width; + int rectangleWidth = this.SourceRectangle.Width; Configuration configuration = this.Configuration; @@ -68,9 +69,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects (rows) => { // Allocate the reusable source buffer, to enable vectorized bulk conversion - using IMemoryOwner sourceRowBuffer = configuration.MemoryAllocator.Allocate(width); + using IMemoryOwner sourceRowBuffer = configuration.MemoryAllocator.Allocate(rowWidth); - Span sourceRow = sourceRowBuffer.Memory.Span; + Span sourceRowVector4Span = sourceRowBuffer.Memory.Span; + Span sourceRowAreaVector4Span = sourceRowVector4Span.Slice(startX, rectangleWidth); // Rent the shared buffer only once per parallel item. using IMemoryOwner bins = configuration.MemoryAllocator.Allocate(levels * 4); @@ -83,7 +85,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects for (int y = rows.Min; y < rows.Max; y++) { - PixelOperations.Instance.ToVector4(configuration, source.GetPixelRowSpan(y), sourceRow); + Span sourceRowPixelSpan = source.GetPixelRowSpan(y); + Span sourceRowAreaPixelSpan = sourceRowPixelSpan.Slice(startX, rectangleWidth); + + PixelOperations.Instance.ToVector4(configuration, sourceRowAreaPixelSpan, sourceRowAreaVector4Span); Span targetRow = targetPixels.GetRowSpan(y); @@ -133,7 +138,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].W; + float alpha = sourceRowVector4Span[x].W; ref TPixel pixel = ref targetRow[x]; pixel.FromVector4(new Vector4(red, green, blue, alpha));