Browse Source

Remove Parent property

pull/326/head
JimBobSquarePants 9 years ago
parent
commit
1b1359995e
  1. 5
      src/ImageSharp/Image/IImageFrame.cs
  2. 40
      src/ImageSharp/Image/ImageFrameCollection.cs
  3. 3
      src/ImageSharp/Image/Image{TPixel}.cs
  4. 26
      src/ImageSharp/Image/PixelAccessor{TPixel}.cs

5
src/ImageSharp/Image/IImageFrame.cs

@ -16,11 +16,6 @@ namespace SixLabors.ImageSharp
internal interface IImageFrame<TPixel> : IImageFrame internal interface IImageFrame<TPixel> : IImageFrame
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
/// <summary>
/// Gets the parent.
/// </summary>
Image<TPixel> Parent { get; }
/// <summary> /// <summary>
/// Gets the pixel buffer. /// Gets the pixel buffer.
/// </summary> /// </summary>

40
src/ImageSharp/Image/ImageFrameCollection.cs

@ -4,16 +4,8 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.MetaData;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp namespace SixLabors.ImageSharp
{ {
@ -24,34 +16,25 @@ namespace SixLabors.ImageSharp
public sealed class ImageFrameCollection<TPixel> : IEnumerable<ImageFrame<TPixel>> public sealed class ImageFrameCollection<TPixel> : IEnumerable<ImageFrame<TPixel>>
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
private IList<ImageFrame<TPixel>> frames = new List<ImageFrame<TPixel>>(); private readonly IList<ImageFrame<TPixel>> frames = new List<ImageFrame<TPixel>>();
private readonly Image<TPixel> parent; private readonly int parentWidth;
private readonly int parentHeight;
internal ImageFrameCollection(Image<TPixel> parent) internal ImageFrameCollection(Image<TPixel> parent)
{ {
this.parent = parent; this.parentWidth = parent.Width;
this.parentHeight = parent.Height;
} }
/// <summary> /// <summary>
/// Gets the count. /// Gets the count.
/// </summary> /// </summary>
public int Count { get => this.frames.Count; } public int Count => this.frames.Count;
/// <summary> /// <summary>
/// Gets the root frame. /// Gets the root frame.
/// </summary> /// </summary>
public ImageFrame<TPixel> RootFrame public ImageFrame<TPixel> RootFrame => this.frames.Count > 0 ? this.frames[0] : null;
{
get
{
if (this.frames.Count > 0)
{
return this.frames[0];
}
return null;
}
}
/// <summary> /// <summary>
/// Gets or sets the <see cref="ImageFrame{TPixel}"/> at the specified index. /// Gets or sets the <see cref="ImageFrame{TPixel}"/> at the specified index.
@ -63,10 +46,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="ImageFrame{TPixel}"/> at the specified index.</returns> /// <returns>The <see cref="ImageFrame{TPixel}"/> at the specified index.</returns>
public ImageFrame<TPixel> this[int index] public ImageFrame<TPixel> this[int index]
{ {
get get => this.frames[index];
{
return this.frames[index];
}
set set
{ {
@ -123,7 +103,7 @@ namespace SixLabors.ImageSharp
{ {
if (this.Count != 0) if (this.Count != 0)
{ {
if (this.parent.Width != frame.Width || this.parent.Height != frame.Height) if (this.parentWidth != frame.Width || this.parentHeight != frame.Height)
{ {
throw new ArgumentException("Frame must have the same dimensions as the image", nameof(frame)); throw new ArgumentException("Frame must have the same dimensions as the image", nameof(frame));
} }

3
src/ImageSharp/Image/Image{TPixel}.cs

@ -136,9 +136,6 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
ImageFrameMetaData IImageFrame.MetaData => this.RootFrame.MetaData; ImageFrameMetaData IImageFrame.MetaData => this.RootFrame.MetaData;
/// <inheritdoc/>
Image<TPixel> IImageFrame<TPixel>.Parent => this.RootFrame.Parent;
/// <summary> /// <summary>
/// Gets or sets the pixel at the specified position. /// Gets or sets the pixel at the specified position.
/// </summary> /// </summary>

26
src/ImageSharp/Image/PixelAccessor{TPixel}.cs

@ -4,8 +4,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory; using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Unsafe = System.Runtime.CompilerServices.Unsafe; using Unsafe = System.Runtime.CompilerServices.Unsafe;
@ -49,8 +48,6 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThan(image.Height, 0, "image height"); Guard.MustBeGreaterThan(image.Height, 0, "image height");
this.SetPixelBufferUnsafe(image.PixelBuffer, false); this.SetPixelBufferUnsafe(image.PixelBuffer, false);
Configuration config = image.Parent.Configuration();
this.ParallelOptions = config.ParallelOptions;
} }
/// <summary> /// <summary>
@ -77,8 +74,6 @@ namespace SixLabors.ImageSharp
Guard.MustBeGreaterThan(height, 0, nameof(height)); Guard.MustBeGreaterThan(height, 0, nameof(height));
this.SetPixelBufferUnsafe(pixels, ownedBuffer); this.SetPixelBufferUnsafe(pixels, ownedBuffer);
this.ParallelOptions = Configuration.Default.ParallelOptions;
} }
/// <summary> /// <summary>
@ -104,21 +99,12 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public int RowStride { get; private set; } public int RowStride { get; private set; }
/// <summary> /// <inheritdoc />
/// Gets the width of the image.
/// </summary>
public int Width { get; private set; } public int Width { get; private set; }
/// <summary> /// <inheritdoc />
/// Gets the height of the image.
/// </summary>
public int Height { get; private set; } public int Height { get; private set; }
/// <summary>
/// Gets the global parallel options for processing tasks in parallel.
/// </summary>
public ParallelOptions ParallelOptions { get; }
/// <inheritdoc /> /// <inheritdoc />
Span<TPixel> IBuffer2D<TPixel>.Span => this.PixelBuffer; Span<TPixel> IBuffer2D<TPixel>.Span => this.PixelBuffer;
@ -147,9 +133,7 @@ namespace SixLabors.ImageSharp
} }
} }
/// <summary> /// <inheritdoc />
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
public void Dispose() public void Dispose()
{ {
if (this.isDisposed || !this.ownedBuffer) if (this.isDisposed || !this.ownedBuffer)
@ -245,7 +229,7 @@ namespace SixLabors.ImageSharp
/// <remarks>If <see cref="M:PixelAccessor.PooledMemory"/> is true then caller is responsible for ensuring <see cref="M:PixelDataPool.Return()"/> is called.</remarks> /// <remarks>If <see cref="M:PixelAccessor.PooledMemory"/> is true then caller is responsible for ensuring <see cref="M:PixelDataPool.Return()"/> is called.</remarks>
internal Buffer2D<TPixel> SwapBufferOwnership(Buffer2D<TPixel> pixels) internal Buffer2D<TPixel> SwapBufferOwnership(Buffer2D<TPixel> pixels)
{ {
var oldPixels = this.PixelBuffer; Buffer2D<TPixel> oldPixels = this.PixelBuffer;
this.SetPixelBufferUnsafe(pixels, this.ownedBuffer); this.SetPixelBufferUnsafe(pixels, this.ownedBuffer);
return oldPixels; return oldPixels;
} }

Loading…
Cancel
Save