Browse Source

Fixed indexing of source row span

af/octree-no-pixelmap
Sergio Pedri 6 years ago
parent
commit
c09a25426e
  1. 15
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

15
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<Vector4> sourceRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(width);
using IMemoryOwner<Vector4> sourceRowBuffer = configuration.MemoryAllocator.Allocate<Vector4>(rowWidth);
Span<Vector4> sourceRow = sourceRowBuffer.Memory.Span;
Span<Vector4> sourceRowVector4Span = sourceRowBuffer.Memory.Span;
Span<Vector4> sourceRowAreaVector4Span = sourceRowVector4Span.Slice(startX, rectangleWidth);
// Rent the shared buffer only once per parallel item.
using IMemoryOwner<float> bins = configuration.MemoryAllocator.Allocate<float>(levels * 4);
@ -83,7 +85,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
for (int y = rows.Min; y < rows.Max; y++)
{
PixelOperations<TPixel>.Instance.ToVector4(configuration, source.GetPixelRowSpan(y), sourceRow);
Span<TPixel> sourceRowPixelSpan = source.GetPixelRowSpan(y);
Span<TPixel> sourceRowAreaPixelSpan = sourceRowPixelSpan.Slice(startX, rectangleWidth);
PixelOperations<TPixel>.Instance.ToVector4(configuration, sourceRowAreaPixelSpan, sourceRowAreaVector4Span);
Span<TPixel> 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));

Loading…
Cancel
Save