Skip to content

Commit f461378

Browse files
Complete encoding tests
1 parent a477ac1 commit f461378

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Six Labors Split License.
33

44
using System.Runtime.InteropServices;
5-
using SixLabors.ImageSharp.Formats.Png;
65
using SixLabors.ImageSharp.Formats.Webp;
76
using SixLabors.ImageSharp.Metadata;
87
using SixLabors.ImageSharp.PixelFormats;
@@ -24,22 +23,41 @@ public void Encode_AnimatedLossless<TPixel>(TestImageProvider<TPixel> provider)
2423
where TPixel : unmanaged, IPixel<TPixel>
2524
{
2625
using Image<TPixel> image = provider.GetImage();
27-
using MemoryStream memStream = new();
28-
image.SaveAsWebp(memStream, new() { FileFormat = WebpFileFormatType.Lossless });
26+
WebpEncoder encoder = new()
27+
{
28+
FileFormat = WebpFileFormatType.Lossless,
29+
Quality = 100
30+
};
31+
32+
// Always save as we need to compare the encoded output.
33+
provider.Utility.SaveTestOutputFile(image, "webp", encoder);
2934

30-
// TODO: DebugSave, VerifySimilarity
35+
// Compare encoded result
36+
image.VerifyEncoder(provider, "webp", string.Empty, encoder);
3137
}
3238

3339
[Theory]
3440
[WithFile(Lossy.Animated, PixelTypes.Rgba32)]
41+
[WithFile(Lossy.AnimatedLandscape, PixelTypes.Rgba32)]
3542
public void Encode_AnimatedLossy<TPixel>(TestImageProvider<TPixel> provider)
3643
where TPixel : unmanaged, IPixel<TPixel>
3744
{
3845
using Image<TPixel> image = provider.GetImage();
39-
using MemoryStream memStream = new();
40-
image.SaveAsWebp(memStream, new());
46+
WebpEncoder encoder = new()
47+
{
48+
FileFormat = WebpFileFormatType.Lossy,
49+
Quality = 100
50+
};
51+
52+
// Always save as we need to compare the encoded output.
53+
provider.Utility.SaveTestOutputFile(image, "webp", encoder);
4154

42-
// TODO: DebugSave, VerifySimilarity
55+
// Compare encoded result
56+
// The reference decoder seems to produce differences up to 0.1% but the input/output have been
57+
// checked to be correct.
58+
string path = provider.Utility.GetTestOutputFileName("webp", null, true);
59+
using Image<Rgba32> encoded = Image.Load<Rgba32>(path);
60+
encoded.CompareToReferenceOutput(ImageComparer.Tolerant(0.01f), provider, null, "webp");
4361
}
4462

4563
[Theory]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:f9ece3c7acc6f40318e3cda6b0189607df6b9b60dd112212c72ec0f6aa26431d
3+
size 409346
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:71800dff476f50ebd2a3d0cf0b4f5bef427a1c2cd8732b415511f10d3d93f9a0
3+
size 126382

0 commit comments

Comments
 (0)