Browse Source

Processed review comments, moved Image.ClearColor to ImageFrame.BackgroundColor.

af/merge-core
woutware 8 years ago
parent
commit
cff22588a9
  1. 6
      src/ImageSharp/ImageFrameCollection.cs
  2. 30
      src/ImageSharp/ImageFrame{TPixel}.cs
  3. 21
      src/ImageSharp/Image{TPixel}.cs
  4. 12
      src/ImageSharp/Memory/BufferExtensions.cs
  5. 2
      tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs

6
src/ImageSharp/ImageFrameCollection.cs

@ -16,14 +16,14 @@ namespace SixLabors.ImageSharp
private readonly 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 Image<TPixel> parent;
internal ImageFrameCollection(Image<TPixel> parent, int width, int height) internal ImageFrameCollection(Image<TPixel> parent, int width, int height, TPixel backgroundColor)
{ {
Guard.NotNull(parent, nameof(parent)); Guard.NotNull(parent, nameof(parent));
this.parent = parent; this.parent = parent;
// Frames are already cloned within the caller // Frames are already cloned within the caller
this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, parent.ClearColor)); this.frames.Add(new ImageFrame<TPixel>(parent.GetConfiguration(), width, height, backgroundColor));
} }
internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames) internal ImageFrameCollection(Image<TPixel> parent, IEnumerable<ImageFrame<TPixel>> frames)
@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp
/// <inheritdoc/> /// <inheritdoc/>
public ImageFrame<TPixel> CreateFrame() public ImageFrame<TPixel> CreateFrame()
{ {
ImageFrame<TPixel> frame = new ImageFrame<TPixel>(this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height, this.parent.ClearColor); var frame = new ImageFrame<TPixel>(this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height, this.RootFrame.BackgroundColor);
this.frames.Add(frame); this.frames.Add(frame);
return frame; return frame;
} }

30
src/ImageSharp/ImageFrame{TPixel}.cs

@ -19,8 +19,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> /// <typeparam name="TPixel">The pixel format.</typeparam>
public sealed class ImageFrame<TPixel> : IPixelSource<TPixel>, IDisposable public sealed class ImageFrame<TPixel> : IPixelSource<TPixel>, IDisposable
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel> {
{
private bool isDisposed; private bool isDisposed;
/// <summary> /// <summary>
@ -30,8 +29,7 @@ namespace SixLabors.ImageSharp
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
internal ImageFrame(MemoryManager memoryManager, int width, int height) internal ImageFrame(MemoryManager memoryManager, int width, int height)
: this(memoryManager, width, height, new ImageFrameMetaData()) : this(memoryManager, width, height, new ImageFrameMetaData()) {
{
} }
/// <summary> /// <summary>
@ -59,10 +57,9 @@ namespace SixLabors.ImageSharp
/// <param name="configuration">The <see cref="Configuration"/> to use for buffer allocation and parallel options to clear the buffer with.</param> /// <param name="configuration">The <see cref="Configuration"/> to use for buffer allocation and parallel options to clear the buffer with.</param>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="clearColor">The color to clear the image with.</param> /// <param name="backgroundColor">The color to clear the image with.</param>
internal ImageFrame(Configuration configuration, int width, int height, TPixel clearColor) internal ImageFrame(Configuration configuration, int width, int height, TPixel backgroundColor)
: this(configuration, width, height, clearColor, new ImageFrameMetaData()) : this(configuration, width, height, backgroundColor, new ImageFrameMetaData()) {
{
} }
/// <summary> /// <summary>
@ -71,9 +68,9 @@ namespace SixLabors.ImageSharp
/// <param name="configuration">The <see cref="Configuration"/> to use for buffer allocation and parallel options to clear the buffer with.</param> /// <param name="configuration">The <see cref="Configuration"/> to use for buffer allocation and parallel options to clear the buffer with.</param>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="clearColor">The color to clear the image with.</param> /// <param name="backgroundColor">The color to clear the image with.</param>
/// <param name="metaData">The meta data.</param> /// <param name="metaData">The meta data.</param>
internal ImageFrame(Configuration configuration, int width, int height, TPixel clearColor, ImageFrameMetaData metaData) internal ImageFrame(Configuration configuration, int width, int height, TPixel backgroundColor, ImageFrameMetaData metaData)
{ {
Guard.NotNull(configuration, nameof(configuration)); Guard.NotNull(configuration, nameof(configuration));
Guard.MustBeGreaterThan(width, 0, nameof(width)); Guard.MustBeGreaterThan(width, 0, nameof(width));
@ -82,7 +79,8 @@ namespace SixLabors.ImageSharp
this.MemoryManager = configuration.MemoryManager; this.MemoryManager = configuration.MemoryManager;
this.PixelBuffer = this.MemoryManager.Allocate2D<TPixel>(width, height, false); this.PixelBuffer = this.MemoryManager.Allocate2D<TPixel>(width, height, false);
this.Clear(configuration.ParallelOptions, clearColor); this.BackgroundColor = backgroundColor;
this.Clear(configuration.ParallelOptions, backgroundColor);
this.MetaData = metaData; this.MetaData = metaData;
} }
@ -93,8 +91,7 @@ namespace SixLabors.ImageSharp
/// <param name="size">The <see cref="Size"/> of the frame.</param> /// <param name="size">The <see cref="Size"/> of the frame.</param>
/// <param name="metaData">The meta data.</param> /// <param name="metaData">The meta data.</param>
internal ImageFrame(MemoryManager memoryManager, Size size, ImageFrameMetaData metaData) internal ImageFrame(MemoryManager memoryManager, Size size, ImageFrameMetaData metaData)
: this(memoryManager, size.Width, size.Height, metaData) : this(memoryManager, size.Width, size.Height, metaData) {
{
} }
/// <summary> /// <summary>
@ -133,6 +130,11 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public int Height => this.PixelBuffer.Height; public int Height => this.PixelBuffer.Height;
/// <summary>
/// Gets the background color.
/// </summary>
public TPixel BackgroundColor { get; }
/// <summary> /// <summary>
/// Gets the meta data of the frame. /// Gets the meta data of the frame.
/// </summary> /// </summary>
@ -306,7 +308,7 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
/// <param name="parallelOptions">The parallel options.</param> /// <param name="parallelOptions">The parallel options.</param>
/// <param name="value">The value to initialize the bitmap with.</param> /// <param name="value">The value to initialize the bitmap with.</param>
public void Clear(ParallelOptions parallelOptions, TPixel value) { internal void Clear(ParallelOptions parallelOptions, TPixel value) {
Parallel.For( Parallel.For(
0, 0,
this.Height, this.Height,

21
src/ImageSharp/Image{TPixel}.cs

@ -22,7 +22,6 @@ namespace SixLabors.ImageSharp
{ {
private readonly Configuration configuration; private readonly Configuration configuration;
private readonly ImageFrameCollection<TPixel> frames; private readonly ImageFrameCollection<TPixel> frames;
private readonly TPixel clearColor;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Image{TPixel}"/> class /// Initializes a new instance of the <see cref="Image{TPixel}"/> class
@ -47,9 +46,9 @@ namespace SixLabors.ImageSharp
/// </param> /// </param>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="clearColor">The color to initialize the pixels with.</param> /// <param name="backgroundColor">The color to initialize the pixels with.</param>
public Image(Configuration configuration, int width, int height, TPixel clearColor) public Image(Configuration configuration, int width, int height, TPixel backgroundColor)
: this(configuration, width, height, clearColor, new ImageMetaData()) : this(configuration, width, height, backgroundColor, new ImageMetaData())
{ {
} }
@ -79,7 +78,7 @@ namespace SixLabors.ImageSharp
this.configuration = configuration ?? Configuration.Default; this.configuration = configuration ?? Configuration.Default;
this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8); this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8);
this.MetaData = metadata ?? new ImageMetaData(); this.MetaData = metadata ?? new ImageMetaData();
this.frames = new ImageFrameCollection<TPixel>(this, width, height); this.frames = new ImageFrameCollection<TPixel>(this, width, height, default(TPixel));
} }
/// <summary> /// <summary>
@ -91,14 +90,13 @@ namespace SixLabors.ImageSharp
/// </param> /// </param>
/// <param name="width">The width of the image in pixels.</param> /// <param name="width">The width of the image in pixels.</param>
/// <param name="height">The height of the image in pixels.</param> /// <param name="height">The height of the image in pixels.</param>
/// <param name="clearColor">The clear color.</param> /// <param name="backgroundColor">The color to initialize the pixels with.</param>
/// <param name="metadata">The images metadata.</param> /// <param name="metadata">The images metadata.</param>
internal Image(Configuration configuration, int width, int height, TPixel clearColor, ImageMetaData metadata) { internal Image(Configuration configuration, int width, int height, TPixel backgroundColor, ImageMetaData metadata) {
this.configuration = configuration ?? Configuration.Default; this.configuration = configuration ?? Configuration.Default;
this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8); this.PixelType = new PixelTypeInfo(Unsafe.SizeOf<TPixel>() * 8);
this.MetaData = metadata ?? new ImageMetaData(); this.MetaData = metadata ?? new ImageMetaData();
this.clearColor = clearColor; this.frames = new ImageFrameCollection<TPixel>(this, width, height, backgroundColor);
this.frames = new ImageFrameCollection<TPixel>(this, width, height);
} }
/// <summary> /// <summary>
@ -139,11 +137,6 @@ namespace SixLabors.ImageSharp
/// </summary> /// </summary>
public IImageFrameCollection<TPixel> Frames => this.frames; public IImageFrameCollection<TPixel> Frames => this.frames;
/// <summary>
/// Gets the clear color to initialize the image frame pixels with.
/// </summary>
internal TPixel ClearColor => this.clearColor;
/// <summary> /// <summary>
/// Gets the root frame. /// Gets the root frame.
/// </summary> /// </summary>

12
src/ImageSharp/Memory/BufferExtensions.cs

@ -52,18 +52,6 @@ namespace SixLabors.ImageSharp.Memory
buffer.Span.Clear(); buffer.Span.Clear();
} }
/// <summary>
/// Fills the contents of this buffer.
/// </summary>
/// <param name="buffer">The buffer</param>
/// <param name="value">The value to fill the buffer with.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Fill<T>(this IBuffer<T> buffer, T value)
where T : struct
{
buffer.Span.Fill(value);
}
public static ref T DangerousGetPinnableReference<T>(this IBuffer<T> buffer) public static ref T DangerousGetPinnableReference<T>(this IBuffer<T> buffer)
where T : struct => where T : struct =>
ref MemoryMarshal.GetReference(buffer.Span); ref MemoryMarshal.GetReference(buffer.Span);

2
tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs

@ -19,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US"); System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");
this.image = new Image<Rgba32>(10, 10); this.image = new Image<Rgba32>(10, 10);
this.collection = new ImageFrameCollection<Rgba32>(this.image, 10, 10); this.collection = new ImageFrameCollection<Rgba32>(this.image, 10, 10, default);
} }
[Fact] [Fact]

Loading…
Cancel
Save