|
|
|
@ -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; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <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="height">The height of the image in pixels.</param>
|
|
|
|
/// <param name="clearColor">The color to clear the image with.</param>
|
|
|
|
internal ImageFrame(Configuration configuration, int width, int height, TPixel clearColor) |
|
|
|
: this(configuration, width, height, clearColor, new ImageFrameMetaData()) |
|
|
|
{ |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <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="height">The height of the image in pixels.</param>
|
|
|
|
/// <param name="clearColor">The color to clear the image with.</param>
|
|
|
|
/// <param name="metaData">The meta data.</param>
|
|
|
|
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<TPixel>(width, height, false); |
|
|
|
this.Clear(configuration.ParallelOptions, clearColor); |
|
|
|
this.MetaData = metaData; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ImageFrame{TPixel}" /> class.
|
|
|
|
/// </summary>
|
|
|
|
@ -267,6 +301,23 @@ namespace SixLabors.ImageSharp |
|
|
|
return target; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clears the bitmap.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="parallelOptions">The parallel options.</param>
|
|
|
|
/// <param name="value">The value to initialize the bitmap with.</param>
|
|
|
|
public void Clear(ParallelOptions parallelOptions, TPixel value) { |
|
|
|
Parallel.For( |
|
|
|
0, |
|
|
|
this.Height, |
|
|
|
parallelOptions, |
|
|
|
(int y) => |
|
|
|
{ |
|
|
|
Span<TPixel> targetRow = this.GetPixelRowSpan(y); |
|
|
|
targetRow.Fill(value); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Clones the current instance.
|
|
|
|
/// </summary>
|
|
|
|
|