From b26dca85983154f6952b095f6e74ff80e1af19a6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sat, 4 Feb 2023 15:40:30 +1000 Subject: [PATCH] Fix up webp alpha compression test for ARM64 --- .../Formats/Gif/GifDecoderTests.cs | 3 + .../Formats/Tga/TgaDecoderTests.cs | 3 + .../Formats/Tiff/TiffDecoderTests.cs | 3 + .../Formats/WebP/WebpDecoderTests.cs | 3 + .../Formats/WebP/WebpEncoderTests.cs | 63 +++++++++++-------- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index 9295dd1509..b4facfa3fe 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/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, diff --git a/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs index 9b95a696fb..8a9aaa7f59 100644 --- a/tests/ImageSharp.Tests/Formats/Tga/TgaDecoderTests.cs +++ b/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, diff --git a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs index 1571ceae5d..75e7d39091 100644 --- a/tests/ImageSharp.Tests/Formats/Tiff/TiffDecoderTests.cs +++ b/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, diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs index 071dd77018..010af3fbbe 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs +++ b/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, diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index 4eb8b3063d..6c5fa50ff6 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/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(TestImageProvider provider, WebpFileFormatType expectedFormat) where TPixel : unmanaged, IPixel { - var options = new WebpEncoder(); + WebpEncoder options = new(); using Image input = provider.GetImage(); - using var memoryStream = new MemoryStream(); + using MemoryStream memoryStream = new(); input.Save(memoryStream, options); memoryStream.Position = 0; - using var output = Image.Load(memoryStream); + using Image output = Image.Load(memoryStream); ImageMetadata meta = output.Metadata; WebpMetadata webpMetaData = meta.GetWebpMetadata(); @@ -43,7 +44,7 @@ public class WebpEncoderTests public void Encode_Lossless_WithPalette_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int quality) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, WebpEncodingMethod method, int quality) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int expectedBytes) where TPixel : unmanaged, IPixel { - var encoder = new WebpEncoder() + WebpEncoder encoder = new() { FileFormat = WebpFileFormatType.Lossless, Method = WebpEncodingMethod.BestQuality }; using Image 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(TestImageProvider provider, int nearLosslessQuality) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, WebpEncodingMethod method) where TPixel : unmanaged, IPixel { - 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(1, 1); - var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossless }; - using (var memStream = new MemoryStream()) + using Image 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(TestImageProvider provider, int quality) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int filterStrength) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int snsStrength) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, WebpEncodingMethod method, int quality) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int expectedFileSize) + [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32)] + public void Encode_Lossy_WithAlpha_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel { - 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(TestImageProvider provider, int expectedFileSize) + [WithFile(TestImages.Png.Transparency, PixelTypes.Rgba32)] + public void Encode_Lossy_WithAlphaUsingCompression_Works(TestImageProvider provider) where TPixel : unmanaged, IPixel { - 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 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 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.File(TestImageLossyFullPath); + TestImageProvider provider = TestImageProvider.File(TestImageLossyFullPath); using Image 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)); }