Browse Source

Add tests for reading webp metadata, fix some test images with metadata

pull/1552/head
Brian Popow 6 years ago
parent
commit
39a28668cf
  1. 17
      src/ImageSharp/Formats/WebP/WebPDecoderCore.cs
  2. 1
      tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs
  3. 21
      tests/ImageSharp.Tests/Formats/WebP/WebPFileHeaderTests.cs
  4. 57
      tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs
  5. 11
      tests/ImageSharp.Tests/TestImages.cs
  6. 0
      tests/Images/Input/WebP/exif_lossy.webp
  7. 0
      tests/Images/Input/WebP/iccp_lossless.webp
  8. 0
      tests/Images/Input/WebP/iccp_lossy.webp

17
src/ImageSharp/Formats/WebP/WebPDecoderCore.cs

@ -215,12 +215,19 @@ namespace SixLabors.ImageSharp.Formats.WebP
if (chunkType is WebPChunkType.Iccp)
{
uint iccpChunkSize = this.ReadChunkSize();
var iccpData = new byte[iccpChunkSize];
this.currentStream.Read(iccpData, 0, (int)iccpChunkSize);
var profile = new IccProfile(iccpData);
if (profile.CheckIsValid())
if (!this.IgnoreMetadata)
{
this.Metadata.IccProfile = profile;
var iccpData = new byte[iccpChunkSize];
this.currentStream.Read(iccpData, 0, (int)iccpChunkSize);
var profile = new IccProfile(iccpData);
if (profile.CheckIsValid())
{
this.Metadata.IccProfile = profile;
}
}
else
{
this.currentStream.Skip((int)iccpChunkSize);
}
}
}

1
tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs

@ -10,7 +10,6 @@ using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
using static SixLabors.ImageSharp.Tests.TestImages.WebP;

21
tests/ImageSharp.Tests/Formats/WebP/WebPFileHeaderTests.cs

@ -1,21 +0,0 @@
using System;
using SixLabors.ImageSharp.Formats.Bmp;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
public class WebPFileHeaderTests
{
[Fact]
public void TestWrite()
{
var header = new BmpFileHeader(1, 2, 3, 4);
var buffer = new byte[14];
header.WriteTo(buffer);
Assert.Equal("AQACAAAAAwAAAAQAAAA=", Convert.ToBase64String(buffer));
}
}
}

57
tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs

@ -0,0 +1,57 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Formats.WebP;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
public class WebPMetadataTests
{
[Theory]
[WithFile(TestImages.WebP.Lossless.WithExif, PixelTypes.Rgba32, false)]
[WithFile(TestImages.WebP.Lossy.WithExif, PixelTypes.Rgba32, true)]
public void IgnoreMetadata_ControlsWhetherExifIsParsed<TPixel>(TestImageProvider<TPixel> provider, bool ignoreMetadata)
where TPixel : unmanaged, IPixel<TPixel>
{
var decoder = new WebPDecoder { IgnoreMetadata = ignoreMetadata };
using (Image<TPixel> image = provider.GetImage(decoder))
{
if (ignoreMetadata)
{
Assert.Null(image.Metadata.ExifProfile);
}
else
{
Assert.NotNull(image.Metadata.ExifProfile);
Assert.NotEmpty(image.Metadata.ExifProfile.Values);
}
}
}
[Theory]
[WithFile(TestImages.WebP.Lossless.WithIccp, PixelTypes.Rgba32, false)]
[WithFile(TestImages.WebP.Lossy.WithIccp, PixelTypes.Rgba32, true)]
public void IgnoreMetadata_ControlsWhetherIccpIsParsed<TPixel>(TestImageProvider<TPixel> provider, bool ignoreMetadata)
where TPixel : unmanaged, IPixel<TPixel>
{
var decoder = new WebPDecoder { IgnoreMetadata = ignoreMetadata };
using (Image<TPixel> image = provider.GetImage(decoder))
{
if (ignoreMetadata)
{
Assert.Null(image.Metadata.IccProfile);
}
else
{
Assert.NotNull(image.Metadata.IccProfile);
Assert.NotEmpty(image.Metadata.IccProfile.Entries);
}
}
}
}
}

11
tests/ImageSharp.Tests/TestImages.cs

@ -390,8 +390,8 @@ namespace SixLabors.ImageSharp.Tests
public const string Bit32Rle = "Tga/targa_32bit_rle.tga";
public const string Bit16Pal = "Tga/targa_16bit_pal.tga";
public const string Bit24Pal = "Tga/targa_24bit_pal.tga";
}
}
public static class WebP
{
public static class Animated
@ -404,6 +404,8 @@ namespace SixLabors.ImageSharp.Tests
public static class Lossless
{
public const string WithExif = "WebP/exif_lossless.webp";
public const string WithIccp = "WebP/iccp_lossless.webp";
public const string NoTransform1 = "WebP/lossless_vec_1_0.webp";
public const string NoTransform2 = "WebP/lossless_vec_2_0.webp";
public const string GreenTransform1 = "WebP/lossless1.webp";
@ -452,6 +454,9 @@ namespace SixLabors.ImageSharp.Tests
public static class Lossy
{
public const string WithExif = "WebP/exif_lossy.webp";
public const string WithIccp = "WebP/iccp_lossy.webp";
// Lossy images without macroblock filtering.
public const string Bike = "WebP/bike_lossy.webp";
public const string NoFilter01 = "WebP/vp80-01-intra-1400.webp";
@ -469,7 +474,7 @@ namespace SixLabors.ImageSharp.Tests
public const string SimpleFilter05 = "WebP/test-nostrong.webp";
// Lossy images with a complex filter.
public const string IccpComplexFilter = "WebP/lossy_iccp.webp";
public const string IccpComplexFilter = "WebP/iccp_lossy.webp";
public const string VeryShort = "WebP/very_short.webp";
public const string BikeComplexFilter = "WebP/bike_lossy_complex_filter.webp";
public const string ComplexFilter01 = "WebP/vp80-02-inter-1418.webp";

0
tests/Images/Input/WebP/exif.webp → tests/Images/Input/WebP/exif_lossy.webp

0
tests/Images/Input/WebP/lossless_iccp.webp → tests/Images/Input/WebP/iccp_lossless.webp

0
tests/Images/Input/WebP/lossy_iccp.webp → tests/Images/Input/WebP/iccp_lossy.webp

Loading…
Cancel
Save