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
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Gets the parent.
/// </summary>
Image<TPixel> Parent { get; }
/// <summary>
/// Gets the pixel buffer.
/// </summary>

40
src/ImageSharp/Image/ImageFrameCollection.cs

@ -4,16 +4,8 @@
using System;
using System.Collections;
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.Processing;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
{
@ -24,34 +16,25 @@ namespace SixLabors.ImageSharp
public sealed class ImageFrameCollection<TPixel> : IEnumerable<ImageFrame<TPixel>>
where TPixel : struct, IPixel<TPixel>
{
private IList<ImageFrame<TPixel>> frames = new List<ImageFrame<TPixel>>();
private readonly Image<TPixel> parent;
private readonly IList<ImageFrame<TPixel>> frames = new List<ImageFrame<TPixel>>();
private readonly int parentWidth;
private readonly int parentHeight;
internal ImageFrameCollection(Image<TPixel> parent)
{
this.parent = parent;
this.parentWidth = parent.Width;
this.parentHeight = parent.Height;
}
/// <summary>
/// Gets the count.
/// </summary>
public int Count { get => this.frames.Count; }
public int Count => this.frames.Count;
/// <summary>
/// Gets the root frame.
/// </summary>
public ImageFrame<TPixel> RootFrame
{
get
{
if (this.frames.Count > 0)
{
return this.frames[0];
}
return null;
}
}
public ImageFrame<TPixel> RootFrame => this.frames.Count > 0 ? this.frames[0] : null;
/// <summary>
/// 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>
public ImageFrame<TPixel> this[int index]
{
get
{
return this.frames[index];
}
get => this.frames[index];
set
{
@ -123,7 +103,7 @@ namespace SixLabors.ImageSharp
{
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));
}

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

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

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

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

Loading…
Cancel
Save