Browse Source

Split up alpha encoding test in compressed and uncompressed test

pull/2258/head
Brian Popow 4 years ago
parent
commit
0ce8a21244
  1. 33
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

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

@ -267,22 +267,45 @@ public class WebpEncoderTests
} }
[Theory] [Theory]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, false, 64020)] [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, 64020)]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, true, 16200)] public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedFileSize)
public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider, bool compressed, int expectedFileSize)
where TPixel : unmanaged, IPixel<TPixel> where TPixel : unmanaged, IPixel<TPixel>
{ {
var encoder = new WebpEncoder() var encoder = new WebpEncoder()
{ {
FileFormat = WebpFileFormatType.Lossy, FileFormat = WebpFileFormatType.Lossy,
UseAlphaCompression = compressed UseAlphaCompression = false
}; };
using Image<TPixel> image = provider.GetImage(); using Image<TPixel> image = provider.GetImage();
string encodedFile = image.VerifyEncoder( string encodedFile = image.VerifyEncoder(
provider, provider,
"webp", "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<TPixel>(TestImageProvider<TPixel> provider, int expectedFileSize)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
{
FileFormat = WebpFileFormatType.Lossy,
UseAlphaCompression = true
};
using Image<TPixel> image = provider.GetImage();
string encodedFile = image.VerifyEncoder(
provider,
"webp",
"with_alpha_compressed",
encoder, encoder,
ImageComparer.Tolerant(0.04f), ImageComparer.Tolerant(0.04f),
referenceDecoder: new MagickReferenceDecoder()); referenceDecoder: new MagickReferenceDecoder());

Loading…
Cancel
Save