From b5957e578ee177bbd3b040c28437686ce2a890f9 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 5 Nov 2019 21:18:38 +1100 Subject: [PATCH] Fix span access --- src/ImageSharp.Drawing/Primitives/ShapeRegion.cs | 6 +++--- .../Processing/BrushApplicator.cs | 6 +++--- src/ImageSharp.Drawing/Processing/ImageBrush.cs | 4 ++-- src/ImageSharp.Drawing/Processing/PatternBrush.cs | 4 ++-- .../Processors/Drawing/FillProcessor{TPixel}.cs | 4 ++-- .../Drawing/FillRegionProcessor{TPixel}.cs | 4 ++-- .../Processors/Text/DrawTextProcessor{TPixel}.cs | 4 ++-- src/ImageSharp.Drawing/Processing/RecolorBrush.cs | 8 ++++---- src/ImageSharp.Drawing/Processing/SolidBrush.cs | 14 +++++++------- src/ImageSharp/Primitives/DenseMatrix{T}.cs | 8 ++++---- 10 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs b/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs index f4a645820..c008f4419 100644 --- a/src/ImageSharp.Drawing/Primitives/ShapeRegion.cs +++ b/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 tempBuffer = configuration.MemoryAllocator.Allocate(buffer.Length)) { - Span innerBuffer = tempBuffer.GetSpan(); + Span 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 } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/BrushApplicator.cs index 7e75d7eff..ab601bb8b 100644 --- a/src/ImageSharp.Drawing/Processing/BrushApplicator.cs +++ b/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 amountBuffer = memoryAllocator.Allocate(scanline.Length)) using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.GetSpan(); - Span overlaySpan = overlay.GetSpan(); + Span amountSpan = amountBuffer.Memory.Span; + Span overlaySpan = overlay.Memory.Span; for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/ImageBrush.cs b/src/ImageSharp.Drawing/Processing/ImageBrush.cs index d56b1fccc..ebcc2c067 100644 --- a/src/ImageSharp.Drawing/Processing/ImageBrush.cs +++ b/src/ImageSharp.Drawing/Processing/ImageBrush.cs @@ -140,8 +140,8 @@ namespace SixLabors.ImageSharp.Processing using (IMemoryOwner amountBuffer = this.Target.MemoryAllocator.Allocate(scanline.Length)) using (IMemoryOwner overlay = this.Target.MemoryAllocator.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.GetSpan(); - Span overlaySpan = overlay.GetSpan(); + Span amountSpan = amountBuffer.Memory.Span; + Span overlaySpan = overlay.Memory.Span; int sourceY = (y - this.offsetY) % this.yLength; int offsetX = x - this.offsetX; diff --git a/src/ImageSharp.Drawing/Processing/PatternBrush.cs b/src/ImageSharp.Drawing/Processing/PatternBrush.cs index d0db44bb3..1b7db970a 100644 --- a/src/ImageSharp.Drawing/Processing/PatternBrush.cs +++ b/src/ImageSharp.Drawing/Processing/PatternBrush.cs @@ -159,8 +159,8 @@ namespace SixLabors.ImageSharp.Processing using (IMemoryOwner amountBuffer = memoryAllocator.Allocate(scanline.Length)) using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.GetSpan(); - Span overlaySpan = overlay.GetSpan(); + Span amountSpan = amountBuffer.Memory.Span; + Span overlaySpan = overlay.Memory.Span; for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs index 4e052818d..1dd4be135 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs +++ b/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); } }); } diff --git a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs index 45d5015ae..69f97ce75 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor{TPixel}.cs +++ b/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 buffer = bBuffer.GetSpan(); - Span scanline = bScanline.GetSpan(); + Span buffer = bBuffer.Memory.Span; + Span scanline = bScanline.Memory.Span; bool isSolidBrushWithoutBlending = this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush); TPixel solidBrushColor = isSolidBrushWithoutBlending ? solidBrush.Color.ToPixel() : default; diff --git a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs index ea042635d..c2e38f67b 100644 --- a/src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor{TPixel}.cs +++ b/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 intersectionSpan = rowIntersectionBuffer.Memory.Span; + Span 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 intersectionSpan = rowIntersectionBuffer.GetSpan(); - Span buffer = bufferBacking.GetSpan(); int pointsFound = path.FindIntersections(start, end, intersectionSpan); if (pointsFound == 0) diff --git a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs b/src/ImageSharp.Drawing/Processing/RecolorBrush.cs index fca95be32..d93110972 100644 --- a/src/ImageSharp.Drawing/Processing/RecolorBrush.cs +++ b/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 amountBuffer = memoryAllocator.Allocate(scanline.Length)) using (IMemoryOwner overlay = memoryAllocator.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.GetSpan(); - Span overlaySpan = overlay.GetSpan(); + Span amountSpan = amountBuffer.Memory.Span; + Span overlaySpan = overlay.Memory.Span; for (int i = 0; i < scanline.Length; i++) { @@ -176,4 +176,4 @@ namespace SixLabors.ImageSharp.Processing } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp.Drawing/Processing/SolidBrush.cs b/src/ImageSharp.Drawing/Processing/SolidBrush.cs index c62566f6b..71738de52 100644 --- a/src/ImageSharp.Drawing/Processing/SolidBrush.cs +++ b/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(source.Width); - this.Colors.GetSpan().Fill(color); + this.Colors.Memory.Span.Fill(color); } /// @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Processing /// /// The color /// - 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]; /// 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 amountBuffer = memoryAllocator.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.GetSpan(); + Span 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); } } } } } -} \ No newline at end of file +} diff --git a/src/ImageSharp/Primitives/DenseMatrix{T}.cs b/src/ImageSharp/Primitives/DenseMatrix{T}.cs index 170292e29..cc5e4a90a 100644 --- a/src/ImageSharp/Primitives/DenseMatrix{T}.cs +++ b/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 } /// - /// Gets a Span wrapping the Data. + /// Gets a span wrapping the . /// - internal Span Span => new Span(this.Data); + public Span Span => new Span(this.Data); /// /// Gets or sets the item at the specified position. @@ -222,4 +222,4 @@ namespace SixLabors.ImageSharp.Primitives /// public override int GetHashCode() => this.Data.GetHashCode(); } -} \ No newline at end of file +}