Browse Source

WebP test input files added, test skeletons added (copied from Bmp tests)

pull/1552/head
Lajos Marton 6 years ago
parent
commit
a9ff1fb6ff
  1. 33
      ImageSharp.sln
  2. 106
      tests/ImageSharp.Tests/Formats/WebP/WebPDecoderTests.cs
  3. 116
      tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs
  4. 21
      tests/ImageSharp.Tests/Formats/WebP/WebPFileHeaderTests.cs
  5. 50
      tests/ImageSharp.Tests/Formats/WebP/WebPMetaDataTests.cs
  6. 2
      tests/Images/External
  7. 3
      tests/Images/Input/WebP/Lossless/1_webp_ll.webp
  8. 3
      tests/Images/Input/WebP/Lossless/2_webp_ll.webp
  9. 3
      tests/Images/Input/WebP/Lossless/3_webp_ll.webp
  10. 3
      tests/Images/Input/WebP/Lossless/4_webp_ll.webp
  11. 3
      tests/Images/Input/WebP/Lossless/5_webp_ll.webp
  12. 3
      tests/Images/Input/WebP/Lossy/1.webp
  13. 3
      tests/Images/Input/WebP/Lossy/2.webp
  14. 3
      tests/Images/Input/WebP/Lossy/3.webp
  15. 3
      tests/Images/Input/WebP/Lossy/4.webp
  16. 3
      tests/Images/Input/WebP/Lossy/5.webp
  17. 3
      tests/Images/Input/WebP/Lossy/Alpha/1_webp_a.webp
  18. 3
      tests/Images/Input/WebP/Lossy/Alpha/2_webp_a.webp
  19. 3
      tests/Images/Input/WebP/Lossy/Alpha/3_webp_a.webp
  20. 3
      tests/Images/Input/WebP/Lossy/Alpha/4_webp_a.webp
  21. 3
      tests/Images/Input/WebP/Lossy/Alpha/5_webp_a.webp

33
ImageSharp.sln

@ -356,6 +356,35 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Benchmarks", "te
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageSharp.Sandbox46", "tests\ImageSharp.Sandbox46\ImageSharp.Sandbox46.csproj", "{561B880A-D9EE-44EF-90F5-817C54A9D9AB}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Webp", "Webp", "{7BEE9435-1833-4686-8B36-C4EE2F13D908}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lossy", "Lossy", "{41D10A70-59CE-4634-9145-CE9B60050371}"
ProjectSection(SolutionItems) = preProject
tests\Images\Input\WebP\Lossy\1.webp = tests\Images\Input\WebP\Lossy\1.webp
tests\Images\Input\WebP\Lossy\2.webp = tests\Images\Input\WebP\Lossy\2.webp
tests\Images\Input\WebP\Lossy\3.webp = tests\Images\Input\WebP\Lossy\3.webp
tests\Images\Input\WebP\Lossy\4.webp = tests\Images\Input\WebP\Lossy\4.webp
tests\Images\Input\WebP\Lossy\5.webp = tests\Images\Input\WebP\Lossy\5.webp
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Lossless", "Lossless", "{F19E6F18-4102-4134-8A96-FEC2AB67F794}"
ProjectSection(SolutionItems) = preProject
tests\Images\Input\WebP\Lossless\1_webp_ll.webp = tests\Images\Input\WebP\Lossless\1_webp_ll.webp
tests\Images\Input\WebP\Lossless\2_webp_ll.webp = tests\Images\Input\WebP\Lossless\2_webp_ll.webp
tests\Images\Input\WebP\Lossless\3_webp_ll.webp = tests\Images\Input\WebP\Lossless\3_webp_ll.webp
tests\Images\Input\WebP\Lossless\4_webp_ll.webp = tests\Images\Input\WebP\Lossless\4_webp_ll.webp
tests\Images\Input\WebP\Lossless\5_webp_ll.webp = tests\Images\Input\WebP\Lossless\5_webp_ll.webp
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Alpha", "Alpha", "{E6B81E19-B27F-4656-9169-4B8415D064A2}"
ProjectSection(SolutionItems) = preProject
tests\Images\Input\WebP\Lossy\Alpha\1_webp_a.webp = tests\Images\Input\WebP\Lossy\Alpha\1_webp_a.webp
tests\Images\Input\WebP\Lossy\Alpha\2_webp_a.webp = tests\Images\Input\WebP\Lossy\Alpha\2_webp_a.webp
tests\Images\Input\WebP\Lossy\Alpha\3_webp_a.webp = tests\Images\Input\WebP\Lossy\Alpha\3_webp_a.webp
tests\Images\Input\WebP\Lossy\Alpha\4_webp_a.webp = tests\Images\Input\WebP\Lossy\Alpha\4_webp_a.webp
tests\Images\Input\WebP\Lossy\Alpha\5_webp_a.webp = tests\Images\Input\WebP\Lossy\Alpha\5_webp_a.webp
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -453,6 +482,10 @@ Global
{EA3000E9-2A91-4EC4-8A68-E566DEBDC4F6} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{2BF743D8-2A06-412D-96D7-F448F00C5EA5} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{561B880A-D9EE-44EF-90F5-817C54A9D9AB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{7BEE9435-1833-4686-8B36-C4EE2F13D908} = {9DA226A1-8656-49A8-A58A-A8B5C081AD66}
{41D10A70-59CE-4634-9145-CE9B60050371} = {7BEE9435-1833-4686-8B36-C4EE2F13D908}
{F19E6F18-4102-4134-8A96-FEC2AB67F794} = {7BEE9435-1833-4686-8B36-C4EE2F13D908}
{E6B81E19-B27F-4656-9169-4B8415D064A2} = {41D10A70-59CE-4634-9145-CE9B60050371}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F8B9D1F-CD8B-4CC5-8216-D531E25BD795}

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

@ -0,0 +1,106 @@
// 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.Metadata;
using static TestImages.Bmp;
public class WebPDecoderTests
{
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.RgbaVector;
public static readonly string[] MiscBmpFiles = Miscellaneous;
public static readonly string[] BitfieldsBmpFiles = BitFields;
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>
{
{ Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
{ V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
{ RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter }
};
[Theory]
[WithFileCollection(nameof(MiscBmpFiles), PixelTypes.Rgba32)]
public void BmpDecoder_CanDecode_MiscellaneousBitmaps<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
{
image.DebugSave(provider);
if (TestEnvironment.IsWindows)
{
image.CompareToOriginal(provider);
}
}
}
[Theory]
[WithFile(Bit16Inverted, PixelTypes.Rgba32)]
[WithFile(Bit8Inverted, PixelTypes.Rgba32)]
public void BmpDecoder_CanDecode_Inverted<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage(new BmpDecoder()))
{
image.DebugSave(provider);
image.CompareToOriginal(provider);
}
}
[Theory]
[InlineData(Bit32Rgb, 32)]
[InlineData(Bit32Rgba, 32)]
[InlineData(Car, 24)]
[InlineData(F, 24)]
[InlineData(NegHeight, 24)]
[InlineData(Bit16, 16)]
[InlineData(Bit16Inverted, 16)]
[InlineData(Bit8, 8)]
[InlineData(Bit8Inverted, 8)]
[InlineData(Bit4, 4)]
[InlineData(Bit1, 1)]
[InlineData(Bit1Pal1, 1)]
public void Identify_DetectsCorrectPixelType(string imagePath, int expectedPixelSize)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
IImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
Assert.Equal(expectedPixelSize, imageInfo.PixelType?.BitsPerPixel);
}
}
[Theory]
[MemberData(nameof(RatioFiles))]
public void Decode_VerifyRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
var decoder = new BmpDecoder();
using (Image<Rgba32> image = decoder.Decode<Rgba32>(Configuration.Default, stream))
{
ImageMetadata meta = image.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
Assert.Equal(resolutionUnit, meta.ResolutionUnits);
}
}
}
}
}

116
tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs

@ -0,0 +1,116 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Processors.Quantization;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
using Xunit.Abstractions;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
using static TestImages.Bmp;
public class WebPEncoderTests
{
public static readonly TheoryData<BmpBitsPerPixel> BitsPerPixel =
new TheoryData<BmpBitsPerPixel>
{
BmpBitsPerPixel.Pixel24,
BmpBitsPerPixel.Pixel32
};
public static readonly TheoryData<string, int, int, PixelResolutionUnit> RatioFiles =
new TheoryData<string, int, int, PixelResolutionUnit>
{
{ Car, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
{ V5Header, 3780, 3780 , PixelResolutionUnit.PixelsPerMeter },
{ RLE8, 2835, 2835, PixelResolutionUnit.PixelsPerMeter }
};
public static readonly TheoryData<string, BmpBitsPerPixel> BmpBitsPerPixelFiles =
new TheoryData<string, BmpBitsPerPixel>
{
{ Car, BmpBitsPerPixel.Pixel24 },
{ Bit32Rgb, BmpBitsPerPixel.Pixel32 }
};
public WebPEncoderTests(ITestOutputHelper output) => this.Output = output;
private ITestOutputHelper Output { get; }
[Theory]
[MemberData(nameof(RatioFiles))]
public void Encode_PreserveRatio(string imagePath, int xResolution, int yResolution, PixelResolutionUnit resolutionUnit)
{
var options = new BmpEncoder();
var testFile = TestFile.Create(imagePath);
using (Image<Rgba32> input = testFile.CreateRgba32Image())
{
using (var memStream = new MemoryStream())
{
input.Save(memStream, options);
memStream.Position = 0;
using (var output = Image.Load<Rgba32>(memStream))
{
ImageMetadata meta = output.Metadata;
Assert.Equal(xResolution, meta.HorizontalResolution);
Assert.Equal(yResolution, meta.VerticalResolution);
Assert.Equal(resolutionUnit, meta.ResolutionUnits);
}
}
}
}
[Theory]
[WithTestPatternImages(nameof(BitsPerPixel), 48, 24, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 47, 8, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 49, 7, PixelTypes.Rgba32)]
[WithSolidFilledImages(nameof(BitsPerPixel), 1, 1, 255, 100, 50, 255, PixelTypes.Rgba32)]
[WithTestPatternImages(nameof(BitsPerPixel), 7, 5, PixelTypes.Rgba32)]
public void Encode_WorksWithDifferentSizes<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel);
[Theory]
[WithFile(Bit32Rgb, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
[WithFile(Bit32Rgba, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
[WithFile(WinBmpv4, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
[WithFile(WinBmpv5, PixelTypes.Rgba32 | PixelTypes.Rgb24, BmpBitsPerPixel.Pixel32)]
public void Encode_32Bit_WithV3Header_Works<TPixel>(TestImageProvider<TPixel> provider, BmpBitsPerPixel bitsPerPixel)
// if supportTransparency is false, a v3 bitmap header will be written
where TPixel : struct, IPixel<TPixel> => TestBmpEncoderCore(provider, bitsPerPixel, supportTransparency: false);
private static void TestBmpEncoderCore<TPixel>(
TestImageProvider<TPixel> provider,
BmpBitsPerPixel bitsPerPixel,
bool supportTransparency = true,
ImageComparer customComparer = null)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
// There is no alpha in bmp with less then 32 bits per pixels, so the reference image will be made opaque.
if (bitsPerPixel != BmpBitsPerPixel.Pixel32)
{
image.Mutate(c => c.MakeOpaque());
}
var encoder = new BmpEncoder { BitsPerPixel = bitsPerPixel, SupportTransparency = supportTransparency };
// Does DebugSave & load reference CompareToReferenceInput():
image.VerifyEncoder(provider, "bmp", bitsPerPixel, encoder, customComparer);
}
}
}
}

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

@ -0,0 +1,21 @@
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));
}
}
}

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

@ -0,0 +1,50 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using SixLabors.ImageSharp.Formats.Bmp;
using Xunit;
// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Tests.Formats.WebP
{
using static TestImages.Bmp;
public class WebPMetaDataTests
{
[Fact]
public void CloneIsDeep()
{
var meta = new BmpMetadata { BitsPerPixel = BmpBitsPerPixel.Pixel24 };
var clone = (BmpMetadata)meta.DeepClone();
clone.BitsPerPixel = BmpBitsPerPixel.Pixel32;
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)]
public void Identify_DetectsCorrectBitmapInfoHeaderType(string imagePath, BmpInfoHeaderType expectedInfoHeaderType)
{
var testFile = TestFile.Create(imagePath);
using (var stream = new MemoryStream(testFile.Bytes, false))
{
IImageInfo imageInfo = Image.Identify(stream);
Assert.NotNull(imageInfo);
BmpMetadata bitmapMetaData = imageInfo.Metadata.GetFormatMetadata(BmpFormat.Instance);
Assert.NotNull(bitmapMetaData);
Assert.Equal(expectedInfoHeaderType, bitmapMetaData.InfoHeaderType);
}
}
}
}

2
tests/Images/External

@ -1 +1 @@
Subproject commit 1d3d4e3652dc95bd8bd420346bfe0f189addc587
Subproject commit 99a2bc523cd4eb00e37af20d1b2088fa11564c57

3
tests/Images/Input/WebP/Lossless/1_webp_ll.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:694f9011eddb7d0f08fc76ddad6b2129f2390d1e44c41a9ed9de0f08bb14c43b
size 81977

3
tests/Images/Input/WebP/Lossless/2_webp_ll.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ee83dd1211ba339e9a61a9af5e24a9fa5b8168ea448eacf4743bdcc36f58452b
size 27669

3
tests/Images/Input/WebP/Lossless/3_webp_ll.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8c96ed502862c0adc1f4221da1bd31d0921853f62eebcbbb89fec4e862ecb1de
size 152634

3
tests/Images/Input/WebP/Lossless/4_webp_ll.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8eff718866d464cd27161e171bb83ad73a05befae0724c2c75a772a7e21ac3b9
size 34096

3
tests/Images/Input/WebP/Lossless/5_webp_ll.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:0da93a44371abecdc68ad082c73ec633c3cd02d547fe28992403086a9e110946
size 99425

3
tests/Images/Input/WebP/Lossy/1.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d8b4596c10a23135931b4e63957eda41e9b3874811d9b724d890b589d66ea12f
size 30319

3
tests/Images/Input/WebP/Lossy/2.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:1ac427ad555ba5898015e8b60396e1852bfc1e9cd7ae5da6dd42c85ea3e169f7
size 60600

3
tests/Images/Input/WebP/Lossy/3.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:ebf4dc48653bd5f3c5b929ae3a411a0e440eb316aa50c80b1591d98db865bd5a
size 203135

3
tests/Images/Input/WebP/Lossy/4.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6f354f8954071f0b979a40866de95f2113a6ce54f4fe483c7f2b269c913f0df3
size 176969

3
tests/Images/Input/WebP/Lossy/5.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:7558b0f5da141787fcc41857743f8bc9417c844e2a19aeaa5fee25f1433abe4e
size 82697

3
tests/Images/Input/WebP/Lossy/Alpha/1_webp_a.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e89d207eff1f1499acd6a5b8dc4a326ecdf3d303e4a7e6fc65c268035326a75f
size 18840

3
tests/Images/Input/WebP/Lossy/Alpha/2_webp_a.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:8c7f6772cdaf74fe5dac79d8acd7da48cc3700159f41e9dd2ebae8dd7c81b548
size 14412

3
tests/Images/Input/WebP/Lossy/Alpha/3_webp_a.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:c648a83fa93378259b8c71db58b4f47e5b4bf6f980b7d418346c4a2cf9ad6664
size 53817

3
tests/Images/Input/WebP/Lossy/Alpha/4_webp_a.webp

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:d2b4164bf2facd2b212e5eb15eb3066254c785b35d14d79341d178d8692e6e28
size 19440

3
tests/Images/Input/WebP/Lossy/Alpha/5_webp_a.webp

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