Browse Source

Clean up public API

af/octree-no-pixelmap
Anton Firszov 6 years ago
parent
commit
2a4c8492f9
  1. 44
      src/ImageSharp/Advanced/AdvancedImageExtensions.cs
  2. 4
      src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
  3. 4
      src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
  4. 20
      src/ImageSharp/Formats/Bmp/BmpDecoderCore.cs
  5. 6
      src/ImageSharp/Formats/Bmp/BmpEncoderCore.cs
  6. 8
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
  7. 10
      src/ImageSharp/Formats/Jpeg/Components/Decoder/HuffmanScanDecoder.cs
  8. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/JpegComponentPostProcessor.cs
  9. 16
      src/ImageSharp/Formats/Jpeg/Components/RowOctet.cs
  10. 14
      src/ImageSharp/Formats/Tga/TgaDecoderCore.cs
  11. 8
      src/ImageSharp/Formats/Tga/TgaEncoderCore.cs
  12. 4
      src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs
  13. 2
      src/ImageSharp/Memory/Allocators/MemoryAllocator.cs
  14. 21
      src/ImageSharp/Memory/Buffer2DExtensions.cs
  15. 33
      src/ImageSharp/Memory/Buffer2D{T}.cs
  16. 20
      src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs
  17. 10
      src/ImageSharp/Processing/Processors/Convolution/BokehBlurProcessor{TPixel}.cs
  18. 2
      src/ImageSharp/Processing/Processors/Convolution/Convolution2DProcessor{TPixel}.cs
  19. 2
      src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor{TPixel}.cs
  20. 2
      src/ImageSharp/Processing/Processors/Convolution/ConvolutionProcessor{TPixel}.cs
  21. 4
      src/ImageSharp/Processing/Processors/Convolution/EdgeDetectorCompassProcessor{TPixel}.cs
  22. 2
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs
  23. 4
      src/ImageSharp/Processing/Processors/Normalization/AdaptiveHistogramEqualizationProcessor{TPixel}.cs
  24. 2
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeKernelMap.cs
  25. 4
      src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs
  26. 4
      src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs
  27. 4
      tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs
  28. 2
      tests/ImageSharp.Tests/Formats/Jpg/Utils/LibJpegTools.ComponentData.cs
  29. 6
      tests/ImageSharp.Tests/Memory/Buffer2DTests.cs
  30. 4
      tests/ImageSharp.Tests/Memory/BufferAreaTests.cs

44
src/ImageSharp/Advanced/AdvancedImageExtensions.cs

@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Advanced
/// </remarks>
public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this ImageFrame<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.PixelBuffer.MemoryGroup.View;
=> source?.PixelBuffer.MemoryGroup.View ?? throw new ArgumentNullException(nameof(source));
/// <summary>
/// Gets the representation of the pixels as a <see cref="IMemoryGroup{T}"/> containing the backing pixel data of the image
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Advanced
/// </remarks>
public static IMemoryGroup<TPixel> GetPixelMemoryGroup<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelMemoryGroup();
=> source?.Frames.RootFrame.GetPixelMemoryGroup() ?? throw new ArgumentNullException(nameof(source));
/// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> in the source image's pixel format
@ -91,6 +91,8 @@ namespace SixLabors.ImageSharp.Advanced
public static Span<TPixel> GetPixelSpan<TPixel>(this ImageFrame<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
Guard.NotNull(source, nameof(source));
IMemoryGroup<TPixel> 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<TPixel> GetPixelSpan<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.Frames.RootFrame.GetPixelSpan();
{
Guard.NotNull(source, nameof(source));
return source.Frames.RootFrame.GetPixelSpan();
}
/// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory
@ -124,7 +130,13 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelRowSpan<TPixel>(this ImageFrame<TPixel> source, int rowIndex)
where TPixel : struct, IPixel<TPixel>
=> 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);
}
/// <summary>
/// Gets the representation of the pixels as <see cref="Span{T}"/> of of contiguous memory
@ -136,7 +148,13 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>The <see cref="Span{TPixel}"/></returns>
public static Span<TPixel> GetPixelRowSpan<TPixel>(this Image<TPixel> source, int rowIndex)
where TPixel : struct, IPixel<TPixel>
=> 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);
}
/// <summary>
/// Gets the representation of the pixels as a <see cref="Span{T}"/> of contiguous memory
@ -148,7 +166,13 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>The <see cref="Span{TPixel}"/></returns>
public static Memory<TPixel> GetPixelRowMemory<TPixel>(this ImageFrame<TPixel> source, int rowIndex)
where TPixel : struct, IPixel<TPixel>
=> 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);
}
/// <summary>
/// Gets the representation of the pixels as <see cref="Span{T}"/> of of contiguous memory
@ -160,7 +184,13 @@ namespace SixLabors.ImageSharp.Advanced
/// <returns>The <see cref="Span{TPixel}"/></returns>
public static Memory<TPixel> GetPixelRowMemory<TPixel>(this Image<TPixel> source, int rowIndex)
where TPixel : struct, IPixel<TPixel>
=> 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);
}
/// <summary>
/// Gets the <see cref="MemoryAllocator"/> assigned to 'source'.

4
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<TPixel> sourceRowSpan = sourcePixels.GetRowSpan(offsetY);
Span<TPixel> 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++)

4
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<TPixel> sourceRowSpan = sourcePixels.GetRowSpan(offsetY);
Span<TPixel> 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<TPixel> sourceRowSpan = sourcePixels.GetRowSpan(offsetY);
Span<TPixel> sourceRowSpan = sourcePixels.GetRowSpanUnchecked(offsetY);
for (int x = 0; x < matrixWidth; x++)
{

20
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<byte> bufferRow = buffer.GetRowSpan(y);
Span<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<byte> bufferRow = buffer.GetRowSpanUnchecked(y);
Span<TPixel> 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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.Instance.FromBgra32Bytes(
this.configuration,
@ -1062,7 +1062,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
width);
int newY = Invert(y, height, inverted);
Span<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> pixelRow = pixels.GetRowSpanUnchecked(newY);
int offset = 0;
for (int x = 0; x < width; x++)

6
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<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgra32Bytes(
this.configuration,
pixelSpan,
@ -264,7 +264,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgr24Bytes(
this.configuration,
pixelSpan,
@ -288,7 +288,7 @@ namespace SixLabors.ImageSharp.Formats.Bmp
{
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgra5551Bytes(
this.configuration,

8
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<float>.Empty;
this.Component2 = Span<float>.Empty;
this.Component3 = Span<float>.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);
}
}
}

10
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<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(blockRow);
Span<Block8x8> 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<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(j);
Span<Block8x8> 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<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(blockRow);
Span<Block8x8> 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<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(j);
Span<Block8x8> 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<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpan(j);
Span<Block8x8> blockSpan = component.SpectralBlocks.GetRowSpanUnchecked(j);
ref Block8x8 blockRef = ref MemoryMarshal.GetReference(blockSpan);
for (int i = 0; i < w; i++)

2
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<Block8x8> blockRow = this.Component.SpectralBlocks.GetRowSpan(yBlock);
Span<Block8x8> blockRow = this.Component.SpectralBlocks.GetRowSpanUnchecked(yBlock);
ref Block8x8 blockRowBase = ref MemoryMarshal.GetReference(blockRow);

16
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<T> this[int y]

14
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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> 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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.Instance.FromL8Bytes(
this.configuration,
row.GetSpan(),
@ -374,7 +374,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
}
int newY = Invert(y, height, inverted);
Span<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.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<TPixel> pixelSpan = pixels.GetRowSpan(newY);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(newY);
PixelOperations<TPixel>.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<TPixel> pixelRow = pixels.GetRowSpan(newY);
Span<TPixel> pixelRow = pixels.GetRowSpanUnchecked(newY);
int rowStartIdx = y * width * bytesPerPixel;
for (int x = 0; x < width; x++)
{

8
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<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToL8Bytes(
this.configuration,
pixelSpan,
@ -268,7 +268,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgra5551Bytes(
this.configuration,
pixelSpan,
@ -292,7 +292,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgr24Bytes(
this.configuration,
pixelSpan,
@ -316,7 +316,7 @@ namespace SixLabors.ImageSharp.Formats.Tga
{
for (int y = pixels.Height - 1; y >= 0; y--)
{
Span<TPixel> pixelSpan = pixels.GetRowSpan(y);
Span<TPixel> pixelSpan = pixels.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.ToBgra32Bytes(
this.configuration,
pixelSpan,

4
src/ImageSharp/Memory/Allocators/ArrayPoolMemoryAllocator.cs

@ -131,10 +131,10 @@ namespace SixLabors.ImageSharp.Memory
Guard.MustBeGreaterThanOrEqualTo(length, 0, nameof(length));
int itemSizeBytes = Unsafe.SizeOf<T>();
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<byte> pool = this.GetArrayPool(bufferSizeInBytes);

2
src/ImageSharp/Memory/Allocators/MemoryAllocator.cs

@ -11,8 +11,6 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
public abstract class MemoryAllocator
{
/// <summary>
/// Gets the length of the largest contiguous buffer that can be handled by this allocator instance in bytes.
/// </summary>

21
src/ImageSharp/Memory/Buffer2DExtensions.cs

@ -14,6 +14,19 @@ namespace SixLabors.ImageSharp.Memory
/// </summary>
public static class Buffer2DExtensions
{
/// <summary>
/// Gets the backing <see cref="IMemoryGroup{T}"/>.
/// </summary>
/// <param name="buffer">The buffer.</param>
/// <typeparam name="T">The element type.</typeparam>
/// <returns>The MemoryGroup.</returns>
public static IMemoryGroup<T> GetMemoryGroup<T>(this Buffer2D<T> buffer)
where T : struct
{
Guard.NotNull(buffer, nameof(buffer));
return buffer.MemoryGroup.View;
}
/// <summary>
/// Gets a <see cref="Span{T}"/> to the backing data of <paramref name="buffer"/>
/// if the backing group consists of one single contiguous memory buffer.
@ -25,7 +38,9 @@ namespace SixLabors.ImageSharp.Memory
/// <exception cref="InvalidOperationException">
/// Thrown when the backing group is discontiguous.
/// </exception>
public static Span<T> GetSingleSpan<T>(this Buffer2D<T> 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<T> GetSingleSpan<T>(this Buffer2D<T> buffer)
where T : struct
{
Guard.NotNull(buffer, nameof(buffer));
@ -48,7 +63,9 @@ namespace SixLabors.ImageSharp.Memory
/// <exception cref="InvalidOperationException">
/// Thrown when the backing group is discontiguous.
/// </exception>
public static Memory<T> GetSingleMemory<T>(this Buffer2D<T> 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<T> GetSingleMemory<T>(this Buffer2D<T> buffer)
where T : struct
{
Guard.NotNull(buffer, nameof(buffer));

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

@ -50,6 +50,11 @@ namespace SixLabors.ImageSharp.Memory
/// <summary>
/// Gets the backing <see cref="MemoryGroup{T}"/>.
/// </summary>
/// <remarks>
/// This property has been kept internal intentionally.
/// It's public counterpart is <see cref="Buffer2DExtensions.GetMemoryGroup{T}"/>,
/// which only exposes the view of the MemoryGroup.
/// </remarks>
internal MemoryGroup<T> MemoryGroup { get; }
/// <summary>
@ -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<T> 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;
}
/// <summary>
/// Same as <see cref="GetRowSpan"/>, but does not validate index in Release mode.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal Span<T> 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;
}
/// <summary>
/// Gets a <see cref="Memory{T}"/> 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<T> 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
/// </summary>
/// <param name="y">The y (row) coordinate.</param>
/// <returns>The <see cref="Span{T}"/>.</returns>
internal Memory<T> GetRowMemorySafe(int y) => this.MemoryGroup.View.GetBoundedSlice(y * this.Width, this.Width);
internal Memory<T> 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);
}
/// <summary>
/// Swaps the contents of 'destination' with 'source' if the buffers are owned (1),

20
src/ImageSharp/Memory/DiscontiguousBuffers/MemoryGroupExtensions.cs

@ -7,7 +7,7 @@ namespace SixLabors.ImageSharp.Memory
{
internal static class MemoryGroupExtensions
{
public static void Fill<T>(this IMemoryGroup<T> group, T value)
internal static void Fill<T>(this IMemoryGroup<T> group, T value)
where T : struct
{
foreach (Memory<T> memory in group)
@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static void Clear<T>(this IMemoryGroup<T> group)
internal static void Clear<T>(this IMemoryGroup<T> group)
where T : struct
{
foreach (Memory<T> 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 <see cref="ArgumentOutOfRangeException"/> is thrown.
/// </summary>
public static Memory<T> GetBoundedSlice<T>(this IMemoryGroup<T> group, long start, int length)
internal static Memory<T> GetBoundedSlice<T>(this IMemoryGroup<T> 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<T>(this IMemoryGroup<T> source, Span<T> target)
internal static void CopyTo<T>(this IMemoryGroup<T> source, Span<T> target)
where T : struct
{
Guard.NotNull(source, nameof(source));
@ -74,11 +74,11 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static void CopyTo<T>(this Span<T> source, IMemoryGroup<T> target)
internal static void CopyTo<T>(this Span<T> source, IMemoryGroup<T> target)
where T : struct
=> CopyTo((ReadOnlySpan<T>)source, target);
public static void CopyTo<T>(this ReadOnlySpan<T> source, IMemoryGroup<T> target)
internal static void CopyTo<T>(this ReadOnlySpan<T> source, IMemoryGroup<T> target)
where T : struct
{
Guard.NotNull(target, nameof(target));
@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static void CopyTo<T>(this IMemoryGroup<T> source, IMemoryGroup<T> target)
internal static void CopyTo<T>(this IMemoryGroup<T> source, IMemoryGroup<T> target)
where T : struct
{
Guard.NotNull(source, nameof(source));
@ -126,7 +126,7 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static void TransformTo<T>(
internal static void TransformTo<T>(
this IMemoryGroup<T> source,
IMemoryGroup<T> target,
TransformItemsDelegate<T> transform)
@ -161,7 +161,7 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static void TransformInplace<T>(
internal static void TransformInplace<T>(
this IMemoryGroup<T> memoryGroup,
TransformItemsInplaceDelegate<T> transform)
where T : struct
@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.Memory
}
}
public static bool IsEmpty<T>(this IMemoryGroup<T> group)
internal static bool IsEmpty<T>(this IMemoryGroup<T> group)
where T : struct
=> group.Count == 0;

10
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<ComplexVector4> targetRowSpan = targetValues.GetRowSpan(y).Slice(startX);
Span<ComplexVector4> 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<Vector4> targetRowSpan = targetValues.GetRowSpan(y).Slice(startX);
Span<Vector4> 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<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
Span<TPixel> targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX);
PixelOperations<TPixel>.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<TPixel> targetPixelSpan = targetPixels.GetRowSpan(y).Slice(startX);
Span<Vector4> sourceRowSpan = sourceValues.GetRowSpan(y).Slice(startX);
Span<TPixel> targetPixelSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX);
Span<Vector4> sourceRowSpan = sourceValues.GetRowSpanUnchecked(y).Slice(startX);
ref Vector4 sourceRef = ref MemoryMarshal.GetReference(sourceRowSpan);
for (int x = 0; x < width; x++)

2
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<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
Span<TPixel> targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(this.Configuration, targetRowSpan.Slice(0, length), vectorSpan);
if (preserveAlpha)

2
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<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
Span<TPixel> targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(configuration, targetRowSpan.Slice(0, length), vectorSpan);
if (preserveAlpha)

2
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<TPixel> targetRowSpan = targetPixels.GetRowSpan(y).Slice(startX);
Span<TPixel> targetRowSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX);
PixelOperations<TPixel>.Instance.ToVector4(this.Configuration, targetRowSpan.Slice(0, length), vectorSpan);
if (preserveAlpha)

4
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++)
{

2
src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor{TPixel}.cs

@ -153,7 +153,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Effects
}
}
Span<TPixel> targetRowAreaPixelSpan = targetPixels.GetRowSpan(y).Slice(startX, rectangleWidth);
Span<TPixel> targetRowAreaPixelSpan = targetPixels.GetRowSpanUnchecked(y).Slice(startX, rectangleWidth);
PixelOperations<TPixel>.Instance.FromVector4Destructive(configuration, targetRowAreaVector4Span, targetRowAreaPixelSpan);
}

4
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<int> histogramBuffer = this.memoryAllocator.Allocate<int>(luminanceLevels))
{
@ -524,7 +524,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Normalization
}
[MethodImpl(InliningOptions.ShortMethod)]
public Span<int> GetCdfLutSpan(int tileX, int tileY) => this.cdfLutBuffer2D.GetRowSpan(tileY).Slice(tileX * this.luminanceLevels, this.luminanceLevels);
public Span<int> GetCdfLutSpan(int tileX, int tileY) => this.cdfLutBuffer2D.GetRowSpanUnchecked(tileY).Slice(tileX * this.luminanceLevels, this.luminanceLevels);
/// <summary>
/// Remaps the grey value with the cdf.

2
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<float> rowSpan = this.data.GetRowSpan(dataRowIndex);
Span<float> rowSpan = this.data.GetRowSpanUnchecked(dataRowIndex);
ref float rowReference = ref MemoryMarshal.GetReference(rowSpan);
float* rowPtr = (float*)Unsafe.AsPointer(ref rowReference);

4
src/ImageSharp/Processing/Processors/Transforms/Resize/ResizeWorker.cs

@ -102,7 +102,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<Vector4> 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<TPixel> targetRowSpan = destination.GetRowSpan(y);
Span<TPixel> targetRowSpan = destination.GetRowSpanUnchecked(y);
PixelOperations<TPixel>.Instance.FromVector4Destructive(this.configuration, tempColSpan, targetRowSpan, this.conversionModifiers);
}

4
src/ImageSharp/Processing/Processors/Transforms/TransformKernelMap.cs

@ -53,7 +53,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <returns>The reference to the first item of the window.</returns>
[MethodImpl(InliningOptions.ShortMethod)]
public ref float GetYStartReference(int y)
=> ref MemoryMarshal.GetReference(this.yBuffer.GetRowSpan(y));
=> ref MemoryMarshal.GetReference(this.yBuffer.GetRowSpanUnchecked(y));
/// <summary>
/// Gets a reference to the first item of the x window.
@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Processing.Processors.Transforms
/// <returns>The reference to the first item of the window.</returns>
[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<TPixel>(
Vector2 transformedPoint,

4
tests/ImageSharp.Benchmarks/PixelBlenders/PorterDuffBulkVsPixel.cs

@ -78,7 +78,7 @@ namespace SixLabors.ImageSharp.Benchmarks
Buffer2D<Rgba32> pixels = image.GetRootFramePixelBuffer();
for (int y = 0; y < image.Height; y++)
{
Span<Rgba32> span = pixels.GetRowSpan(y);
Span<Rgba32> span = pixels.GetRowSpanUnchecked(y);
this.BulkVectorConvert(span, span, span, amounts.GetSpan());
}
@ -98,7 +98,7 @@ namespace SixLabors.ImageSharp.Benchmarks
Buffer2D<Rgba32> pixels = image.GetRootFramePixelBuffer();
for (int y = 0; y < image.Height; y++)
{
Span<Rgba32> span = pixels.GetRowSpan(y);
Span<Rgba32> span = pixels.GetRowSpanUnchecked(y);
this.BulkPixelConvert(span, span, span, amounts.GetSpan());
}

2
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<Block8x8> blockRow = c.SpectralBlocks.GetRowSpan(y);
Span<Block8x8> blockRow = c.SpectralBlocks.GetRowSpanUnchecked(y);
for (int x = 0; x < result.WidthInBlocks; x++)
{
short[] data = blockRow[x].ToArray();

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

@ -95,7 +95,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
using (Buffer2D<TestStructs.Foo> buffer = this.MemoryAllocator.Allocate2D<TestStructs.Foo>(width, height))
{
Span<TestStructs.Foo> span = buffer.GetRowSpan(y);
Span<TestStructs.Foo> 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<float> row = b.GetRowSpan(y);
Span<float> row = b.GetRowSpanUnchecked(y);
Span<float> s = row.Slice(startIndex, columnCount);
Span<float> d = row.Slice(destIndex, columnCount);
@ -195,7 +195,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
for (int y = 0; y < b.Height; y++)
{
Span<float> row = b.GetRowSpan(y);
Span<float> row = b.GetRowSpanUnchecked(y);
Span<float> s = row.Slice(0, 22);
Span<float> d = row.Slice(50, 22);

4
tests/ImageSharp.Tests/Memory/BufferAreaTests.cs

@ -127,7 +127,7 @@ namespace SixLabors.ImageSharp.Tests.Memory
for (int y = 0; y < 13; y++)
{
Span<int> row = buffer.GetRowSpan(y);
Span<int> 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<int> span = buffer.GetRowSpan(y).Slice(area.Rectangle.X, area.Width);
Span<int> span = buffer.GetRowSpanUnchecked(y).Slice(area.Rectangle.X, area.Width);
Assert.True(span.SequenceEqual(new int[area.Width]));
}
}

Loading…
Cancel
Save