From 02fc4ef43b7834f4d0e7de927de0ec41a5725afe Mon Sep 17 00:00:00 2001
From: woutware <35376607+woutware@users.noreply.github.com>
Date: Sun, 29 Apr 2018 23:19:28 +0200
Subject: [PATCH] I think I forgot to commit this one.
---
src/ImageSharp/ImageFrame{TPixel}.cs | 51 ++++++++++++++++++++++++++++
1 file changed, 51 insertions(+)
diff --git a/src/ImageSharp/ImageFrame{TPixel}.cs b/src/ImageSharp/ImageFrame{TPixel}.cs
index cf7a1ae4f..cb15fe3db 100644
--- a/src/ImageSharp/ImageFrame{TPixel}.cs
+++ b/src/ImageSharp/ImageFrame{TPixel}.cs
@@ -4,6 +4,7 @@
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
@@ -52,6 +53,39 @@ namespace SixLabors.ImageSharp
this.MetaData = metaData;
}
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// 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())
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// 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 meta data.
+ internal ImageFrame(Configuration configuration, int width, int height, TPixel clearColor, ImageFrameMetaData metaData)
+ {
+ Guard.NotNull(configuration, nameof(configuration));
+ Guard.MustBeGreaterThan(width, 0, nameof(width));
+ Guard.MustBeGreaterThan(height, 0, nameof(height));
+ Guard.NotNull(metaData, nameof(metaData));
+
+ this.MemoryManager = configuration.MemoryManager;
+ this.PixelBuffer = this.MemoryManager.Allocate2D(width, height, false);
+ this.Clear(configuration.ParallelOptions, clearColor);
+ this.MetaData = metaData;
+ }
+
///
/// Initializes a new instance of the class.
///
@@ -267,6 +301,23 @@ namespace SixLabors.ImageSharp
return target;
}
+ ///
+ /// Clears the bitmap.
+ ///
+ /// The parallel options.
+ /// The value to initialize the bitmap with.
+ public void Clear(ParallelOptions parallelOptions, TPixel value) {
+ Parallel.For(
+ 0,
+ this.Height,
+ parallelOptions,
+ (int y) =>
+ {
+ Span targetRow = this.GetPixelRowSpan(y);
+ targetRow.Fill(value);
+ });
+ }
+
///
/// Clones the current instance.
///