From 0ce8a212442a9aea66d823434ed3c951546d970d Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Sat, 8 Oct 2022 17:28:32 +0200 Subject: [PATCH] Split up alpha encoding test in compressed and uncompressed test --- .../Formats/WebP/WebpEncoderTests.cs | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index 5e70f04f1d..4eb8b3063d 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -267,22 +267,45 @@ public class WebpEncoderTests } [Theory] - [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, false, 64020)] - [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, true, 16200)] - public void Encode_Lossy_WithAlpha_Works(TestImageProvider provider, bool compressed, int expectedFileSize) + [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, 64020)] + public void Encode_Lossy_WithAlpha_Works(TestImageProvider provider, int expectedFileSize) where TPixel : unmanaged, IPixel { var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy, - UseAlphaCompression = compressed + UseAlphaCompression = false }; using Image image = provider.GetImage(); string encodedFile = image.VerifyEncoder( provider, "webp", - $"with_alpha_compressed_{compressed}", + "with_alpha", + encoder, + ImageComparer.Tolerant(0.04f), + referenceDecoder: new MagickReferenceDecoder()); + + int encodedBytes = File.ReadAllBytes(encodedFile).Length; + Assert.True(encodedBytes <= expectedFileSize, $"encoded bytes are {encodedBytes} and should be smaller then expected file size of {expectedFileSize}"); + } + + [Theory] + [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, 16200)] + public void Encode_Lossy_WithAlphaUsingCompression_Works(TestImageProvider provider, int expectedFileSize) + where TPixel : unmanaged, IPixel + { + var encoder = new WebpEncoder() + { + FileFormat = WebpFileFormatType.Lossy, + UseAlphaCompression = true + }; + + using Image image = provider.GetImage(); + string encodedFile = image.VerifyEncoder( + provider, + "webp", + "with_alpha_compressed", encoder, ImageComparer.Tolerant(0.04f), referenceDecoder: new MagickReferenceDecoder());