Browse Source

Fix span access

af/merge-core
James Jackson-South 7 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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -49,7 +49,7 @@ namespace SixLabors.ImageSharp.Primitives
using (IMemoryOwner<PointF> tempBuffer = configuration.MemoryAllocator.Allocate<PointF>(buffer.Length)) 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); int count = this.Shape.FindIntersections(start, end, innerBuffer);
for (int i = 0; i < count; i++) 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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -71,8 +71,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length)) using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length)) using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.GetSpan(); Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.GetSpan(); Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++) 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<float> amountBuffer = this.Target.MemoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = this.Target.MemoryAllocator.Allocate<TPixel>(scanline.Length)) using (IMemoryOwner<TPixel> overlay = this.Target.MemoryAllocator.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.GetSpan(); Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.GetSpan(); Span<TPixel> overlaySpan = overlay.Memory.Span;
int sourceY = (y - this.offsetY) % this.yLength; int sourceY = (y - this.offsetY) % this.yLength;
int offsetX = x - this.offsetX; 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<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length)) using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.GetSpan(); Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.GetSpan(); Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++) 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, sourceRectangle,
options)) options))
{ {
amount.GetSpan().Fill(1f); amount.Memory.Span.Fill(1f);
ParallelHelper.IterateRows( ParallelHelper.IterateRows(
workingRect, workingRect,
@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
int offsetY = y - startY; int offsetY = y - startY;
int offsetX = minX - startX; 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 subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / subpixelCount; float subpixelFractionPoint = subpixelFraction / subpixelCount;
Span<float> buffer = bBuffer.GetSpan(); Span<float> buffer = bBuffer.Memory.Span;
Span<float> scanline = bScanline.GetSpan(); Span<float> scanline = bScanline.Memory.Span;
bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush); bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush);
TPixel solidBrushColor = isSolidBrushWithoutBlending ? solidBrush.Color.ToPixel<TPixel>() : default; 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 subpixelFraction = 1f / subpixelCount;
float subpixelFractionPoint = subpixelFraction / 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++) 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 start = new PointF(path.Bounds.Left - 1, subPixel);
var end = new PointF(path.Bounds.Right + 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); int pointsFound = path.FindIntersections(start, end, intersectionSpan);
if (pointsFound == 0) 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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -151,8 +151,8 @@ namespace SixLabors.ImageSharp.Processing
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length)) using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length))
using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length)) using (IMemoryOwner<TPixel> overlay = memoryAllocator.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.GetSpan(); Span<float> amountSpan = amountBuffer.Memory.Span;
Span<TPixel> overlaySpan = overlay.GetSpan(); Span<TPixel> overlaySpan = overlay.Memory.Span;
for (int i = 0; i < scanline.Length; i++) 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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Processing
: base(source, options) : base(source, options)
{ {
this.Colors = source.MemoryAllocator.Allocate<TPixel>(source.Width); this.Colors = source.MemoryAllocator.Allocate<TPixel>(source.Width);
this.Colors.GetSpan().Fill(color); this.Colors.Memory.Span.Fill(color);
} }
/// <summary> /// <summary>
@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </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 /> /// <inheritdoc />
public override void Dispose() public override void Dispose()
@ -106,13 +106,13 @@ namespace SixLabors.ImageSharp.Processing
if (this.Options.BlendPercentage == 1f) 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 else
{ {
using (IMemoryOwner<float> amountBuffer = memoryAllocator.Allocate<float>(scanline.Length)) 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++) for (int i = 0; i < scanline.Length; i++)
{ {
@ -123,11 +123,11 @@ namespace SixLabors.ImageSharp.Processing
configuration, configuration,
destinationRow, destinationRow,
destinationRow, destinationRow,
this.Colors.GetSpan(), this.Colors.Memory.Span,
amountSpan); 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. // Licensed under the Apache License, Version 2.0.
using System; using System;
@ -98,9 +98,9 @@ namespace SixLabors.ImageSharp.Primitives
} }
/// <summary> /// <summary>
/// Gets a Span wrapping the Data. /// Gets a span wrapping the <see cref="Data"/>.
/// </summary> /// </summary>
internal Span<T> Span => new Span<T>(this.Data); public Span<T> Span => new Span<T>(this.Data);
/// <summary> /// <summary>
/// Gets or sets the item at the specified position. /// Gets or sets the item at the specified position.
@ -222,4 +222,4 @@ namespace SixLabors.ImageSharp.Primitives
/// <inheritdoc/> /// <inheritdoc/>
public override int GetHashCode() => this.Data.GetHashCode(); public override int GetHashCode() => this.Data.GetHashCode();
} }
} }

Loading…
Cancel
Save