Browse Source

Add test case for uint pixel type with alpha

pull/3096/head
Brian Popow 4 weeks ago
parent
commit
29f558a801
  1. 2
      src/ImageSharp/Formats/Exr/ExrDecoderCore.cs
  2. 14
      tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/External/ReferenceOutput/ExrDecoderTests/ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Uint_Rgba32_rgba_uint_zip_compressed.png
  5. 3
      tests/Images/Input/Exr/rgba_uint_zip_compressed.exr

2
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());
}

14
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider)

1
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";

3
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

3
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
Loading…
Cancel
Save