diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs index c546663353..83bff9c472 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/BrushApplicator.cs @@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs index c2e3a16eff..dfdc1721d4 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/ImageBrush{TPixel}.cs @@ -121,8 +121,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = this.Target.MemoryManager.Allocate(scanline.Length)) using (IBuffer overlay = this.Target.MemoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); int sourceY = (y - this.offsetY) % this.yLength; int offsetX = x - this.offsetX; diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs index 765f2a1326..b5bc5a7ef5 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/PatternBrush{TPixel}.cs @@ -156,8 +156,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs index 324c54e186..05607472ed 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/RecolorBrush{TPixel}.cs @@ -141,8 +141,8 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) using (IBuffer overlay = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; - Span overlaySpan = overlay.Span; + Span amountSpan = amountBuffer.GetSpan(); + Span overlaySpan = overlay.GetSpan(); for (int i = 0; i < scanline.Length; i++) { diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs index f2054ee0d7..a32152ba0c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Brushes/SolidBrush{TPixel}.cs @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes : base(source, options) { this.Colors = source.MemoryManager.Allocate(source.Width); - this.Colors.Span.Fill(color); + this.Colors.GetSpan().Fill(color); } /// @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes /// /// The color /// - internal override TPixel this[int x, int y] => this.Colors.Span[x]; + internal override TPixel this[int x, int y] => this.Colors.GetSpan()[x]; /// public override void Dispose() @@ -92,20 +92,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Brushes 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 { using (IBuffer amountBuffer = memoryManager.Allocate(scanline.Length)) { - Span amountSpan = amountBuffer.Span; + Span amountSpan = amountBuffer.GetSpan(); for (int i = 0; i < scanline.Length; i++) { 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); } } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs index 7b6e36d9d1..c5691aa64c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/DrawImageProcessor.cs @@ -137,7 +137,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors using (IBuffer amount = memoryManager.Allocate(width)) { - amount.Span.Fill(this.Opacity); + amount.GetSpan().Fill(this.Opacity); Parallel.For( minY, @@ -147,7 +147,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors { Span background = source.GetPixelRowSpan(y).Slice(minX, width); Span foreground = targetImage.GetPixelRowSpan(y - locationY).Slice(targetX, width); - blender.Blend(memoryManager, background, background, foreground, amount.Span); + blender.Blend(memoryManager, background, background, foreground, amount.GetSpan()); }); } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs index 645ff03537..3cf2f7d630 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillProcessor.cs @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors sourceRectangle, this.options)) { - amount.Span.Fill(1f); + amount.GetSpan().Fill(1f); Parallel.For( minY, @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing.Processors int offsetY = y - startY; int offsetX = minX - startX; - applicator.Apply(amount.Span, offsetX, offsetY); + applicator.Apply(amount.GetSpan(), offsetX, offsetY); }); } } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs b/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs index 95ac3fe298..0bb3abc504 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/Processors/FillRegionProcessor.cs +++ b/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); } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 26bd97b810..a3df87ff41 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -342,7 +342,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp TPixel color = default; var rgba = new Rgba32(0, 0, 0, 255); - Span rowSpan = row.Span; + Span rowSpan = row.GetSpan(); for (int y = 0; y < height; y++) { @@ -434,7 +434,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(row); int newY = Invert(y, height, inverted); Span pixelSpan = pixels.GetRowSpan(newY); - PixelOperations.Instance.PackFromBgr24Bytes(row.Span, pixelSpan, width); + PixelOperations.Instance.PackFromBgr24Bytes(row.GetSpan(), pixelSpan, width); } } } @@ -459,7 +459,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(row); int newY = Invert(y, height, inverted); Span pixelSpan = pixels.GetRowSpan(newY); - PixelOperations.Instance.PackFromBgra32Bytes(row.Span, pixelSpan, width); + PixelOperations.Instance.PackFromBgra32Bytes(row.GetSpan(), pixelSpan, width); } } } diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 2b0c907338..aefcda402c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int y = pixels.Height - 1; y >= 0; y--) { Span pixelSpan = pixels.GetRowSpan(y); - PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.Span, pixelSpan.Length); + PixelOperations.Instance.ToBgra32Bytes(pixelSpan, row.GetSpan(), pixelSpan.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--) { Span pixelSpan = pixels.GetRowSpan(y); - PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.Span, pixelSpan.Length); + PixelOperations.Instance.ToBgr24Bytes(pixelSpan, row.GetSpan(), pixelSpan.Length); stream.Write(row.Array, 0, row.Length()); } } diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs index 4fbd4baf51..d37682a3d7 100644 --- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs +++ b/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); - this.ReadFrameIndices(imageDescriptor, indices.Span); - ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).Span); - this.ReadFrameColors(ref image, ref previousFrame, indices.Span, colorTable, imageDescriptor); + this.ReadFrameIndices(imageDescriptor, indices.GetSpan()); + ReadOnlySpan colorTable = MemoryMarshal.Cast((localColorTable ?? this.globalColorTable).GetSpan()); + this.ReadFrameColors(ref image, ref previousFrame, indices.GetSpan(), colorTable, imageDescriptor); // Skip any remaining blocks this.Skip(0); diff --git a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs index 747867c805..6f134c4bd1 100644 --- a/src/ImageSharp/Formats/Gif/GifEncoderCore.cs +++ b/src/ImageSharp/Formats/Gif/GifEncoderCore.cs @@ -320,7 +320,7 @@ namespace SixLabors.ImageSharp.Formats.Gif using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) { ref TPixel paletteRef = ref MemoryMarshal.GetReference(image.Palette.AsSpan()); - ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.Span)); + ref Rgb24 rgb24Ref = ref Unsafe.As(ref MemoryMarshal.GetReference(colorTable.GetSpan())); for (int i = 0; i < pixelCount; i++) { ref TPixel entry = ref Unsafe.Add(ref paletteRef, i); diff --git a/src/ImageSharp/Formats/Gif/LzwDecoder.cs b/src/ImageSharp/Formats/Gif/LzwDecoder.cs index 9f9e070e20..f52a8b2408 100644 --- a/src/ImageSharp/Formats/Gif/LzwDecoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwDecoder.cs @@ -102,9 +102,9 @@ namespace SixLabors.ImageSharp.Formats.Gif int data = 0; int first = 0; - ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.Span); - ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.Span); - ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.Span); + ref int prefixRef = ref MemoryMarshal.GetReference(this.prefix.GetSpan()); + ref int suffixRef = ref MemoryMarshal.GetReference(this.suffix.GetSpan()); + ref int pixelStackRef = ref MemoryMarshal.GetReference(this.pixelStack.GetSpan()); ref byte pixelsRef = ref MemoryMarshal.GetReference(pixels); for (code = 0; code < clearCode; code++) diff --git a/src/ImageSharp/Formats/Gif/LzwEncoder.cs b/src/ImageSharp/Formats/Gif/LzwEncoder.cs index 1dc7e99e83..a23d2f4e2a 100644 --- a/src/ImageSharp/Formats/Gif/LzwEncoder.cs +++ b/src/ImageSharp/Formats/Gif/LzwEncoder.cs @@ -246,7 +246,7 @@ namespace SixLabors.ImageSharp.Formats.Gif [MethodImpl(MethodImplOptions.AggressiveInlining)] private void ResetCodeTable() { - this.hashTable.Span.Fill(-1); + this.hashTable.GetSpan().Fill(-1); } /// @@ -293,8 +293,8 @@ namespace SixLabors.ImageSharp.Formats.Gif this.Output(this.clearCode, stream); - ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.Span); - ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.Span); + ref int hashTableRef = ref MemoryMarshal.GetReference(this.hashTable.GetSpan()); + ref int codeTableRef = ref MemoryMarshal.GetReference(this.codeTable.GetSpan()); while (this.position < this.pixelArray.Length) { diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs index 38340b2380..a8def1e193 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegImagePostProcessor.cs @@ -155,11 +155,11 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder int y = yy - this.PixelRowCounter; var values = new JpegColorConverter.ComponentValues(buffers, y); - this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.Span); + this.colorConverter.ConvertToRgba(values, this.rgbaBuffer.GetSpan()); Span destRow = destination.GetPixelRowSpan(yy); - PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.Span, destRow, destination.Width); + PixelOperations.Instance.PackFromVector4(this.rgbaBuffer.GetSpan(), destRow, destination.Width); } } } diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs index 875a862638..e8e0054f22 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs +++ b/src/ImageSharp/Formats/Jpeg/PdfJsPort/Components/PdfJsHuffmanTable.cs @@ -46,8 +46,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort.Components using (IBuffer huffsize = memoryManager.Allocate(length)) using (IBuffer huffcode = memoryManager.Allocate(length)) { - ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.Span); - ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.Span); + ref short huffsizeRef = ref MemoryMarshal.GetReference(huffsize.GetSpan()); + ref short huffcodeRef = ref MemoryMarshal.GetReference(huffcode.GetSpan()); GenerateSizeTable(lengths, ref huffsizeRef); GenerateCodeTable(ref huffsizeRef, ref huffcodeRef, length); diff --git a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs index 752e72dd2e..69994ee594 100644 --- a/src/ImageSharp/Formats/Jpeg/PdfJsPort/PdfJsJpegDecoderCore.cs +++ b/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)) { - ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.Span); + ref byte huffmanDataRef = ref MemoryMarshal.GetReference(huffmanData.GetSpan()); for (int i = 2; i < remaining;) { byte huffmanTableSpec = (byte)this.InputStream.ReadByte(); @@ -713,7 +713,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort 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; for (int j = 1; j < 17; j++) @@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.PdfJsPort this.BuildHuffmanTable( huffmanTableSpec >> 4 == 0 ? this.dcHuffmanTables : this.acHuffmanTables, huffmanTableSpec & 15, - codeLengths.Span, - huffmanValues.Span); + codeLengths.GetSpan(), + huffmanValues.GetSpan()); } } } diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index cc98b8450b..15edf2ad3f 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -531,7 +531,7 @@ namespace SixLabors.ImageSharp.Formats.Png } this.currentRowBytesRead = 0; - Span scanlineSpan = this.scanline.Span; + Span scanlineSpan = this.scanline.GetSpan(); var filterType = (FilterType)scanlineSpan[0]; switch (filterType) @@ -546,17 +546,17 @@ namespace SixLabors.ImageSharp.Formats.Png case FilterType.Up: - UpFilter.Decode(scanlineSpan, this.previousScanline.Span); + UpFilter.Decode(scanlineSpan, this.previousScanline.GetSpan()); break; case FilterType.Average: - AverageFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); + AverageFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel); break; case FilterType.Paeth: - PaethFilter.Decode(scanlineSpan, this.previousScanline.Span, this.bytesPerPixel); + PaethFilter.Decode(scanlineSpan, this.previousScanline.GetSpan(), this.bytesPerPixel); break; default: @@ -639,7 +639,7 @@ namespace SixLabors.ImageSharp.Formats.Png } Span 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(); @@ -730,8 +730,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); - PixelOperations.Instance.PackFromRgb24Bytes(compressed.Span, rowSpan, this.header.Width); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); + PixelOperations.Instance.PackFromRgb24Bytes(compressed.GetSpan(), rowSpan, this.header.Width); } } else @@ -747,9 +747,9 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); - Span rgb24Span = MemoryMarshal.Cast(compressed.Span); + Span rgb24Span = MemoryMarshal.Cast(compressed.GetSpan()); for (int x = 0; x < this.header.Width; x++) { ref Rgb24 rgb24 = ref rgb24Span[x]; @@ -788,8 +788,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { // TODO: Should we use pack from vector here instead? - this.From16BitTo8Bit(scanlineBuffer, compressed.Span, length); - PixelOperations.Instance.PackFromRgba32Bytes(compressed.Span, rowSpan, this.header.Width); + this.From16BitTo8Bit(scanlineBuffer, compressed.GetSpan(), length); + PixelOperations.Instance.PackFromRgba32Bytes(compressed.GetSpan(), rowSpan, this.header.Width); } } else @@ -986,7 +986,7 @@ namespace SixLabors.ImageSharp.Formats.Png int length = this.header.Width * 3; using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { - Span compressedSpan = compressed.Span; + Span compressedSpan = compressed.GetSpan(); // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); @@ -1056,7 +1056,7 @@ namespace SixLabors.ImageSharp.Formats.Png int length = this.header.Width * 4; using (IBuffer compressed = this.configuration.MemoryManager.Allocate(length)) { - Span compressedSpan = compressed.Span; + Span compressedSpan = compressed.GetSpan(); // TODO: Should we use pack from vector here instead? this.From16BitTo8Bit(scanlineBuffer, compressedSpan, length); @@ -1229,7 +1229,7 @@ namespace SixLabors.ImageSharp.Formats.Png { this.crc.Reset(); this.crc.Update(this.chunkTypeBuffer); - this.crc.Update(chunk.Data.Span); + this.crc.Update(chunk.Data.GetSpan()); if (this.crc.Value != chunk.Crc) { diff --git a/src/ImageSharp/Formats/Png/PngEncoderCore.cs b/src/ImageSharp/Formats/Png/PngEncoderCore.cs index f17c9009a6..b9e09070e2 100644 --- a/src/ImageSharp/Formats/Png/PngEncoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngEncoderCore.cs @@ -283,11 +283,11 @@ namespace SixLabors.ImageSharp.Formats.Png { if (this.bytesPerPixel == 4) { - PixelOperations.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.Span, this.width); + PixelOperations.Instance.ToRgba32Bytes(rowSpan, this.rawScanline.GetSpan(), this.width); } else { - PixelOperations.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.Span, this.width); + PixelOperations.Instance.ToRgb24Bytes(rowSpan, this.rawScanline.GetSpan(), this.width); } } @@ -320,23 +320,23 @@ namespace SixLabors.ImageSharp.Formats.Png switch (this.pngFilterMethod) { case PngFilterMethod.None: - NoneFilter.Encode(this.rawScanline.Span, this.result.Span); + NoneFilter.Encode(this.rawScanline.GetSpan(), this.result.GetSpan()); return this.result; 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; 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; 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; 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; default: @@ -354,21 +354,21 @@ namespace SixLabors.ImageSharp.Formats.Png // Palette images don't compress well with adaptive filtering. 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; } - Span scanSpan = this.rawScanline.Span; - Span prevSpan = this.previousScanline.Span; + Span scanSpan = this.rawScanline.GetSpan(); + Span prevSpan = this.previousScanline.GetSpan(); // 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. - UpFilter.Encode(scanSpan, prevSpan, this.up.Span, out int currentSum); + UpFilter.Encode(scanSpan, prevSpan, this.up.GetSpan(), out int currentSum); int lowestSum = currentSum; 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) { @@ -376,7 +376,7 @@ namespace SixLabors.ImageSharp.Formats.Png 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) { @@ -384,7 +384,7 @@ namespace SixLabors.ImageSharp.Formats.Png 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) { @@ -463,8 +463,8 @@ namespace SixLabors.ImageSharp.Formats.Png using (IManagedByteBuffer colorTable = this.memoryManager.AllocateManagedByteBuffer(colorTableLength)) using (IManagedByteBuffer alphaTable = this.memoryManager.AllocateManagedByteBuffer(pixelCount)) { - Span colorTableSpan = colorTable.Span; - Span alphaTableSpan = alphaTable.Span; + Span colorTableSpan = colorTable.GetSpan(); + Span alphaTableSpan = alphaTable.GetSpan(); for (byte i = 0; i < pixelCount; i++) { diff --git a/src/ImageSharp/Image.Decode.cs b/src/ImageSharp/Image.Decode.cs index 6b44c893bc..3f3dbb7e28 100644 --- a/src/ImageSharp/Image.Decode.cs +++ b/src/ImageSharp/Image.Decode.cs @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp long startPosition = stream.Position; stream.Read(buffer.Array, 0, maxHeaderSize); 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); } } diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index 0caacd8a8d..5886ca6fde 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -289,7 +289,7 @@ namespace SixLabors.ImageSharp { Span sourceRow = this.GetPixelRowSpan(y); Span targetRow = target.GetPixelRowSpan(y); - Span tempRowSpan = tempRowBuffer.Span; + Span tempRowSpan = tempRowBuffer.GetSpan(); PixelOperations.Instance.ToScaledVector4(sourceRow, tempRowSpan, sourceRow.Length); PixelOperations.Instance.PackFromScaledVector4(tempRowSpan, targetRow, targetRow.Length); diff --git a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs index 5ca81b5ecb..ecf064339c 100644 --- a/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs +++ b/src/ImageSharp/Memory/ArrayPoolMemoryManager.Buffer{T}.cs @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Memory protected byte[] Data { get; private set; } /// - public Span Span => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); + public Span GetSpan() => MemoryMarshal.Cast(this.Data.AsSpan()).Slice(0, this.length); /// public void Dispose() diff --git a/src/ImageSharp/Memory/BasicArrayBuffer.cs b/src/ImageSharp/Memory/BasicArrayBuffer.cs index dd2f7ef866..7574887552 100644 --- a/src/ImageSharp/Memory/BasicArrayBuffer.cs +++ b/src/ImageSharp/Memory/BasicArrayBuffer.cs @@ -25,8 +25,6 @@ namespace SixLabors.ImageSharp.Memory public int Length { get; } - public Span Span => this.Array.AsSpan(0, this.Length); - /// /// Returns a reference to specified element of the buffer. /// @@ -39,11 +37,14 @@ namespace SixLabors.ImageSharp.Memory { DebugGuard.MustBeLessThan(index, this.Length, nameof(index)); - Span span = this.Span; + Span span = this.GetSpan(); return ref span[index]; } } + /// + public Span GetSpan() => this.Array.AsSpan(0, this.Length); + public void Dispose() { } diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index dc992368c9..0c780426d3 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Gets the span to the whole area. /// - public Span Span => this.Buffer.Span; + public Span Span => this.Buffer.GetSpan(); /// /// Gets the backing @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Memory { DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); - Span span = this.Buffer.Span; + Span span = this.Buffer.GetSpan(); return ref span[(this.Width * y) + x]; } } diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index dd3114c21c..0f04f34f20 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -12,7 +12,7 @@ namespace SixLabors.ImageSharp.Memory { [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int Length(this IBuffer buffer) - where T : struct => buffer.Span.Length; + where T : struct => buffer.GetSpan().Length; /// /// Gets a to an offseted position inside the buffer. @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Memory public static Span Slice(this IBuffer buffer, int start) where T : struct { - return buffer.Span.Slice(start); + return buffer.GetSpan().Slice(start); } /// @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Memory public static Span Slice(this IBuffer buffer, int start, int length) where T : struct { - return buffer.Span.Slice(start, length); + return buffer.GetSpan().Slice(start, length); } /// @@ -49,12 +49,12 @@ namespace SixLabors.ImageSharp.Memory public static void Clear(this IBuffer buffer) where T : struct { - buffer.Span.Clear(); + buffer.GetSpan().Clear(); } public static ref T DangerousGetPinnableReference(this IBuffer buffer) where T : struct => - ref MemoryMarshal.GetReference(buffer.Span); + ref MemoryMarshal.GetReference(buffer.GetSpan()); public static void Read(this Stream stream, IManagedByteBuffer buffer) { diff --git a/src/ImageSharp/Memory/IBuffer{T}.cs b/src/ImageSharp/Memory/IBuffer{T}.cs index db6bf5b389..9943134f53 100644 --- a/src/ImageSharp/Memory/IBuffer{T}.cs +++ b/src/ImageSharp/Memory/IBuffer{T}.cs @@ -16,6 +16,7 @@ namespace SixLabors.ImageSharp.Memory /// /// Gets the span to the memory "promised" by this buffer /// - Span Span { get; } + /// The + Span GetSpan(); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs index b676f6a122..5b87727908 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs @@ -70,8 +70,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer amount = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture colorSpan & amountSpan in the lambda below! - Span colorSpan = colors.Span; - Span amountSpan = amount.Span; + Span colorSpan = colors.GetSpan(); + Span amountSpan = amount.GetSpan(); // TODO: Use Span.Fill? for (int i = 0; i < width; i++) @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span 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 - blender.Blend(source.MemoryManager, destination, colors.Span, destination, amount.Span); + blender.Blend(source.MemoryManager, destination, colors.GetSpan(), destination, amount.GetSpan()); }); } } diff --git a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs index ac5d3dc82e..b5571ffd04 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs @@ -115,7 +115,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! - Span rowColorsSpan = rowColors.Span; + Span rowColorsSpan = rowColors.GetSpan(); for (int i = 0; i < width; i++) { @@ -130,7 +130,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors { using (IBuffer amounts = source.MemoryManager.Allocate(width)) { - Span amountsSpan = amounts.Span; + Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; int offsetX = minX - startX; for (int i = 0; i < width; i++) @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span 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); } }); } diff --git a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs index ec286db626..06bf668d4b 100644 --- a/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs @@ -117,7 +117,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors using (IBuffer rowColors = source.MemoryManager.Allocate(width)) { // Be careful! Do not capture rowColorsSpan in the lambda below! - Span rowColorsSpan = rowColors.Span; + Span rowColorsSpan = rowColors.GetSpan(); for (int i = 0; i < width; i++) { @@ -132,7 +132,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors { using (IBuffer amounts = source.MemoryManager.Allocate(width)) { - Span amountsSpan = amounts.Span; + Span amountsSpan = amounts.GetSpan(); int offsetY = y - startY; int offsetX = minX - startX; for (int i = 0; i < width; i++) @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors Span 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); } }); } diff --git a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs b/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs index bc7a2df715..7887b1b2ea 100644 --- a/src/ImageSharp/Processing/Quantization/FrameQuantizers/WuFrameQuantizer{TPixel}.cs +++ b/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); - 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) { - float r = Volume(ref this.colorCube[k], this.vmr.Span); - float g = Volume(ref this.colorCube[k], this.vmg.Span); - float b = Volume(ref this.colorCube[k], this.vmb.Span); - float a = Volume(ref this.colorCube[k], this.vma.Span); + float r = Volume(ref this.colorCube[k], this.vmr.GetSpan()); + float g = Volume(ref this.colorCube[k], this.vmg.GetSpan()); + float b = Volume(ref this.colorCube[k], this.vmb.GetSpan()); + float a = Volume(ref this.colorCube[k], this.vma.GetSpan()); ref TPixel color = ref this.palette[k]; 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); - Span vwtSpan = this.vwt.Span; - Span vmrSpan = this.vmr.Span; - Span vmgSpan = this.vmg.Span; - Span vmbSpan = this.vmb.Span; - Span vmaSpan = this.vma.Span; - Span m2Span = this.m2.Span; + Span vwtSpan = this.vwt.GetSpan(); + Span vmrSpan = this.vmr.GetSpan(); + Span vmgSpan = this.vmg.GetSpan(); + Span vmbSpan = this.vmb.GetSpan(); + Span vmaSpan = this.vma.GetSpan(); + Span m2Span = this.m2.GetSpan(); vwtSpan[index]++; vmrSpan[index] += rgba.R; @@ -466,12 +466,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// private void Get3DMoments(MemoryManager memoryManager) { - Span vwtSpan = this.vwt.Span; - Span vmrSpan = this.vmr.Span; - Span vmgSpan = this.vmg.Span; - Span vmbSpan = this.vmb.Span; - Span vmaSpan = this.vma.Span; - Span m2Span = this.m2.Span; + Span vwtSpan = this.vwt.GetSpan(); + Span vmrSpan = this.vmr.GetSpan(); + Span vmgSpan = this.vmg.GetSpan(); + Span vmbSpan = this.vmb.GetSpan(); + Span vmaSpan = this.vma.GetSpan(); + Span m2Span = this.m2.GetSpan(); using (IBuffer volume = memoryManager.Allocate(IndexCount * IndexAlphaCount)) using (IBuffer volumeR = memoryManager.Allocate(IndexCount * IndexAlphaCount)) @@ -487,19 +487,19 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers using (IBuffer areaA = memoryManager.Allocate(IndexAlphaCount)) using (IBuffer area2 = memoryManager.Allocate(IndexAlphaCount)) { - Span volumeSpan = volume.Span; - Span volumeRSpan = volumeR.Span; - Span volumeGSpan = volumeG.Span; - Span volumeBSpan = volumeB.Span; - Span volumeASpan = volumeA.Span; - Span volume2Span = volume2.Span; - - Span areaSpan = area.Span; - Span areaRSpan = areaR.Span; - Span areaGSpan = areaG.Span; - Span areaBSpan = areaB.Span; - Span areaASpan = areaA.Span; - Span area2Span = area2.Span; + Span volumeSpan = volume.GetSpan(); + Span volumeRSpan = volumeR.GetSpan(); + Span volumeGSpan = volumeG.GetSpan(); + Span volumeBSpan = volumeB.GetSpan(); + Span volumeASpan = volumeA.GetSpan(); + Span volume2Span = volume2.GetSpan(); + + Span areaSpan = area.GetSpan(); + Span areaRSpan = areaR.GetSpan(); + Span areaGSpan = areaG.GetSpan(); + Span areaBSpan = areaB.GetSpan(); + Span areaASpan = areaA.GetSpan(); + Span area2Span = area2.GetSpan(); for (int r = 1; r < IndexCount; r++) { @@ -577,12 +577,12 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The . private float Variance(ref Box cube) { - float dr = Volume(ref cube, this.vmr.Span); - float dg = Volume(ref cube, this.vmg.Span); - float db = Volume(ref cube, this.vmb.Span); - float da = Volume(ref cube, this.vma.Span); + float dr = Volume(ref cube, this.vmr.GetSpan()); + float dg = Volume(ref cube, this.vmg.GetSpan()); + float db = Volume(ref cube, this.vmb.GetSpan()); + float da = Volume(ref cube, this.vma.GetSpan()); - Span m2Span = this.m2.Span; + Span m2Span = this.m2.GetSpan(); float xx = 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)]; 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())); } /// @@ -626,22 +626,22 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// The . 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 baseG = Bottom(ref cube, direction, this.vmg.Span); - long baseB = Bottom(ref cube, direction, this.vmb.Span); - long baseA = Bottom(ref cube, direction, this.vma.Span); - long baseW = Bottom(ref cube, direction, this.vwt.Span); + long baseR = Bottom(ref cube, direction, this.vmr.GetSpan()); + long baseG = Bottom(ref cube, direction, this.vmg.GetSpan()); + long baseB = Bottom(ref cube, direction, this.vmb.GetSpan()); + long baseA = Bottom(ref cube, direction, this.vma.GetSpan()); + long baseW = Bottom(ref cube, direction, this.vwt.GetSpan()); float max = 0F; cut = -1; for (int i = first; i < last; i++) { - float halfR = baseR + Top(ref cube, direction, i, this.vmr.Span); - float halfG = baseG + Top(ref cube, direction, i, this.vmg.Span); - float halfB = baseB + Top(ref cube, direction, i, this.vmb.Span); - float halfA = baseA + Top(ref cube, direction, i, this.vma.Span); - float halfW = baseW + Top(ref cube, direction, i, this.vwt.Span); + float halfR = baseR + Top(ref cube, direction, i, this.vmr.GetSpan()); + float halfG = baseG + Top(ref cube, direction, i, this.vmg.GetSpan()); + float halfB = baseB + Top(ref cube, direction, i, this.vmb.GetSpan()); + float halfA = baseA + Top(ref cube, direction, i, this.vma.GetSpan()); + float halfW = baseW + Top(ref cube, direction, i, this.vwt.GetSpan()); if (MathF.Abs(halfW) < Constants.Epsilon) { @@ -685,11 +685,11 @@ namespace SixLabors.ImageSharp.Processing.Quantization.FrameQuantizers /// Returns a value indicating whether the box has been split. private bool Cut(ref Box set1, ref Box set2) { - float wholeR = Volume(ref set1, this.vmr.Span); - float wholeG = Volume(ref set1, this.vmg.Span); - float wholeB = Volume(ref set1, this.vmb.Span); - float wholeA = Volume(ref set1, this.vma.Span); - float wholeW = Volume(ref set1, this.vwt.Span); + float wholeR = Volume(ref set1, this.vmr.GetSpan()); + float wholeG = Volume(ref set1, this.vmg.GetSpan()); + float wholeB = Volume(ref set1, this.vmb.GetSpan()); + float wholeA = Volume(ref set1, this.vma.GetSpan()); + 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 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 /// A label. private void Mark(ref Box cube, byte label) { - Span tagSpan = this.tag.Span; + Span tagSpan = this.tag.GetSpan(); 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 a = rgba.A >> (8 - IndexAlphaBits); - Span tagSpan = this.tag.Span; + Span tagSpan = this.tag.GetSpan(); return tagSpan[GetPaletteIndex(r + 1, g + 1, b + 1, a + 1)]; } diff --git a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs b/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs index 773b16e73d..fc8d943627 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/ResizeProcessor.cs +++ b/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)); Span sourceRow = source.GetPixelRowSpan(y); - Span tempRowSpan = tempRowBuffer.Span; + Span tempRowSpan = tempRowBuffer.GetSpan(); PixelOperations.Instance.ToVector4(sourceRow, tempRowSpan, sourceRow.Length); diff --git a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs index a211052728..0eac88fd32 100644 --- a/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs +++ b/src/ImageSharp/Processing/Transforms/Processors/WeightsWindow.cs @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Transforms.Processors [MethodImpl(MethodImplOptions.AggressiveInlining)] public ref float GetStartReference() { - Span span = this.buffer.Span; + Span span = this.buffer.GetSpan(); return ref span[this.flatStartIndex]; } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs index af754ba344..329fcbe670 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromVector4.cs @@ -37,8 +37,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - ref Vector4 s = ref MemoryMarshal.GetReference(this.source.Span); - ref TPixel d = ref MemoryMarshal.GetReference(this.destination.Span); + ref Vector4 s = ref MemoryMarshal.GetReference(this.source.GetSpan()); + ref TPixel d = ref MemoryMarshal.GetReference(this.destination.GetSpan()); for (int i = 0; i < this.Count; i++) { @@ -49,13 +49,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().PackFromVector4(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.PackFromVector4(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.PackFromVector4(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs index 64327d378f..31583bfe26 100644 --- a/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs +++ b/tests/ImageSharp.Benchmarks/Color/Bulk/PackFromXyzw.cs @@ -35,8 +35,8 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark(Baseline = true)] public void PerElement() { - Span s = this.source.Span; - Span d = this.destination.Span; + Span s = this.source.GetSpan(); + Span d = this.destination.GetSpan(); for (int i = 0; i < this.Count; i++) { @@ -50,13 +50,13 @@ namespace SixLabors.ImageSharp.Benchmarks.ColorSpaces.Bulk [Benchmark] public void CommonBulk() { - new PixelOperations().PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + new PixelOperations().PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } [Benchmark] public void OptimizedBulk() { - PixelOperations.Instance.PackFromRgba32Bytes(this.source.Span, this.destination.Span, this.Count); + PixelOperations.Instance.PackFromRgba32Bytes(this.source.GetSpan(), this.destination.GetSpan(), this.Count); } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs index 811af96757..46a688b49c 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/SpectralJpegTests.cs @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg this.Output.WriteLine($"Component{i}: {diff}"); averageDifference += diff.average; totalDifference += diff.total; - tolerance += libJpegComponent.SpectralBlocks.Buffer.Span.Length; + tolerance += libJpegComponent.SpectralBlocks.Buffer.GetSpan().Length; } averageDifference /= componentCount; diff --git a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs index bacdfb504d..c3d59b0398 100644 --- a/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs +++ b/tests/ImageSharp.Tests/Memory/ArrayPoolMemoryManagerTests.cs @@ -132,13 +132,13 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer firstAlloc = this.MemoryManager.Allocate(42)) { - firstAlloc.Span.Fill(666); + firstAlloc.GetSpan().Fill(666); } using (IBuffer secondAlloc = this.MemoryManager.Allocate(42, clean)) { 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) { IBuffer buffer = this.MemoryManager.Allocate(32); - ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.Span); + ref int ptrToPrev0 = ref MemoryMarshal.GetReference(buffer.GetSpan()); if (!keepBufferAlive) { diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index d092df45a6..896bde0359 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -119,7 +119,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (Buffer2D buffer = this.MemoryManager.Allocate2D(width, height)) { - Span span = buffer.Buffer.Span; + Span span = buffer.Buffer.GetSpan(); ref TestStructs.Foo actual = ref buffer[x, y]; diff --git a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs index eff1f197a0..68c6632b9b 100644 --- a/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs +++ b/tests/ImageSharp.Tests/Memory/BufferTestSuite.cs @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer buffer = this.MemoryManager.Allocate(desiredLength)) { - Assert.Equal(desiredLength, buffer.Span.Length); + Assert.Equal(desiredLength, buffer.GetSpan().Length); } } @@ -141,7 +141,7 @@ namespace SixLabors.ImageSharp.Tests.Memory { using (IBuffer buffer = this.Allocate(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 buffer = this.Allocate(desiredLength, false, testManagedByteBuffer)) { - ref T a = ref MemoryMarshal.GetReference(buffer.Span); - ref T b = ref MemoryMarshal.GetReference(buffer.Span); - ref T c = ref MemoryMarshal.GetReference(buffer.Span); + ref T a = ref MemoryMarshal.GetReference(buffer.GetSpan()); + ref T b = ref MemoryMarshal.GetReference(buffer.GetSpan()); + ref T c = ref MemoryMarshal.GetReference(buffer.GetSpan()); Assert.True(Unsafe.AreSame(ref a, ref b)); 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++) { - Span span = buffer.Span; + Span span = buffer.GetSpan(); expectedVals[i] = getExpectedValue(i); span[i] = expectedVals[i]; } for (int i = 0; i < buffer.Length(); i++) { - Span span = buffer.Span; + Span span = buffer.GetSpan(); Assert.Equal(expectedVals[i], span[i]); } } @@ -244,21 +244,21 @@ namespace SixLabors.ImageSharp.Tests.Memory Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength]; }); Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength + 1]; }); Assert.ThrowsAny( () => { - Span span = buffer.Span; + Span span = buffer.GetSpan(); dummy = span[desiredLength + 42]; }); } @@ -279,7 +279,7 @@ namespace SixLabors.ImageSharp.Tests.Memory ref byte span0 = ref buffer.DangerousGetPinnableReference(); Assert.True(Unsafe.AreSame(ref span0, ref array0)); - Assert.True(buffer.Array.Length >= buffer.Span.Length); + Assert.True(buffer.Array.Length >= buffer.GetSpan().Length); } } } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs index 4ae11301d5..97e4615c04 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, 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, () => { - PixelOperations.Instance.ToVector4(source.Span, dest.Span, count); + PixelOperations.Instance.ToVector4(source.GetSpan(), dest.GetSpan(), count); }); } } @@ -133,7 +133,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats TestOperation( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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( source, 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 expected = MemoryMarshal.Cast(this.ExpectedDestBuffer.AsSpan()); - Span actual = MemoryMarshal.Cast(this.ActualDestBuffer.Span); + Span actual = MemoryMarshal.Cast(this.ActualDestBuffer.GetSpan()); for (int i = 0; i < count; i++) { @@ -471,7 +471,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats else { Span expected = this.ExpectedDestBuffer.AsSpan(); - Span actual = this.ActualDestBuffer.Span; + Span actual = this.ActualDestBuffer.GetSpan(); for (int i = 0; i < count; i++) { Assert.Equal(expected[i], actual[i]); diff --git a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs index d04d2343f6..650b1a0539 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/SystemDrawingBridge.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs byte* sourcePtr = sourcePtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); - PixelOperations.Instance.PackFromBgra32(workBuffer.Span, row, row.Length); + PixelOperations.Instance.PackFromBgra32(workBuffer.GetSpan(), row, row.Length); } } } @@ -87,9 +87,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs byte* sourcePtr = sourcePtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount); - PixelOperations.Instance.PackFromBgr24(workBuffer.Span, row, row.Length); + PixelOperations.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++) { Span row = image.Frames.RootFrame.GetPixelRowSpan(y); - PixelOperations.Instance.ToBgra32(row, workBuffer.Span, row.Length); + PixelOperations.Instance.ToBgra32(row, workBuffer.GetSpan(), row.Length); byte* destPtr = destPtrBase + data.Stride * y; Buffer.MemoryCopy(sourcePtr, destPtr, destRowByteCount, sourceRowByteCount);