Browse Source

remove IBuffer2D<T>

(abstraction is no longer useful)
af/merge-core
Anton Firszov 8 years ago
parent
commit
79c4ddc809
  1. 2
      src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs
  2. 28
      src/ImageSharp/Memory/Buffer2DExtensions.cs
  3. 10
      src/ImageSharp/Memory/Buffer2D{T}.cs
  4. 8
      src/ImageSharp/Memory/BufferArea{T}.cs
  5. 31
      src/ImageSharp/Memory/IBuffer2D{T}.cs

2
src/ImageSharp/Formats/Jpeg/Components/Decoder/ColorConverters/JpegColorConverter.cs

@ -101,7 +101,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
/// </summary>
/// <param name="componentBuffers">The 1-4 sized list of component buffers.</param>
/// <param name="row">The row to convert</param>
public ComponentValues(IReadOnlyList<IBuffer2D<float>> componentBuffers, int row)
public ComponentValues(IReadOnlyList<Buffer2D<float>> componentBuffers, int row)
{
this.ComponentCount = componentBuffers.Count;

28
src/ImageSharp/Memory/Buffer2DExtensions.cs

@ -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);
}
}

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

@ -12,7 +12,7 @@ namespace SixLabors.Memory
/// interpreted as a 2D region of <see cref="Width"/> x <see cref="Height"/> elements.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
internal class Buffer2D<T> : IBuffer2D<T>, IDisposable
internal class Buffer2D<T> : IDisposable
where T : struct
{
/// <summary>
@ -28,10 +28,14 @@ namespace SixLabors.Memory
this.Height = height;
}
/// <inheritdoc />
/// <summary>
/// Gets the width.
/// </summary>
public int Width { get; private set; }
/// <inheritdoc />
/// <summary>
/// Gets the height.
/// </summary>
public int Height { get; private set; }
/// <summary>

8
src/ImageSharp/Memory/BufferArea{T}.cs

@ -18,7 +18,7 @@ namespace SixLabors.Memory
public readonly Rectangle Rectangle;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferArea(IBuffer2D<T> destinationBuffer, Rectangle rectangle)
public BufferArea(Buffer2D<T> destinationBuffer, Rectangle rectangle)
{
ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.X, 0, nameof(rectangle));
ImageSharp.DebugGuard.MustBeGreaterThanOrEqualTo(rectangle.Y, 0, nameof(rectangle));
@ -30,15 +30,15 @@ namespace SixLabors.Memory
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public BufferArea(IBuffer2D<T> destinationBuffer)
public BufferArea(Buffer2D<T> destinationBuffer)
: this(destinationBuffer, destinationBuffer.FullRectangle())
{
}
/// <summary>
/// Gets the <see cref="IBuffer2D{T}"/> being pointed by this instance.
/// Gets the <see cref="Buffer2D{T}"/> being pointed by this instance.
/// </summary>
public IBuffer2D<T> DestinationBuffer { get; }
public Buffer2D<T> DestinationBuffer { get; }
/// <summary>
/// Gets the size of the area.

31
src/ImageSharp/Memory/IBuffer2D{T}.cs

@ -1,31 +0,0 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
namespace SixLabors.Memory
{
/// <summary>
/// An interface that represents a contigous 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 IBuffer2D<T>
where T : struct
{
/// <summary>
/// Gets the width.
/// </summary>
int Width { get; }
/// <summary>
/// Gets the height.
/// </summary>
int Height { get; }
/// <summary>
/// Gets the contigous buffer being wrapped.
/// </summary>
IBuffer<T> Buffer { get; }
}
}
Loading…
Cancel
Save