|
|
|
@ -7,6 +7,7 @@ using System.Runtime.InteropServices; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using ImageMagick; |
|
|
|
using ImageMagick.Formats.Bmp; |
|
|
|
using SixLabors.ImageSharp.Formats; |
|
|
|
using SixLabors.ImageSharp.Memory; |
|
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
|
@ -18,7 +19,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs |
|
|
|
public static MagickReferenceDecoder Instance { get; } = new MagickReferenceDecoder(); |
|
|
|
|
|
|
|
private static void FromRgba32Bytes<TPixel>(Configuration configuration, Span<byte> rgbaBytes, IMemoryGroup<TPixel> destinationGroup) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel> |
|
|
|
{ |
|
|
|
foreach (Memory<TPixel> m in destinationGroup) |
|
|
|
{ |
|
|
|
@ -33,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs |
|
|
|
} |
|
|
|
|
|
|
|
private static void FromRgba64Bytes<TPixel>(Configuration configuration, Span<byte> rgbaBytes, IMemoryGroup<TPixel> destinationGroup) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel> |
|
|
|
{ |
|
|
|
foreach (Memory<TPixel> m in destinationGroup) |
|
|
|
{ |
|
|
|
@ -48,17 +49,25 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs |
|
|
|
} |
|
|
|
|
|
|
|
public Task<Image<TPixel>> DecodeAsync<TPixel>(Configuration configuration, Stream stream, CancellationToken cancellationToken) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel> |
|
|
|
=> Task.FromResult(this.Decode<TPixel>(configuration, stream)); |
|
|
|
|
|
|
|
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel> |
|
|
|
{ |
|
|
|
var bmpReadDefines = new BmpReadDefines |
|
|
|
{ |
|
|
|
IgnoreFileSize = true |
|
|
|
}; |
|
|
|
|
|
|
|
var settings = new MagickReadSettings(); |
|
|
|
settings.SetDefines(bmpReadDefines); |
|
|
|
|
|
|
|
using var magickImage = new MagickImage(stream); |
|
|
|
var result = new Image<TPixel>(configuration, magickImage.Width, magickImage.Height); |
|
|
|
MemoryGroup<TPixel> resultPixels = result.GetRootFramePixelBuffer().FastMemoryGroup; |
|
|
|
|
|
|
|
using (IPixelCollection pixels = magickImage.GetPixelsUnsafe()) |
|
|
|
using (IUnsafePixelCollection<ushort> pixels = magickImage.GetPixelsUnsafe()) |
|
|
|
{ |
|
|
|
if (magickImage.Depth == 8) |
|
|
|
{ |
|
|
|
|