Browse Source

Add false positive tests for #517 #518

pull/525/head
James Jackson-South 9 years ago
parent
commit
66a2564ea4
  1. 54
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 2
      tests/ImageSharp.Tests/TestImages.cs
  3. 2
      tests/Images/External
  4. BIN
      tests/Images/Input/Jpg/issues/Issue517-No-EOI.jpg
  5. BIN
      tests/Images/Input/Jpg/issues/Issue518-Bad-RST.jpg

54
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -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)

2
tests/ImageSharp.Tests/TestImages.cs

@ -133,6 +133,8 @@ namespace SixLabors.ImageSharp.Tests
public const string BadCoeffsProgressive178 = "Jpg/issues/Issue178-BadCoeffsProgressive-Lemon.jpg"; public const string BadCoeffsProgressive178 = "Jpg/issues/Issue178-BadCoeffsProgressive-Lemon.jpg";
public const string BadZigZagProgressive385 = "Jpg/issues/Issue385-BadZigZag-Progressive.jpg"; public const string BadZigZagProgressive385 = "Jpg/issues/Issue385-BadZigZag-Progressive.jpg";
public const string MultiHuffmanBaseline394 = "Jpg/issues/Issue394-MultiHuffmanBaseline-Speakers.jpg"; public const string MultiHuffmanBaseline394 = "Jpg/issues/Issue394-MultiHuffmanBaseline-Speakers.jpg";
public const string NoEOI517 = "Jpg/issues/Issue517-No-EOI.jpg";
public const string BadRST518 = "Jpg/issues/Issue518-Bad-RST.jpg";
} }
public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray(); public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();

2
tests/Images/External

@ -1 +1 @@
Subproject commit 5a66c9c6da02bf27345f90adc05d415c0d0450ea Subproject commit 818afb087aa0e651a885f45401fd66903b7420d4

BIN
tests/Images/Input/Jpg/issues/Issue517-No-EOI.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 MiB

BIN
tests/Images/Input/Jpg/issues/Issue518-Bad-RST.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 MiB

Loading…
Cancel
Save