Browse Source

Add tests for exr metadata

pull/3096/head
Brian Popow 1 month ago
parent
commit
b95663489e
  1. 19
      src/ImageSharp/Formats/Exr/ExrMetadata.cs
  2. 2
      tests/ImageSharp.Benchmarks/Codecs/Exr/DecodeExr.cs
  3. 54
      tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs
  4. 70
      tests/ImageSharp.Tests/Formats/Exr/ExrMetadataTests.cs
  5. 3
      tests/ImageSharp.Tests/TestImages.cs
  6. 3
      tests/Images/Input/Exr/Calliphora_uncompressed_rgba.exr

19
src/ImageSharp/Formats/Exr/ExrMetadata.cs

@ -89,20 +89,25 @@ public class ExrMetadata : IFormatMetadata<ExrMetadata>
};
}
/// <inheritdoc/>
public void AfterImageApply<TPixel>(Image<TPixel> destination, Matrix4x4 matrix)
where TPixel : unmanaged, IPixel<TPixel> => throw new NotImplementedException();
public FormatConnectingMetadata ToFormatConnectingMetadata() => new()
{
EncodingType = EncodingType.Lossless,
PixelTypeInfo = this.GetPixelTypeInfo()
};
/// <inheritdoc/>
public FormatConnectingMetadata ToFormatConnectingMetadata() => throw new NotImplementedException();
public static ExrMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => new() { PixelType = ExrPixelType.Half };
/// <inheritdoc/>
public static ExrMetadata FromFormatConnectingMetadata(FormatConnectingMetadata metadata) => throw new NotImplementedException();
ExrMetadata IDeepCloneable<ExrMetadata>.DeepClone() => new(this);
/// <inheritdoc/>
ExrMetadata IDeepCloneable<ExrMetadata>.DeepClone() => throw new NotImplementedException();
public IDeepCloneable DeepClone() => new ExrMetadata(this);
/// <inheritdoc/>
public IDeepCloneable DeepClone() => new ExrMetadata(this);
public void AfterImageApply<TPixel>(Image<TPixel> destination, Matrix4x4 matrix)
where TPixel : unmanaged, IPixel<TPixel>
{
}
}

2
tests/ImageSharp.Benchmarks/Codecs/Exr/DecodeExr.cs

@ -21,7 +21,7 @@ public class DecodeExr
private string TestImageFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, this.TestImage);
[Params(TestImages.Exr.Benchamrk)]
[Params(TestImages.Exr.Benchmark)]
public string TestImage { get; set; }
[GlobalSetup]

54
tests/ImageSharp.Tests/Formats/Exr/ExrDecoderTests.cs

@ -15,61 +15,9 @@ public class ExrDecoderTests
{
private static MagickReferenceDecoder ReferenceDecoder => MagickReferenceDecoder.Exr;
[Theory]
[InlineData(TestImages.Exr.Uncompressed, 199, 297)]
public void ExrDecoder_Identify_DetectsCorrectWidthAndHeight<TPixel>(string imagePath, int expectedWidth, int expectedHeight)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedWidth, imageInfo.Width);
Assert.Equal(expectedHeight, imageInfo.Height);
}
[Theory]
[InlineData(TestImages.Exr.Uncompressed)]
public void ExrDecoder_Identify_DetectsCorrectPixelType_Half<TPixel>(string imagePath)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
ExrMetadata exrMetaData = imageInfo.Metadata.GetExrMetadata();
Assert.NotNull(imageInfo);
Assert.Equal(ExrPixelType.Half, exrMetaData.PixelType);
}
[Theory]
[InlineData(TestImages.Exr.UncompressedFloatRgb)]
public void ExrDecoder_Identify_DetectsCorrectPixelType_Float<TPixel>(string imagePath)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
ExrMetadata exrMetaData = imageInfo.Metadata.GetExrMetadata();
Assert.NotNull(imageInfo);
Assert.Equal(ExrPixelType.Float, exrMetaData.PixelType);
}
[Theory]
[InlineData(TestImages.Exr.UncompressedUintRgb)]
public void ExrDecoder_Identify_DetectsCorrectPixelType_Int<TPixel>(string imagePath)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
ExrMetadata exrMetaData = imageInfo.Metadata.GetExrMetadata();
Assert.NotNull(imageInfo);
Assert.Equal(ExrPixelType.UnsignedInt, exrMetaData.PixelType);
}
[Theory]
[WithFile(TestImages.Exr.Uncompressed, PixelTypes.Rgba32)]
public void ExrDecoder_CanDecode_Uncompressed_Rgba_ExrPixelType_Half<TPixel>(TestImageProvider<TPixel> provider)
public void ExrDecoder_CanDecode_Uncompressed_Rgb_ExrPixelType_Half<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using Image<TPixel> image = provider.GetImage(ExrDecoder.Instance);

70
tests/ImageSharp.Tests/Formats/Exr/ExrMetadataTests.cs

@ -0,0 +1,70 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using SixLabors.ImageSharp.Formats.Exr;
using SixLabors.ImageSharp.Formats.Exr.Constants;
namespace SixLabors.ImageSharp.Tests.Formats.Exr;
[Trait("Format", "Exr")]
public class ExrMetadataTests
{
[Fact]
public void CloneIsDeep()
{
ExrMetadata meta = new()
{ ImageDataType = ExrImageDataType.Rgb, PixelType = ExrPixelType.Half };
ExrMetadata clone = (ExrMetadata)meta.DeepClone();
clone.ImageDataType = ExrImageDataType.Gray;
clone.PixelType = ExrPixelType.Float;
Assert.False(meta.ImageDataType.Equals(clone.ImageDataType));
Assert.False(meta.PixelType.Equals(clone.PixelType));
}
[Theory]
[InlineData(TestImages.Exr.Uncompressed, 199, 297)]
public void Identify_DetectsCorrectWidthAndHeight<TPixel>(string imagePath, int expectedWidth, int expectedHeight)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedWidth, imageInfo.Width);
Assert.Equal(expectedHeight, imageInfo.Height);
}
[Theory]
[InlineData(TestImages.Exr.Uncompressed, ExrPixelType.Half)]
[InlineData(TestImages.Exr.UncompressedFloatRgb, ExrPixelType.Float)]
[InlineData(TestImages.Exr.UncompressedUintRgb, ExrPixelType.UnsignedInt)]
public void Identify_DetectsCorrectPixelType(string imagePath, ExrPixelType expectedPixelType)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
ExrMetadata metadata = imageInfo.Metadata.GetExrMetadata();
Assert.NotNull(metadata);
Assert.Equal(expectedPixelType, metadata.PixelType);
}
[Theory]
[InlineData(TestImages.Exr.UncompressedRgba, ExrImageDataType.Rgba)]
[InlineData(TestImages.Exr.Rgb, ExrImageDataType.Rgb)]
[InlineData(TestImages.Exr.Gray, ExrImageDataType.Gray)]
public void Identify_DetectsCorrectImageDataType(string imagePath, ExrImageDataType expectedImageDataType)
{
TestFile testFile = TestFile.Create(imagePath);
using MemoryStream stream = new(testFile.Bytes, false);
ImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
ExrMetadata metadata = imageInfo.Metadata.GetExrMetadata();
Assert.NotNull(metadata);
Assert.Equal(expectedImageDataType, metadata.ImageDataType);
}
}

3
tests/ImageSharp.Tests/TestImages.cs

@ -1383,8 +1383,9 @@ public static class TestImages
public static class Exr
{
public const string Benchamrk = "Exr/Calliphora_benchmark.exr";
public const string Benchmark = "Exr/Calliphora_benchmark.exr";
public const string Uncompressed = "Exr/Calliphora_uncompressed.exr";
public const string UncompressedRgba = "Exr/Calliphora_uncompressed_rgba.exr";
public const string UncompressedFloatRgb = "Exr/rgb_float32_uncompressed.exr";
public const string UncompressedUintRgb = "Exr/rgb_uint32_uncompressed.exr";
public const string Zip = "Exr/Calliphora_zip.exr";

3
tests/Images/Input/Exr/Calliphora_uncompressed_rgba.exr

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8e9f6b5afa3c10c895ba67b51568295be40c2b1057224437600028487c581291
size 481899
Loading…
Cancel
Save