Browse Source

Internalize memory objects

pull/137/head
James Jackson-South 9 years ago
parent
commit
56be333c0a
  1. 2
      src/ImageSharp/Common/Memory/PixelDataPool{T}.cs
  2. 68
      src/ImageSharp/Image/PixelAccessor{TColor}.cs
  3. 4
      src/ImageSharp/Image/PixelArea{TColor}.cs

2
src/ImageSharp/Common/Memory/PixelDataPool{T}.cs

@ -12,7 +12,7 @@ namespace ImageSharp
/// Provides a resource pool that enables reusing instances of value type arrays for image data <see cref="T:T[]"/>.
/// </summary>
/// <typeparam name="T">The value type.</typeparam>
public class PixelDataPool<T>
internal class PixelDataPool<T>
where T : struct
{
/// <summary>

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

@ -148,6 +148,37 @@ namespace ImageSharp
}
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (this.isDisposed)
{
return;
}
// Note disposing is done.
this.isDisposed = true;
this.pixelBuffer.Dispose();
// 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>
/// Resets all the pixels to it's initial value.
/// </summary>
public void Reset()
{
Unsafe.InitBlock(this.pixelsBase, 0, (uint)(this.RowStride * this.Height));
}
/// <summary>
/// Copy an area of pixels to the image.
/// </summary>
@ -157,7 +188,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </exception>
public void CopyFrom(PixelArea<TColor> area, int targetY, int targetX = 0)
internal void CopyFrom(PixelArea<TColor> area, int targetY, int targetX = 0)
{
this.CheckCoordinates(area, targetX, targetY);
@ -173,7 +204,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </exception>
public void CopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0)
internal void CopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0)
{
this.CheckCoordinates(area, sourceX, sourceY);
@ -190,7 +221,7 @@ namespace ImageSharp
/// <exception cref="NotSupportedException">
/// Thrown when an unsupported component order value is passed.
/// </exception>
public void SafeCopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0)
internal void SafeCopyTo(PixelArea<TColor> area, int sourceY, int sourceX = 0)
{
int width = Math.Min(area.Width, this.Width - sourceX);
if (width < 1)
@ -207,37 +238,6 @@ namespace ImageSharp
this.CopyTo(area, sourceX, sourceY, width, height);
}
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose()
{
if (this.isDisposed)
{
return;
}
// Note disposing is done.
this.isDisposed = true;
this.pixelBuffer.Dispose();
// 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>
/// Resets all the pixels to it's initial value.
/// </summary>
public void Reset()
{
Unsafe.InitBlock(this.pixelsBase, 0, (uint)(this.RowStride * this.Height));
}
/// <summary>
/// Gets a <see cref="BufferPointer{TColor}"/> to the row 'y' beginning from the pixel at 'x'.
/// </summary>

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

@ -5,17 +5,15 @@
namespace ImageSharp
{
using System;
using System.Buffers;
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
/// <summary>
/// Represents an area of generic <see cref="Image{TColor}"/> pixels.
/// </summary>
/// <typeparam name="TColor">The pixel format.</typeparam>
public sealed unsafe class PixelArea<TColor> : IDisposable
internal sealed unsafe class PixelArea<TColor> : IDisposable
where TColor : struct, IPixel<TColor>
{
/// <summary>

Loading…
Cancel
Save