|
|
|
@ -77,6 +77,8 @@ namespace ImageSharp |
|
|
|
this.ComponentOrder = componentOrder; |
|
|
|
this.RowStride = width * GetComponentCount(componentOrder); |
|
|
|
this.Bytes = bytes; |
|
|
|
this.Length = bytes.Length; |
|
|
|
this.isBufferRented = false; |
|
|
|
this.pixelsHandle = GCHandle.Alloc(this.Bytes, GCHandleType.Pinned); |
|
|
|
|
|
|
|
// TODO: Why is Resharper warning us about an impure method call?
|
|
|
|
@ -88,34 +90,31 @@ namespace ImageSharp |
|
|
|
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="width">The width.</param>
|
|
|
|
/// <param name="height">The height.</param>
|
|
|
|
/// <param name="componentOrder">The component order.</param>
|
|
|
|
/// <param name="usePool">True if the buffer should be rented from ArrayPool</param>
|
|
|
|
public PixelArea(int width, int height, ComponentOrder componentOrder, bool usePool = false) |
|
|
|
: this(width, height, componentOrder, 0, usePool) |
|
|
|
public PixelArea(int width, ComponentOrder componentOrder) |
|
|
|
: this(width, 1, componentOrder, 0) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="width">The width.</param>
|
|
|
|
/// <param name="width">The width. </param>
|
|
|
|
/// <param name="componentOrder">The component order.</param>
|
|
|
|
/// <param name="usePool">True if the buffer should be rented from ArrayPool</param>
|
|
|
|
public PixelArea(int width, ComponentOrder componentOrder, bool usePool = false) |
|
|
|
: this(width, 1, componentOrder, 0, usePool) |
|
|
|
/// <param name="padding">The number of bytes to pad each row.</param>
|
|
|
|
public PixelArea(int width, ComponentOrder componentOrder, int padding) |
|
|
|
: this(width, 1, componentOrder, padding) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="PixelArea{TColor}"/> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="width">The width. </param>
|
|
|
|
/// <param name="width">The width.</param>
|
|
|
|
/// <param name="height">The height.</param>
|
|
|
|
/// <param name="componentOrder">The component order.</param>
|
|
|
|
/// <param name="padding">The number of bytes to pad each row.</param>
|
|
|
|
/// <param name="usePool">True if the buffer should be rented from ArrayPool</param>
|
|
|
|
public PixelArea(int width, ComponentOrder componentOrder, int padding, bool usePool = false) |
|
|
|
: this(width, 1, componentOrder, padding, usePool) |
|
|
|
public PixelArea(int width, int height, ComponentOrder componentOrder) |
|
|
|
: this(width, height, componentOrder, 0) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
@ -126,27 +125,15 @@ namespace ImageSharp |
|
|
|
/// <param name="height">The height.</param>
|
|
|
|
/// <param name="componentOrder">The component order.</param>
|
|
|
|
/// <param name="padding">The number of bytes to pad each row.</param>
|
|
|
|
/// <param name="usePool">True if the buffer should be rented from ArrayPool</param>
|
|
|
|
public PixelArea(int width, int height, ComponentOrder componentOrder, int padding, bool usePool = false) |
|
|
|
public PixelArea(int width, int height, ComponentOrder componentOrder, int padding) |
|
|
|
{ |
|
|
|
this.Width = width; |
|
|
|
this.Height = height; |
|
|
|
this.ComponentOrder = componentOrder; |
|
|
|
this.RowStride = (width * GetComponentCount(componentOrder)) + padding; |
|
|
|
|
|
|
|
int bufferSize = this.RowStride * height; |
|
|
|
|
|
|
|
if (usePool) |
|
|
|
{ |
|
|
|
this.Bytes = BytesPool.Rent(bufferSize); |
|
|
|
this.isBufferRented = true; |
|
|
|
Array.Clear(this.Bytes, 0, bufferSize); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
this.Bytes = new byte[bufferSize]; |
|
|
|
} |
|
|
|
|
|
|
|
this.Length = this.RowStride * height; |
|
|
|
this.Bytes = BytesPool.Rent(this.Length); |
|
|
|
this.isBufferRented = true; |
|
|
|
this.pixelsHandle = GCHandle.Alloc(this.Bytes, GCHandleType.Pinned); |
|
|
|
|
|
|
|
// TODO: Why is Resharper warning us about an impure method call?
|
|
|
|
@ -167,6 +154,11 @@ namespace ImageSharp |
|
|
|
/// </summary>
|
|
|
|
public byte[] Bytes { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the length of the buffer.
|
|
|
|
/// </summary>
|
|
|
|
public int Length { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the component order.
|
|
|
|
/// </summary>
|
|
|
|
@ -198,9 +190,8 @@ namespace ImageSharp |
|
|
|
public int Width { get; } |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the pool used to rent <see cref="Bytes"/>, when it's not coming from an external source
|
|
|
|
/// Gets the pool used to rent bytes, when it's not coming from an external source.
|
|
|
|
/// </summary>
|
|
|
|
// ReSharper disable once StaticMemberInGenericType
|
|
|
|
// TODO: Use own pool?
|
|
|
|
private static ArrayPool<byte> BytesPool => ArrayPool<byte>.Shared; |
|
|
|
|
|
|
|
@ -210,6 +201,13 @@ namespace ImageSharp |
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
this.Dispose(true); |
|
|
|
|
|
|
|
// This object will be cleaned up by the Dispose method.
|
|
|
|
// Therefore, you should call GC.SuppressFinalize to
|
|
|
|
// take this object off the finalization queue
|
|
|
|
// and prevent finalization code for this object
|
|
|
|
// from executing a second time.
|
|
|
|
GC.SuppressFinalize(this); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -218,7 +216,7 @@ namespace ImageSharp |
|
|
|
/// <param name="stream">The stream.</param>
|
|
|
|
public void Read(Stream stream) |
|
|
|
{ |
|
|
|
stream.Read(this.Bytes, 0, this.Bytes.Length); |
|
|
|
stream.Read(this.Bytes, 0, this.Length); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -227,7 +225,7 @@ namespace ImageSharp |
|
|
|
/// <param name="stream">The stream.</param>
|
|
|
|
public void Write(Stream stream) |
|
|
|
{ |
|
|
|
stream.Write(this.Bytes, 0, this.Bytes.Length); |
|
|
|
stream.Write(this.Bytes, 0, this.Length); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -315,13 +313,6 @@ namespace ImageSharp |
|
|
|
this.PixelBase = null; |
|
|
|
|
|
|
|
this.isDisposed = true; |
|
|
|
|
|
|
|
// This object will be cleaned up by the Dispose method.
|
|
|
|
// Therefore, you should call GC.SuppressFinalize to
|
|
|
|
// take this object off the finalization queue
|
|
|
|
// and prevent finalization code for this object
|
|
|
|
// from executing a second time.
|
|
|
|
GC.SuppressFinalize(this); |
|
|
|
} |
|
|
|
} |
|
|
|
} |