Browse Source

WebP tests WIP

pull/1147/head
Lajos Marton 6 years ago
parent
commit
c5474e9b24
  1. 12
      tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs
  2. 24
      tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs
  3. 49
      tests/ImageSharp.Tests/TestImages.cs

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

@ -1,19 +1,15 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.IO;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.ImageSharp.Tests.TestUtilities.ReferenceCodecs;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
using SixLabors.ImageSharp.Formats.WebP;
using SixLabors.ImageSharp.Metadata;
using static TestImages.Bmp;
@ -38,7 +34,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
public void BmpDecoder_CanDecode_MiscellaneousBitmaps<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
using (Image<TPixel> image = provider.GetImage(new WebPDecoder()))
{
image.DebugSave(provider);
if (TestEnvironment.IsWindows)
@ -54,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
public void BmpDecoder_CanDecode_Inverted<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
using (Image<TPixel> image = provider.GetImage(new WebPDecoder()))
{
image.DebugSave(provider);
image.CompareToOriginal(provider);
@ -92,7 +88,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
var decoder = new BmpDecoder();
var decoder = new WebPDecoder();
using (Image<Rgba32> image = decoder.Decode<Rgba32>(Configuration.Default, stream))
{
ImageMetadata meta = image.Metadata;

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

@ -4,6 +4,7 @@
using System.IO;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.WebP;
using Xunit;
// ReSharper disable InconsistentNaming
@ -17,23 +18,17 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
[Fact]
public void CloneIsDeep()
{
var meta = new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel24 };
var clone = (BmpMetadata)meta.DeepClone();
/* TODO:
var meta = new WebPMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel24 };
var clone = (WebPMetadata)meta.DeepClone();
clone.BitsPerPixel = BmpBitsPerPixel.Pixel32;
Assert.False(meta.BitsPerPixel.Equals(clone.BitsPerPixel));
Assert.False(meta.BitsPerPixel.Equals(clone.BitsPerPixel));*/
}
[Theory]
[InlineData(WinBmpv2, BmpInfoHeaderType.WinVersion2)]
[InlineData(WinBmpv3, BmpInfoHeaderType.WinVersion3)]
[InlineData(WinBmpv4, BmpInfoHeaderType.WinVersion4)]
[InlineData(WinBmpv5, BmpInfoHeaderType.WinVersion5)]
[InlineData(Os2v2Short, BmpInfoHeaderType.Os2Version2Short)]
[InlineData(Rgb32h52AdobeV3, BmpInfoHeaderType.AdobeVersion3)]
[InlineData(Rgba32bf56AdobeV3, BmpInfoHeaderType.AdobeVersion3WithAlpha)]
[InlineData(Os2v2, BmpInfoHeaderType.Os2Version2)]
[InlineData(TestImages.WebP.Lossy.SampleWebpOne, BmpInfoHeaderType.WinVersion2)]
public void Identify_DetectsCorrectBitmapInfoHeaderType(string imagePath, BmpInfoHeaderType expectedInfoHeaderType)
{
var testFile = TestFile.Create(imagePath);
@ -41,9 +36,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
IImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
BmpMetadata bitmapMetaData = imageInfo.Metadata.GetFormatMetadata(BmpFormat.Instance);
Assert.NotNull(bitmapMetaData);
Assert.Equal(expectedInfoHeaderType, bitmapMetaData.InfoHeaderType);
WebPMetadata webpMetaData = imageInfo.Metadata.GetFormatMetadata(WebPFormat.Instance);
Assert.NotNull(webpMetaData);
//TODO:
//Assert.Equal(expectedInfoHeaderType, webpMetaData.InfoHeaderType);
}
}
}

49
tests/ImageSharp.Tests/TestImages.cs

@ -365,5 +365,54 @@ namespace SixLabors.ImageSharp.Tests
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };
}
public static class WebP
{
public static class Lossless
{
public const string SampleWebpOne = "WebP/Lossless/1_webp_ll.webp";
public const string SampleWebpTwo = "WebP/Lossless/2_webp_ll.webp";
public const string SampleWebpThree = "WebP/Lossless/3_webp_ll.webp";
public const string SampleWebpFour = "WebP/Lossless/4_webp_ll.webp";
public const string SampleWebpFive = "WebP/Lossless/5_webp_ll.webp";
}
public static class Lossy
{
public const string SampleWebpOne = "WebP/Lossy/1.webp";
public const string SampleWebpTwo = "WebP/Lossy/2.webp";
public const string SampleWebpThree = "WebP/Lossy/3.webp";
public const string SampleWebpFour = "WebP/Lossy/4.webp";
public const string SampleWebpFive = "WebP/Lossy/5.webp";
public static class Alpha
{
public const string SampleWebpOne = "WebP/Lossy/Alpha/1_webp_a.webp";
public const string SampleWebpTwo = "WebP/Lossy/Alpha/2_webp_a.webp";
public const string SampleWebpThree = "WebP/Lossy/Alpha/3_webp_a.webp";
public const string SampleWebpFour = "WebP/Lossy/Alpha/4_webp_a.webp";
public const string SampleWebpFive = "WebP/Lossy/Alpha/5_webp_a.webp";
}
}
public static readonly string[] All =
{
Lossless.SampleWebpOne,
Lossless.SampleWebpTwo,
Lossless.SampleWebpThree,
Lossless.SampleWebpFour,
Lossless.SampleWebpFive,
Lossy.SampleWebpOne,
Lossy.SampleWebpTwo,
Lossy.SampleWebpThree,
Lossy.SampleWebpFour,
Lossy.SampleWebpFive,
Lossy.Alpha.SampleWebpOne,
Lossy.Alpha.SampleWebpTwo,
Lossy.Alpha.SampleWebpThree,
Lossy.Alpha.SampleWebpFour,
Lossy.Alpha.SampleWebpFive
};
}
}
}

Loading…
Cancel
Save