From caecf2288ebfb121761763c9d2274e99e7aa58f5 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 15 May 2018 22:23:15 +0200 Subject: [PATCH] scatter JpegDecoderTests into multiple files --- .../Formats/Jpg/JpegDecoderTests.Baseline.cs | 89 +++++++ .../Formats/Jpg/JpegDecoderTests.Images.cs | 72 ++++++ .../Jpg/JpegDecoderTests.Progressive.cs | 81 ++++++ .../Formats/Jpg/JpegDecoderTests.cs | 232 ------------------ 4 files changed, 242 insertions(+), 232 deletions(-) create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs create mode 100644 tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs new file mode 100644 index 000000000..778459775 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Baseline.cs @@ -0,0 +1,89 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] + public void DecodeBaselineJpeg_Orig(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (SkipTest(provider)) + { + return; + } + + // For 32 bit test enviroments: + provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + + using (Image image = provider.GetImage(GolangJpegDecoder)) + { + image.DebugSave(provider); + provider.Utility.TestName = DecodeBaselineJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + + provider.Configuration.MemoryManager.ReleaseRetainedResources(); + } + + [Theory] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] + public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) + { + // skipping to avoid OutOfMemoryException on CI + return; + } + + using (Image image = provider.GetImage(PdfJsJpegDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeBaselineJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + } + + [Theory] + [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] + public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Golang(TestImageProvider provider) + where TPixel : struct, IPixel + { + // TODO: We need a public ImageDecoderException class in ImageSharp! + Assert.ThrowsAny(() => provider.GetImage(GolangJpegDecoder)); + } + + [Theory] + [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] + public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + // TODO: We need a public ImageDecoderException class in ImageSharp! + Assert.ThrowsAny(() => provider.GetImage(PdfJsJpegDecoder)); + } + + [Theory(Skip = "Debug only, enable manually!")] + [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] + public void CompareJpegDecoders_Baseline(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs new file mode 100644 index 000000000..539ab7319 --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Images.cs @@ -0,0 +1,72 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Collections.Generic; + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + public static string[] BaselineTestJpegs = + { + TestImages.Jpeg.Baseline.Calliphora, + TestImages.Jpeg.Baseline.Cmyk, TestImages.Jpeg.Baseline.Ycck, + TestImages.Jpeg.Baseline.Jpeg400, + TestImages.Jpeg.Baseline.Testorig420, + + // BUG: The following image has a high difference compared to the expected output: + // TestImages.Jpeg.Baseline.Jpeg420Small, + + TestImages.Jpeg.Baseline.Jpeg444, + TestImages.Jpeg.Baseline.Bad.BadEOF, + TestImages.Jpeg.Issues.MultiHuffmanBaseline394, + TestImages.Jpeg.Baseline.MultiScanBaselineCMYK, + TestImages.Jpeg.Baseline.Bad.BadRST + }; + + public static string[] ProgressiveTestJpegs = + { + TestImages.Jpeg.Progressive.Fb, + TestImages.Jpeg.Progressive.Progress, + TestImages.Jpeg.Progressive.Festzug, + TestImages.Jpeg.Progressive.Bad.BadEOF, + TestImages.Jpeg.Issues.BadCoeffsProgressive178, + TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, + TestImages.Jpeg.Issues.BadZigZagProgressive385, + TestImages.Jpeg.Progressive.Bad.ExifUndefType, + TestImages.Jpeg.Issues.NoEoiProgressive517, + TestImages.Jpeg.Issues.BadRstProgressive518, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, + }; + + /// + /// Golang decoder is unable to decode these + /// + public static string[] PdfJsOnly = + { + TestImages.Jpeg.Issues.NoEoiProgressive517, TestImages.Jpeg.Issues.BadRstProgressive518, + TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159 + }; + + private static readonly Dictionary CustomToleranceValues = + new Dictionary + { + // Baseline: + [TestImages.Jpeg.Baseline.Calliphora] = 0.00002f / 100, + [TestImages.Jpeg.Baseline.Bad.BadEOF] = 0.38f / 100, + [TestImages.Jpeg.Baseline.Testorig420] = 0.38f / 100, + [TestImages.Jpeg.Baseline.Bad.BadRST] = 0.0589f / 100, + + // Progressive: + [TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159] = 0.34f / 100, + [TestImages.Jpeg.Issues.BadCoeffsProgressive178] = 0.38f / 100, + [TestImages.Jpeg.Progressive.Bad.BadEOF] = 0.3f / 100, + [TestImages.Jpeg.Progressive.Festzug] = 0.02f / 100, + [TestImages.Jpeg.Progressive.Fb] = 0.16f / 100, + [TestImages.Jpeg.Progressive.Progress] = 0.31f / 100, + [TestImages.Jpeg.Issues.BadZigZagProgressive385] = 0.23f / 100, + [TestImages.Jpeg.Progressive.Bad.ExifUndefType] = 0.011f / 100, + }; + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs new file mode 100644 index 000000000..83983691e --- /dev/null +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.Progressive.cs @@ -0,0 +1,81 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using System.Linq; +using SixLabors.ImageSharp.Memory; +using SixLabors.ImageSharp.PixelFormats; +using Xunit; +// ReSharper disable InconsistentNaming + +namespace SixLabors.ImageSharp.Tests.Formats.Jpg +{ + public partial class JpegDecoderTests + { + public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; + + [Theory] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] + public void DecodeProgressiveJpeg_Orig(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) + { + // skipping to avoid OutOfMemoryException on CI + return; + } + + // Golang decoder is unable to decode these: + if (PdfJsOnly.Any(fn => fn.Contains(provider.SourceFileOrDescription))) + { + return; + } + + // For 32 bit test enviroments: + provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); + + using (Image image = provider.GetImage(GolangJpegDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeProgressiveJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + + provider.Configuration.MemoryManager.ReleaseRetainedResources(); + } + + [Theory] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] + public void DecodeProgressiveJpeg_PdfJs(TestImageProvider provider) + where TPixel : struct, IPixel + { + if (SkipTest(provider)) + { + // skipping to avoid OutOfMemoryException on CI + return; + } + + using (Image image = provider.GetImage(PdfJsJpegDecoder)) + { + image.DebugSave(provider); + + provider.Utility.TestName = DecodeProgressiveJpegOutputName; + image.CompareToReferenceOutput( + this.GetImageComparer(provider), + provider, + appendPixelTypeToFileName: false); + } + } + + [Theory(Skip = "Debug only, enable manually!")] + [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] + public void CompareJpegDecoders_Progressive(TestImageProvider provider) + where TPixel : struct, IPixel + { + this.CompareJpegDecodersImpl(provider, DecodeProgressiveJpegOutputName); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs index ae86de59a..cfd5989f5 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs @@ -24,68 +24,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg // TODO: Scatter test cases into multiple test classes public partial class JpegDecoderTests { - public static string[] BaselineTestJpegs = - { - TestImages.Jpeg.Baseline.Calliphora, - TestImages.Jpeg.Baseline.Cmyk, - TestImages.Jpeg.Baseline.Ycck, - TestImages.Jpeg.Baseline.Jpeg400, - TestImages.Jpeg.Baseline.Testorig420, - - // BUG: The following image has a high difference compared to the expected output: - // TestImages.Jpeg.Baseline.Jpeg420Small, - - TestImages.Jpeg.Baseline.Jpeg444, - TestImages.Jpeg.Baseline.Bad.BadEOF, - TestImages.Jpeg.Issues.MultiHuffmanBaseline394, - TestImages.Jpeg.Baseline.MultiScanBaselineCMYK, - TestImages.Jpeg.Baseline.Bad.BadRST - }; - - public static string[] ProgressiveTestJpegs = - { - TestImages.Jpeg.Progressive.Fb, TestImages.Jpeg.Progressive.Progress, - TestImages.Jpeg.Progressive.Festzug, TestImages.Jpeg.Progressive.Bad.BadEOF, - TestImages.Jpeg.Issues.BadCoeffsProgressive178, - TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159, - TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, - TestImages.Jpeg.Issues.BadZigZagProgressive385, - TestImages.Jpeg.Progressive.Bad.ExifUndefType, - - TestImages.Jpeg.Issues.NoEoiProgressive517, - TestImages.Jpeg.Issues.BadRstProgressive518, - TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159, - }; - - /// - /// Golang decoder is unable to decode these - /// - public static string[] PdfJsOnly = - { - TestImages.Jpeg.Issues.NoEoiProgressive517, - TestImages.Jpeg.Issues.BadRstProgressive518, - TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159 - }; - - private static readonly Dictionary CustomToleranceValues = new Dictionary - { - // Baseline: - [TestImages.Jpeg.Baseline.Calliphora] = 0.00002f / 100, - [TestImages.Jpeg.Baseline.Bad.BadEOF] = 0.38f / 100, - [TestImages.Jpeg.Baseline.Testorig420] = 0.38f / 100, - [TestImages.Jpeg.Baseline.Bad.BadRST] = 0.0589f / 100, - - // Progressive: - [TestImages.Jpeg.Issues.MissingFF00ProgressiveGirl159] = 0.34f / 100, - [TestImages.Jpeg.Issues.BadCoeffsProgressive178] = 0.38f / 100, - [TestImages.Jpeg.Progressive.Bad.BadEOF] = 0.3f / 100, - [TestImages.Jpeg.Progressive.Festzug] = 0.02f / 100, - [TestImages.Jpeg.Progressive.Fb] = 0.16f / 100, - [TestImages.Jpeg.Progressive.Progress] = 0.31f / 100, - [TestImages.Jpeg.Issues.BadZigZagProgressive385] = 0.23f / 100, - [TestImages.Jpeg.Progressive.Bad.ExifUndefType] = 0.011f / 100, - }; - public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; private const float BaselineTolerance = 0.001F / 100; @@ -174,132 +112,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg provider.Configuration.MemoryManager.ReleaseRetainedResources(); } - [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_Orig(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(GolangJpegDecoder)) - { - image.DebugSave(provider); - provider.Utility.TestName = DecodeBaselineJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryManager.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeBaselineJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - } - - [Theory] - [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Golang(TestImageProvider provider) - where TPixel : struct, IPixel - { - // TODO: We need a public ImageDecoderException class in ImageSharp! - Assert.ThrowsAny(() => provider.GetImage(GolangJpegDecoder)); - } - - [Theory] - [WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] - public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - // TODO: We need a public ImageDecoderException class in ImageSharp! - Assert.ThrowsAny(() => provider.GetImage(PdfJsJpegDecoder)); - } - - public const string DecodeProgressiveJpegOutputName = "DecodeProgressiveJpeg"; - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_Orig(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - // Golang decoder is unable to decode these: - if (PdfJsOnly.Any(fn => fn.Contains(provider.SourceFileOrDescription))) - { - return; - } - - // For 32 bit test enviroments: - provider.Configuration.MemoryManager = ArrayPoolMemoryManager.CreateWithModeratePooling(); - - using (Image image = provider.GetImage(GolangJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeProgressiveJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - - provider.Configuration.MemoryManager.ReleaseRetainedResources(); - } - - [Theory] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void DecodeProgressiveJpeg_PdfJs(TestImageProvider provider) - where TPixel : struct, IPixel - { - if (SkipTest(provider)) - { - // skipping to avoid OutOfMemoryException on CI - return; - } - - using (Image image = provider.GetImage(PdfJsJpegDecoder)) - { - image.DebugSave(provider); - - provider.Utility.TestName = DecodeProgressiveJpegOutputName; - image.CompareToReferenceOutput( - this.GetImageComparer(provider), - provider, - appendPixelTypeToFileName: false); - } - } - private string GetDifferenceInPercentageString(Image image, TestImageProvider provider) where TPixel : struct, IPixel { @@ -339,50 +151,6 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg } } - [Theory(Skip = "Debug only, enable manually!")] - [WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Baseline(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName); - } - - [Theory(Skip = "Debug only, enable manually!")] - [WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)] - public void CompareJpegDecoders_Progressive(TestImageProvider provider) - where TPixel : struct, IPixel - { - this.CompareJpegDecodersImpl(provider, DecodeProgressiveJpegOutputName); - } - - [Theory] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 75)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 100)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 75)] - [WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] - [WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)] - public void DecodeGenerated( - TestImageProvider provider, - JpegSubsample subsample, - int quality) - where TPixel : struct, IPixel - { - byte[] data; - using (Image image = provider.GetImage()) - { - var encoder = new JpegEncoder { Subsample = subsample, Quality = quality }; - - data = new byte[65536]; - using (var ms = new MemoryStream(data)) - { - image.Save(ms, encoder); - } - } - - var mirror = Image.Load(data, GolangJpegDecoder); - mirror.DebugSave(provider, $"_{subsample}_Q{quality}"); - } - // DEBUG ONLY! // The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm" // into "\tests\Images\ActualOutput\JpegDecoderTests\"