77using System . Threading ;
88using System . Threading . Tasks ;
99using ImageMagick ;
10+ using ImageMagick . Formats . Bmp ;
1011using SixLabors . ImageSharp . Formats ;
1112using SixLabors . ImageSharp . Memory ;
1213using SixLabors . ImageSharp . PixelFormats ;
@@ -18,7 +19,7 @@ public class MagickReferenceDecoder : IImageDecoder
1819 public static MagickReferenceDecoder Instance { get ; } = new MagickReferenceDecoder ( ) ;
1920
2021 private static void FromRgba32Bytes < TPixel > ( Configuration configuration , Span < byte > rgbaBytes , IMemoryGroup < TPixel > destinationGroup )
21- where TPixel : unmanaged, IPixel < TPixel >
22+ where TPixel : unmanaged, ImageSharp . PixelFormats . IPixel < TPixel >
2223 {
2324 foreach ( Memory < TPixel > m in destinationGroup )
2425 {
@@ -33,7 +34,7 @@ private static void FromRgba32Bytes<TPixel>(Configuration configuration, Span<by
3334 }
3435
3536 private static void FromRgba64Bytes < TPixel > ( Configuration configuration , Span < byte > rgbaBytes , IMemoryGroup < TPixel > destinationGroup )
36- where TPixel : unmanaged, IPixel < TPixel >
37+ where TPixel : unmanaged, ImageSharp . PixelFormats . IPixel < TPixel >
3738 {
3839 foreach ( Memory < TPixel > m in destinationGroup )
3940 {
@@ -48,17 +49,28 @@ private static void FromRgba64Bytes<TPixel>(Configuration configuration, Span<by
4849 }
4950
5051 public Task < Image < TPixel > > DecodeAsync < TPixel > ( Configuration configuration , Stream stream , CancellationToken cancellationToken )
51- where TPixel : unmanaged, IPixel < TPixel >
52+ where TPixel : unmanaged, ImageSharp . PixelFormats . IPixel < TPixel >
5253 => Task . FromResult ( this . Decode < TPixel > ( configuration , stream ) ) ;
5354
5455 public Image < TPixel > Decode < TPixel > ( Configuration configuration , Stream stream )
55- where TPixel : unmanaged, IPixel < TPixel >
56+ where TPixel : unmanaged, ImageSharp . PixelFormats . IPixel < TPixel >
5657 {
57- using var magickImage = new MagickImage ( stream ) ;
58+ var bmpReadDefines = new BmpReadDefines
59+ {
60+ // See https://github.com/SixLabors/ImageSharp/issues/1380
61+ // Validation fails on Ubuntu despite identical header generation
62+ // on all platforms.
63+ IgnoreFileSize = ! TestEnvironment . IsWindows
64+ } ;
65+
66+ var settings = new MagickReadSettings ( ) ;
67+ settings . SetDefines ( bmpReadDefines ) ;
68+
69+ using var magickImage = new MagickImage ( stream , settings ) ;
5870 var result = new Image < TPixel > ( configuration , magickImage . Width , magickImage . Height ) ;
5971 MemoryGroup < TPixel > resultPixels = result . GetRootFramePixelBuffer ( ) . FastMemoryGroup ;
6072
61- using ( IPixelCollection pixels = magickImage . GetPixelsUnsafe ( ) )
73+ using ( IUnsafePixelCollection < ushort > pixels = magickImage . GetPixelsUnsafe ( ) )
6274 {
6375 if ( magickImage . Depth == 8 )
6476 {
0 commit comments