Browse Source

optimized the number of test cases in JpegDecoderTests

af/merge-core
Anton Firszov 9 years ago
parent
commit
ce14310922
  1. 28
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  2. 4
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  3. 8
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  4. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

28
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, bool useOldDecoder)
where TPixel : struct, IPixel<TPixel>
{
IImageDecoder decoder = useOldDecoder ? OldJpegDecoder : PdfJsJpegDecoder;
using (Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixelA, TPixelB>(

8
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;
}
/// <summary>
@ -36,7 +36,7 @@
/// The threshold of the individual pixels before they acumulate towards the overall difference.
/// For an individual <see cref="Rgba32"/> pixel the value it's calculated as: pixel.R + pixel.G + pixel.B + pixel.A
/// </summary>
public int PixelThresholdInPixelByteSum { get; }
public int PixelThresholdHammingDistance { get; }
public override ImageSimilarityReport CompareImagesOrFrames<TPixelA, TPixelB>(ImageBase<TPixelA> expected, ImageBase<TPixelB> 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);

2
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);
}
}

Loading…
Cancel
Save