Browse Source

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

af/merge-core
Anton Firszov 9 years ago
parent
commit
ad766e6d2c
  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. 3
      tests/Images/Input/Png/SnakeGame.png

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

@ -12,6 +12,8 @@ using Xunit;
namespace ImageSharp.Tests namespace ImageSharp.Tests
{ {
using ImageSharp.Tests.TestUtilities.ImageComparison;
public class PngDecoderTests public class PngDecoderTests
{ {
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32; 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 = public static readonly string[] TestFiles =
{ {
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar, 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] [Theory]
[WithFileCollection(nameof(TestFiles), PixelTypes)] [WithFileCollection(nameof(TestFiles), PixelTypes)]
public void Decode<TPixel>(TestImageProvider<TPixel> imageProvider) public void Decode<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> 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 Bike = "Png/Bike.png";
public const string BikeGrayscale = "Png/BikeGrayscale.png"; public const string BikeGrayscale = "Png/BikeGrayscale.png";
public const string Rgb48BppInterlaced = "Png/rgb-48bpp-interlaced.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 // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
public const string Filter0 = "Png/filter0.png"; 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 abstract class ImageComparer
{ {
public static ImageComparer Exact { get; } = ExactImageComparer.Instance; public static ImageComparer Exact { get; } = Tolerant(0, 0);
public static ImageComparer Tolerant( public static ImageComparer Tolerant(
float imageThreshold = TolerantImageComparer.DefaultImageThreshold, float imageThreshold = TolerantImageComparer.DefaultImageThreshold,

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

@ -66,7 +66,7 @@
for (int x = 0; x < width; x++) 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) if (d > this.PixelThresholdInPixelByteSum)
{ {
@ -92,7 +92,7 @@
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [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); 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); return Configuration.FindEncoder(format);
} }
private static IImageFormat GetImageFormat(string filePath) internal static IImageFormat GetImageFormat(string filePath)
{ {
string extension = Path.GetExtension(filePath).ToLower(); string extension = Path.GetExtension(filePath).ToLower();
if (extension[0] == '.') extension = extension.Substring(1); 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;
using System.IO; using System.IO;
using System.Linq;
using ImageSharp.Formats;
using ImageSharp.PixelFormats; using ImageSharp.PixelFormats;
using ImageSharp.Tests.TestUtilities.ImageComparison; using ImageSharp.Tests.TestUtilities.ImageComparison;
using ImageSharp.Tests.TestUtilities.ReferenceCodecs; using ImageSharp.Tests.TestUtilities.ReferenceCodecs;
@ -137,9 +139,17 @@ namespace ImageSharp.Tests
var testFile = TestFile.Create(path); 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); comparer.VerifySimilarity(original, image);
} }

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

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:b6d874f98a08647047ecfc015b39f035ff863713699263251114690be6283a2d
size 6958
Loading…
Cancel
Save