diff --git a/src/ImageSharp/ImageFrameCollection.cs b/src/ImageSharp/ImageFrameCollection.cs index f2e35812b..1d4735fd8 100644 --- a/src/ImageSharp/ImageFrameCollection.cs +++ b/src/ImageSharp/ImageFrameCollection.cs @@ -16,14 +16,14 @@ namespace SixLabors.ImageSharp private readonly IList> frames = new List>(); private readonly Image parent; - internal ImageFrameCollection(Image parent, int width, int height) + internal ImageFrameCollection(Image parent, int width, int height, TPixel backgroundColor) { Guard.NotNull(parent, nameof(parent)); this.parent = parent; // Frames are already cloned within the caller - this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, parent.ClearColor)); + this.frames.Add(new ImageFrame(parent.GetConfiguration(), width, height, backgroundColor)); } internal ImageFrameCollection(Image parent, IEnumerable> frames) @@ -143,7 +143,7 @@ namespace SixLabors.ImageSharp /// public ImageFrame CreateFrame() { - ImageFrame frame = new ImageFrame(this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height, this.parent.ClearColor); + var frame = new ImageFrame(this.parent.GetConfiguration(), this.RootFrame.Width, this.RootFrame.Height, this.RootFrame.BackgroundColor); this.frames.Add(frame); return frame; } diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs index cb15fe3db..1c26bb558 100644 --- a/src/ImageSharp/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/ImageFrame{TPixel}.cs @@ -19,8 +19,7 @@ namespace SixLabors.ImageSharp /// /// The pixel format. public sealed class ImageFrame : IPixelSource, IDisposable - where TPixel : struct, IPixel - { + where TPixel : struct, IPixel { private bool isDisposed; /// @@ -30,8 +29,7 @@ namespace SixLabors.ImageSharp /// The width of the image in pixels. /// The height of the image in pixels. internal ImageFrame(MemoryManager memoryManager, int width, int height) - : this(memoryManager, width, height, new ImageFrameMetaData()) - { + : this(memoryManager, width, height, new ImageFrameMetaData()) { } /// @@ -59,10 +57,9 @@ namespace SixLabors.ImageSharp /// The to use for buffer allocation and parallel options to clear the buffer with. /// The width of the image in pixels. /// The height of the image in pixels. - /// The color to clear the image with. - internal ImageFrame(Configuration configuration, int width, int height, TPixel clearColor) - : this(configuration, width, height, clearColor, new ImageFrameMetaData()) - { + /// The color to clear the image with. + internal ImageFrame(Configuration configuration, int width, int height, TPixel backgroundColor) + : this(configuration, width, height, backgroundColor, new ImageFrameMetaData()) { } /// @@ -71,9 +68,9 @@ namespace SixLabors.ImageSharp /// The to use for buffer allocation and parallel options to clear the buffer with. /// The width of the image in pixels. /// The height of the image in pixels. - /// The color to clear the image with. + /// The color to clear the image with. /// The meta data. - 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.MustBeGreaterThan(width, 0, nameof(width)); @@ -82,7 +79,8 @@ namespace SixLabors.ImageSharp this.MemoryManager = configuration.MemoryManager; this.PixelBuffer = this.MemoryManager.Allocate2D(width, height, false); - this.Clear(configuration.ParallelOptions, clearColor); + this.BackgroundColor = backgroundColor; + this.Clear(configuration.ParallelOptions, backgroundColor); this.MetaData = metaData; } @@ -93,8 +91,7 @@ namespace SixLabors.ImageSharp /// The of the frame. /// The meta data. internal ImageFrame(MemoryManager memoryManager, Size size, ImageFrameMetaData metaData) - : this(memoryManager, size.Width, size.Height, metaData) - { + : this(memoryManager, size.Width, size.Height, metaData) { } /// @@ -133,6 +130,11 @@ namespace SixLabors.ImageSharp /// public int Height => this.PixelBuffer.Height; + /// + /// Gets the background color. + /// + public TPixel BackgroundColor { get; } + /// /// Gets the meta data of the frame. /// @@ -306,7 +308,7 @@ namespace SixLabors.ImageSharp /// /// The parallel options. /// The value to initialize the bitmap with. - public void Clear(ParallelOptions parallelOptions, TPixel value) { + internal void Clear(ParallelOptions parallelOptions, TPixel value) { Parallel.For( 0, this.Height, diff --git a/src/ImageSharp/Image{TPixel}.cs b/src/ImageSharp/Image{TPixel}.cs index 599116414..2d9869602 100644 --- a/src/ImageSharp/Image{TPixel}.cs +++ b/src/ImageSharp/Image{TPixel}.cs @@ -22,7 +22,6 @@ namespace SixLabors.ImageSharp { private readonly Configuration configuration; private readonly ImageFrameCollection frames; - private readonly TPixel clearColor; /// /// Initializes a new instance of the class @@ -47,9 +46,9 @@ namespace SixLabors.ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// The color to initialize the pixels with. - public Image(Configuration configuration, int width, int height, TPixel clearColor) - : this(configuration, width, height, clearColor, new ImageMetaData()) + /// The color to initialize the pixels with. + public Image(Configuration configuration, int width, int height, TPixel backgroundColor) + : this(configuration, width, height, backgroundColor, new ImageMetaData()) { } @@ -79,7 +78,7 @@ namespace SixLabors.ImageSharp this.configuration = configuration ?? Configuration.Default; this.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); this.MetaData = metadata ?? new ImageMetaData(); - this.frames = new ImageFrameCollection(this, width, height); + this.frames = new ImageFrameCollection(this, width, height, default(TPixel)); } /// @@ -91,14 +90,13 @@ namespace SixLabors.ImageSharp /// /// The width of the image in pixels. /// The height of the image in pixels. - /// The clear color. + /// The color to initialize the pixels with. /// The images metadata. - 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.PixelType = new PixelTypeInfo(Unsafe.SizeOf() * 8); this.MetaData = metadata ?? new ImageMetaData(); - this.clearColor = clearColor; - this.frames = new ImageFrameCollection(this, width, height); + this.frames = new ImageFrameCollection(this, width, height, backgroundColor); } /// @@ -139,11 +137,6 @@ namespace SixLabors.ImageSharp /// public IImageFrameCollection Frames => this.frames; - /// - /// Gets the clear color to initialize the image frame pixels with. - /// - internal TPixel ClearColor => this.clearColor; - /// /// Gets the root frame. /// diff --git a/src/ImageSharp/Memory/BufferExtensions.cs b/src/ImageSharp/Memory/BufferExtensions.cs index 1347f2882..dd3114c21 100644 --- a/src/ImageSharp/Memory/BufferExtensions.cs +++ b/src/ImageSharp/Memory/BufferExtensions.cs @@ -52,18 +52,6 @@ namespace SixLabors.ImageSharp.Memory buffer.Span.Clear(); } - /// - /// Fills the contents of this buffer. - /// - /// The buffer - /// The value to fill the buffer with. - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static void Fill(this IBuffer buffer, T value) - where T : struct - { - buffer.Span.Fill(value); - } - public static ref T DangerousGetPinnableReference(this IBuffer buffer) where T : struct => ref MemoryMarshal.GetReference(buffer.Span); diff --git a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs b/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs index 4c760e681..cb185d977 100644 --- a/tests/ImageSharp.Tests/Image/ImageFramesCollectionTests.cs +++ b/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"); this.image = new Image(10, 10); - this.collection = new ImageFrameCollection(this.image, 10, 10); + this.collection = new ImageFrameCollection(this.image, 10, 10, default); } [Fact]