Browse Source

Change IBuffer<T>.Span to IBuffer<T>.GetSpan() to match System.Buffers.MemoryManager<T> API

af/merge-core
Anton Firszov 8 years ago
parent
commit
e610fd0f7a
  1. 4
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs
  2. 4
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs
  3. 4
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs
  4. 4
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs
  5. 10
      src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs
  6. 4
      src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs
  7. 4
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs
  8. 2
      src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs
  9. 6
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  10. 4
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  11. 6
      src/ImageSharp/Formats/Gif/GifDecoderCore.cs
  12. 2
      src/ImageSharp/Formats/Gif/GifEncoderCore.cs
  13. 6
      src/ImageSharp/Formats/Gif/LzwDecoder.cs
  14. 6
      src/ImageSharp/Formats/Gif/LzwEncoder.cs
  15. 4
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs
  16. 4
      src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs
  17. 8
      src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs
  18. 28
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  19. 32
      src/ImageSharp/Formats/Png/PngEncoderCore.cs
  20. 2
      src/ImageSharp/Image.Decode.cs
  21. 2
      src/ImageSharp/ImageFrame{TPixel}.cs
  22. 2
      src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs
  23. 7
      src/ImageSharp/Memory/BasicArrayBuffer.cs
  24. 4
      src/ImageSharp/Memory/Buffer2D{T}.cs
  25. 10
      src/ImageSharp/Memory/BufferExtensions.cs
  26. 3
      src/ImageSharp/Memory/IBuffer{T}.cs
  27. 6
      src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs
  28. 6
      src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs
  29. 6
      src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs
  30. 106
      src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs
  31. 2
      src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs
  32. 2
      src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs
  33. 8
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs
  34. 8
      tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs
  35. 2
      tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs
  36. 6
      tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs
  37. 2
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
  38. 22
      tests/ImageSharp.Tests/Memory/BufferTestSuite.cs
  39. 36
      tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs
  40. 8
      tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs

4
src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs

@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++) for (int i = 0; i < scanline.Length; i++)
{ {

4
src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs

@ -121,8 +121,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = this.Target.MemoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = this.Target.MemoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.GetSpan();
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/Drawing/Brushes/PatternBrush{TPixel}.cs

@ -156,8 +156,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++) for (int i = 0; i < scanline.Length; i++)
{ {

4
src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length)) using (IBuffer<TPixel> overlay = memoryManager.Allocate<TPixel>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.GetSpan();
Span<TPixel> overlaySpan = overlay.Span; Span<TPixel> overlaySpan = overlay.GetSpan();
for (int i = 0; i < scanline.Length; i++) for (int i = 0; i < scanline.Length; i++)
{ {

10
src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs

@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
: base(source, options) : base(source, options)
{ {
this.Colors = source.MemoryManager.Allocate<TPixel>(source.Width); this.Colors = source.MemoryManager.Allocate<TPixel>(source.Width);
this.Colors.Span.Fill(color); this.Colors.GetSpan().Fill(color);
} }
/// <summary> /// <summary>
@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
/// <returns> /// <returns>
/// The color /// The color
/// </returns> /// </returns>
internal override TPixel this[int x, int y] => this.Colors.Span[x]; internal override TPixel this[int x, int y] => this.Colors.GetSpan()[x];
/// <inheritdoc /> /// <inheritdoc />
public override void Dispose() public override void Dispose()
@ -92,20 +92,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes
if (this.Options.BlendPercentage == 1f) if (this.Options.BlendPercentage == 1f)
{ {
this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, scanline); this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), scanline);
} }
else else
{ {
using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length)) using (IBuffer<float> amountBuffer = memoryManager.Allocate<float>(scanline.Length))
{ {
Span<float> amountSpan = amountBuffer.Span; Span<float> amountSpan = amountBuffer.GetSpan();
for (int i = 0; i < scanline.Length; i++) for (int i = 0; i < scanline.Length; i++)
{ {
amountSpan[i] = scanline[i] * this.Options.BlendPercentage; amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
} }
this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.Span, amountSpan); this.Blender.Blend(memoryManager, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan);
} }
} }
} }

4
src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs

@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
using (IBuffer<float> amount = memoryManager.Allocate<float>(width)) using (IBuffer<float> amount = memoryManager.Allocate<float>(width))
{ {
amount.Span.Fill(this.Opacity); amount.GetSpan().Fill(this.Opacity);
Parallel.For( Parallel.For(
minY, minY,
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
{ {
Span<TPixel> background = source.GetPixelRowSpan(y).Slice(minX, width); Span<TPixel> background = source.GetPixelRowSpan(y).Slice(minX, width);
Span<TPixel> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); Span<TPixel> foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width);
blender.Blend(memoryManager, background, background, foreground, amount.Span); blender.Blend(memoryManager, background, background, foreground, amount.GetSpan());
}); });
} }
} }

4
src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs

@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
sourceRectangle, sourceRectangle,
this.options)) this.options))
{ {
amount.Span.Fill(1f); amount.GetSpan().Fill(1f);
Parallel.For( Parallel.For(
minY, minY,
@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
int offsetY = y - startY; int offsetY = y - startY;
int offsetX = minX - startX; int offsetX = minX - startX;
applicator.Apply(amount.Span, offsetX, offsetY); applicator.Apply(amount.GetSpan(), offsetX, offsetY);
}); });
} }
} }

2
src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs

@ -181,7 +181,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors
} }
} }
applicator.Apply(scanline.Span, minX, y); applicator.Apply(scanline.GetSpan(), minX, y);
} }
} }
} }

6
src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs

@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
TPixel color = default; TPixel color = default;
var rgba = new Rgba32(0, 0, 0, 255); var rgba = new Rgba32(0, 0, 0, 255);
Span<byte> rowSpan = row.Span; Span<byte> rowSpan = row.GetSpan();
for (int y = 0; y < height; y++) for (int y = 0; y < height; y++)
{ {
@ -434,7 +434,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
this.stream.Read(row); this.stream.Read(row);
int newY = Invert(y, height, inverted); int newY = Invert(y, height, inverted);
Span<TPixel> pixelSpan = pixels.GetRowSpan(newY); Span<TPixel> pixelSpan = pixels.GetRowSpan(newY);
PixelOperations<TPixel>.Instance.PackFromBgr24Bytes(row.Span, pixelSpan, width); PixelOperations<TPixel>.Instance.PackFromBgr24Bytes(row.GetSpan(), pixelSpan, width);
} }
} }
} }
@ -459,7 +459,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
this.stream.Read(row); this.stream.Read(row);
int newY = Invert(y, height, inverted); int newY = Invert(y, height, inverted);
Span<TPixel> pixelSpan = pixels.GetRowSpan(newY); Span<TPixel> pixelSpan = pixels.GetRowSpan(newY);
PixelOperations<TPixel>.Instance.PackFromBgra32Bytes(row.Span, pixelSpan, width); PixelOperations<TPixel>.Instance.PackFromBgra32Bytes(row.GetSpan(), pixelSpan, width);
} }
} }
} }

4
src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs

@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)
{ {
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
PixelOperations<TPixel>.Instance.ToBgra32Bytes(pixelSpan, row.Span, pixelSpan.Length); PixelOperations<TPixel>.Instance.ToBgra32Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length);
stream.Write(row.Array, 0, row.Length()); stream.Write(row.Array, 0, row.Length());
} }
} }
@ -146,7 +146,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
for (int y = pixels.Height - 1; y >= 0; y--) for (int y = pixels.Height - 1; y >= 0; y--)
{ {
Span<TPixel> pixelSpan = pixels.GetRowSpan(y); Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
PixelOperations<TPixel>.Instance.ToBgr24Bytes(pixelSpan, row.Span, pixelSpan.Length); PixelOperations<TPixel>.Instance.ToBgr24Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length);
stream.Write(row.Array, 0, row.Length()); stream.Write(row.Array, 0, row.Length());
} }
} }

6
src/ImageSharp/Formats/Gif/GifDecoderCore.cs

@ -327,9 +327,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
indices = this.configuration.MemoryManager.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true); indices = this.configuration.MemoryManager.AllocateManagedByteBuffer(imageDescriptor.Width * imageDescriptor.Height, true);
this.ReadFrameIndices(imageDescriptor, indices.Span); this.ReadFrameIndices(imageDescriptor, indices.GetSpan());
ReadOnlySpan<Rgb24> colorTable = MemoryMarshal.Cast<byte, Rgb24>((localColorTable ?? this.globalColorTable).Span); ReadOnlySpan<Rgb24> colorTable = MemoryMarshal.Cast<byte, Rgb24>((localColorTable ?? this.globalColorTable).GetSpan());
this.ReadFrameColors(ref image, ref previousFrame, indices.Span, colorTable, imageDescriptor); this.ReadFrameColors(ref image, ref previousFrame, indices.GetSpan(), colorTable, imageDescriptor);
// Skip any remaining blocks // Skip any remaining blocks
this.Skip(0); this.Skip(0);

2
src/ImageSharp/Formats/Gif/GifEncoderCore.cs

@ -320,7 +320,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength))
{ {
ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan()); ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan());
ref Rgb24 rgb24Ref = ref Unsafe.As<byte, Rgb24>(ref MemoryMarshal.GetReference(colorTable.Span)); ref Rgb24 rgb24Ref = ref Unsafe.As<byte, Rgb24>(ref MemoryMarshal.GetReference(colorTable.GetSpan()));
for (int i = 0; i < pixelCount; i++) for (int i = 0; i < pixelCount; i++)
{ {
ref TPixel entry = ref Unsafe.Add(ref paletteRef, i); ref TPixel entry = ref Unsafe.Add(ref paletteRef, i);

6
src/ImageSharp/Formats/Gif/LzwDecoder.cs

@ -102,9 +102,9 @@ namespace SixLabors.ImageSharp.Formats.Gif
int data = 0; int data = 0;
int first = 0; int first = 0;
ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.Span); ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.GetSpan());
ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.Span); ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.GetSpan());
ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.Span); ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.GetSpan());
ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels); ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels);
for (code = 0; code < clearCode; code++) for (code = 0; code < clearCode; code++)

6
src/ImageSharp/Formats/Gif/LzwEncoder.cs

@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Gif
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ResetCodeTable() private void ResetCodeTable()
{ {
this.hashTable.Span.Fill(-1); this.hashTable.GetSpan().Fill(-1);
} }
/// <summary> /// <summary>
@ -293,8 +293,8 @@ namespace SixLabors.ImageSharp.Formats.Gif
this.Output(this.clearCode, stream); this.Output(this.clearCode, stream);
ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.Span); ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan());
ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.Span); ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan());
while (this.position < this.pixelArray.Length) while (this.position < this.pixelArray.Length)
{ {

4
src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs

@ -155,11 +155,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder
int y = yy - this.PixelRowCounter; int y = yy - this.PixelRowCounter;
var values = new JpegColorConverter.ComponentValues(buffers, y); var values = new JpegColorConverter.ComponentValues(buffers, y);
this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.Span); this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan());
Span<TPixel> destRow = destination.GetPixelRowSpan(yy); Span<TPixel> destRow = destination.GetPixelRowSpan(yy);
PixelOperations<TPixel>.Instance.PackFromVector4(this.rgbaBuffer.Span, destRow, destination.Width); PixelOperations<TPixel>.Instance.PackFromVector4(this.rgbaBuffer.GetSpan(), destRow, destination.Width);
} }
} }
} }

4
src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs

@ -46,8 +46,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components
using (IBuffer<short> huffsize = memoryManager.Allocate<short>(length)) using (IBuffer<short> huffsize = memoryManager.Allocate<short>(length))
using (IBuffer<short> huffcode = memoryManager.Allocate<short>(length)) using (IBuffer<short> huffcode = memoryManager.Allocate<short>(length))
{ {
ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.Span); ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan());
ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span); ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan());
GenerateSizeTable(lengths, ref huffsizeRef); GenerateSizeTable(lengths, ref huffsizeRef);
GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length); GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length);

8
src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs

@ -705,7 +705,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
using (IManagedByteBuffer huffmanData = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(256)) using (IManagedByteBuffer huffmanData = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(256))
{ {
ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.Span); ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan());
for (int i = 2; i < remaining;) for (int i = 2; i < remaining;)
{ {
byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); byte huffmanTableSpec = (byte)this.InputStream.ReadByte();
@ -713,7 +713,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
using (IManagedByteBuffer codeLengths = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(17)) using (IManagedByteBuffer codeLengths = this.configuration.MemoryManager.AllocateCleanManagedByteBuffer(17))
{ {
ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.Span); ref byte codeLengthsRef = ref MemoryMarshal.GetReference(codeLengths.GetSpan());
int codeLengthSum = 0; int codeLengthSum = 0;
for (int j = 1; j < 17; j++) for (int j = 1; j < 17; j++)
@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort
this.BuildHuffmanTable( this.BuildHuffmanTable(
huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables,
huffmanTableSpec & 15, huffmanTableSpec & 15,
codeLengths.Span, codeLengths.GetSpan(),
huffmanValues.Span); huffmanValues.GetSpan());
} }
} }
} }

28
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -531,7 +531,7 @@ namespace SixLabors.ImageSharp.Formats.Png
} }
this.currentRowBytesRead = 0; this.currentRowBytesRead = 0;
Span<byte> scanlineSpan = this.scanline.Span; Span<byte> scanlineSpan = this.scanline.GetSpan();
var filterType = (FilterType)scanlineSpan[0]; var filterType = (FilterType)scanlineSpan[0];
switch (filterType) switch (filterType)
@ -546,17 +546,17 @@ namespace SixLabors.ImageSharp.Formats.Png
case FilterType.Up: case FilterType.Up:
UpFilter.Decode(scanlineSpan, this.previousScanline.Span); UpFilter.Decode(scanlineSpan, this.previousScanline.GetSpan());
break; break;
case FilterType.Average: case FilterType.Average:
AverageFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); AverageFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
break; break;
case FilterType.Paeth: case FilterType.Paeth:
PaethFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); PaethFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel);
break; break;
default: default:
@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Png
} }
Span<TPixel> rowSpan = image.GetPixelRowSpan(this.currentRow); Span<TPixel> rowSpan = image.GetPixelRowSpan(this.currentRow);
this.ProcessInterlacedDefilteredScanline(this.scanline.Span, rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]); this.ProcessInterlacedDefilteredScanline(this.scanline.GetSpan(), rowSpan, Adam7FirstColumn[this.pass], Adam7ColumnIncrement[this.pass]);
this.SwapBuffers(); this.SwapBuffers();
@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Png
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length)) using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
{ {
// TODO: Should we use pack from vector here instead? // TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length);
PixelOperations<TPixel>.Instance.PackFromRgb24Bytes(compressed.Span, rowSpan, this.header.Width); PixelOperations<TPixel>.Instance.PackFromRgb24Bytes(compressed.GetSpan(), rowSpan, this.header.Width);
} }
} }
else else
@ -747,9 +747,9 @@ namespace SixLabors.ImageSharp.Formats.Png
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length)) using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
{ {
// TODO: Should we use pack from vector here instead? // TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length);
Span<Rgb24> rgb24Span = MemoryMarshal.Cast<byte, Rgb24>(compressed.Span); Span<Rgb24> rgb24Span = MemoryMarshal.Cast<byte, Rgb24>(compressed.GetSpan());
for (int x = 0; x < this.header.Width; x++) for (int x = 0; x < this.header.Width; x++)
{ {
ref Rgb24 rgb24 = ref rgb24Span[x]; ref Rgb24 rgb24 = ref rgb24Span[x];
@ -788,8 +788,8 @@ namespace SixLabors.ImageSharp.Formats.Png
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length)) using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
{ {
// TODO: Should we use pack from vector here instead? // TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length);
PixelOperations<TPixel>.Instance.PackFromRgba32Bytes(compressed.Span, rowSpan, this.header.Width); PixelOperations<TPixel>.Instance.PackFromRgba32Bytes(compressed.GetSpan(), rowSpan, this.header.Width);
} }
} }
else else
@ -986,7 +986,7 @@ namespace SixLabors.ImageSharp.Formats.Png
int length = this.header.Width * 3; int length = this.header.Width * 3;
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length)) using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
{ {
Span<byte> compressedSpan = compressed.Span; Span<byte> compressedSpan = compressed.GetSpan();
// TODO: Should we use pack from vector here instead? // TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length);
@ -1056,7 +1056,7 @@ namespace SixLabors.ImageSharp.Formats.Png
int length = this.header.Width * 4; int length = this.header.Width * 4;
using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length)) using (IBuffer<byte> compressed = this.configuration.MemoryManager.Allocate<byte>(length))
{ {
Span<byte> compressedSpan = compressed.Span; Span<byte> compressedSpan = compressed.GetSpan();
// TODO: Should we use pack from vector here instead? // TODO: Should we use pack from vector here instead?
this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length);
@ -1229,7 +1229,7 @@ namespace SixLabors.ImageSharp.Formats.Png
{ {
this.crc.Reset(); this.crc.Reset();
this.crc.Update(this.chunkTypeBuffer); this.crc.Update(this.chunkTypeBuffer);
this.crc.Update(chunk.Data.Span); this.crc.Update(chunk.Data.GetSpan());
if (this.crc.Value != chunk.Crc) if (this.crc.Value != chunk.Crc)
{ {

32
src/ImageSharp/Formats/Png/PngEncoderCore.cs

@ -283,11 +283,11 @@ namespace SixLabors.ImageSharp.Formats.Png
{ {
if (this.bytesPerPixel == 4) if (this.bytesPerPixel == 4)
{ {
PixelOperations<TPixel>.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.Span, this.width); PixelOperations<TPixel>.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.GetSpan(), this.width);
} }
else else
{ {
PixelOperations<TPixel>.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.Span, this.width); PixelOperations<TPixel>.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.GetSpan(), this.width);
} }
} }
@ -320,23 +320,23 @@ namespace SixLabors.ImageSharp.Formats.Png
switch (this.pngFilterMethod) switch (this.pngFilterMethod)
{ {
case PngFilterMethod.None: case PngFilterMethod.None:
NoneFilter.Encode(this.rawScanline.Span, this.result.Span); NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan());
return this.result; return this.result;
case PngFilterMethod.Sub: case PngFilterMethod.Sub:
SubFilter.Encode(this.rawScanline.Span, this.sub.Span, this.bytesPerPixel, out int _); SubFilter.Encode(this.rawScanline.GetSpan(), this.sub.GetSpan(), this.bytesPerPixel, out int _);
return this.sub; return this.sub;
case PngFilterMethod.Up: case PngFilterMethod.Up:
UpFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.up.Span, out int _); UpFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.up.GetSpan(), out int _);
return this.up; return this.up;
case PngFilterMethod.Average: case PngFilterMethod.Average:
AverageFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.average.Span, this.bytesPerPixel, out int _); AverageFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.average.GetSpan(), this.bytesPerPixel, out int _);
return this.average; return this.average;
case PngFilterMethod.Paeth: case PngFilterMethod.Paeth:
PaethFilter.Encode(this.rawScanline.Span, this.previousScanline.Span, this.paeth.Span, this.bytesPerPixel, out int _); PaethFilter.Encode(this.rawScanline.GetSpan(), this.previousScanline.GetSpan(), this.paeth.GetSpan(), this.bytesPerPixel, out int _);
return this.paeth; return this.paeth;
default: default:
@ -354,21 +354,21 @@ namespace SixLabors.ImageSharp.Formats.Png
// Palette images don't compress well with adaptive filtering. // Palette images don't compress well with adaptive filtering.
if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8) if (this.pngColorType == PngColorType.Palette || this.bitDepth < 8)
{ {
NoneFilter.Encode(this.rawScanline.Span, this.result.Span); NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan());
return this.result; return this.result;
} }
Span<byte> scanSpan = this.rawScanline.Span; Span<byte> scanSpan = this.rawScanline.GetSpan();
Span<byte> prevSpan = this.previousScanline.Span; Span<byte> prevSpan = this.previousScanline.GetSpan();
// This order, while different to the enumerated order is more likely to produce a smaller sum // This order, while different to the enumerated order is more likely to produce a smaller sum
// early on which shaves a couple of milliseconds off the processing time. // early on which shaves a couple of milliseconds off the processing time.
UpFilter.Encode(scanSpan, prevSpan, this.up.Span, out int currentSum); UpFilter.Encode(scanSpan, prevSpan, this.up.GetSpan(), out int currentSum);
int lowestSum = currentSum; int lowestSum = currentSum;
IManagedByteBuffer actualResult = this.up; IManagedByteBuffer actualResult = this.up;
PaethFilter.Encode(scanSpan, prevSpan, this.paeth.Span, this.bytesPerPixel, out currentSum); PaethFilter.Encode(scanSpan, prevSpan, this.paeth.GetSpan(), this.bytesPerPixel, out currentSum);
if (currentSum < lowestSum) if (currentSum < lowestSum)
{ {
@ -376,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Png
actualResult = this.paeth; actualResult = this.paeth;
} }
SubFilter.Encode(scanSpan, this.sub.Span, this.bytesPerPixel, out currentSum); SubFilter.Encode(scanSpan, this.sub.GetSpan(), this.bytesPerPixel, out currentSum);
if (currentSum < lowestSum) if (currentSum < lowestSum)
{ {
@ -384,7 +384,7 @@ namespace SixLabors.ImageSharp.Formats.Png
actualResult = this.sub; actualResult = this.sub;
} }
AverageFilter.Encode(scanSpan, prevSpan, this.average.Span, this.bytesPerPixel, out currentSum); AverageFilter.Encode(scanSpan, prevSpan, this.average.GetSpan(), this.bytesPerPixel, out currentSum);
if (currentSum < lowestSum) if (currentSum < lowestSum)
{ {
@ -463,8 +463,8 @@ namespace SixLabors.ImageSharp.Formats.Png
using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength))
using (IManagedByteBuffer alphaTable = this.memoryManager.AllocateManagedByteBuffer(pixelCount)) using (IManagedByteBuffer alphaTable = this.memoryManager.AllocateManagedByteBuffer(pixelCount))
{ {
Span<byte> colorTableSpan = colorTable.Span; Span<byte> colorTableSpan = colorTable.GetSpan();
Span<byte> alphaTableSpan = alphaTable.Span; Span<byte> alphaTableSpan = alphaTable.GetSpan();
for (byte i = 0; i < pixelCount; i++) for (byte i = 0; i < pixelCount; i++)
{ {

2
src/ImageSharp/Image.Decode.cs

@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp
long startPosition = stream.Position; long startPosition = stream.Position;
stream.Read(buffer.Array, 0, maxHeaderSize); stream.Read(buffer.Array, 0, maxHeaderSize);
stream.Position = startPosition; stream.Position = startPosition;
return config.ImageFormatsManager.FormatDetectors.Select(x => x.DetectFormat(buffer.Span)).LastOrDefault(x => x != null); return config.ImageFormatsManager.FormatDetectors.Select(x => x.DetectFormat(buffer.GetSpan())).LastOrDefault(x => x != null);
} }
} }

2
src/ImageSharp/ImageFrame{TPixel}.cs

@ -289,7 +289,7 @@ namespace SixLabors.ImageSharp
{ {
Span<TPixel> sourceRow = this.GetPixelRowSpan(y); Span<TPixel> sourceRow = this.GetPixelRowSpan(y);
Span<TPixel2> targetRow = target.GetPixelRowSpan(y); Span<TPixel2> targetRow = target.GetPixelRowSpan(y);
Span<Vector4> tempRowSpan = tempRowBuffer.Span; Span<Vector4> tempRowSpan = tempRowBuffer.GetSpan();
PixelOperations<TPixel>.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length); PixelOperations<TPixel>.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length);
PixelOperations<TPixel2>.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length); PixelOperations<TPixel2>.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length);

2
src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs

@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Memory
protected byte[] Data { get; private set; } protected byte[] Data { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public Span<T> Span => MemoryMarshal.Cast<byte, T>(this.Data.AsSpan()).Slice(0, this.length); public Span<T> GetSpan() => MemoryMarshal.Cast<byte, T>(this.Data.AsSpan()).Slice(0, this.length);
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()

7
src/ImageSharp/Memory/BasicArrayBuffer.cs

@ -25,8 +25,6 @@ namespace SixLabors.ImageSharp.Memory
public int Length { get; } public int Length { get; }
public Span<T> Span => this.Array.AsSpan(0, this.Length);
/// <summary> /// <summary>
/// Returns a reference to specified element of the buffer. /// Returns a reference to specified element of the buffer.
/// </summary> /// </summary>
@ -39,11 +37,14 @@ namespace SixLabors.ImageSharp.Memory
{ {
DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); DebugGuard.MustBeLessThan(index, this.Length, nameof(index));
Span<T> span = this.Span; Span<T> span = this.GetSpan();
return ref span[index]; return ref span[index];
} }
} }
/// <inheritdoc />
public Span<T> GetSpan() => this.Array.AsSpan(0, this.Length);
public void Dispose() public void Dispose()
{ {
} }

4
src/ImageSharp/Memory/Buffer2D{T}.cs

@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Memory
/// <summary> /// <summary>
/// Gets the span to the whole area. /// Gets the span to the whole area.
/// </summary> /// </summary>
public Span<T> Span => this.Buffer.Span; public Span<T> Span => this.Buffer.GetSpan();
/// <summary> /// <summary>
/// Gets the backing <see cref="IBuffer{T}"/> /// Gets the backing <see cref="IBuffer{T}"/>
@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Memory
{ {
DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(x, this.Width, nameof(x));
DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y));
Span<T> span = this.Buffer.Span; Span<T> span = this.Buffer.GetSpan();
return ref span[(this.Width * y) + x]; return ref span[(this.Width * y) + x];
} }
} }

10
src/ImageSharp/Memory/BufferExtensions.cs

@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Memory
{ {
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int Length<T>(this IBuffer<T> buffer) public static int Length<T>(this IBuffer<T> buffer)
where T : struct => buffer.Span.Length; where T : struct => buffer.GetSpan().Length;
/// <summary> /// <summary>
/// Gets a <see cref="Span{T}"/> to an offseted position inside the buffer. /// Gets a <see cref="Span{T}"/> to an offseted position inside the buffer.
@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Memory
public static Span<T> Slice<T>(this IBuffer<T> buffer, int start) public static Span<T> Slice<T>(this IBuffer<T> buffer, int start)
where T : struct where T : struct
{ {
return buffer.Span.Slice(start); return buffer.GetSpan().Slice(start);
} }
/// <summary> /// <summary>
@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Memory
public static Span<T> Slice<T>(this IBuffer<T> buffer, int start, int length) public static Span<T> Slice<T>(this IBuffer<T> buffer, int start, int length)
where T : struct where T : struct
{ {
return buffer.Span.Slice(start, length); return buffer.GetSpan().Slice(start, length);
} }
/// <summary> /// <summary>
@ -49,12 +49,12 @@ namespace SixLabors.ImageSharp.Memory
public static void Clear<T>(this IBuffer<T> buffer) public static void Clear<T>(this IBuffer<T> buffer)
where T : struct where T : struct
{ {
buffer.Span.Clear(); buffer.GetSpan().Clear();
} }
public static ref T DangerousGetPinnableReference<T>(this IBuffer<T> buffer) public static ref T DangerousGetPinnableReference<T>(this IBuffer<T> buffer)
where T : struct => where T : struct =>
ref MemoryMarshal.GetReference(buffer.Span); ref MemoryMarshal.GetReference(buffer.GetSpan());
public static void Read(this Stream stream, IManagedByteBuffer buffer) public static void Read(this Stream stream, IManagedByteBuffer buffer)
{ {

3
src/ImageSharp/Memory/IBuffer{T}.cs

@ -16,6 +16,7 @@ namespace SixLabors.ImageSharp.Memory
/// <summary> /// <summary>
/// Gets the span to the memory "promised" by this buffer /// Gets the span to the memory "promised" by this buffer
/// </summary> /// </summary>
Span<T> Span { get; } /// <returns>The <see cref="Span{T}"/></returns>
Span<T> GetSpan();
} }
} }

6
src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs

@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
using (IBuffer<float> amount = source.MemoryManager.Allocate<float>(width)) using (IBuffer<float> amount = source.MemoryManager.Allocate<float>(width))
{ {
// Be careful! Do not capture colorSpan & amountSpan in the lambda below! // Be careful! Do not capture colorSpan & amountSpan in the lambda below!
Span<TPixel> colorSpan = colors.Span; Span<TPixel> colorSpan = colors.GetSpan();
Span<float> amountSpan = amount.Span; Span<float> amountSpan = amount.GetSpan();
// TODO: Use Span.Fill? // TODO: Use Span.Fill?
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width); Span<TPixel> destination = source.GetPixelRowSpan(y - startY).Slice(minX - startX, width);
// This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one // This switched color & destination in the 2nd and 3rd places because we are applying the target color under the current one
blender.Blend(source.MemoryManager, destination, colors.Span, destination, amount.Span); blender.Blend(source.MemoryManager, destination, colors.GetSpan(), destination, amount.GetSpan());
}); });
} }
} }

6
src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs

@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width)) using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width))
{ {
// Be careful! Do not capture rowColorsSpan in the lambda below! // Be careful! Do not capture rowColorsSpan in the lambda below!
Span<TPixel> rowColorsSpan = rowColors.Span; Span<TPixel> rowColorsSpan = rowColors.GetSpan();
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
{ {
@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
{ {
using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width)) using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width))
{ {
Span<float> amountsSpan = amounts.Span; Span<float> amountsSpan = amounts.GetSpan();
int offsetY = y - startY; int offsetY = y - startY;
int offsetX = minX - startX; int offsetX = minX - startX;
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width);
this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan);
} }
}); });
} }

6
src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs

@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width)) using (IBuffer<TPixel> rowColors = source.MemoryManager.Allocate<TPixel>(width))
{ {
// Be careful! Do not capture rowColorsSpan in the lambda below! // Be careful! Do not capture rowColorsSpan in the lambda below!
Span<TPixel> rowColorsSpan = rowColors.Span; Span<TPixel> rowColorsSpan = rowColors.GetSpan();
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
{ {
@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
{ {
using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width)) using (IBuffer<float> amounts = source.MemoryManager.Allocate<float>(width))
{ {
Span<float> amountsSpan = amounts.Span; Span<float> amountsSpan = amounts.GetSpan();
int offsetY = y - startY; int offsetY = y - startY;
int offsetX = minX - startX; int offsetX = minX - startX;
for (int i = 0; i < width; i++) for (int i = 0; i < width; i++)
@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width); Span<TPixel> destination = source.GetPixelRowSpan(offsetY).Slice(offsetX, width);
this.blender.Blend(source.MemoryManager, destination, destination, rowColors.Span, amountsSpan); this.blender.Blend(source.MemoryManager, destination, destination, rowColors.GetSpan(), amountsSpan);
} }
}); });
} }

106
src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs

@ -177,14 +177,14 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
{ {
this.Mark(ref this.colorCube[k], (byte)k); this.Mark(ref this.colorCube[k], (byte)k);
float weight = Volume(ref this.colorCube[k], this.vwt.Span); float weight = Volume(ref this.colorCube[k], this.vwt.GetSpan());
if (MathF.Abs(weight) > Constants.Epsilon) if (MathF.Abs(weight) > Constants.Epsilon)
{ {
float r = Volume(ref this.colorCube[k], this.vmr.Span); float r = Volume(ref this.colorCube[k], this.vmr.GetSpan());
float g = Volume(ref this.colorCube[k], this.vmg.Span); float g = Volume(ref this.colorCube[k], this.vmg.GetSpan());
float b = Volume(ref this.colorCube[k], this.vmb.Span); float b = Volume(ref this.colorCube[k], this.vmb.GetSpan());
float a = Volume(ref this.colorCube[k], this.vma.Span); float a = Volume(ref this.colorCube[k], this.vma.GetSpan());
ref TPixel color = ref this.palette[k]; ref TPixel color = ref this.palette[k];
color.PackFromVector4(new Vector4(r, g, b, a) / weight / 255F); color.PackFromVector4(new Vector4(r, g, b, a) / weight / 255F);
@ -209,12 +209,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
int index = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1); int index = GetPaletteIndex(r + 1, g + 1, b + 1, a + 1);
Span<long> vwtSpan = this.vwt.Span; Span<long> vwtSpan = this.vwt.GetSpan();
Span<long> vmrSpan = this.vmr.Span; Span<long> vmrSpan = this.vmr.GetSpan();
Span<long> vmgSpan = this.vmg.Span; Span<long> vmgSpan = this.vmg.GetSpan();
Span<long> vmbSpan = this.vmb.Span; Span<long> vmbSpan = this.vmb.GetSpan();
Span<long> vmaSpan = this.vma.Span; Span<long> vmaSpan = this.vma.GetSpan();
Span<float> m2Span = this.m2.Span; Span<float> m2Span = this.m2.GetSpan();
vwtSpan[index]++; vwtSpan[index]++;
vmrSpan[index] += rgba.R; vmrSpan[index] += rgba.R;
@ -466,12 +466,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
/// </summary> /// </summary>
private void Get3DMoments(MemoryManager memoryManager) private void Get3DMoments(MemoryManager memoryManager)
{ {
Span<long> vwtSpan = this.vwt.Span; Span<long> vwtSpan = this.vwt.GetSpan();
Span<long> vmrSpan = this.vmr.Span; Span<long> vmrSpan = this.vmr.GetSpan();
Span<long> vmgSpan = this.vmg.Span; Span<long> vmgSpan = this.vmg.GetSpan();
Span<long> vmbSpan = this.vmb.Span; Span<long> vmbSpan = this.vmb.GetSpan();
Span<long> vmaSpan = this.vma.Span; Span<long> vmaSpan = this.vma.GetSpan();
Span<float> m2Span = this.m2.Span; Span<float> m2Span = this.m2.GetSpan();
using (IBuffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volume = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
using (IBuffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount)) using (IBuffer<long> volumeR = memoryManager.Allocate<long>(IndexCount * IndexAlphaCount))
@ -487,19 +487,19 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
using (IBuffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount)) using (IBuffer<long> areaA = memoryManager.Allocate<long>(IndexAlphaCount))
using (IBuffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount)) using (IBuffer<float> area2 = memoryManager.Allocate<float>(IndexAlphaCount))
{ {
Span<long> volumeSpan = volume.Span; Span<long> volumeSpan = volume.GetSpan();
Span<long> volumeRSpan = volumeR.Span; Span<long> volumeRSpan = volumeR.GetSpan();
Span<long> volumeGSpan = volumeG.Span; Span<long> volumeGSpan = volumeG.GetSpan();
Span<long> volumeBSpan = volumeB.Span; Span<long> volumeBSpan = volumeB.GetSpan();
Span<long> volumeASpan = volumeA.Span; Span<long> volumeASpan = volumeA.GetSpan();
Span<float> volume2Span = volume2.Span; Span<float> volume2Span = volume2.GetSpan();
Span<long> areaSpan = area.Span; Span<long> areaSpan = area.GetSpan();
Span<long> areaRSpan = areaR.Span; Span<long> areaRSpan = areaR.GetSpan();
Span<long> areaGSpan = areaG.Span; Span<long> areaGSpan = areaG.GetSpan();
Span<long> areaBSpan = areaB.Span; Span<long> areaBSpan = areaB.GetSpan();
Span<long> areaASpan = areaA.Span; Span<long> areaASpan = areaA.GetSpan();
Span<float> area2Span = area2.Span; Span<float> area2Span = area2.GetSpan();
for (int r = 1; r < IndexCount; r++) for (int r = 1; r < IndexCount; r++)
{ {
@ -577,12 +577,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
/// <returns>The <see cref="float"/>.</returns> /// <returns>The <see cref="float"/>.</returns>
private float Variance(ref Box cube) private float Variance(ref Box cube)
{ {
float dr = Volume(ref cube, this.vmr.Span); float dr = Volume(ref cube, this.vmr.GetSpan());
float dg = Volume(ref cube, this.vmg.Span); float dg = Volume(ref cube, this.vmg.GetSpan());
float db = Volume(ref cube, this.vmb.Span); float db = Volume(ref cube, this.vmb.GetSpan());
float da = Volume(ref cube, this.vma.Span); float da = Volume(ref cube, this.vma.GetSpan());
Span<float> m2Span = this.m2.Span; Span<float> m2Span = this.m2.GetSpan();
float xx = float xx =
m2Span[GetPaletteIndex(cube.R1, cube.G1, cube.B1, cube.A1)] m2Span[GetPaletteIndex(cube.R1, cube.G1, cube.B1, cube.A1)]
@ -603,7 +603,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
+ m2Span[GetPaletteIndex(cube.R0, cube.G0, cube.B0, cube.A0)]; + m2Span[GetPaletteIndex(cube.R0, cube.G0, cube.B0, cube.A0)];
var vector = new Vector4(dr, dg, db, da); var vector = new Vector4(dr, dg, db, da);
return xx - (Vector4.Dot(vector, vector) / Volume(ref cube, this.vwt.Span)); return xx - (Vector4.Dot(vector, vector) / Volume(ref cube, this.vwt.GetSpan()));
} }
/// <summary> /// <summary>
@ -626,22 +626,22 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
/// <returns>The <see cref="float"/>.</returns> /// <returns>The <see cref="float"/>.</returns>
private float Maximize(ref Box cube, int direction, int first, int last, out int cut, float wholeR, float wholeG, float wholeB, float wholeA, float wholeW) private float Maximize(ref Box cube, int direction, int first, int last, out int cut, float wholeR, float wholeG, float wholeB, float wholeA, float wholeW)
{ {
long baseR = Bottom(ref cube, direction, this.vmr.Span); long baseR = Bottom(ref cube, direction, this.vmr.GetSpan());
long baseG = Bottom(ref cube, direction, this.vmg.Span); long baseG = Bottom(ref cube, direction, this.vmg.GetSpan());
long baseB = Bottom(ref cube, direction, this.vmb.Span); long baseB = Bottom(ref cube, direction, this.vmb.GetSpan());
long baseA = Bottom(ref cube, direction, this.vma.Span); long baseA = Bottom(ref cube, direction, this.vma.GetSpan());
long baseW = Bottom(ref cube, direction, this.vwt.Span); long baseW = Bottom(ref cube, direction, this.vwt.GetSpan());
float max = 0F; float max = 0F;
cut = -1; cut = -1;
for (int i = first; i < last; i++) for (int i = first; i < last; i++)
{ {
float halfR = baseR + Top(ref cube, direction, i, this.vmr.Span); float halfR = baseR + Top(ref cube, direction, i, this.vmr.GetSpan());
float halfG = baseG + Top(ref cube, direction, i, this.vmg.Span); float halfG = baseG + Top(ref cube, direction, i, this.vmg.GetSpan());
float halfB = baseB + Top(ref cube, direction, i, this.vmb.Span); float halfB = baseB + Top(ref cube, direction, i, this.vmb.GetSpan());
float halfA = baseA + Top(ref cube, direction, i, this.vma.Span); float halfA = baseA + Top(ref cube, direction, i, this.vma.GetSpan());
float halfW = baseW + Top(ref cube, direction, i, this.vwt.Span); float halfW = baseW + Top(ref cube, direction, i, this.vwt.GetSpan());
if (MathF.Abs(halfW) < Constants.Epsilon) if (MathF.Abs(halfW) < Constants.Epsilon)
{ {
@ -685,11 +685,11 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
/// <returns>Returns a value indicating whether the box has been split.</returns> /// <returns>Returns a value indicating whether the box has been split.</returns>
private bool Cut(ref Box set1, ref Box set2) private bool Cut(ref Box set1, ref Box set2)
{ {
float wholeR = Volume(ref set1, this.vmr.Span); float wholeR = Volume(ref set1, this.vmr.GetSpan());
float wholeG = Volume(ref set1, this.vmg.Span); float wholeG = Volume(ref set1, this.vmg.GetSpan());
float wholeB = Volume(ref set1, this.vmb.Span); float wholeB = Volume(ref set1, this.vmb.GetSpan());
float wholeA = Volume(ref set1, this.vma.Span); float wholeA = Volume(ref set1, this.vma.GetSpan());
float wholeW = Volume(ref set1, this.vwt.Span); float wholeW = Volume(ref set1, this.vwt.GetSpan());
float maxr = this.Maximize(ref set1, 3, set1.R0 + 1, set1.R1, out int cutr, wholeR, wholeG, wholeB, wholeA, wholeW); float maxr = this.Maximize(ref set1, 3, set1.R0 + 1, set1.R1, out int cutr, wholeR, wholeG, wholeB, wholeA, wholeW);
float maxg = this.Maximize(ref set1, 2, set1.G0 + 1, set1.G1, out int cutg, wholeR, wholeG, wholeB, wholeA, wholeW); float maxg = this.Maximize(ref set1, 2, set1.G0 + 1, set1.G1, out int cutg, wholeR, wholeG, wholeB, wholeA, wholeW);
@ -773,7 +773,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
/// <param name="label">A label.</param> /// <param name="label">A label.</param>
private void Mark(ref Box cube, byte label) private void Mark(ref Box cube, byte label)
{ {
Span<byte> tagSpan = this.tag.Span; Span<byte> tagSpan = this.tag.GetSpan();
for (int r = cube.R0 + 1; r <= cube.R1; r++) for (int r = cube.R0 + 1; r <= cube.R1; r++)
{ {
@ -866,7 +866,7 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers
int b = rgba.B >> (8 - IndexBits); int b = rgba.B >> (8 - IndexBits);
int a = rgba.A >> (8 - IndexAlphaBits); int a = rgba.A >> (8 - IndexAlphaBits);
Span<byte> tagSpan = this.tag.Span; Span<byte> tagSpan = this.tag.GetSpan();
return tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)]; return tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)];
} }

2
src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs

@ -308,7 +308,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
{ {
ref Vector4 firstPassRow = ref MemoryMarshal.GetReference(firstPassPixels.GetRowSpan(y)); ref Vector4 firstPassRow = ref MemoryMarshal.GetReference(firstPassPixels.GetRowSpan(y));
Span<TPixel> sourceRow = source.GetPixelRowSpan(y); Span<TPixel> sourceRow = source.GetPixelRowSpan(y);
Span<Vector4> tempRowSpan = tempRowBuffer.Span; Span<Vector4> tempRowSpan = tempRowBuffer.GetSpan();
PixelOperations<TPixel>.Instance.ToVector4(sourceRow, tempRowSpan, sourceRow.Length); PixelOperations<TPixel>.Instance.ToVector4(sourceRow, tempRowSpan, sourceRow.Length);

2
src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs

@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref float GetStartReference() public ref float GetStartReference()
{ {
Span<float> span = this.buffer.Span; Span<float> span = this.buffer.GetSpan();
return ref span[this.flatStartIndex]; return ref span[this.flatStartIndex];
} }

8
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs

@ -37,8 +37,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark(Baseline = true)] [Benchmark(Baseline = true)]
public void PerElement() public void PerElement()
{ {
ref Vector4 s = ref MemoryMarshal.GetReference(this.source.Span); ref Vector4 s = ref MemoryMarshal.GetReference(this.source.GetSpan());
ref TPixel d = ref MemoryMarshal.GetReference(this.destination.Span); ref TPixel d = ref MemoryMarshal.GetReference(this.destination.GetSpan());
for (int i = 0; i < this.Count; i++) for (int i = 0; i < this.Count; i++)
{ {
@ -49,13 +49,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark] [Benchmark]
public void CommonBulk() public void CommonBulk()
{ {
new PixelOperations<TPixel>().PackFromVector4(this.source.Span, this.destination.Span, this.Count); new PixelOperations<TPixel>().PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count);
} }
[Benchmark] [Benchmark]
public void OptimizedBulk() public void OptimizedBulk()
{ {
PixelOperations<TPixel>.Instance.PackFromVector4(this.source.Span, this.destination.Span, this.Count); PixelOperations<TPixel>.Instance.PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count);
} }
} }

8
tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs

@ -35,8 +35,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark(Baseline = true)] [Benchmark(Baseline = true)]
public void PerElement() public void PerElement()
{ {
Span<byte> s = this.source.Span; Span<byte> s = this.source.GetSpan();
Span<TPixel> d = this.destination.Span; Span<TPixel> d = this.destination.GetSpan();
for (int i = 0; i < this.Count; i++) for (int i = 0; i < this.Count; i++)
{ {
@ -50,13 +50,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk
[Benchmark] [Benchmark]
public void CommonBulk() public void CommonBulk()
{ {
new PixelOperations<TPixel>().PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); new PixelOperations<TPixel>().PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count);
} }
[Benchmark] [Benchmark]
public void OptimizedBulk() public void OptimizedBulk()
{ {
PixelOperations<TPixel>.Instance.PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); PixelOperations<TPixel>.Instance.PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count);
} }
} }

2
tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs

@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg
this.Output.WriteLine($"Component{i}: {diff}"); this.Output.WriteLine($"Component{i}: {diff}");
averageDifference += diff.average; averageDifference += diff.average;
totalDifference += diff.total; totalDifference += diff.total;
tolerance += libJpegComponent.SpectralBlocks.Buffer.Span.Length; tolerance += libJpegComponent.SpectralBlocks.Buffer.GetSpan().Length;
} }
averageDifference /= componentCount; averageDifference /= componentCount;

6
tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs

@ -132,13 +132,13 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using (IBuffer<int> firstAlloc = this.MemoryManager.Allocate<int>(42)) using (IBuffer<int> firstAlloc = this.MemoryManager.Allocate<int>(42))
{ {
firstAlloc.Span.Fill(666); firstAlloc.GetSpan().Fill(666);
} }
using (IBuffer<int> secondAlloc = this.MemoryManager.Allocate<int>(42, clean)) using (IBuffer<int> secondAlloc = this.MemoryManager.Allocate<int>(42, clean))
{ {
int expected = clean ? 0 : 666; int expected = clean ? 0 : 666;
Assert.Equal(expected, secondAlloc.Span[0]); Assert.Equal(expected, secondAlloc.GetSpan()[0]);
} }
} }
@ -148,7 +148,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive) public void ReleaseRetainedResources_ReplacesInnerArrayPool(bool keepBufferAlive)
{ {
IBuffer<int> buffer = this.MemoryManager.Allocate<int>(32); IBuffer<int> buffer = this.MemoryManager.Allocate<int>(32);
ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.Span); ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan());
if (!keepBufferAlive) if (!keepBufferAlive)
{ {

2
tests/ImageSharp.Tests/Memory/Buffer2DTests.cs

@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height)) using (Buffer2D<TestStructs.Foo> buffer = this.MemoryManager.Allocate2D<TestStructs.Foo>(width, height))
{ {
Span<TestStructs.Foo> span = buffer.Buffer.Span; Span<TestStructs.Foo> span = buffer.Buffer.GetSpan();
ref TestStructs.Foo actual = ref buffer[x, y]; ref TestStructs.Foo actual = ref buffer[x, y];

22
tests/ImageSharp.Tests/Memory/BufferTestSuite.cs

@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using (IBuffer<T> buffer = this.MemoryManager.Allocate<T>(desiredLength)) using (IBuffer<T> buffer = this.MemoryManager.Allocate<T>(desiredLength))
{ {
Assert.Equal(desiredLength, buffer.Span.Length); Assert.Equal(desiredLength, buffer.GetSpan().Length);
} }
} }
@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using (IBuffer<T> buffer = this.Allocate<T>(desiredLength, true, testManagedByteBuffer)) using (IBuffer<T> buffer = this.Allocate<T>(desiredLength, true, testManagedByteBuffer))
{ {
Assert.True(buffer.Span.SequenceEqual(expected)); Assert.True(buffer.GetSpan().SequenceEqual(expected));
} }
} }
} }
@ -166,9 +166,9 @@ namespace SixLabors.ImageSharp.Tests.Memory
{ {
using (IBuffer<T> buffer = this.Allocate<T>(desiredLength, false, testManagedByteBuffer)) using (IBuffer<T> buffer = this.Allocate<T>(desiredLength, false, testManagedByteBuffer))
{ {
ref T a = ref MemoryMarshal.GetReference(buffer.Span); ref T a = ref MemoryMarshal.GetReference(buffer.GetSpan());
ref T b = ref MemoryMarshal.GetReference(buffer.Span); ref T b = ref MemoryMarshal.GetReference(buffer.GetSpan());
ref T c = ref MemoryMarshal.GetReference(buffer.Span); ref T c = ref MemoryMarshal.GetReference(buffer.GetSpan());
Assert.True(Unsafe.AreSame(ref a, ref b)); Assert.True(Unsafe.AreSame(ref a, ref b));
Assert.True(Unsafe.AreSame(ref b, ref c)); Assert.True(Unsafe.AreSame(ref b, ref c));
@ -199,14 +199,14 @@ namespace SixLabors.ImageSharp.Tests.Memory
for (int i = 0; i < buffer.Length(); i++) for (int i = 0; i < buffer.Length(); i++)
{ {
Span<T> span = buffer.Span; Span<T> span = buffer.GetSpan();
expectedVals[i] = getExpectedValue(i); expectedVals[i] = getExpectedValue(i);
span[i] = expectedVals[i]; span[i] = expectedVals[i];
} }
for (int i = 0; i < buffer.Length(); i++) for (int i = 0; i < buffer.Length(); i++)
{ {
Span<T> span = buffer.Span; Span<T> span = buffer.GetSpan();
Assert.Equal(expectedVals[i], span[i]); Assert.Equal(expectedVals[i], span[i]);
} }
} }
@ -244,21 +244,21 @@ namespace SixLabors.ImageSharp.Tests.Memory
Assert.ThrowsAny<Exception>( Assert.ThrowsAny<Exception>(
() => () =>
{ {
Span<T> span = buffer.Span; Span<T> span = buffer.GetSpan();
dummy = span[desiredLength]; dummy = span[desiredLength];
}); });
Assert.ThrowsAny<Exception>( Assert.ThrowsAny<Exception>(
() => () =>
{ {
Span<T> span = buffer.Span; Span<T> span = buffer.GetSpan();
dummy = span[desiredLength + 1]; dummy = span[desiredLength + 1];
}); });
Assert.ThrowsAny<Exception>( Assert.ThrowsAny<Exception>(
() => () =>
{ {
Span<T> span = buffer.Span; Span<T> span = buffer.GetSpan();
dummy = span[desiredLength + 42]; dummy = span[desiredLength + 42];
}); });
} }
@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
ref byte span0 = ref buffer.DangerousGetPinnableReference(); ref byte span0 = ref buffer.DangerousGetPinnableReference();
Assert.True(Unsafe.AreSame(ref span0, ref array0)); Assert.True(Unsafe.AreSame(ref span0, ref array0));
Assert.True(buffer.Array.Length >= buffer.Span.Length); Assert.True(buffer.Array.Length >= buffer.GetSpan().Length);
} }
} }
} }

36
tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs

@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => ImageSharp.PixelFormats.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.Span, 64) (s, d) => ImageSharp.PixelFormats.Rgba32.PixelOperations.ToVector4SimdAligned(s, d.GetSpan(), 64)
); );
} }
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
times, times,
() => () =>
{ {
PixelOperations<ImageSharp.PixelFormats.Rgba32>.Instance.ToVector4(source.Span, dest.Span, count); PixelOperations<ImageSharp.PixelFormats.Rgba32>.Instance.ToVector4(source.GetSpan(), dest.GetSpan(), count);
}); });
} }
} }
@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromVector4(s, d.Span, count) (s, d) => Operations.PackFromVector4(s, d.GetSpan(), count)
); );
} }
@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromScaledVector4(s, d.Span, count) (s, d) => Operations.PackFromScaledVector4(s, d.GetSpan(), count)
); );
} }
@ -183,7 +183,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToVector4(s, d.Span, count) (s, d) => Operations.ToVector4(s, d.GetSpan(), count)
); );
} }
@ -197,7 +197,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToScaledVector4(s, d.Span, count) (s, d) => Operations.ToScaledVector4(s, d.GetSpan(), count)
); );
} }
@ -218,7 +218,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromRgb24Bytes(s, d.Span, count) (s, d) => Operations.PackFromRgb24Bytes(s, d.GetSpan(), count)
); );
} }
@ -242,7 +242,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToRgb24Bytes(s, d.Span, count) (s, d) => Operations.ToRgb24Bytes(s, d.GetSpan(), count)
); );
} }
@ -263,7 +263,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromRgba32Bytes(s, d.Span, count) (s, d) => Operations.PackFromRgba32Bytes(s, d.GetSpan(), count)
); );
} }
@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToRgba32Bytes(s, d.Span, count) (s, d) => Operations.ToRgba32Bytes(s, d.GetSpan(), count)
); );
} }
@ -309,7 +309,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromBgr24Bytes(s, d.Span, count) (s, d) => Operations.PackFromBgr24Bytes(s, d.GetSpan(), count)
); );
} }
@ -333,7 +333,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToBgr24Bytes(s, d.Span, count) (s, d) => Operations.ToBgr24Bytes(s, d.GetSpan(), count)
); );
} }
@ -354,7 +354,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromBgra32Bytes(s, d.Span, count) (s, d) => Operations.PackFromBgra32Bytes(s, d.GetSpan(), count)
); );
} }
@ -379,7 +379,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToBgra32Bytes(s, d.Span, count) (s, d) => Operations.ToBgra32Bytes(s, d.GetSpan(), count)
); );
} }
@ -400,7 +400,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.PackFromArgb32Bytes(s, d.Span, count) (s, d) => Operations.PackFromArgb32Bytes(s, d.GetSpan(), count)
); );
} }
@ -425,7 +425,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
TestOperation( TestOperation(
source, source,
expected, expected,
(s, d) => Operations.ToArgb32Bytes(s, d.Span, count) (s, d) => Operations.ToArgb32Bytes(s, d.GetSpan(), count)
); );
} }
@ -459,7 +459,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
{ {
Span<Vector4> expected = MemoryMarshal.Cast<TDest, Vector4>(this.ExpectedDestBuffer.AsSpan()); Span<Vector4> expected = MemoryMarshal.Cast<TDest, Vector4>(this.ExpectedDestBuffer.AsSpan());
Span<Vector4> actual = MemoryMarshal.Cast<TDest, Vector4>(this.ActualDestBuffer.Span); Span<Vector4> actual = MemoryMarshal.Cast<TDest, Vector4>(this.ActualDestBuffer.GetSpan());
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
@ -471,7 +471,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats
else else
{ {
Span<TDest> expected = this.ExpectedDestBuffer.AsSpan(); Span<TDest> expected = this.ExpectedDestBuffer.AsSpan();
Span<TDest> actual = this.ActualDestBuffer.Span; Span<TDest> actual = this.ActualDestBuffer.GetSpan();
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
Assert.Equal(expected[i], actual[i]); Assert.Equal(expected[i], actual[i]);

8
tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs

@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
byte* sourcePtr = sourcePtrBase + data.Stride * y; byte* sourcePtr = sourcePtrBase + data.Stride * y;
Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount);
PixelOperations<TPixel>.Instance.PackFromBgra32(workBuffer.Span, row, row.Length); PixelOperations<TPixel>.Instance.PackFromBgra32(workBuffer.GetSpan(), row, row.Length);
} }
} }
} }
@ -87,9 +87,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
byte* sourcePtr = sourcePtrBase + data.Stride * y; byte* sourcePtr = sourcePtrBase + data.Stride * y;
Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount);
PixelOperations<TPixel>.Instance.PackFromBgr24(workBuffer.Span, row, row.Length); PixelOperations<TPixel>.Instance.PackFromBgr24(workBuffer.GetSpan(), row, row.Length);
// FromRgb24(workBuffer.Span, row); // FromRgb24(workBuffer.GetSpan(), row);
} }
} }
} }
@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs
for (int y = 0; y < h; y++) for (int y = 0; y < h; y++)
{ {
Span<TPixel> row = image.Frames.RootFrame.GetPixelRowSpan(y); Span<TPixel> row = image.Frames.RootFrame.GetPixelRowSpan(y);
PixelOperations<TPixel>.Instance.ToBgra32(row, workBuffer.Span, row.Length); PixelOperations<TPixel>.Instance.ToBgra32(row, workBuffer.GetSpan(), row.Length);
byte* destPtr = destPtrBase + data.Stride * y; byte* destPtr = destPtrBase + data.Stride * y;
Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount);

Loading…
Cancel
Save