|
|
@ -1,14 +1,7 @@ |
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Copyright (c) Six Labors and contributors.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
{ |
|
|
|
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
@ -21,11 +14,13 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.PixelFormats; |
|
|
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; |
|
|
using SixLabors.ImageSharp.Tests.Formats.Jpg.Utils; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison; |
|
|
using SixLabors.Primitives; |
|
|
|
|
|
|
|
|
|
|
|
using Xunit; |
|
|
using Xunit; |
|
|
using Xunit.Abstractions; |
|
|
using Xunit.Abstractions; |
|
|
|
|
|
|
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
|
namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
{ |
|
|
// TODO: Scatter test cases into multiple test classes
|
|
|
// TODO: Scatter test cases into multiple test classes
|
|
|
public class JpegDecoderTests |
|
|
public class JpegDecoderTests |
|
|
{ |
|
|
{ |
|
|
@ -57,6 +52,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
TestImages.Jpeg.Progressive.Bad.ExifUndefType |
|
|
TestImages.Jpeg.Progressive.Bad.ExifUndefType |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
public static string[] FalsePositiveIssueJpegs = |
|
|
|
|
|
{ |
|
|
|
|
|
TestImages.Jpeg.Issues.NoEOI517, |
|
|
|
|
|
TestImages.Jpeg.Issues.BadRST518, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
private static readonly Dictionary<string, float> CustomToleranceValues = new Dictionary<string, float> |
|
|
private static readonly Dictionary<string, float> CustomToleranceValues = new Dictionary<string, float> |
|
|
{ |
|
|
{ |
|
|
// Baseline:
|
|
|
// Baseline:
|
|
|
@ -78,11 +79,10 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
|
|
|
|
|
|
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; |
|
|
public const PixelTypes CommonNonDefaultPixelTypes = PixelTypes.Rgba32 | PixelTypes.Argb32 | PixelTypes.RgbaVector; |
|
|
|
|
|
|
|
|
private const float BaselineTolerance_Orig = 0.001f / 100; |
|
|
private const float BaselineTolerance_Orig = 0.001F / 100; |
|
|
private const float BaselineTolerance_PdfJs = 0.005f; |
|
|
private const float BaselineTolerance_PdfJs = 0.005F; |
|
|
|
|
|
private const float ProgressiveTolerance_Orig = 0.2F / 100; |
|
|
private const float ProgressiveTolerance_Orig = 0.2f / 100; |
|
|
private const float ProgressiveTolerance_PdfJs = 0.33F / 100; |
|
|
private const float ProgressiveTolerance_PdfJs = 0.33f / 100; |
|
|
|
|
|
|
|
|
|
|
|
private ImageComparer GetImageComparerForOrigDecoder<TPixel>(TestImageProvider<TPixel> provider) |
|
|
private ImageComparer GetImageComparerForOrigDecoder<TPixel>(TestImageProvider<TPixel> provider) |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
@ -158,7 +158,7 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
image.DebugSave(provider); |
|
|
image.DebugSave(provider); |
|
|
|
|
|
|
|
|
provider.Utility.TestName = DecodeBaselineJpegOutputName; |
|
|
provider.Utility.TestName = DecodeBaselineJpegOutputName; |
|
|
image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance_PdfJs), provider, appendPixelTypeToFileName: false); |
|
|
image.CompareToReferenceOutput(ImageComparer.Tolerant(BaselineTolerance_Orig), provider, appendPixelTypeToFileName: false); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
provider.Configuration.MemoryManager.ReleaseRetainedResources(); |
|
|
provider.Configuration.MemoryManager.ReleaseRetainedResources(); |
|
|
@ -213,6 +213,32 @@ namespace SixLabors.ImageSharp.Tests.Formats.Jpg |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Only <see cref="PdfJsJpegDecoder"/> can decode these images.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <typeparam name="TPixel">The pixel format</typeparam>
|
|
|
|
|
|
/// <param name="provider">The test image provider</param>
|
|
|
|
|
|
[Theory] |
|
|
|
|
|
[WithFileCollection(nameof(FalsePositiveIssueJpegs), PixelTypes.Rgba32)] |
|
|
|
|
|
public void DecodeFalsePositiveJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
|
|
{ |
|
|
|
|
|
if (TestEnvironment.RunsOnCI && !TestEnvironment.Is64BitProcess) |
|
|
|
|
|
{ |
|
|
|
|
|
// skipping to avoid OutOfMemoryException on CI
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder)) |
|
|
|
|
|
{ |
|
|
|
|
|
image.DebugSave(provider); |
|
|
|
|
|
image.CompareToReferenceOutput( |
|
|
|
|
|
ImageComparer.Tolerant(BaselineTolerance_Orig), |
|
|
|
|
|
provider, |
|
|
|
|
|
appendPixelTypeToFileName: true); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
[Theory] |
|
|
[Theory] |
|
|
[WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] |
|
|
[WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)] |
|
|
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Orig<TPixel>(TestImageProvider<TPixel> provider) |
|
|
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Orig<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|