Browse Source

Fix up webp alpha compression test for ARM64

pull/2341/head
James Jackson-South 3 years ago
parent
commit
b26dca8598
  1. 3
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  2. 3
      tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs
  3. 3
      tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs
  4. 3
      tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
  5. 63
      tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs

3
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -50,6 +50,9 @@ public class GifDecoderTests
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false);
// Floating point differences result in minor pixel differences.
// Output have been manually verified.
image.CompareToReferenceOutput(
ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0002F : 0.0001F),
provider,

3
tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs

@ -759,6 +759,9 @@ public class TgaDecoderTests
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false);
// Floating point differences result in minor pixel differences.
// Output have been manually verified.
image.CompareToReferenceOutput(
ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.00017F : 0.0001F),
provider,

3
tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs

@ -766,6 +766,9 @@ public class TiffDecoderTests : TiffDecoderBaseTester
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false);
// Floating point differences result in minor pixel differences.
// Output have been manually verified.
image.CompareToReferenceOutput(
TestEnvironment.OSArchitecture == Architecture.Arm64 ? ImageComparer.TolerantPercentage(0.0006F) : ImageComparer.Exact,
provider,

3
tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs

@ -366,6 +366,9 @@ public class WebpDecoderTests
FormattableString details = $"{options.TargetSize.Value.Width}_{options.TargetSize.Value.Height}";
image.DebugSave(provider, testOutputDetails: details, appendPixelTypeToFileName: false);
// Floating point differences result in minor pixel differences.
// Output have been manually verified.
image.CompareToReferenceOutput(
ImageComparer.TolerantPercentage(TestEnvironment.OSArchitecture == Architecture.Arm64 ? 0.0156F : 0.0007F),
provider,

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

@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Runtime.InteropServices;
using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.Metadata;
using SixLabors.ImageSharp.PixelFormats;
@ -23,13 +24,13 @@ public class WebpEncoderTests
public void Encode_PreserveRatio<TPixel>(TestImageProvider<TPixel> provider, WebpFileFormatType expectedFormat)
where TPixel : unmanaged, IPixel<TPixel>
{
var options = new WebpEncoder();
WebpEncoder options = new();
using Image<TPixel> input = provider.GetImage();
using var memoryStream = new MemoryStream();
using MemoryStream memoryStream = new();
input.Save(memoryStream, options);
memoryStream.Position = 0;
using var output = Image.Load<Rgba32>(memoryStream);
using Image<Rgba32> output = Image.Load<Rgba32>(memoryStream);
ImageMetadata meta = output.Metadata;
WebpMetadata webpMetaData = meta.GetWebpMetadata();
@ -43,7 +44,7 @@ public class WebpEncoderTests
public void Encode_Lossless_WithPalette_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
Quality = 100,
@ -61,7 +62,7 @@ public class WebpEncoderTests
public void Encode_Lossless_WithDifferentQuality_Works<TPixel>(TestImageProvider<TPixel> provider, int quality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
Quality = quality
@ -90,7 +91,7 @@ public class WebpEncoderTests
public void Encode_Lossless_WithDifferentMethodAndQuality_Works<TPixel>(TestImageProvider<TPixel> provider, WebpEncodingMethod method, int quality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
Method = method,
@ -107,14 +108,14 @@ public class WebpEncoderTests
public void Encode_Lossless_WithBestQuality_HasExpectedSize<TPixel>(TestImageProvider<TPixel> provider, int expectedBytes)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
Method = WebpEncodingMethod.BestQuality
};
using Image<TPixel> image = provider.GetImage();
using var memoryStream = new MemoryStream();
using MemoryStream memoryStream = new();
image.Save(memoryStream, encoder);
Assert.Equal(memoryStream.Length, expectedBytes);
@ -130,7 +131,7 @@ public class WebpEncoderTests
public void Encode_Lossless_WithNearLosslessFlag_Works<TPixel>(TestImageProvider<TPixel> provider, int nearLosslessQuality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
NearLossless = true,
@ -154,7 +155,7 @@ public class WebpEncoderTests
public void Encode_Lossless_WithPreserveTransparentColor_Works<TPixel>(TestImageProvider<TPixel> provider, WebpEncodingMethod method)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossless,
Method = method,
@ -170,9 +171,9 @@ public class WebpEncoderTests
public void Encode_Lossless_OneByOnePixel_Works()
{
// Just make sure, encoding 1 pixel by 1 pixel does not throw an exception.
using var image = new Image<Rgba32>(1, 1);
var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless };
using (var memStream = new MemoryStream())
using Image<Rgba32> image = new(1, 1);
WebpEncoder encoder = new() { FileFormat = WebpFileFormatType.Lossless };
using (MemoryStream memStream = new())
{
image.SaveAsWebp(memStream, encoder);
}
@ -185,7 +186,7 @@ public class WebpEncoderTests
public void Encode_Lossy_WithDifferentQuality_Works<TPixel>(TestImageProvider<TPixel> provider, int quality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
Quality = quality
@ -205,7 +206,7 @@ public class WebpEncoderTests
public void Encode_Lossy_WithDifferentFilterStrength_Works<TPixel>(TestImageProvider<TPixel> provider, int filterStrength)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
FilterStrength = filterStrength
@ -225,7 +226,7 @@ public class WebpEncoderTests
public void Encode_Lossy_WithDifferentSpatialNoiseShapingStrength_Works<TPixel>(TestImageProvider<TPixel> provider, int snsStrength)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
SpatialNoiseShaping = snsStrength
@ -254,7 +255,7 @@ public class WebpEncoderTests
public void Encode_Lossy_WithDifferentMethodsAndQuality_Works<TPixel>(TestImageProvider<TPixel> provider, WebpEncodingMethod method, int quality)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
Method = method,
@ -267,11 +268,15 @@ public class WebpEncoderTests
}
[Theory]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, 64020)]
public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedFileSize)
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32)]
public void Encode_Lossy_WithAlpha_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
// Floating point differences result in minor pixel differences affecting compression.
// Output have been manually verified.
int expectedFileSize = TestEnvironment.OSArchitecture == Architecture.Arm64 ? 64060 : 64020;
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
UseAlphaCompression = false
@ -291,11 +296,15 @@ public class WebpEncoderTests
}
[Theory]
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32, 16200)]
public void Encode_Lossy_WithAlphaUsingCompression_Works<TPixel>(TestImageProvider<TPixel> provider, int expectedFileSize)
[WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32)]
public void Encode_Lossy_WithAlphaUsingCompression_Works<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
var encoder = new WebpEncoder()
// Floating point differences result in minor pixel differences affecting compression.
// Output have been manually verified.
int expectedFileSize = TestEnvironment.OSArchitecture == Architecture.Arm64 ? 16240 : 16200;
WebpEncoder encoder = new()
{
FileFormat = WebpFileFormatType.Lossy,
UseAlphaCompression = true
@ -322,7 +331,7 @@ public class WebpEncoderTests
{
using Image<TPixel> image = provider.GetImage();
var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless };
WebpEncoder encoder = new() { FileFormat = WebpFileFormatType.Lossless };
image.VerifyEncoder(provider, "webp", string.Empty, encoder);
}
@ -334,16 +343,16 @@ public class WebpEncoderTests
{
using Image<TPixel> image = provider.GetImage();
var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy };
WebpEncoder encoder = new() { FileFormat = WebpFileFormatType.Lossy };
image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f));
}
public static void RunEncodeLossy_WithPeakImage()
{
var provider = TestImageProvider<Rgba32>.File(TestImageLossyFullPath);
TestImageProvider<Rgba32> provider = TestImageProvider<Rgba32>.File(TestImageLossyFullPath);
using Image<Rgba32> image = provider.GetImage();
var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy };
WebpEncoder encoder = new() { FileFormat = WebpFileFormatType.Lossy };
image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f));
}

Loading…
Cancel
Save