Browse Source

Add test for ICC profile

pull/2110/head
Brian Popow 4 years ago
parent
commit
d645ba4bf3
  1. 1
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.Chunks.cs
  2. 29
      tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs

1
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.Chunks.cs

@ -302,6 +302,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
{
PngChunkType.Header,
PngChunkType.Gamma,
PngChunkType.EmbeddedColorProfile,
PngChunkType.Palette,
PngChunkType.InternationalText,
PngChunkType.Text,

29
tests/ImageSharp.Tests/Formats/Png/PngMetadataTests.cs

@ -17,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
public class PngMetadataTests
{
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>
new()
{
{ TestImages.Png.Splash, 11810, 11810, PixelResolutionUnit.PixelsPerMeter },
{ TestImages.Png.Ratio1x4, 1, 4, PixelResolutionUnit.AspectRatio },
@ -222,6 +222,33 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
}
}
[Theory]
[WithFile(TestImages.Png.PngWithMetadata, PixelTypes.Rgba32)]
public void Encode_PreservesColorProfile<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
using (Image<TPixel> input = provider.GetImage(new PngDecoder()))
{
ImageSharp.Metadata.Profiles.Icc.IccProfile expectedProfile = input.Metadata.IccProfile;
byte[] expectedProfileBytes = expectedProfile.ToByteArray();
using (var memStream = new MemoryStream())
{
input.Save(memStream, new PngEncoder());
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))
{
ImageSharp.Metadata.Profiles.Icc.IccProfile actualProfile = output.Metadata.IccProfile;
byte[] actualProfileBytes = actualProfile.ToByteArray();
Assert.NotNull(actualProfile);
Assert.Equal(expectedProfileBytes, actualProfileBytes);
}
}
}
}
[Theory]
[MemberData(nameof(RatioFiles))]
public void Identify_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)

Loading…
Cancel
Save