|
|
|
@ -8,14 +8,14 @@ using SixLabors.Primitives; |
|
|
|
namespace SixLabors.Memory |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Defines extension methods for <see cref="IBuffer2D{T}"/>.
|
|
|
|
/// Defines extension methods for <see cref="Buffer2D{T}"/>.
|
|
|
|
/// </summary>
|
|
|
|
internal static class Buffer2DExtensions |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Gets a <see cref="Span{T}"/> to the backing buffer of <paramref name="buffer"/>.
|
|
|
|
/// </summary>
|
|
|
|
internal static Span<T> GetSpan<T>(this IBuffer2D<T> buffer) |
|
|
|
internal static Span<T> GetSpan<T>(this Buffer2D<T> buffer) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return buffer.Buffer.GetSpan(); |
|
|
|
@ -30,7 +30,7 @@ namespace SixLabors.Memory |
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <returns>The <see cref="Span{T}"/></returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static Span<T> GetRowSpan<T>(this IBuffer2D<T> buffer, int x, int y) |
|
|
|
public static Span<T> GetRowSpan<T>(this Buffer2D<T> buffer, int x, int y) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return buffer.GetSpan().Slice((y * buffer.Width) + x, buffer.Width - x); |
|
|
|
@ -44,7 +44,7 @@ namespace SixLabors.Memory |
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <returns>The <see cref="Span{T}"/></returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static Span<T> GetRowSpan<T>(this IBuffer2D<T> buffer, int y) |
|
|
|
public static Span<T> GetRowSpan<T>(this Buffer2D<T> buffer, int y) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return buffer.GetSpan().Slice(y * buffer.Width, buffer.Width); |
|
|
|
@ -58,7 +58,7 @@ namespace SixLabors.Memory |
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <returns>The <see cref="Span{T}"/></returns>
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
|
|
|
public static Memory<T> GetRowMemory<T>(this IBuffer2D<T> buffer, int y) |
|
|
|
public static Memory<T> GetRowMemory<T>(this Buffer2D<T> buffer, int y) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return buffer.Buffer.Memory.Slice(y * buffer.Width, buffer.Width); |
|
|
|
@ -68,9 +68,9 @@ namespace SixLabors.Memory |
|
|
|
/// Returns the size of the buffer.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <param name="buffer">The <see cref="IBuffer2D{T}"/></param>
|
|
|
|
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
|
|
|
|
/// <returns>The <see cref="Size{T}"/> of the buffer</returns>
|
|
|
|
public static Size Size<T>(this IBuffer2D<T> buffer) |
|
|
|
public static Size Size<T>(this Buffer2D<T> buffer) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return new Size(buffer.Width, buffer.Height); |
|
|
|
@ -80,9 +80,9 @@ namespace SixLabors.Memory |
|
|
|
/// Returns a <see cref="Rectangle"/> representing the full area of the buffer.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <param name="buffer">The <see cref="IBuffer2D{T}"/></param>
|
|
|
|
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
|
|
|
|
/// <returns>The <see cref="Rectangle"/></returns>
|
|
|
|
public static Rectangle FullRectangle<T>(this IBuffer2D<T> buffer) |
|
|
|
public static Rectangle FullRectangle<T>(this Buffer2D<T> buffer) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
return new Rectangle(0, 0, buffer.Width, buffer.Height); |
|
|
|
@ -92,13 +92,13 @@ namespace SixLabors.Memory |
|
|
|
/// Return a <see cref="BufferArea{T}"/> to the subarea represented by 'rectangle'
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <param name="buffer">The <see cref="IBuffer2D{T}"/></param>
|
|
|
|
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
|
|
|
|
/// <param name="rectangle">The rectangle subarea</param>
|
|
|
|
/// <returns>The <see cref="BufferArea{T}"/></returns>
|
|
|
|
public static BufferArea<T> GetArea<T>(this IBuffer2D<T> buffer, Rectangle rectangle) |
|
|
|
public static BufferArea<T> GetArea<T>(this Buffer2D<T> buffer, Rectangle rectangle) |
|
|
|
where T : struct => new BufferArea<T>(buffer, rectangle); |
|
|
|
|
|
|
|
public static BufferArea<T> GetArea<T>(this IBuffer2D<T> buffer, int x, int y, int width, int height) |
|
|
|
public static BufferArea<T> GetArea<T>(this Buffer2D<T> buffer, int x, int y, int width, int height) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
var rectangle = new Rectangle(x, y, width, height); |
|
|
|
@ -109,9 +109,9 @@ namespace SixLabors.Memory |
|
|
|
/// Return a <see cref="BufferArea{T}"/> to the whole area of 'buffer'
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="T">The element type</typeparam>
|
|
|
|
/// <param name="buffer">The <see cref="IBuffer2D{T}"/></param>
|
|
|
|
/// <param name="buffer">The <see cref="Buffer2D{T}"/></param>
|
|
|
|
/// <returns>The <see cref="BufferArea{T}"/></returns>
|
|
|
|
public static BufferArea<T> GetArea<T>(this IBuffer2D<T> buffer) |
|
|
|
public static BufferArea<T> GetArea<T>(this Buffer2D<T> buffer) |
|
|
|
where T : struct => new BufferArea<T>(buffer); |
|
|
|
} |
|
|
|
} |