Skip to content

Commit

Permalink
refactor jpeg tests + add another test image for #159
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed May 15, 2018
1 parent 4e47a08 commit 6ca57aa
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
62 changes: 23 additions & 39 deletions tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,23 @@ public partial class JpegDecoderTests
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.Progressive.Bad.ExifUndefType,

TestImages.Jpeg.Issues.NoEoiProgressive517,
TestImages.Jpeg.Issues.BadRstProgressive518,
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159,
};

public static string[] FalsePositiveIssueJpegs =
/// <summary>
/// Golang decoder is unable to decode these
/// </summary>
public static string[] PdfJsOnly =
{
TestImages.Jpeg.Issues.NoEOI517,
TestImages.Jpeg.Issues.BadRST518,
TestImages.Jpeg.Issues.NoEoiProgressive517,
TestImages.Jpeg.Issues.BadRstProgressive518,
TestImages.Jpeg.Issues.MissingFF00ProgressiveBedroom159
};

private static readonly Dictionary<string, float> CustomToleranceValues = new Dictionary<string, float>
Expand Down Expand Up @@ -213,33 +222,7 @@ public void DecodeBaselineJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provider)
appendPixelTypeToFileName: false);
}
}

/// <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),
provider,
appendPixelTypeToFileName: true);
}
}


[Theory]
[WithFile(TestImages.Jpeg.Issues.CriticalEOF214, PixelTypes.Rgba32)]
public void DecodeBaselineJpeg_CriticalEOF_ShouldThrow_Golang<TPixel>(TestImageProvider<TPixel> provider)
Expand Down Expand Up @@ -271,6 +254,12 @@ public void DecodeProgressiveJpeg_Orig<TPixel>(TestImageProvider<TPixel> provide
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();

Expand Down Expand Up @@ -298,7 +287,7 @@ public void DecodeProgressiveJpeg_PdfJs<TPixel>(TestImageProvider<TPixel> provid
// skipping to avoid OutOfMemoryException on CI
return;
}

using (Image<TPixel> image = provider.GetImage(PdfJsJpegDecoder))
{
image.DebugSave(provider);
Expand Down Expand Up @@ -333,11 +322,6 @@ private string GetDifferenceInPercentageString<TPixel>(Image<TPixel> image, Test
private void CompareJpegDecodersImpl<TPixel>(TestImageProvider<TPixel> provider, string testName)
where TPixel : struct, IPixel<TPixel>
{
if (TestEnvironment.RunsOnCI) // Debug only test
{
return;
}

this.Output.WriteLine(provider.SourceFileOrDescription);
provider.Utility.TestName = testName;

Expand All @@ -355,15 +339,15 @@ private void CompareJpegDecodersImpl<TPixel>(TestImageProvider<TPixel> provider,
}
}

[Theory]
[Theory(Skip = "Debug only, enable manually!")]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32)]
public void CompareJpegDecoders_Baseline<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
this.CompareJpegDecodersImpl(provider, DecodeBaselineJpegOutputName);
}

[Theory]
[Theory(Skip = "Debug only, enable manually!")]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32)]
public void CompareJpegDecoders_Progressive<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
Expand Down
5 changes: 3 additions & 2 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ public class Issues
{
public const string CriticalEOF214 = "Jpg/issues/Issue214-CriticalEOF.jpg";
public const string MissingFF00ProgressiveGirl159 = "Jpg/issues/Issue159-MissingFF00-Progressive-Girl.jpg";
public const string MissingFF00ProgressiveBedroom159 = "Jpg/issues/Issue159-MissingFF00-Progressive-Bedroom.jpg";
public const string BadCoeffsProgressive178 = "Jpg/issues/Issue178-BadCoeffsProgressive-Lemon.jpg";
public const string BadZigZagProgressive385 = "Jpg/issues/Issue385-BadZigZag-Progressive.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 const string NoEoiProgressive517 = "Jpg/issues/Issue517-No-EOI-Progressive.jpg";
public const string BadRstProgressive518 = "Jpg/issues/Issue518-Bad-RST-Progressive.jpg";
}

public static readonly string[] All = Baseline.All.Concat(Progressive.All).ToArray();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ca57aa

Please sign in to comment.