Browse Source

Fix span access

af/merge-core
James Jackson-South 6 years ago
parent
commit
b5957e578e
  1. 6
      src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
  2. 6
      src/ImageSharp.Drawing/Processing/BrushApplicator.cs
  3. 4
      src/ImageSharp.Drawing/Processing/ImageBrush.cs
  4. 4
      src/ImageSharp.Drawing/Processing/PatternBrush.cs
  5. 4
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs
  6. 4
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs
  7. 4
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs
  8. 8
      src/ImageSharp.Drawing/Processing/RecolorBrush.cs
  9. 14
      src/ImageSharp.Drawing/Processing/SolidBrush.cs
  10. 8
      src/ImageSharp/Primitives/DenseMatrix{T}.cs

6
src/ImageSharp.Drawing/Primitives/ShapeRegion.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Primitives
using (IMemoryOwner<PointF> tempBuffer = configuration.MemoryAllocator.Allocate<PointF>(buffer.Length))
{
Span<PointF> innerBuffer = tempBuffer.GetSpan();
Span<PointF> innerBuffer = tempBuffer.Memory.Span;
int count = this.Shape.FindIntersections(start, end, innerBuffer);
for (int i = 0; i < count; i++)
@ -61,4 +61,4 @@ namespace SixLabors.ImageSharp.Primitives
}
}
}
}
}

6
src/ImageSharp.Drawing/Processing/BrushApplicator.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -71,8 +71,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++)
{

4
src/ImageSharp.Drawing/Processing/ImageBrush.cs

@ -140,8 +140,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = this.Target.MemoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = this.Target.MemoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.Memory.Span;
int sourceY = (y - this.offsetY) % this.yLength;
int offsetX = x - this.offsetX;

4
src/ImageSharp.Drawing/Processing/PatternBrush.cs

@ -159,8 +159,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++)
{

4
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs

@ -88,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
sourceRectangle,
options))
{
amount.GetSpan().Fill(1f);
amount.Memory.Span.Fill(1f);
ParallelHelper.IterateRows(
workingRect,
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
int offsetY = y - startY;
int offsetX = minX - startX;
applicator.Apply(amount.GetSpan(), offsetX, offsetY);
applicator.Apply(amount.Memory.Span, offsetX, offsetY);
}
});
}

4
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs

@ -81,8 +81,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
float subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount;
Span<float> buffer = bBuffer.GetSpan();
Span<float> scanline = bScanline.GetSpan();
Span<float> buffer = bBuffer.Memory.Span;
Span<float> scanline = bScanline.Memory.Span;
bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush);
TPixel solidBrushColor = isSolidBrushWithoutBlending ? solidBrush.Color.ToPixel<TPixel>() : default;

4
src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs

@ -326,6 +326,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
{
float subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount;
Span<PointF> intersectionSpan = rowIntersectionBuffer.Memory.Span;
Span<float> buffer = bufferBacking.Memory.Span;
for (int y = 0; y <= size.Height; y++)
{
@ -337,8 +339,6 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
{
var start = new PointF(path.Bounds.Left - 1, subPixel);
var end = new PointF(path.Bounds.Right + 1, subPixel);
Span<PointF> intersectionSpan = rowIntersectionBuffer.GetSpan();
Span<float> buffer = bufferBacking.GetSpan();
int pointsFound = path.FindIntersections(start, end, intersectionSpan);
if (pointsFound == 0)

8
src/ImageSharp.Drawing/Processing/RecolorBrush.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -151,8 +151,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.GetSpan();
Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++)
{
@ -176,4 +176,4 @@ namespace SixLabors.ImageSharp.Processing
}
}
}
}
}

14
src/ImageSharp.Drawing/Processing/SolidBrush.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Processing
: base(source, options)
{
this.Colors = source.MemoryAllocator.Allocate<TPixel>(source.Width);
this.Colors.GetSpan().Fill(color);
this.Colors.Memory.Span.Fill(color);
}
/// <summary>
@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns>
/// The color
/// </returns>
internal override TPixel this[int x, int y] => this.Colors.GetSpan()[x];
internal override TPixel this[int x, int y] => this.Colors.Memory.Span[x];
/// <inheritdoc />
public override void Dispose()
@ -106,13 +106,13 @@ namespace SixLabors.ImageSharp.Processing
if (this.Options.BlendPercentage == 1f)
{
this.Blender.Blend(configuration, destinationRow, destinationRow, this.Colors.GetSpan(), scanline);
this.Blender.Blend(configuration, destinationRow, destinationRow, this.Colors.Memory.Span, scanline);
}
else
{
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
{
Span<float> amountSpan = amountBuffer.GetSpan();
Span<float> amountSpan = amountBuffer.Memory.Span;
for (int i = 0; i < scanline.Length; i++)
{
@ -123,11 +123,11 @@ namespace SixLabors.ImageSharp.Processing
configuration,
destinationRow,
destinationRow,
this.Colors.GetSpan(),
this.Colors.Memory.Span,
amountSpan);
}
}
}
}
}
}
}

8
src/ImageSharp/Primitives/DenseMatrix{T}.cs

@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
@ -98,9 +98,9 @@ namespace SixLabors.ImageSharp.Primitives
}
/// <summary>
/// Gets a Span wrapping the Data.
/// Gets a span wrapping the <see cref="Data"/>.
/// </summary>
internal Span<T> Span => new Span<T>(this.Data);
public Span<T> Span => new Span<T>(this.Data);
/// <summary>
/// Gets or sets the item at the specified position.
@ -222,4 +222,4 @@ namespace SixLabors.ImageSharp.Primitives
/// <inheritdoc/>
public override int GetHashCode() => this.Data.GetHashCode();
}
}
}

Loading…
Cancel
Save