From 29f558a801c8eab05ebe8ba422d79bf3679d1a54 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sun, 12 Apr 2026 17:23:39 +0200 Subject: [PATCH] Add test case for uint pixel type with alpha --- src/ImageSharp/Formats/Exr/ExrDecoderCore.cs | 2 +- .../Formats/Exr/ExrDecoderTests.cs | 14 ++++++++++++++ tests/ImageSharp.Tests/TestImages.cs | 1 + ...elType_Uint_Rgba32_rgba_uint_zip_compressed.png | 3 +++ .../Images/Input/Exr/rgba_uint_zip_compressed.exr | 3 +++ 5 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/Images/External/ReferenceOutput/ExrDecoderTests/ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint_Rgba32_rgba_uint_zip_compressed.png create mode 100644 tests/Images/Input/Exr/rgba_uint_zip_compressed.exr diff --git a/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs b/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs index 62d3591f5b..a4fa4b0ac2 100644 --- a/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs +++ b/src/ImageSharp/Formats/Exr/ExrDecoderCore.cs @@ -223,7 +223,7 @@ internal sealed class ExrDecoderCore : ImageDecoderCore for (int x = 0; x < width; x++) { - Rgb96 pixelValue = new(redPixelData[x], greenPixelData[x], bluePixelData[x]); + Rgba128 pixelValue = new(redPixelData[x], greenPixelData[x], bluePixelData[x], hasAlpha ? alphaPixelData[x] : uint.MaxValue); pixelRow[x] = TPixel.FromVector4(pixelValue.ToVector4()); } diff --git a/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs index e6a00c84d5..b81dba7555 100644 --- a/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs @@ -55,6 +55,20 @@ public class ExrDecoderTests Assert.Equal(ExrPixelType.UnsignedInt, exrMetaData.PixelType); } + [Theory] + [WithFile(TestImages.Exr.UintRgba, PixelTypes.Rgba32)] + public void ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint(TestImageProvider provider) + where TPixel : unmanaged, IPixel + { + using Image image = provider.GetImage(ExrDecoder.Instance); + ExrMetadata exrMetaData = image.Metadata.GetExrMetadata(); + image.DebugSave(provider); + + // Compare to referene output, since the reference decoder does not support this pixel type. + image.CompareToReferenceOutput(provider); + Assert.Equal(ExrPixelType.UnsignedInt, exrMetaData.PixelType); + } + [Theory] [WithFile(TestImages.Exr.Rgb, PixelTypes.Rgba32)] public void ExrDecoder_CanDecode_Rgb(TestImageProvider provider) diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 210bd9ea43..343024785f 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -1389,6 +1389,7 @@ public static class TestImages public const string UncompressedRgba = "Exr/Calliphora_uncompressed_rgba.exr"; public const string UncompressedFloatRgb = "Exr/rgb_float32_uncompressed.exr"; public const string UncompressedUintRgb = "Exr/Calliphora_uint32_uncompressed.exr"; + public const string UintRgba = "Exr/rgba_uint_zip_compressed.exr"; public const string Zip = "Exr/Calliphora_zip.exr"; public const string Zips = "Exr/Calliphora_zips.exr"; public const string Rle = "Exr/Calliphora_rle.exr"; diff --git a/tests/Images/External/ReferenceOutput/ExrDecoderTests/ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint_Rgba32_rgba_uint_zip_compressed.png b/tests/Images/External/ReferenceOutput/ExrDecoderTests/ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint_Rgba32_rgba_uint_zip_compressed.png new file mode 100644 index 0000000000..26de0f2d1a --- /dev/null +++ b/tests/Images/External/ReferenceOutput/ExrDecoderTests/ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint_Rgba32_rgba_uint_zip_compressed.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:843bea4db378f52935e2f19f60d289df8ebe20ddde3977c63225f1d58a10bd62 +size 48119 diff --git a/tests/Images/Input/Exr/rgba_uint_zip_compressed.exr b/tests/Images/Input/Exr/rgba_uint_zip_compressed.exr new file mode 100644 index 0000000000..bdcd9e1ffe --- /dev/null +++ b/tests/Images/Input/Exr/rgba_uint_zip_compressed.exr @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff2ff1cdcfd219415430ba30a18962b54860d88bfc3adf337e97574c33c5e214 +size 119614