diff --git a/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs index b989259a3c..fd4404d91c 100644 --- a/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/WebP/PredictorEncoderTests.cs @@ -3,7 +3,7 @@ using System; using System.IO; -using System.Runtime.CompilerServices; +using SixLabors.ImageSharp.Formats.Experimental.Webp; using SixLabors.ImageSharp.Formats.Experimental.Webp.Lossless; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Tests.TestUtilities; @@ -15,26 +15,47 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP public class PredictorEncoderTests { [Fact] - public static void ColorSpaceTransform_ProducesExpectedData() + public static void ColorSpaceTransform_WithBikeImage_ProducesExpectedData() { - RunColorSpaceTransformTest(); + RunColorSpaceTransformTestWithBikeImage(); } + // Note: only run with netcoreapp, because the test fails with net472 in Release mode (not in Debug mode) for unknown reason. +#if NETCOREAPP + [Fact] + public static void ColorSpaceTransform_WithPeakImage_ProducesExpectedData() + { + RunColorSpaceTransformTestWithPeakImage(); + } +#endif + #if SUPPORTS_RUNTIME_INTRINSICS [Fact] - public void ColorSpaceTransform_WithHardwareIntrinsics_Works() + public void ColorSpaceTransform_WithPeakImage_WithHardwareIntrinsics_Works() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.AllowAll); + } + + [Fact] + public void ColorSpaceTransform_WithPeakImage_WithoutSSE41_Works() { - FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_ProducesExpectedData, HwIntrinsics.AllowAll); + FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithPeakImage_ProducesExpectedData, HwIntrinsics.DisableSSE41); } [Fact] - public void ColorSpaceTransform_WithoutSSE41_Works() + public void ColorSpaceTransform_WithBikeImage_WithHardwareIntrinsics_Works() { - FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_ProducesExpectedData, HwIntrinsics.DisableSSE41); + FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.AllowAll); + } + + [Fact] + public void ColorSpaceTransform_WithBikeImage_WithoutSSE41_Works() + { + FeatureTestRunner.RunWithHwIntrinsicsFeature(ColorSpaceTransform_WithBikeImage_ProducesExpectedData, HwIntrinsics.DisableSSE41); } #endif - private static void RunColorSpaceTransformTest() + private static void RunColorSpaceTransformTestWithPeakImage() { // arrange uint[] expectedData = @@ -90,6 +111,35 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP Assert.Equal(expectedData, transformData); } + private static void RunColorSpaceTransformTestWithBikeImage() + { + // arrange + uint[] expectedData = + { + 4278714368, 4278192876, 4278198304, 4278198304, 4278190304, 4278190080, 4278190080, 4278198272, + 4278197760, 4278198816, 4278197794, 4278197774, 4278190080, 4278190080, 4278198816, 4278197281, + 4278197280, 4278197792, 4278200353, 4278191343, 4278190304, 4294713873, 4278198784, 4294844416, + 4278201578, 4278200044, 4278191343, 4278190288, 4294705200, 4294717139, 4278203628, 4278201064, + 4278201586, 4278197792, 4279240909 + }; + + // Convert image pixels to bgra array. + var imgBytes = File.ReadAllBytes(TestImageFullPath(TestImages.WebP.Lossless.BikeSmall)); + using var image = Image.Load(imgBytes, new WebpDecoder()); + uint[] bgra = ToBgra(image); + + int colorTransformBits = 4; + int transformWidth = LosslessUtils.SubSampleSize(image.Width, colorTransformBits); + int transformHeight = LosslessUtils.SubSampleSize(image.Height, colorTransformBits); + var transformData = new uint[transformWidth * transformHeight]; + + // act + PredictorEncoder.ColorSpaceTransform(image.Width, image.Height, colorTransformBits, 75, bgra, transformData); + + // assert + Assert.Equal(expectedData, transformData); + } + private static uint[] ToBgra(Image image) where TPixel : unmanaged, IPixel { @@ -107,7 +157,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.WebP return bgra; } - [MethodImpl(MethodImplOptions.AggressiveInlining)] private static Bgra32 ToBgra32(TPixel color) where TPixel : unmanaged, IPixel { diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index 5f98875afe..737c662d87 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -551,6 +551,8 @@ namespace SixLabors.ImageSharp.Tests public const string ThreeTransforms7 = "WebP/lossless_vec_2_15.webp"; // color_indexing, predictor, cross_color public const string BikeThreeTransforms = "WebP/bike_lossless.webp"; // substract_green, predictor, cross_color + public const string BikeSmall = "WebP/bike_lossless_small.webp"; + // Invalid / corrupted images // Below images have errors according to webpinfo. The error message webpinfo gives is "Truncated data detected when parsing RIFF payload." public const string LossLessCorruptImage1 = "WebP/lossless_big_random_alpha.webp"; // substract_green, predictor, cross_color. diff --git a/tests/Images/Input/WebP/bike_lossless_small.webp b/tests/Images/Input/WebP/bike_lossless_small.webp new file mode 100644 index 0000000000..6611294517 --- /dev/null +++ b/tests/Images/Input/WebP/bike_lossless_small.webp @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d0cff46a5bbc4903e8e372ee79e988942c101a6cc6642658cb92a9f377443dca +size 2598