Class Buffer2D<T>
- Namespace
- SixLabors.ImageSharp.Memory
- Assembly
- SixLabors.ImageSharp.dll
public sealed class Buffer2D<T> : IDisposable where T : struct
Type Parameters
TThe value type.
- Inheritance
-
Buffer2D<T>
- Implements
- Inherited Members
- Extension Methods
Properties
Bounds
Gets the bounds of the buffer.
public Rectangle Bounds { get; }
Property Value
Height
Gets the height.
public int Height { get; }
Property Value
this[int, int]
Gets a reference to the element at the specified position.
public ref T this[int x, int y] { get; }
Parameters
Property Value
- T
A reference to the element.
Exceptions
- IndexOutOfRangeException
When index is out of range of the buffer.
MemoryGroup
Gets the backing IMemoryGroup<T>.
public IMemoryGroup<T> MemoryGroup { get; }
Property Value
- IMemoryGroup<T>
The MemoryGroup.
RowStride
Gets the number of elements between row starts in the backing memory.
public int RowStride { get; }
Property Value
Size
Gets the size of the buffer.
public Size Size { get; }
Property Value
Width
Gets the width.
public int Width { get; }
Property Value
Methods
DangerousGetRowSpan(int)
Gets a Span<T> to the row 'y' beginning from the pixel at the first pixel on that row.
public Span<T> DangerousGetRowSpan(int y)
Parameters
yintThe row index.
Returns
Remarks
This method does not validate the y argument for performance reason, ArgumentOutOfRangeException is being propagated from lower levels.
Exceptions
- ArgumentOutOfRangeException
Thrown when row index is out of range.
DangerousTryGetSingleMemory(out Memory<T>)
Gets the representation of the values as a single contiguous Memory<T> when the backing group is a single tightly packed segment.
public bool DangerousTryGetSingleMemory(out Memory<T> memory)
Parameters
Returns
- bool
true when the buffer can be copied as one contiguous block without per-row handling; otherwise false.
Dispose()
Disposes the Buffer2D<T> instance
public void Dispose()
WrapMemory(Memory<T>, int, int)
Wraps an existing memory area as a Buffer2D<T> with tightly packed rows.
public static Buffer2D<T> WrapMemory(Memory<T> memory, int width, int height)
Parameters
memoryMemory<T>The source memory.
widthintThe number of elements in each row.
heightintThe number of rows.
Returns
- Buffer2D<T>
The wrapped Buffer2D<T> instance.
Remarks
This method does not transfer ownership of memory to the returned Buffer2D<T>.
The caller is responsible for ensuring that the memory remains valid for the entire lifetime of the returned buffer.
If memory originates from an IMemoryOwner<T> (for example from MemoryPool<T>),
do not dispose that owner while the returned buffer is still in use.
Exceptions
- ArgumentOutOfRangeException
Thrown when
widthorheightis not positive.- ArgumentException
Thrown when
memoryis shorter thanwidth * height.
WrapMemory(Memory<T>, int, int, int)
Wraps an existing memory area as a Buffer2D<T> using the specified row stride.
public static Buffer2D<T> WrapMemory(Memory<T> memory, int width, int height, int stride)
Parameters
memoryMemory<T>The source memory.
widthintThe number of elements in each row.
heightintThe number of rows.
strideintThe number of elements between row starts in the source memory.
Returns
- Buffer2D<T>
The wrapped Buffer2D<T> instance.
Remarks
This method does not transfer ownership of memory to the returned Buffer2D<T>.
The caller is responsible for ensuring that the memory remains valid for the entire lifetime of the returned buffer.
If memory originates from an IMemoryOwner<T> (for example from MemoryPool<T>),
do not dispose that owner while the returned buffer is still in use.
The minimum required length is ((height - 1) * stride) + width elements.
Exceptions
- ArgumentOutOfRangeException
Thrown when
widthorheightis not positive, or whenstrideis less thanwidth.- ArgumentException
Thrown when
memoryis shorter than the required buffer size.