Skip to content

Commit 581efcf

Browse files
Merge pull request #1383 from SixLabors/dl/upgrade-magick-net
Upgraded Magick.NET.
2 parents d67cb43 + 0f144c6 commit 581efcf

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

tests/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<PackageReference Update="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1" Condition="'$(OS)' == 'Windows_NT'" />
3030
<PackageReference Update="Colourful" Version="2.0.5" />
3131
<PackageReference Update="coverlet.collector" Version="1.3.1-preview.27.gdd2237a3be" PrivateAssets="All"/>
32-
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.15.5" />
32+
<PackageReference Update="Magick.NET-Q16-AnyCPU" Version="7.22.0" />
3333
<PackageReference Update="Microsoft.DotNet.RemoteExecutor" Version="5.0.0-beta.20069.1" />
3434
<PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.5.0" />
3535
<PackageReference Update="Moq" Version="4.14.5" />

tests/ImageSharp.Tests/Formats/Tga/TgaTestUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void CompareWithReferenceDecoder<TPixel>(
1818
Image<TPixel> image,
1919
bool useExactComparer = true,
2020
float compareTolerance = 0.01f)
21-
where TPixel : unmanaged, IPixel<TPixel>
21+
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel>
2222
{
2323
string path = TestImageProvider<TPixel>.GetFilePathOrNull(provider);
2424
if (path == null)
@@ -39,7 +39,7 @@ public static void CompareWithReferenceDecoder<TPixel>(
3939
}
4040

4141
public static Image<TPixel> DecodeWithMagick<TPixel>(Configuration configuration, FileInfo fileInfo)
42-
where TPixel : unmanaged, IPixel<TPixel>
42+
where TPixel : unmanaged, ImageSharp.PixelFormats.IPixel<TPixel>
4343
{
4444
using (var magickImage = new MagickImage(fileInfo))
4545
{
@@ -48,7 +48,7 @@ public static Image<TPixel> DecodeWithMagick<TPixel>(Configuration configuration
4848

4949
Assert.True(result.TryGetSinglePixelSpan(out Span<TPixel> resultPixels));
5050

51-
using (IPixelCollection pixels = magickImage.GetPixelsUnsafe())
51+
using (IUnsafePixelCollection<ushort> pixels = magickImage.GetPixelsUnsafe())
5252
{
5353
byte[] data = pixels.ToByteArray(PixelMapping.RGBA);
5454

tests/ImageSharp.Tests/TestUtilities/ReferenceCodecs/MagickReferenceDecoder.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Threading;
88
using System.Threading.Tasks;
99
using ImageMagick;
10+
using ImageMagick.Formats.Bmp;
1011
using SixLabors.ImageSharp.Formats;
1112
using SixLabors.ImageSharp.Memory;
1213
using 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

Comments
 (0)