diff --git a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs index fc6ba10b0..fd9f98ac9 100644 --- a/src/ImageSharp/Advanced/AdvancedImageExtensions.cs +++ b/src/ImageSharp/Advanced/AdvancedImageExtensions.cs @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Advanced /// public static IMemoryGroup GetPixelMemoryGroup(this ImageFrame source) where TPixel : struct, IPixel - => source.PixelBuffer.MemoryGroup.View; + => source?.PixelBuffer.MemoryGroup.View ?? throw new ArgumentNullException(nameof(source)); /// /// Gets the representation of the pixels as a containing the backing pixel data of the image @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Advanced /// public static IMemoryGroup GetPixelMemoryGroup(this Image source) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelMemoryGroup(); + => source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source)); /// /// Gets the representation of the pixels as a in the source image's pixel format @@ -91,6 +91,8 @@ namespace SixLabors.ImageSharp.Advanced public static Span GetPixelSpan(this ImageFrame source) where TPixel : struct, IPixel { + Guard.NotNull(source, nameof(source)); + IMemoryGroup mg = source.GetPixelMemoryGroup(); if (mg.Count > 1) { @@ -112,7 +114,11 @@ namespace SixLabors.ImageSharp.Advanced @"GetPixelSpan might fail, because the backing buffer could be discontiguous for large images. Use GetPixelMemoryGroup or GetPixelRowSpan instead!")] public static Span GetPixelSpan(this Image source) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelSpan(); + { + Guard.NotNull(source, nameof(source)); + + return source.Frames.RootFrame.GetPixelSpan(); + } /// /// Gets the representation of the pixels as a of contiguous memory @@ -124,7 +130,13 @@ namespace SixLabors.ImageSharp.Advanced /// The public static Span GetPixelRowSpan(this ImageFrame source, int rowIndex) where TPixel : struct, IPixel - => source.PixelBuffer.GetRowSpan(rowIndex); + { + Guard.NotNull(source, nameof(source)); + Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex)); + Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex)); + + return source.PixelBuffer.GetRowSpanUnchecked(rowIndex); + } /// /// Gets the representation of the pixels as of of contiguous memory @@ -136,7 +148,13 @@ namespace SixLabors.ImageSharp.Advanced /// The public static Span GetPixelRowSpan(this Image source, int rowIndex) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelRowSpan(rowIndex); + { + Guard.NotNull(source, nameof(source)); + Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex)); + Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex)); + + return source.Frames.RootFrame.PixelBuffer.GetRowSpanUnchecked(rowIndex); + } /// /// Gets the representation of the pixels as a of contiguous memory @@ -148,7 +166,13 @@ namespace SixLabors.ImageSharp.Advanced /// The public static Memory GetPixelRowMemory(this ImageFrame source, int rowIndex) where TPixel : struct, IPixel - => source.PixelBuffer.GetRowMemorySafe(rowIndex); + { + Guard.NotNull(source, nameof(source)); + Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex)); + Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex)); + + return source.PixelBuffer.GetRowMemorySafe(rowIndex); + } /// /// Gets the representation of the pixels as of of contiguous memory @@ -160,7 +184,13 @@ namespace SixLabors.ImageSharp.Advanced /// The public static Memory GetPixelRowMemory(this Image source, int rowIndex) where TPixel : struct, IPixel - => source.Frames.RootFrame.GetPixelRowMemory(rowIndex); + { + Guard.NotNull(source, nameof(source)); + Guard.MustBeGreaterThanOrEqualTo(rowIndex, 0, nameof(rowIndex)); + Guard.MustBeLessThan(rowIndex, source.Height, nameof(rowIndex)); + + return source.Frames.RootFrame.PixelBuffer.GetRowMemorySafe(rowIndex); + } /// /// Gets the assigned to 'source'. diff --git a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs index f82774601..677520ddd 100644 --- a/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs +++ b/src/ImageSharp/Common/Helpers/Buffer2DUtils.cs @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp { int offsetY = (row + i - radiusY).Clamp(minRow, maxRow); int offsetX = sourceOffsetColumnBase.Clamp(minColumn, maxColumn); - Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); + Span sourceRowSpan = sourcePixels.GetRowSpanUnchecked(offsetY); var currentColor = sourceRowSpan[offsetX].ToVector4(); vector.Sum(Unsafe.Add(ref baseRef, i) * currentColor); @@ -94,7 +94,7 @@ namespace SixLabors.ImageSharp int sourceOffsetColumnBase = column + minColumn; int offsetY = row.Clamp(minRow, maxRow); - ref ComplexVector4 sourceRef = ref MemoryMarshal.GetReference(sourceValues.GetRowSpan(offsetY)); + ref ComplexVector4 sourceRef = ref MemoryMarshal.GetReference(sourceValues.GetRowSpanUnchecked(offsetY)); ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel); for (int x = 0; x < kernelLength; x++) diff --git a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs index ff6e3a4ec..baab397f8 100644 --- a/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs +++ b/src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp for (int y = 0; y < matrixHeight; y++) { int offsetY = (row + y - radiusY).Clamp(minRow, maxRow); - Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); + Span sourceRowSpan = sourcePixels.GetRowSpanUnchecked(offsetY); for (int x = 0; x < matrixWidth; x++) { @@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp for (int y = 0; y < matrixHeight; y++) { int offsetY = (row + y - radiusY).Clamp(minRow, maxRow); - Span sourceRowSpan = sourcePixels.GetRowSpan(offsetY); + Span sourceRowSpan = sourcePixels.GetRowSpanUnchecked(offsetY); for (int x = 0; x < matrixWidth; x++) { diff --git a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs index 3e1637e70..c46504cce 100644 --- a/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs @@ -311,8 +311,8 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int y = 0; y < height; y++) { int newY = Invert(y, height, inverted); - Span bufferRow = buffer.GetRowSpan(y); - Span pixelRow = pixels.GetRowSpan(newY); + Span bufferRow = buffer.GetRowSpanUnchecked(y); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); bool rowHasUndefinedPixels = rowsWithUndefinedPixelsSpan[y]; if (rowHasUndefinedPixels) @@ -381,7 +381,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp for (int y = 0; y < height; y++) { int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); bool rowHasUndefinedPixels = rowsWithUndefinedPixelsSpan[y]; if (rowHasUndefinedPixels) { @@ -830,7 +830,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp int newY = Invert(y, height, inverted); this.stream.Read(row.Array, 0, row.Length()); int offset = 0; - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); for (int x = 0; x < arrayWidth; x++) { @@ -882,7 +882,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { this.stream.Read(buffer.Array, 0, stride); int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); int offset = 0; for (int x = 0; x < width; x++) @@ -938,7 +938,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { this.stream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgr24Bytes( this.configuration, row.GetSpan(), @@ -967,7 +967,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { this.stream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgra32Bytes( this.configuration, row.GetSpan(), @@ -1039,7 +1039,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp this.stream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgra32Bytes( this.configuration, @@ -1062,7 +1062,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp width); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); for (int x = 0; x < width; x++) { @@ -1117,7 +1117,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { this.stream.Read(buffer.Array, 0, stride); int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); int offset = 0; for (int x = 0; x < width; x++) diff --git a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs index 1c7c606ca..12056fb0c 100644 --- a/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs +++ b/src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs @@ -240,7 +240,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgra32Bytes( this.configuration, pixelSpan, @@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgr24Bytes( this.configuration, pixelSpan, @@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgra5551Bytes( this.configuration, diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs index 61e359869..87f5233e9 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs @@ -136,20 +136,20 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters { this.ComponentCount = componentBuffers.Count; - this.Component0 = componentBuffers[0].GetRowSpan(row); + this.Component0 = componentBuffers[0].GetRowSpanUnchecked(row); this.Component1 = Span.Empty; this.Component2 = Span.Empty; this.Component3 = Span.Empty; if (this.ComponentCount > 1) { - this.Component1 = componentBuffers[1].GetRowSpan(row); + this.Component1 = componentBuffers[1].GetRowSpanUnchecked(row); if (this.ComponentCount > 2) { - this.Component2 = componentBuffers[2].GetRowSpan(row); + this.Component2 = componentBuffers[2].GetRowSpanUnchecked(row); if (this.ComponentCount > 3) { - this.Component3 = componentBuffers[3].GetRowSpan(row); + this.Component3 = componentBuffers[3].GetRowSpanUnchecked(row); } } } diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs index fbb2b5272..294d1da19 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs @@ -167,7 +167,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int y = 0; y < v; y++) { int blockRow = (mcuRow * v) + y; - Span blockSpan = component.SpectralBlocks.GetRowSpan(blockRow); + Span blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(blockRow); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); for (int x = 0; x < h; x++) @@ -211,7 +211,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int j = 0; j < h; j++) { - Span blockSpan = component.SpectralBlocks.GetRowSpan(j); + Span blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(j); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); for (int i = 0; i < w; i++) @@ -334,7 +334,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int y = 0; y < v; y++) { int blockRow = (mcuRow * v) + y; - Span blockSpan = component.SpectralBlocks.GetRowSpan(blockRow); + Span blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(blockRow); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); for (int x = 0; x < h; x++) @@ -377,7 +377,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int j = 0; j < h; j++) { - Span blockSpan = component.SpectralBlocks.GetRowSpan(j); + Span blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(j); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); for (int i = 0; i < w; i++) @@ -403,7 +403,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder for (int j = 0; j < h; j++) { - Span blockSpan = component.SpectralBlocks.GetRowSpan(j); + Span blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(j); ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan); for (int i = 0; i < w; i++) diff --git a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs index 39c8be312..5a52c3ac4 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder int yBuffer = y * this.blockAreaSize.Height; - Span blockRow = this.Component.SpectralBlocks.GetRowSpan(yBlock); + Span blockRow = this.Component.SpectralBlocks.GetRowSpanUnchecked(yBlock); ref Block8x8 blockRowBase = ref MemoryMarshal.GetReference(blockRow); diff --git a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs index 57a134703..54976110b 100644 --- a/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs +++ b/src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs @@ -27,14 +27,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components { int y = startY; int height = buffer.Height; - this.row0 = y < height ? buffer.GetRowSpan(y++) : default; - this.row1 = y < height ? buffer.GetRowSpan(y++) : default; - this.row2 = y < height ? buffer.GetRowSpan(y++) : default; - this.row3 = y < height ? buffer.GetRowSpan(y++) : default; - this.row4 = y < height ? buffer.GetRowSpan(y++) : default; - this.row5 = y < height ? buffer.GetRowSpan(y++) : default; - this.row6 = y < height ? buffer.GetRowSpan(y++) : default; - this.row7 = y < height ? buffer.GetRowSpan(y) : default; + this.row0 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row1 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row2 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row3 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row4 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row5 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row6 = y < height ? buffer.GetRowSpanUnchecked(y++) : default; + this.row7 = y < height ? buffer.GetRowSpanUnchecked(y) : default; } public Span this[int y] diff --git a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs index 91cc93e19..5846e88dc 100644 --- a/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaDecoderCore.cs @@ -228,7 +228,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { this.currentStream.Read(row); int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); switch (colorMapPixelSizeInBytes) { case 2: @@ -292,7 +292,7 @@ namespace SixLabors.ImageSharp.Formats.Tga for (int y = 0; y < height; y++) { int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); int rowStartIdx = y * width * bytesPerPixel; for (int x = 0; x < width; x++) { @@ -339,7 +339,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { this.currentStream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromL8Bytes( this.configuration, row.GetSpan(), @@ -374,7 +374,7 @@ namespace SixLabors.ImageSharp.Formats.Tga } int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgra5551Bytes( this.configuration, rowSpan, @@ -401,7 +401,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { this.currentStream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgr24Bytes( this.configuration, row.GetSpan(), @@ -428,7 +428,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { this.currentStream.Read(row); int newY = Invert(y, height, inverted); - Span pixelSpan = pixels.GetRowSpan(newY); + Span pixelSpan = pixels.GetRowSpanUnchecked(newY); PixelOperations.Instance.FromBgra32Bytes( this.configuration, row.GetSpan(), @@ -458,7 +458,7 @@ namespace SixLabors.ImageSharp.Formats.Tga for (int y = 0; y < height; y++) { int newY = Invert(y, height, inverted); - Span pixelRow = pixels.GetRowSpan(newY); + Span pixelRow = pixels.GetRowSpanUnchecked(newY); int rowStartIdx = y * width * bytesPerPixel; for (int x = 0; x < width; x++) { diff --git a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs index 1306061c5..f3451a8e2 100644 --- a/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs +++ b/src/ImageSharp/Formats/Tga/TgaEncoderCore.cs @@ -244,7 +244,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToL8Bytes( this.configuration, pixelSpan, @@ -268,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgra5551Bytes( this.configuration, pixelSpan, @@ -292,7 +292,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgr24Bytes( this.configuration, pixelSpan, @@ -316,7 +316,7 @@ namespace SixLabors.ImageSharp.Formats.Tga { for (int y = pixels.Height - 1; y >= 0; y--) { - Span pixelSpan = pixels.GetRowSpan(y); + Span pixelSpan = pixels.GetRowSpanUnchecked(y); PixelOperations.Instance.ToBgra32Bytes( this.configuration, pixelSpan, diff --git a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs index 62f23ba01..8043c1888 100644 --- a/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs +++ b/src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs @@ -131,10 +131,10 @@ namespace SixLabors.ImageSharp.Memory Guard.MustBeGreaterThanOrEqualTo(length, 0, nameof(length)); int itemSizeBytes = Unsafe.SizeOf(); int bufferSizeInBytes = length * itemSizeBytes; - if (bufferSizeInBytes < 0 || bufferSizeInBytes > BufferCapacityInBytes) + if (bufferSizeInBytes < 0 || bufferSizeInBytes > this.BufferCapacityInBytes) { throw new InvalidMemoryOperationException( - $"Requested allocation {length} elements of {typeof(T).Name} is over the capacity of the MemoryAllocator."); + $"Requested allocation: {length} elements of {typeof(T).Name} is over the capacity of the MemoryAllocator."); } ArrayPool pool = this.GetArrayPool(bufferSizeInBytes); diff --git a/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs b/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs index d02d50d9d..a4e1de197 100644 --- a/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs +++ b/src/ImageSharp/Memory/Allocators/MemoryAllocator.cs @@ -11,8 +11,6 @@ namespace SixLabors.ImageSharp.Memory /// public abstract class MemoryAllocator { - - /// /// Gets the length of the largest contiguous buffer that can be handled by this allocator instance in bytes. /// diff --git a/src/ImageSharp/Memory/Buffer2DExtensions.cs b/src/ImageSharp/Memory/Buffer2DExtensions.cs index 829a2767a..810d55a77 100644 --- a/src/ImageSharp/Memory/Buffer2DExtensions.cs +++ b/src/ImageSharp/Memory/Buffer2DExtensions.cs @@ -14,6 +14,19 @@ namespace SixLabors.ImageSharp.Memory /// public static class Buffer2DExtensions { + /// + /// Gets the backing . + /// + /// The buffer. + /// The element type. + /// The MemoryGroup. + public static IMemoryGroup GetMemoryGroup(this Buffer2D buffer) + where T : struct + { + Guard.NotNull(buffer, nameof(buffer)); + return buffer.MemoryGroup.View; + } + /// /// Gets a to the backing data of /// if the backing group consists of one single contiguous memory buffer. @@ -25,7 +38,9 @@ namespace SixLabors.ImageSharp.Memory /// /// Thrown when the backing group is discontiguous. /// - public static Span GetSingleSpan(this Buffer2D buffer) + // TODO: Review all usages, should be only used with buffers which do not scale fully with image size! + [Obsolete("TODO: Review all usages!")] + internal static Span GetSingleSpan(this Buffer2D buffer) where T : struct { Guard.NotNull(buffer, nameof(buffer)); @@ -48,7 +63,9 @@ namespace SixLabors.ImageSharp.Memory /// /// Thrown when the backing group is discontiguous. /// - public static Memory GetSingleMemory(this Buffer2D buffer) + // TODO: Review all usages, should be only used with buffers which do not scale fully with image size! + [Obsolete("TODO: Review all usages!")] + internal static Memory GetSingleMemory(this Buffer2D buffer) where T : struct { Guard.NotNull(buffer, nameof(buffer)); diff --git a/src/ImageSharp/Memory/Buffer2D{T}.cs b/src/ImageSharp/Memory/Buffer2D{T}.cs index bb00b48cd..29e22767f 100644 --- a/src/ImageSharp/Memory/Buffer2D{T}.cs +++ b/src/ImageSharp/Memory/Buffer2D{T}.cs @@ -50,6 +50,11 @@ namespace SixLabors.ImageSharp.Memory /// /// Gets the backing . /// + /// + /// This property has been kept internal intentionally. + /// It's public counterpart is , + /// which only exposes the view of the MemoryGroup. + /// internal MemoryGroup MemoryGroup { get; } /// @@ -66,7 +71,7 @@ namespace SixLabors.ImageSharp.Memory DebugGuard.MustBeLessThan(x, this.Width, nameof(x)); DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); - return ref this.GetRowSpan(y)[x]; + return ref this.GetRowSpanUnchecked(y)[x]; } } @@ -78,6 +83,9 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span GetRowSpan(int y) { + Guard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); + Guard.MustBeLessThan(y, this.Height, nameof(y)); + return this.cachedMemory.Length > 0 ? this.cachedMemory.Span.Slice(y * this.Width, this.Width) : this.GetRowMemorySlow(y).Span; @@ -92,6 +100,20 @@ namespace SixLabors.ImageSharp.Memory this.cachedMemory = default; } + /// + /// Same as , but does not validate index in Release mode. + /// + [MethodImpl(MethodImplOptions.AggressiveInlining)] + internal Span GetRowSpanUnchecked(int y) + { + DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); + DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); + + return this.cachedMemory.Length > 0 + ? this.cachedMemory.Span.Slice(y * this.Width, this.Width) + : this.GetRowMemorySlow(y).Span; + } + /// /// Gets a to the row 'y' beginning from the pixel at the first pixel on that row. /// This method is intended for internal use only, since it does not use the indirection provided by @@ -102,6 +124,8 @@ namespace SixLabors.ImageSharp.Memory [MethodImpl(MethodImplOptions.AggressiveInlining)] internal Memory GetRowMemoryFast(int y) { + DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); + DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); return this.cachedMemory.Length > 0 ? this.cachedMemory.Slice(y * this.Width, this.Width) : this.GetRowMemorySlow(y); @@ -112,7 +136,12 @@ namespace SixLabors.ImageSharp.Memory /// /// The y (row) coordinate. /// The . - internal Memory GetRowMemorySafe(int y) => this.MemoryGroup.View.GetBoundedSlice(y * this.Width, this.Width); + internal Memory GetRowMemorySafe(int y) + { + DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y)); + DebugGuard.MustBeLessThan(y, this.Height, nameof(y)); + return this.MemoryGroup.View.GetBoundedSlice(y * this.Width, this.Width); + } /// /// Swaps the contents of 'destination' with 'source' if the buffers are owned (1), diff --git a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs index 1b4c297f3..7d6afbc7b 100644 --- a/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs +++ b/src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs @@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Memory { internal static class MemoryGroupExtensions { - public static void Fill(this IMemoryGroup group, T value) + internal static void Fill(this IMemoryGroup group, T value) where T : struct { foreach (Memory memory in group) @@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Memory } } - public static void Clear(this IMemoryGroup group) + internal static void Clear(this IMemoryGroup group) where T : struct { foreach (Memory memory in group) @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Memory /// Returns a slice that is expected to be within the bounds of a single buffer. /// Otherwise is thrown. /// - public static Memory GetBoundedSlice(this IMemoryGroup group, long start, int length) + internal static Memory GetBoundedSlice(this IMemoryGroup group, long start, int length) where T : struct { Guard.NotNull(group, nameof(group)); @@ -55,7 +55,7 @@ namespace SixLabors.ImageSharp.Memory return memory.Slice(bufferStart, length); } - public static void CopyTo(this IMemoryGroup source, Span target) + internal static void CopyTo(this IMemoryGroup source, Span target) where T : struct { Guard.NotNull(source, nameof(source)); @@ -74,11 +74,11 @@ namespace SixLabors.ImageSharp.Memory } } - public static void CopyTo(this Span source, IMemoryGroup target) + internal static void CopyTo(this Span source, IMemoryGroup target) where T : struct => CopyTo((ReadOnlySpan)source, target); - public static void CopyTo(this ReadOnlySpan source, IMemoryGroup target) + internal static void CopyTo(this ReadOnlySpan source, IMemoryGroup target) where T : struct { Guard.NotNull(target, nameof(target)); @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Memory } } - public static void CopyTo(this IMemoryGroup source, IMemoryGroup target) + internal static void CopyTo(this IMemoryGroup source, IMemoryGroup target) where T : struct { Guard.NotNull(source, nameof(source)); @@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Memory } } - public static void TransformTo( + internal static void TransformTo( this IMemoryGroup source, IMemoryGroup target, TransformItemsDelegate transform) @@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.Memory } } - public static void TransformInplace( + internal static void TransformInplace( this IMemoryGroup memoryGroup, TransformItemsInplaceDelegate transform) where T : struct @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Memory } } - public static bool IsEmpty(this IMemoryGroup group) + internal static bool IsEmpty(this IMemoryGroup group) where T : struct => group.Count == 0; diff --git a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs index 316579da7..e44076b3b 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs @@ -349,7 +349,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution { for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetValues.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetValues.GetRowSpanUnchecked(y).Slice(startX); for (int x = 0; x < width; x++) { @@ -396,7 +396,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution { for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetValues.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetValues.GetRowSpanUnchecked(y).Slice(startX); for (int x = 0; x < width; x++) { @@ -438,7 +438,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX); PixelOperations.Instance.ToVector4(configuration, targetRowSpan.Slice(0, length), vectorSpan, PixelConversionModifiers.Premultiply); ref Vector4 baseRef = ref MemoryMarshal.GetReference(vectorSpan); @@ -489,8 +489,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int y = rows.Min; y < rows.Max; y++) { - Span targetPixelSpan = targetPixels.GetRowSpan(y).Slice(startX); - Span sourceRowSpan = sourceValues.GetRowSpan(y).Slice(startX); + Span targetPixelSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX); + Span sourceRowSpan = sourceValues.GetRowSpanUnchecked(y).Slice(startX); ref Vector4 sourceRef = ref MemoryMarshal.GetReference(sourceRowSpan); for (int x = 0; x < width; x++) diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs index c2b85a4ab..1e30d6a4a 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs @@ -90,7 +90,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX); PixelOperations.Instance.ToVector4(this.Configuration, targetRowSpan.Slice(0, length), vectorSpan); if (preserveAlpha) diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs index 32bdf6bc5..f36d5d6d0 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs @@ -109,7 +109,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX); PixelOperations.Instance.ToVector4(configuration, targetRowSpan.Slice(0, length), vectorSpan); if (preserveAlpha) diff --git a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs index 285bcab27..779360bde 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs @@ -80,7 +80,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution for (int y = rows.Min; y < rows.Max; y++) { - Span targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX); + Span targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX); PixelOperations.Instance.ToVector4(this.Configuration, targetRowSpan.Slice(0, length), vectorSpan); if (preserveAlpha) diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs index c1897bed8..29178300e 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs @@ -118,8 +118,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Convolution { int offsetY = y - shiftY; - ref TPixel passPixelsBase = ref MemoryMarshal.GetReference(passPixels.GetRowSpan(offsetY)); - ref TPixel targetPixelsBase = ref MemoryMarshal.GetReference(targetPixels.GetRowSpan(offsetY)); + ref TPixel passPixelsBase = ref MemoryMarshal.GetReference(passPixels.GetRowSpanUnchecked(offsetY)); + ref TPixel targetPixelsBase = ref MemoryMarshal.GetReference(targetPixels.GetRowSpanUnchecked(offsetY)); for (int x = minX; x < maxX; x++) { diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs index 472c07aa7..049fb6d02 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs @@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects } } - Span targetRowAreaPixelSpan = targetPixels.GetRowSpan(y).Slice(startX, rectangleWidth); + Span targetRowAreaPixelSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX, rectangleWidth); PixelOperations.Instance.FromVector4Destructive(configuration, targetRowAreaVector4Span, targetRowAreaPixelSpan); } diff --git a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs index b5b8cfe56..227d1b969 100644 --- a/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs +++ b/src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs @@ -487,7 +487,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization int y = this.tileYStartPositions[index].y; int endY = Math.Min(y + tileHeight, sourceHeight); ref TPixel sourceBase = ref source.GetPixelReference(0, 0); - ref int cdfMinBase = ref MemoryMarshal.GetReference(this.cdfMinBuffer2D.GetRowSpan(cdfY)); + ref int cdfMinBase = ref MemoryMarshal.GetReference(this.cdfMinBuffer2D.GetRowSpanUnchecked(cdfY)); using (IMemoryOwner histogramBuffer = this.memoryAllocator.Allocate(luminanceLevels)) { @@ -524,7 +524,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization } [MethodImpl(InliningOptions.ShortMethod)] - public Span GetCdfLutSpan(int tileX, int tileY) => this.cdfLutBuffer2D.GetRowSpan(tileY).Slice(tileX * this.luminanceLevels, this.luminanceLevels); + public Span GetCdfLutSpan(int tileX, int tileY) => this.cdfLutBuffer2D.GetRowSpanUnchecked(tileY).Slice(tileX * this.luminanceLevels, this.luminanceLevels); /// /// Remaps the grey value with the cdf. diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs index 06eef76e2..b91a27373 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs @@ -241,7 +241,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms $"Error in KernelMap.CreateKernel({dataRowIndex},{left},{right}): left > this.data.Width"); } - Span rowSpan = this.data.GetRowSpan(dataRowIndex); + Span rowSpan = this.data.GetRowSpanUnchecked(dataRowIndex); ref float rowReference = ref MemoryMarshal.GetReference(rowSpan); float* rowPtr = (float*)Unsafe.AsPointer(ref rowReference); diff --git a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs index 57663c07d..ccd36780c 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs @@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms [MethodImpl(MethodImplOptions.AggressiveInlining)] public Span GetColumnSpan(int x, int startY) { - return this.transposedFirstPassBuffer.GetRowSpan(x).Slice(startY - this.currentWindow.Min); + return this.transposedFirstPassBuffer.GetRowSpanUnchecked(x).Slice(startY - this.currentWindow.Min); } public void Initialize() @@ -138,7 +138,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms Unsafe.Add(ref tempRowBase, x) = kernel.ConvolveCore(ref firstPassColumnBase); } - Span targetRowSpan = destination.GetRowSpan(y); + Span targetRowSpan = destination.GetRowSpanUnchecked(y); PixelOperations.Instance.FromVector4Destructive(this.configuration, tempColSpan, targetRowSpan, this.conversionModifiers); } diff --git a/src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs b/src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs index a0d44cb7a..7e261b81e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs @@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The reference to the first item of the window. [MethodImpl(InliningOptions.ShortMethod)] public ref float GetYStartReference(int y) - => ref MemoryMarshal.GetReference(this.yBuffer.GetRowSpan(y)); + => ref MemoryMarshal.GetReference(this.yBuffer.GetRowSpanUnchecked(y)); /// /// Gets a reference to the first item of the x window. @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms /// The reference to the first item of the window. [MethodImpl(InliningOptions.ShortMethod)] public ref float GetXStartReference(int y) - => ref MemoryMarshal.GetReference(this.xBuffer.GetRowSpan(y)); + => ref MemoryMarshal.GetReference(this.xBuffer.GetRowSpanUnchecked(y)); public void Convolve( Vector2 transformedPoint, diff --git a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs index 4241a12f6..68cfa96ed 100644 --- a/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs +++ b/tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs @@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Benchmarks Buffer2D pixels = image.GetRootFramePixelBuffer(); for (int y = 0; y < image.Height; y++) { - Span span = pixels.GetRowSpan(y); + Span span = pixels.GetRowSpanUnchecked(y); this.BulkVectorConvert(span, span, span, amounts.GetSpan()); } @@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Benchmarks Buffer2D pixels = image.GetRootFramePixelBuffer(); for (int y = 0; y < image.Height; y++) { - Span span = pixels.GetRowSpan(y); + Span span = pixels.GetRowSpanUnchecked(y); this.BulkPixelConvert(span, span, span, amounts.GetSpan()); } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs index b9526994e..d97c75dc6 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs @@ -65,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg.Utils for (int y = 0; y < result.HeightInBlocks; y++) { - Span blockRow = c.SpectralBlocks.GetRowSpan(y); + Span blockRow = c.SpectralBlocks.GetRowSpanUnchecked(y); for (int x = 0; x < result.WidthInBlocks; x++) { short[] data = blockRow[x].ToArray(); diff --git a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs index 03a5f2273..b44e4c903 100644 --- a/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs +++ b/tests/ImageSharp.Tests/Memory/Buffer2DTests.cs @@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Tests.Memory using (Buffer2D buffer = this.MemoryAllocator.Allocate2D(width, height)) { - Span span = buffer.GetRowSpan(y); + Span span = buffer.GetRowSpanUnchecked(y); Assert.Equal(width, span.Length); @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int y = 0; y < b.Height; y++) { - Span row = b.GetRowSpan(y); + Span row = b.GetRowSpanUnchecked(y); Span s = row.Slice(startIndex, columnCount); Span d = row.Slice(destIndex, columnCount); @@ -195,7 +195,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int y = 0; y < b.Height; y++) { - Span row = b.GetRowSpan(y); + Span row = b.GetRowSpanUnchecked(y); Span s = row.Slice(0, 22); Span d = row.Slice(50, 22); diff --git a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs index 77e899a4c..eeddb7daa 100644 --- a/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs +++ b/tests/ImageSharp.Tests/Memory/BufferAreaTests.cs @@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int y = 0; y < 13; y++) { - Span row = buffer.GetRowSpan(y); + Span row = buffer.GetRowSpanUnchecked(y); Assert.True(row.SequenceEqual(emptyRow)); } } @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Tests.Memory for (int y = area.Rectangle.Y; y < area.Rectangle.Bottom; y++) { - Span span = buffer.GetRowSpan(y).Slice(area.Rectangle.X, area.Width); + Span span = buffer.GetRowSpanUnchecked(y).Slice(area.Rectangle.X, area.Width); Assert.True(span.SequenceEqual(new int[area.Width])); } }