Browse Source

PngDecoder is covered now, and proven to be buggy :P

pull/298/head
Anton Firszov 9 years ago
parent
commit
02eb5f2f13
  1. 12
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  2. 1
      tests/ImageSharp.Tests/TestImages.cs
  3. 2
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  4. 4
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  5. 2
      tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs
  6. 14
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  7. BIN
      tests/Images/Input/Png/SnakeGame.png

12
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -12,6 +12,8 @@ using Xunit;
namespace ImageSharp.Tests
{
using ImageSharp.Tests.TestUtilities.ImageComparison;
public class PngDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
@ -19,17 +21,19 @@ namespace ImageSharp.Tests
public static readonly string[] TestFiles =
{
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar,
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp, TestImages.Png.Rgb48BppInterlaced
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2, TestImages.Png.Rgb48Bpp,
TestImages.Png.Rgb48BppInterlaced, TestImages.Png.SnakeGame
};
[Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)]
public void Decode<TPixel>(TestImageProvider<TPixel> imageProvider)
public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = imageProvider.GetImage())
using (Image<TPixel> image = provider.GetImage(new PngDecoder()))
{
image.DebugSave(imageProvider);
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
}

1
tests/ImageSharp.Tests/TestImages.cs

@ -31,6 +31,7 @@ namespace ImageSharp.Tests
public const string Bike = "Png/Bike.png";
public const string BikeGrayscale = "Png/BikeGrayscale.png";
public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.png";
public const string SnakeGame = "Png/SnakeGame.png";
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public const string Filter0 = "Png/filter0.png";

2
tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs

@ -10,7 +10,7 @@ namespace ImageSharp.Tests.TestUtilities.ImageComparison
public abstract class ImageComparer
{
public static ImageComparer Exact { get; } = ExactImageComparer.Instance;
public static ImageComparer Exact { get; } = Tolerant(0, 0);
public static ImageComparer Tolerant(
float imageThreshold = TolerantImageComparer.DefaultImageThreshold,

4
tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs

@ -66,7 +66,7 @@
for (int x = 0; x < width; x++)
{
int d = GetDifferenceInPixelByteSum(ref aBuffer[x], ref bBuffer[x]);
int d = GetHammingDistanceInRgbaSpace(ref aBuffer[x], ref bBuffer[x]);
if (d > this.PixelThresholdInPixelByteSum)
{
@ -92,7 +92,7 @@
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int GetDifferenceInPixelByteSum(ref Rgba32 a, ref Rgba32 b)
private static int GetHammingDistanceInRgbaSpace(ref Rgba32 a, ref Rgba32 b)
{
return Diff(a.R, b.R) + Diff(a.G, b.G) + Diff(a.B, b.B) + Diff(a.A, b.A);
}

2
tests/ImageSharp.Tests/TestUtilities/TestEnvironment.cs

@ -119,7 +119,7 @@ namespace ImageSharp.Tests
return Configuration.FindEncoder(format);
}
private static IImageFormat GetImageFormat(string filePath)
internal static IImageFormat GetImageFormat(string filePath)
{
string extension = Path.GetExtension(filePath).ToLower();
if (extension[0] == '.') extension = extension.Substring(1);

14
tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

@ -7,7 +7,9 @@ namespace ImageSharp.Tests
{
using System;
using System.IO;
using System.Linq;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
using ImageSharp.Tests.TestUtilities.ImageComparison;
using ImageSharp.Tests.TestUtilities.ReferenceCodecs;
@ -137,9 +139,17 @@ namespace ImageSharp.Tests
var testFile = TestFile.Create(path);
using (var original = Image.Load<TPixel>(testFile.Bytes, SystemDrawingReferenceDecoder.Instance))
IImageDecoder referenceDecoder = TestEnvironment.GetReferenceDecoder(path);
IImageFormat format = TestEnvironment.GetImageFormat(path);
IImageDecoder defaultDecoder = Configuration.Default.FindDecoder(format);
if (referenceDecoder.GetType() == defaultDecoder.GetType())
{
throw new InvalidOperationException($"Can't use CompareToOriginal(): no actual reference decoder registered for {format.Name}");
}
using (var original = Image.Load<TPixel>(testFile.Bytes, referenceDecoder))
{
//original.DebugSave(provider, "__SYSTEMDRAWING__");
comparer.VerifySimilarity(original, image);
}

BIN
tests/Images/Input/Png/SnakeGame.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Loading…
Cancel
Save