Browse Source

introduced PinnedImageBuffer<T>

pull/141/head
Anton Firszov 9 years ago
parent
commit
fa40b26216
  1. 13
      src/ImageSharp/Common/Memory/BufferSpan{T}.cs
  2. 31
      src/ImageSharp/Common/Memory/IPinnedImageBuffer{T}.cs
  3. 32
      src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs
  4. 45
      src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs
  5. 62
      src/ImageSharp/Common/Memory/PinnedImageBuffer{T}.cs
  6. 51
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  7. 2
      src/ImageSharp/Image/PixelArea{TColor}.cs
  8. 4
      tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs
  9. 88
      tests/ImageSharp.Tests/Common/PinnedBufferTests.cs
  10. 86
      tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs

13
src/ImageSharp/Common/Memory/BufferSpan{T}.cs

@ -180,12 +180,14 @@ namespace ImageSharp
}
/// <summary>
/// Clears `count` elements beginning from the pointed position.
/// Clears `count` elements from the beginning of the span.
/// </summary>
/// <param name="count">The number of elements to clear</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear(int count)
{
DebugGuard.MustBeLessThanOrEqualTo(count, this.Length, nameof(count));
if (count < 256)
{
Unsafe.InitBlock((void*)this.PointerAtOffset, 0, BufferSpan.USizeOf<T>(count));
@ -196,6 +198,15 @@ namespace ImageSharp
}
}
/// <summary>
/// Clears the the span
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
{
this.Clear(this.Length);
}
[Conditional("DEBUG")]
private static void GuardArrayAndPointer(T[] array, void* pointerToArray)
{

31
src/ImageSharp/Common/Memory/IPinnedImageBuffer{T}.cs

@ -0,0 +1,31 @@
// <copyright file="IPinnedImageBuffer{T}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
/// <summary>
/// An interface that represents a pinned buffer of value type objects
/// interpreted as a 2D region of <see cref="Width"/> x <see cref="Height"/> elements.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
internal interface IPinnedImageBuffer<T>
where T : struct
{
/// <summary>
/// Gets the width.
/// </summary>
int Width { get; }
/// <summary>
/// Gets the height.
/// </summary>
int Height { get; }
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to the backing buffer.
/// </summary>
BufferSpan<T> Span { get; }
}
}

32
src/ImageSharp/Common/Memory/PinnedBuffer{T}.cs

@ -11,7 +11,7 @@ namespace ImageSharp
using System.Runtime.InteropServices;
/// <summary>
/// Manages a pinned buffer of value type data 'T' as a Disposable resource.
/// Manages a pinned buffer of value type objects as a Disposable resource.
/// The backing array is either pooled or comes from the outside.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
@ -56,9 +56,9 @@ namespace ImageSharp
/// <summary>
/// Initializes a new instance of the <see cref="PinnedBuffer{T}"/> class.
/// </summary>
/// <param name="length">The count of "relevant" elements in 'array'.</param>
/// <param name="array">The array to pin.</param>
public PinnedBuffer(int length, T[] array)
/// <param name="length">The count of "relevant" elements in 'array'.</param>
public PinnedBuffer(T[] array, int length)
{
if (array.Length < length)
{
@ -99,14 +99,19 @@ namespace ImageSharp
/// </summary>
public IntPtr Pointer { get; private set; }
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to the backing buffer.
/// </summary>
public BufferSpan<T> Span => this;
/// <summary>
/// Converts <see cref="PinnedBuffer{T}"/> to an <see cref="BufferSpan{T}"/>.
/// </summary>
/// <param name="buffer">The <see cref="PinnedBuffer{T}"/> to convert.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator BufferSpan<T>(PinnedBuffer<T> buffer)
public static unsafe implicit operator BufferSpan<T>(PinnedBuffer<T> buffer)
{
return buffer.Slice();
return new BufferSpan<T>(buffer.Array, (void*)buffer.Pointer, 0, buffer.Length);
}
/// <summary>
@ -114,6 +119,7 @@ namespace ImageSharp
/// </summary>
/// <param name="count">The desired count of elements. (Minimum size for <see cref="Array"/>)</param>
/// <returns>The <see cref="PinnedBuffer{T}"/> instance</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static PinnedBuffer<T> CreateClean(int count)
{
PinnedBuffer<T> buffer = new PinnedBuffer<T>(count);
@ -122,24 +128,26 @@ namespace ImageSharp
}
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to the beginning of the raw data of the buffer.
/// Gets a <see cref="BufferSpan{T}"/> to an offseted position inside the buffer.
/// </summary>
/// <param name="start">The start</param>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferSpan<T> Slice()
public unsafe BufferSpan<T> Slice(int start)
{
return new BufferSpan<T>(this.Array, (void*)this.Pointer);
return new BufferSpan<T>(this.Array, (void*)this.Pointer, start, this.Length - start);
}
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to an offseted position inside the buffer.
/// </summary>
/// <param name="offset">The offset</param>
/// <param name="start">The start</param>
/// <param name="length">The length of the slice</param>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public unsafe BufferSpan<T> Slice(int offset)
public unsafe BufferSpan<T> Slice(int start, int length)
{
return new BufferSpan<T>(this.Array, (void*)this.Pointer, offset);
return new BufferSpan<T>(this.Array, (void*)this.Pointer, start, length);
}
/// <summary>
@ -195,7 +203,7 @@ namespace ImageSharp
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Clear()
{
this.Slice().Clear(this.Length);
((BufferSpan<T>)this).Clear();
}
/// <summary>

45
src/ImageSharp/Common/Memory/PinnedImageBufferExtensions.cs

@ -0,0 +1,45 @@
// <copyright file="PinnedImageBufferExtensions{T}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Runtime.CompilerServices;
/// <summary>
/// Defines extension methods for <see cref="IPinnedImageBuffer{T}"/>.
/// </summary>
internal static class PinnedImageBufferExtensions
{
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to the row 'y' beginning from the pixel at 'x'.
/// </summary>
/// <param name="buffer">The buffer</param>
/// <param name="x">The x coordinate (position in the row)</param>
/// <param name="y">The y (row) coordinate</param>
/// <typeparam name="T">The element type</typeparam>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BufferSpan<T> GetRowSpan<T>(this IPinnedImageBuffer<T> buffer, int x, int y)
where T : struct
{
return buffer.Span.Slice((y * buffer.Width) + x, buffer.Width - x);
}
/// <summary>
/// Gets a <see cref="BufferSpan{T}"/> to the row 'y' beginning from the pixel at 'x'.
/// </summary>
/// <param name="buffer">The buffer</param>
/// <param name="y">The y (row) coordinate</param>
/// <typeparam name="T">The element type</typeparam>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static BufferSpan<T> GetRowSpan<T>(this IPinnedImageBuffer<T> buffer, int y)
where T : struct
{
return buffer.Span.Slice(y * buffer.Width, buffer.Width);
}
}
}

62
src/ImageSharp/Common/Memory/PinnedImageBuffer{T}.cs

@ -0,0 +1,62 @@
// <copyright file="PinnedImageBuffer{T}.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
/// <summary>
/// Represents a pinned buffer of value type objects
/// interpreted as a 2D region of <see cref="Width"/> x <see cref="Height"/> elements.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
internal class PinnedImageBuffer<T> : PinnedBuffer<T>, IPinnedImageBuffer<T>
where T : struct
{
/// <summary>
/// Initializes a new instance of the <see cref="PinnedImageBuffer{T}"/> class.
/// </summary>
/// <param name="width">The number of elements in a row</param>
/// <param name="height">The number of rows</param>
public PinnedImageBuffer(int width, int height)
: base(width * height)
{
this.Width = width;
this.Height = height;
}
/// <summary>
/// Initializes a new instance of the <see cref="PinnedImageBuffer{T}"/> class.
/// </summary>
/// <param name="array">The array to pin</param>
/// <param name="width">The number of elements in a row</param>
/// <param name="height">The number of rows</param>
public PinnedImageBuffer(T[] array, int width, int height)
: base(array, width * height)
{
this.Width = width;
this.Height = height;
}
/// <inheritdoc />
public int Width { get; }
/// <inheritdoc />
public int Height { get; }
/// <summary>
/// Creates a clean instance of <see cref="PinnedImageBuffer{T}"/> initializing it's elements with 'default(T)'.
/// </summary>
/// <param name="width">The number of elements in a row</param>
/// <param name="height">The number of rows</param>
/// <returns>The <see cref="PinnedBuffer{T}"/> instance</returns>
public static PinnedImageBuffer<T> CreateClean(int width, int height)
{
PinnedImageBuffer<T> buffer = new PinnedImageBuffer<T>(width, height);
buffer.Clear();
return buffer;
}
}
}

51
src/ImageSharp/Image/PixelAccessor{TColor}.cs

@ -15,7 +15,7 @@ namespace ImageSharp
/// Provides per-pixel access to generic <see cref="Image{TColor}"/> pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public sealed unsafe class PixelAccessor<TColor> : IDisposable
public sealed unsafe class PixelAccessor<TColor> : IDisposable, IPinnedImageBuffer<TColor>
where TColor : struct, IPixel<TColor>
{
/// <summary>
@ -37,7 +37,7 @@ namespace ImageSharp
/// <summary>
/// The <see cref="PinnedBuffer{T}"/> containing the pixel data.
/// </summary>
private PinnedBuffer<TColor> pixelBuffer;
private PinnedImageBuffer<TColor> pixelBuffer;
/// <summary>
/// Initializes a new instance of the <see cref="PixelAccessor{TColor}"/> class.
@ -59,7 +59,7 @@ namespace ImageSharp
/// <param name="width">The width of the image represented by the pixel buffer.</param>
/// <param name="height">The height of the image represented by the pixel buffer.</param>
public PixelAccessor(int width, int height)
: this(width, height, PinnedBuffer<TColor>.CreateClean(width * height))
: this(width, height, PinnedImageBuffer<TColor>.CreateClean(width, height))
{
}
@ -69,7 +69,7 @@ namespace ImageSharp
/// <param name="width">The width of the image represented by the pixel buffer.</param>
/// <param name="height">The height of the image represented by the pixel buffer.</param>
/// <param name="pixels">The pixel buffer.</param>
private PixelAccessor(int width, int height, PinnedBuffer<TColor> pixels)
private PixelAccessor(int width, int height, PinnedImageBuffer<TColor> pixels)
{
Guard.NotNull(pixels, nameof(pixels));
Guard.MustBeGreaterThan(width, 0, nameof(width));
@ -123,6 +123,9 @@ namespace ImageSharp
/// </summary>
public ParallelOptions ParallelOptions { get; }
/// <inheritdoc />
BufferSpan<TColor> IPinnedImageBuffer<TColor>.Span => this.pixelBuffer;
private static BulkPixelOperations<TColor> Operations => BulkPixelOperations<TColor>.Instance;
/// <summary>
@ -244,9 +247,9 @@ namespace ImageSharp
/// <param name="x">The x coordinate</param>
/// <param name="y">The y coordinate</param>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
internal BufferSpan<TColor> GetRowPointer(int x, int y)
internal BufferSpan<TColor> GetRowSpan(int x, int y)
{
return this.pixelBuffer.Slice((y * this.Width) + x);
return this.pixelBuffer.Slice((y * this.Width) + x, this.Width - x);
}
/// <summary>
@ -288,8 +291,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<byte> source = area.GetRowPointer(y);
BufferSpan<TColor> destination = this.GetRowPointer(targetX, targetY + y);
BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxBytes(source, destination, width);
}
@ -308,8 +311,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<byte> source = area.GetRowPointer(y);
BufferSpan<TColor> destination = this.GetRowPointer(targetX, targetY + y);
BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromZyxwBytes(source, destination, width);
}
@ -328,8 +331,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<byte> source = area.GetRowPointer(y);
BufferSpan<TColor> destination = this.GetRowPointer(targetX, targetY + y);
BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzBytes(source, destination, width);
}
@ -348,8 +351,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<byte> source = area.GetRowPointer(y);
BufferSpan<TColor> destination = this.GetRowPointer(targetX, targetY + y);
BufferSpan<byte> source = area.GetRowSpan(y);
BufferSpan<TColor> destination = this.GetRowSpan(targetX, targetY + y);
Operations.PackFromXyzwBytes(source, destination, width);
}
}
@ -367,8 +370,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<TColor> source = this.GetRowPointer(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowPointer(y);
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxBytes(source, destination, width);
}
}
@ -386,8 +389,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<TColor> source = this.GetRowPointer(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowPointer(y);
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToZyxwBytes(source, destination, width);
}
}
@ -405,8 +408,8 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<TColor> source = this.GetRowPointer(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowPointer(y);
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToXyzBytes(source, destination, width);
}
}
@ -424,15 +427,15 @@ namespace ImageSharp
{
for (int y = 0; y < height; y++)
{
BufferSpan<TColor> source = this.GetRowPointer(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowPointer(y);
BufferSpan<TColor> source = this.GetRowSpan(sourceX, sourceY + y);
BufferSpan<byte> destination = area.GetRowSpan(y);
Operations.ToXyzwBytes(source, destination, width);
}
}
private void SetPixelBufferUnsafe(int width, int height, TColor[] pixels)
{
this.SetPixelBufferUnsafe(width, height, new PinnedBuffer<TColor>(width * height, pixels));
this.SetPixelBufferUnsafe(width, height, new PinnedImageBuffer<TColor>(pixels, width, height));
}
/// <summary>
@ -441,7 +444,7 @@ namespace ImageSharp
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
/// <param name="pixels">The pixel buffer</param>
private void SetPixelBufferUnsafe(int width, int height, PinnedBuffer<TColor> pixels)
private void SetPixelBufferUnsafe(int width, int height, PinnedImageBuffer<TColor> pixels)
{
this.pixelBuffer = pixels;
this.pixelsBase = (byte*)pixels.Pointer;

2
src/ImageSharp/Image/PixelArea{TColor}.cs

@ -206,7 +206,7 @@ namespace ImageSharp
/// </summary>
/// <param name="y">The y coordinate</param>
/// <returns>The <see cref="BufferSpan{T}"/></returns>
internal BufferSpan<byte> GetRowPointer(int y)
internal BufferSpan<byte> GetRowSpan(int y)
{
return this.byteBuffer.Slice(y * this.RowStride);
}

4
tests/ImageSharp.Tests/Colors/BulkPixelOperationsTests.cs

@ -314,8 +314,8 @@ namespace ImageSharp.Tests.Colors
public PinnedBuffer<TDest> ActualDestBuffer { get; }
public PinnedBuffer<TDest> ExpectedDestBuffer { get; }
public BufferSpan<TSource> Source => this.SourceBuffer.Slice();
public BufferSpan<TDest> ActualDest => this.ActualDestBuffer.Slice();
public BufferSpan<TSource> Source => this.SourceBuffer;
public BufferSpan<TDest> ActualDest => this.ActualDestBuffer;
public TestBuffers(TSource[] source, TDest[] expectedDest)
{

88
tests/ImageSharp.Tests/Common/PinnedBufferTests.cs

@ -66,18 +66,17 @@
[Fact]
public void CreateClean()
{
Parallel.For(0, 100,
i =>
for (int i = 0; i < 100; i++)
{
using (PinnedBuffer<int> buffer = PinnedBuffer<int>.CreateClean(42))
{
for (int j = 0; j < buffer.Length; j++)
{
using (PinnedBuffer<int> buffer = PinnedBuffer<int>.CreateClean(42))
{
for (int j = 0; j < buffer.Length; j++)
{
Assert.Equal(0, buffer.Array[j]);
buffer.Array[j] = 666;
}
}
});
Assert.Equal(0, buffer.Array[j]);
buffer.Array[j] = 666;
}
}
}
}
[Fact]
@ -89,21 +88,72 @@
Assert.True(buffer.IsDisposedOrLostArrayOwnership);
}
[Theory]
[InlineData(7)]
[InlineData(123)]
public void CastToSpan(int bufferLength)
{
using (PinnedBuffer<Foo> buffer = new PinnedBuffer<Foo>(bufferLength))
{
BufferSpan<Foo> span = buffer;
Assert.Equal(buffer.Array, span.Array);
Assert.Equal(0, span.Start);
Assert.Equal(buffer.Pointer, span.PointerAtOffset);
Assert.Equal(span.Length, bufferLength);
}
}
[Fact]
public void Slice()
public void Span()
{
Foo[] a = { new Foo() { A = 1, B = 2 }, new Foo() { A = 3, B = 4 } };
using (PinnedBuffer<Foo> buffer = new PinnedBuffer<Foo>(a))
using (PinnedBuffer<Foo> buffer = new PinnedBuffer<Foo>(42))
{
BufferSpan<Foo> arrayPtr = buffer.Slice();
BufferSpan<Foo> span = buffer.Span;
Assert.Equal(a, arrayPtr.Array);
Assert.Equal(0, arrayPtr.Start);
Assert.Equal(buffer.Pointer, arrayPtr.PointerAtOffset);
Assert.Equal(buffer.Array, span.Array);
Assert.Equal(0, span.Start);
Assert.Equal(buffer.Pointer, span.PointerAtOffset);
Assert.Equal(span.Length, 42);
}
}
public class Slice
{
[Theory]
[InlineData(7, 2)]
[InlineData(123, 17)]
public void WithStartOnly(int bufferLength, int start)
{
using (PinnedBuffer<Foo> buffer = new PinnedBuffer<Foo>(bufferLength))
{
BufferSpan<Foo> span = buffer.Slice(start);
Assert.Equal(buffer.Array, span.Array);
Assert.Equal(start, span.Start);
Assert.Equal(buffer.Pointer + start * Unsafe.SizeOf<Foo>(), span.PointerAtOffset);
Assert.Equal(span.Length, bufferLength - start);
}
}
[Theory]
[InlineData(7, 2, 5)]
[InlineData(123, 17, 42)]
public void WithStartAndLength(int bufferLength, int start, int spanLength)
{
using (PinnedBuffer<Foo> buffer = new PinnedBuffer<Foo>(bufferLength))
{
BufferSpan<Foo> span = buffer.Slice(start, spanLength);
Assert.Equal(buffer.Array, span.Array);
Assert.Equal(start, span.Start);
Assert.Equal(buffer.Pointer + start * Unsafe.SizeOf<Foo>(), span.PointerAtOffset);
Assert.Equal(span.Length, spanLength);
}
}
}
[Fact]
public void UnPinAndTakeArrayOwnership()
{

86
tests/ImageSharp.Tests/Common/PinnedImageBufferTests.cs

@ -0,0 +1,86 @@
// ReSharper disable InconsistentNaming
namespace ImageSharp.Tests.Common
{
using System.Runtime.CompilerServices;
using Xunit;
public unsafe class PinnedImageBufferTests
{
[Theory]
[InlineData(7, 42)]
[InlineData(1025, 17)]
public void Construct(int width, int height)
{
using (PinnedImageBuffer<int> buffer = new PinnedImageBuffer<int>(width, height))
{
Assert.Equal(width, buffer.Width);
Assert.Equal(height, buffer.Height);
Assert.Equal(width * height, buffer.Length);
}
}
[Theory]
[InlineData(7, 42)]
[InlineData(1025, 17)]
public void Construct_FromExternalArray(int width, int height)
{
int[] array = new int[width * height + 10];
using (PinnedImageBuffer<int> buffer = new PinnedImageBuffer<int>(array, width, height))
{
Assert.Equal(width, buffer.Width);
Assert.Equal(height, buffer.Height);
Assert.Equal(width * height, buffer.Length);
}
}
[Fact]
public void CreateClean()
{
for (int i = 0; i < 100; i++)
{
using (PinnedImageBuffer<int> buffer = PinnedImageBuffer<int>.CreateClean(42, 42))
{
for (int j = 0; j < buffer.Length; j++)
{
Assert.Equal(0, buffer.Array[j]);
buffer.Array[j] = 666;
}
}
}
}
[Theory]
[InlineData(7, 42, 0)]
[InlineData(7, 42, 10)]
[InlineData(17, 42, 41)]
public void GetRowSpanY(int width, int height, int y)
{
using (PinnedImageBuffer<int> buffer = new PinnedImageBuffer<int>(width, height))
{
BufferSpan<int> span = buffer.GetRowSpan(y);
Assert.Equal(width * y, span.Start);
Assert.Equal(width, span.Length);
Assert.Equal(buffer.Pointer + sizeof(int) * width * y, span.PointerAtOffset);
}
}
[Theory]
[InlineData(7, 42, 0, 0)]
[InlineData(7, 42, 3, 10)]
[InlineData(17, 42, 0, 41)]
public void GetRowSpanXY(int width, int height, int x, int y)
{
using (PinnedImageBuffer<int> buffer = new PinnedImageBuffer<int>(width, height))
{
BufferSpan<int> span = buffer.GetRowSpan(x, y);
Assert.Equal(width * y + x, span.Start);
Assert.Equal(width - x, span.Length);
Assert.Equal(buffer.Pointer + sizeof(int) * (width * y + x), span.PointerAtOffset);
}
}
}
}
Loading…
Cancel
Save