|
|
|
@ -20,30 +20,32 @@ namespace SixLabors.ImageSharp |
|
|
|
/// <summary>
|
|
|
|
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the given byte array in <typeparamref name="TPixel"/> format.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="memoryManager">The memory manager to use for allocations</param>
|
|
|
|
/// <param name="data">The byte array containing image data.</param>
|
|
|
|
/// <param name="width">The width of the final image.</param>
|
|
|
|
/// <param name="height">The height of the final image.</param>
|
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
|
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|
|
|
public static ImageFrame<TPixel> LoadPixelData<TPixel>(Span<byte> data, int width, int height) |
|
|
|
public static ImageFrame<TPixel> LoadPixelData<TPixel>(MemoryManager memoryManager, Span<byte> data, int width, int height) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
=> LoadPixelData(data.NonPortableCast<byte, TPixel>(), width, height); |
|
|
|
=> LoadPixelData(memoryManager, data.NonPortableCast<byte, TPixel>(), width, height); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Create a new instance of the <see cref="Image{TPixel}"/> class from the raw <typeparamref name="TPixel"/> data.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="memoryManager">The memory manager to use for allocations</param>
|
|
|
|
/// <param name="data">The Span containing the image Pixel data.</param>
|
|
|
|
/// <param name="width">The width of the final image.</param>
|
|
|
|
/// <param name="height">The height of the final image.</param>
|
|
|
|
/// <typeparam name="TPixel">The pixel format.</typeparam>
|
|
|
|
/// <returns>A new <see cref="Image{TPixel}"/>.</returns>
|
|
|
|
public static ImageFrame<TPixel> LoadPixelData<TPixel>(Span<TPixel> data, int width, int height) |
|
|
|
public static ImageFrame<TPixel> LoadPixelData<TPixel>(MemoryManager memoryManager, Span<TPixel> data, int width, int height) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
int count = width * height; |
|
|
|
Guard.MustBeGreaterThanOrEqualTo(data.Length, count, nameof(data)); |
|
|
|
|
|
|
|
var image = new ImageFrame<TPixel>(Configuration.Default.MemoryManager, width, height); |
|
|
|
var image = new ImageFrame<TPixel>(memoryManager, width, height); |
|
|
|
SpanHelper.Copy(data, image.GetPixelSpan(), count); |
|
|
|
|
|
|
|
return image; |
|
|
|
|