|
|
|
@ -3,6 +3,7 @@ |
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
// </copyright>
|
|
|
|
|
|
|
|
|
|
|
|
namespace ImageProcessorCore |
|
|
|
{ |
|
|
|
using System; |
|
|
|
@ -15,10 +16,15 @@ namespace ImageProcessorCore |
|
|
|
/// <typeparam name="TColor">The pixel format.</typeparam>
|
|
|
|
/// <typeparam name="TPacked">The packed format. <example>uint, long, float.</example></typeparam>
|
|
|
|
[DebuggerDisplay("Image: {Width}x{Height}")] |
|
|
|
public abstract class ImageBase<TColor, TPacked> : IImageBase<TColor, TPacked> |
|
|
|
public abstract unsafe class ImageBase<TColor, TPacked> : IImageBase<TColor, TPacked> |
|
|
|
where TColor : IPackedVector<TPacked> |
|
|
|
where TPacked : struct |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// The image pixels
|
|
|
|
/// </summary>
|
|
|
|
private TColor[] pixelBuffer; |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="ImageBase{TColor, TPacked}"/> class.
|
|
|
|
/// </summary>
|
|
|
|
@ -41,7 +47,7 @@ namespace ImageProcessorCore |
|
|
|
|
|
|
|
this.Width = width; |
|
|
|
this.Height = height; |
|
|
|
this.Pixels = new TColor[width * height]; |
|
|
|
this.pixelBuffer = new TColor[width * height]; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -61,9 +67,13 @@ namespace ImageProcessorCore |
|
|
|
this.Height = other.Height; |
|
|
|
this.CopyProperties(other); |
|
|
|
|
|
|
|
// Copy the pixels. Don't use Unsafe.Copy as it is breaking edge detection.
|
|
|
|
this.Pixels = new TColor[this.Width * this.Height]; |
|
|
|
Array.Copy(other.Pixels, this.Pixels, other.Pixels.Length); |
|
|
|
// Copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here.
|
|
|
|
this.pixelBuffer = new TColor[this.Width * this.Height]; |
|
|
|
using (PixelAccessor<TColor, TPacked> sourcePixels = other.Lock()) |
|
|
|
using (PixelAccessor<TColor, TPacked> target = this.Lock()) |
|
|
|
{ |
|
|
|
sourcePixels.CopyImage(target); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -73,7 +83,8 @@ namespace ImageProcessorCore |
|
|
|
public int MaxHeight { get; set; } = int.MaxValue; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public TColor[] Pixels { get; private set; } |
|
|
|
//public TColor[] Pixels { get; private set; }
|
|
|
|
public TColor[] Pixels => this.pixelBuffer; |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
public int Width { get; private set; } |
|
|
|
@ -106,7 +117,7 @@ namespace ImageProcessorCore |
|
|
|
|
|
|
|
this.Width = width; |
|
|
|
this.Height = height; |
|
|
|
this.Pixels = pixels; |
|
|
|
this.pixelBuffer = pixels; |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
@ -123,9 +134,9 @@ namespace ImageProcessorCore |
|
|
|
this.Width = width; |
|
|
|
this.Height = height; |
|
|
|
|
|
|
|
// Copy the pixels. Don't use Unsafe.Copy as it is breaking edge detection.
|
|
|
|
this.Pixels = new TColor[pixels.Length]; |
|
|
|
Array.Copy(pixels, this.Pixels, pixels.Length); |
|
|
|
// Copy the pixels. TODO: use Unsafe.Copy.
|
|
|
|
this.pixelBuffer = new TColor[pixels.Length]; |
|
|
|
Array.Copy(pixels, this.pixelBuffer, pixels.Length); |
|
|
|
} |
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|