Browse Source

Replace broken webp image with exif data

pull/1985/head
Brian Popow 4 years ago
parent
commit
7d0dd42b0d
  1. 4
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  2. 2
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs
  3. 28
      tests/ImageSharp.Tests/Formats/WebP/WebpMetaDataTests.cs
  4. 5
      tests/ImageSharp.Tests/TestImages.cs
  5. 0
      tests/Images/Input/Webp/bike_lossy_small.webp
  6. 0
      tests/Images/Input/Webp/bike_lossy_with_exif.webp

4
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
[InlineData(Lossless.NoTransform2, 128, 128, 32)]
[InlineData(Lossy.Alpha1, 1000, 307, 32)]
[InlineData(Lossy.Alpha2, 1000, 307, 32)]
[InlineData(Lossy.Bike, 250, 195, 24)]
[InlineData(Lossy.BikeWithExif, 250, 195, 24)]
public void Identify_DetectsCorrectDimensionsAndBitDepth(
string imagePath,
int expectedWidth,
@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
}
[Theory]
[WithFile(Lossy.Bike, PixelTypes.Rgba32)]
[WithFile(Lossy.BikeWithExif, PixelTypes.Rgba32)]
[WithFile(Lossy.NoFilter01, PixelTypes.Rgba32)]
[WithFile(Lossy.NoFilter02, PixelTypes.Rgba32)]
[WithFile(Lossy.NoFilter03, PixelTypes.Rgba32)]

2
tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
[Theory]
[WithFile(Flag, PixelTypes.Rgba32, WebpFileFormatType.Lossy)] // If its not a webp input image, it should default to lossy.
[WithFile(Lossless.NoTransform1, PixelTypes.Rgba32, WebpFileFormatType.Lossless)]
[WithFile(Lossy.Bike, PixelTypes.Rgba32, WebpFileFormatType.Lossy)]
[WithFile(Lossy.BikeWithExif, PixelTypes.Rgba32, WebpFileFormatType.Lossy)]
public void Encode_PreserveRatio<TPixel>(TestImageProvider<TPixel> provider, WebpFileFormatType expectedFormat)
where TPixel : unmanaged, IPixel<TPixel>
{

28
tests/ImageSharp.Tests/Formats/WebP/WebpMetaDataTests.cs

@ -16,11 +16,31 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
private static WebpDecoder WebpDecoder => new() { IgnoreMetadata = false };
[Theory]
[WithFile(TestImages.Webp.Lossy.WithExif, PixelTypes.Rgba32, false)]
[WithFile(TestImages.Webp.Lossy.WithExif, PixelTypes.Rgba32, true)]
[WithFile(TestImages.Webp.Lossy.BikeWithExif, PixelTypes.Rgba32, false)]
[WithFile(TestImages.Webp.Lossy.BikeWithExif, PixelTypes.Rgba32, true)]
public void IgnoreMetadata_ControlsWhetherExifIsParsed_WithLossyImage<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
{
ExifProfile exifProfile = image.Metadata.ExifProfile;
Assert.NotNull(exifProfile);
Assert.NotEmpty(exifProfile.Values);
Assert.Contains(exifProfile.Values, m => m.Tag.Equals(ExifTag.Software) && m.GetValue().Equals("GIMP 2.10.2"));
}
}
[Theory]
[WithFile(TestImages.Webp.Lossless.WithExif, PixelTypes.Rgba32, false)]
[WithFile(TestImages.Webp.Lossless.WithExif, PixelTypes.Rgba32, true)]
public void IgnoreMetadata_ControlsWhetherExifIsParsed<TPixel>(TestImageProvider<TPixel> provider, bool ignoreMetadata)
public void IgnoreMetadata_ControlsWhetherExifIsParsed_WithLosslessImage<TPixel>(TestImageProvider<TPixel> provider, bool ignoreMetadata)
where TPixel : unmanaged, IPixel<TPixel>
{
var decoder = new WebpDecoder { IgnoreMetadata = ignoreMetadata };
@ -109,7 +129,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp
}
[Theory]
[WithFile(TestImages.Webp.Lossy.WithExif, PixelTypes.Rgba32)]
[WithFile(TestImages.Webp.Lossy.BikeWithExif, PixelTypes.Rgba32)]
public void EncodeLossyWebp_PreservesExif<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{

5
tests/ImageSharp.Tests/TestImages.cs

@ -632,13 +632,12 @@ namespace SixLabors.ImageSharp.Tests
public static class Lossy
{
public const string Earth = "Webp/earth_lossy.webp";
public const string WithExif = "Webp/exif_lossy.webp";
public const string WithIccp = "Webp/lossy_with_iccp.webp";
public const string WithXmp = "Webp/xmp_lossy.webp";
public const string BikeSmall = "Webp/bike_lossless_small.webp";
public const string BikeSmall = "Webp/bike_lossy_small.webp";
// Lossy images without macroblock filtering.
public const string Bike = "Webp/bike_lossy.webp";
public const string BikeWithExif = "Webp/bike_lossy_with_exif.webp";
public const string NoFilter01 = "Webp/vp80-01-intra-1400.webp";
public const string NoFilter02 = "Webp/vp80-00-comprehensive-010.webp";
public const string NoFilter03 = "Webp/vp80-00-comprehensive-005.webp";

0
tests/Images/Input/Webp/bike_lossless_small.webp → tests/Images/Input/Webp/bike_lossy_small.webp

0
tests/Images/Input/Webp/bike_lossy.webp → tests/Images/Input/Webp/bike_lossy_with_exif.webp

Loading…
Cancel
Save