diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index 2d31a59f9..a2f7bd8b5 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -39,9 +39,11 @@ namespace SixLabors.ImageSharp.Tests TestImages.Jpeg.Progressive.Festzug, TestImages.Jpeg.Progressive.Bad.BadEOF }; + public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; + // TODO: We should make this comparer less tolerant ... private static readonly ImageComparer VeryTolerantJpegComparer = - ImageComparer.Tolerant(0.005f, pixelThresholdInPixelByteSum: 4); + ImageComparer.Tolerant(0.005f, pixelThresholdHammingDistance: 4); public JpegDecoderTests(ITestOutputHelper output) { @@ -55,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests private static IImageDecoder PdfJsJpegDecoder => new JpegDecoder(); [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] public void DecodeBaselineJpeg(TestImageProvider provider) where TPixel : struct, IPixel { @@ -68,7 +70,23 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + [WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, false)] + [WithFile(TestImages.Jpeg.Baseline.Calliphora, CommonNonDefaultPixelTypes, true)] + public void JpegDecoder_IsNotBoundToSinglePixelType(TestImageProvider provider, bool useOldDecoder) + where TPixel : struct, IPixel + { + IImageDecoder decoder = useOldDecoder ? OldJpegDecoder : PdfJsJpegDecoder; + using (Image image = provider.GetImage(decoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = nameof(this.DecodeBaselineJpeg); + image.CompareToReferenceOutput(provider, VeryTolerantJpegComparer, appendPixelTypeToFileName: false); + } + } + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] public void DecodeBaselineJpeg_Old(TestImageProvider provider) where TPixel : struct, IPixel { @@ -82,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] public void DecodeProgressiveJpeg(TestImageProvider provider) where TPixel : struct, IPixel { @@ -95,7 +113,7 @@ namespace SixLabors.ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] public void DecodeProgressiveJpeg_Old(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index a95d231bb..ff9756e03 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -17,9 +17,9 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison public static ImageComparer Tolerant( float imageThreshold = TolerantImageComparer.DefaultImageThreshold, - int pixelThresholdInPixelByteSum = 0) + int pixelThresholdHammingDistance = 0) { - return new TolerantImageComparer(imageThreshold, pixelThresholdInPixelByteSum); + return new TolerantImageComparer(imageThreshold, pixelThresholdHammingDistance); } public abstract ImageSimilarityReport CompareImagesOrFrames( diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index c015a4b2f..c74de50ce 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -12,10 +12,10 @@ { public const float DefaultImageThreshold = 1.0f / (100 * 100 * 255); - public TolerantImageComparer(float imageThreshold, int pixelThresholdInPixelByteSum = 0) + public TolerantImageComparer(float imageThreshold, int pixelThresholdHammingDistance = 0) { this.ImageThreshold = imageThreshold; - this.PixelThresholdInPixelByteSum = pixelThresholdInPixelByteSum; + this.PixelThresholdHammingDistance = pixelThresholdHammingDistance; } /// @@ -36,7 +36,7 @@ /// The threshold of the individual pixels before they acumulate towards the overall difference. /// For an individual pixel the value it's calculated as: pixel.R + pixel.G + pixel.B + pixel.A /// - public int PixelThresholdInPixelByteSum { get; } + public int PixelThresholdHammingDistance { get; } public override ImageSimilarityReport CompareImagesOrFrames(ImageBase expected, ImageBase actual) { @@ -68,7 +68,7 @@ { int d = GetHammingDistanceInRgbaSpace(ref aBuffer[x], ref bBuffer[x]); - if (d > this.PixelThresholdInPixelByteSum) + if (d > this.PixelThresholdHammingDistance) { var diff = new PixelDifference(new Point(x, y), aBuffer[x], bBuffer[x]); differences.Add(diff); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs index 0329b88f9..45e20f3fb 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs @@ -96,7 +96,7 @@ namespace SixLabors.ImageSharp.Tests ImagingTestCaseUtility.ModifyPixel(clone, 1, 0, 10); ImagingTestCaseUtility.ModifyPixel(clone, 2, 0, 10); - var comparer = ImageComparer.Tolerant(pixelThresholdInPixelByteSum: 42); + var comparer = ImageComparer.Tolerant(pixelThresholdHammingDistance: 42); comparer.VerifySimilarity(image, clone); } }