Browse Source

Use tolerant comparer for lossy webp encoder tests

pull/1552/head
Brian Popow 6 years ago
parent
commit
1b296c9109
  1. 20
      tests/ImageSharp.Tests/Formats/WebP/WebPEncoderTests.cs

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

@ -3,6 +3,7 @@
using SixLabors.ImageSharp.Formats.WebP;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Formats.WebP
@ -67,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossy", "_q", quality);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(quality));
}
[Theory]
@ -81,16 +82,29 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP
public void Encode_Lossy_WithDifferentMethods_Works<TPixel>(TestImageProvider<TPixel> provider, int method)
where TPixel : unmanaged, IPixel<TPixel>
{
int quality = 75;
var encoder = new WebPEncoder()
{
Lossy = true,
Method = method,
Quality = 75
Quality = quality
};
using Image<TPixel> image = provider.GetImage();
var testOutputDetails = string.Concat("lossy", "_m", method);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder);
image.VerifyEncoder(provider, "webp", testOutputDetails, encoder, customComparer: GetComparer(quality));
}
private static ImageComparer GetComparer(int quality)
{
float tolerance = 0.01f; // ~1.0%
if (quality < 30)
{
tolerance = 0.02f; // ~2.0%
}
return ImageComparer.Tolerant(tolerance);
}
}
}

Loading…
Cancel
Save