From 4694be382aff9100b210945c5effdf090743d4d3 Mon Sep 17 00:00:00 2001 From: Brian Popow Date: Mon, 20 Dec 2021 14:33:25 +0100 Subject: [PATCH] Add Vp8Residual tests --- .../Formats/WebP/Vp8ResidualTests.cs | 37 +++++++++++++++++++ .../Formats/WebP/WebpEncoderTests.cs | 20 ++++++++++ 2 files changed, 57 insertions(+) create mode 100644 tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs diff --git a/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs new file mode 100644 index 000000000..2bca632db --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/WebP/Vp8ResidualTests.cs @@ -0,0 +1,37 @@ +// Copyright (c) Six Labors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.Formats.Webp.Lossy; +using SixLabors.ImageSharp.Tests.TestUtilities; +using Xunit; + +namespace SixLabors.ImageSharp.Tests.Formats.WebP +{ + [Trait("Format", "Webp")] + public class Vp8ResidualTests + { + private static void RunSetCoeffsTest() + { + // arrange + var residual = new Vp8Residual(); + short[] coeffs = { 110, 0, -2, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0 }; + + // act + residual.SetCoeffs(coeffs); + + // assert + Assert.Equal(9, residual.Last); + } + + [Fact] + public void RunSetCoeffsTest_Works() => RunSetCoeffsTest(); + +#if SUPPORTS_RUNTIME_INTRINSICS + [Fact] + public void RunSetCoeffsTest_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.AllowAll); + + [Fact] + public void RunSetCoeffsTest_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunSetCoeffsTest, HwIntrinsics.DisableHWIntrinsic); +#endif + } +} diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs index 607d4c764..cad39224e 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/WebpEncoderTests.cs @@ -5,6 +5,7 @@ using System.IO; using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Metadata; using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; using Xunit; using static SixLabors.ImageSharp.Tests.TestImages.Webp; @@ -14,6 +15,8 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp [Trait("Format", "Webp")] public class WebpEncoderTests { + private static string TestImageLossyFullPath => Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, Lossy.NoFilter06); + [Theory] [WithFile(Flag, PixelTypes.Rgba32, WebpFileFormatType.Lossless)] // if its not a webp input image, it should default to lossless. [WithFile(Lossless.NoTransform1, PixelTypes.Rgba32, WebpFileFormatType.Lossless)] @@ -288,6 +291,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Webp image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f)); } + public static void RunEncodeLossy_WithPeakImage() + { + var provider = TestImageProvider.File(TestImageLossyFullPath); + using Image image = provider.GetImage(); + + var encoder = new WebpEncoder() { FileFormat = WebpFileFormatType.Lossy }; + image.VerifyEncoder(provider, "webp", string.Empty, encoder, ImageComparer.Tolerant(0.04f)); + } + +#if SUPPORTS_RUNTIME_INTRINSICS + [Fact] + public void RunEncodeLossy_WithPeakImage_WithHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunEncodeLossy_WithPeakImage, HwIntrinsics.AllowAll); + + [Fact] + public void RunEncodeLossy_WithPeakImage_WithoutHardwareIntrinsics_Works() => FeatureTestRunner.RunWithHwIntrinsicsFeature(RunEncodeLossy_WithPeakImage, HwIntrinsics.DisableHWIntrinsic); +#endif + private static ImageComparer GetComparer(int quality) { float tolerance = 0.01f; // ~1.0%