Browse Source

ReferenceOutput + ResizeTests prototype

pull/298/head
Anton Firszov 9 years ago
parent
commit
24433e999f
  1. 6
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  2. 13
      tests/ImageSharp.Tests/ImageComparer.cs
  3. 2
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs
  4. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Bicubic.png
  5. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Box.png
  6. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Hermite.png
  7. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos3.png
  8. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos5.png
  9. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos8.png
  10. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_MitchellNetravali.png
  11. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_NearestNeighbor.png
  12. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Robidoux.png
  13. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_RobidouxSharp.png
  14. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Spline.png
  15. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Triangle.png
  16. BIN
      tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Welch.png
  17. 3
      tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs
  18. 5
      tests/ImageSharp.Tests/TestUtilities/Integration/IntegrationTestUtils.cs
  19. 40
      tests/ImageSharp.Tests/TestUtilities/Integration/ReferenceDecoder.cs
  20. 31
      tests/ImageSharp.Tests/TestUtilities/Integration/ReferencePngDecoder.cs
  21. 57
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs
  22. 2
      tests/ImageSharp.Tests/TestUtilities/Tests/IntegrationTestUtilsTests.cs

6
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -35,7 +35,7 @@ namespace ImageSharp.Tests.Formats.Png
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.CheckSimilarity(image, img2);
ImageComparer.VerifySimilarity(image, img2);
}
}
}
@ -56,7 +56,7 @@ namespace ImageSharp.Tests.Formats.Png
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{
// img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder());
ImageComparer.CheckSimilarity(image, img2, 0.03f);
ImageComparer.VerifySimilarity(image, img2, 0.03f);
}
}
}
@ -121,7 +121,7 @@ namespace ImageSharp.Tests.Formats.Png
ms.Position = 0;
using (Image<Rgba32> img2 = Image.Load<Rgba32>(ms, new PngDecoder()))
{
ImageComparer.CheckSimilarity(image, img2);
ImageComparer.VerifySimilarity(image, img2);
}
}
}

13
tests/ImageSharp.Tests/ImageComparer.cs

@ -17,9 +17,9 @@ namespace ImageSharp.Tests
/// </summary>
public static class ImageComparer
{
const int DefaultScalingFactor = 32; // This is means the images get scaled into a 32x32 image to sample pixels
const int DefaultSegmentThreshold = 3; // The greyscale difference between 2 segements my be > 3 before it influences the overall difference
const float DefaultImageThreshold = 0.000F; // After segment thresholds the images must have no differences
internal const int DefaultScalingFactor = 32; // This is means the images get scaled into a 32x32 image to sample pixels
internal const int DefaultSegmentThreshold = 3; // The greyscale difference between 2 segements my be > 3 before it influences the overall difference
internal const float DefaultImageThreshold = 0.000F; // After segment thresholds the images must have no differences
/// <summary>
/// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith
@ -50,7 +50,7 @@ namespace ImageSharp.Tests
expected.Fill(NamedColors<TPixelA>.HotPink, bounds);
actual.Fill(NamedColors<TPixelB>.HotPink, bounds);
CheckSimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor);
VerifySimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor);
}
/// <summary>
@ -72,7 +72,7 @@ namespace ImageSharp.Tests
/// This is a sampling factor we sample a grid of average pixels <paramref name="scalingFactor"/> width by <paramref name="scalingFactor"/> high
/// The default undefined value is <see cref="DefaultScalingFactor"/>
/// </param>
public static void CheckSimilarity<TPixelA, TPixelB>(
public static void VerifySimilarity<TPixelA, TPixelB>(
Image<TPixelA> expected,
Image<TPixelB> actual,
float imageTheshold = DefaultImageThreshold,
@ -80,6 +80,9 @@ namespace ImageSharp.Tests
int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA> where TPixelB : struct, IPixel<TPixelB>
{
Assert.Equal(expected.Width, actual.Width);
Assert.Equal(expected.Height, actual.Height);
float percentage = expected.PercentageDifference(actual, segmentThreshold, scalingFactor);
Assert.InRange(percentage, 0, imageTheshold);

2
tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

@ -40,7 +40,7 @@ namespace ImageSharp.Tests.Processing.Transforms
using (Image<TPixel> image = provider.GetImage())
{
image.Resize(image.Width / 2, image.Height / 2, sampler, true)
.DebugSave(provider, name, Extensions.Bmp);
.CompareToReferenceOutput(provider, name);
}
}

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Bicubic.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 437 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Box.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 440 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Hermite.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 421 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos3.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 448 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos5.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Lanczos8.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 458 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_MitchellNetravali.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_NearestNeighbor.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Robidoux.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 417 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_RobidouxSharp.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Spline.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 381 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Triangle.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 408 KiB

BIN
tests/ImageSharp.Tests/ReferenceOutput/ResizeTests/ImageShouldResize_Rgba32_Calliphora_Welch.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 450 KiB

3
tests/ImageSharp.Tests/TestUtilities/ImagingTestCaseUtility.cs

@ -112,6 +112,9 @@ namespace ImageSharp.Tests
}
}
internal string GetReferenceOutputFileName(string extension = null, string tag = null)
=> this.GetTestOutputFileName(extension, tag).Replace("TestOutput", "ReferenceOutput");
internal void Init(string typeName, string methodName)
{
this.TestGroupName = typeName;

5
tests/ImageSharp.Tests/TestUtilities/Integration/IntegrationTestUtils.cs

@ -57,6 +57,11 @@
var fullRect = new System.Drawing.Rectangle(0, 0, w, h);
if (bmp.PixelFormat != PixelFormat.Format32bppArgb)
{
throw new ArgumentException("FromSystemDrawingBitmap(): pixel format not supported", nameof(bmp));
}
BitmapData data = bmp.LockBits(fullRect, ImageLockMode.ReadWrite, bmp.PixelFormat);
byte* sourcePtrBase = (byte*)data.Scan0;

40
tests/ImageSharp.Tests/TestUtilities/Integration/ReferenceDecoder.cs

@ -0,0 +1,40 @@
namespace ImageSharp.Tests.TestUtilities.Integration
{
using System;
using System.Drawing;
using System.IO;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class ReferenceDecoder : IImageDecoder
{
public static ReferenceDecoder Instance { get; } = new ReferenceDecoder();
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
using (var sourceBitmap = new System.Drawing.Bitmap(stream))
{
if (sourceBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
{
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(sourceBitmap);
}
using (var convertedBitmap = new System.Drawing.Bitmap(
sourceBitmap.Width,
sourceBitmap.Height,
System.Drawing.Imaging.PixelFormat.Format32bppArgb))
{
using (var g = Graphics.FromImage(convertedBitmap))
{
g.DrawImage(sourceBitmap, new PointF(0, 0));
}
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(convertedBitmap);
}
}
}
}
}

31
tests/ImageSharp.Tests/TestUtilities/Integration/ReferencePngDecoder.cs

@ -1,31 +0,0 @@
namespace ImageSharp.Tests.TestUtilities.Integration
{
using System;
using System.IO;
using ImageSharp.Formats;
using ImageSharp.PixelFormats;
public class ReferencePngDecoder : IImageDecoder
{
public static ReferencePngDecoder Instance { get; } = new ReferencePngDecoder();
public Image<TPixel> Decode<TPixel>(Configuration configuration, Stream stream, IDecoderOptions options)
where TPixel : struct, IPixel<TPixel>
{
using (var sdBitmap = new System.Drawing.Bitmap(stream))
{
if (!sdBitmap.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png))
{
throw new Exception("Reference image should be a Png!");
}
if (sdBitmap.PixelFormat != System.Drawing.Imaging.PixelFormat.Format32bppArgb)
{
throw new Exception("Reference image pixel format should be PixelFormat.Format32bppArgb!");
}
return IntegrationTestUtils.FromSystemDrawingBitmap<TPixel>(sdBitmap);
}
}
}
}

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

@ -7,10 +7,12 @@ namespace ImageSharp.Tests
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using ImageSharp.PixelFormats;
using ImageSharp.Tests.TestUtilities.Integration;
public static class TestImageExtensions
{
@ -57,5 +59,60 @@ namespace ImageSharp.Tests
provider.Utility.SaveTestOutputFile(image, extension, tag: tag);
return image;
}
public static Image<TPixel> CompareToReferenceOutput<TPixel>(
this Image<TPixel> image,
ITestImageProvider provider,
object settings = null,
string extension = "png",
float imageTheshold = ImageComparer.DefaultImageThreshold,
byte segmentThreshold = ImageComparer.DefaultSegmentThreshold,
int scalingFactor = ImageComparer.DefaultScalingFactor)
where TPixel : struct, IPixel<TPixel>
{
// We are running locally then we want to save it out
string tag = null;
string s = settings as string;
if (s != null)
{
tag = s;
}
else if (settings != null)
{
Type type = settings.GetType();
TypeInfo info = type.GetTypeInfo();
if (info.IsPrimitive || info.IsEnum || type == typeof(decimal))
{
tag = settings.ToString();
}
else
{
IEnumerable<PropertyInfo> properties = settings.GetType().GetRuntimeProperties();
tag = string.Join("_", properties.ToDictionary(x => x.Name, x => x.GetValue(settings)).Select(x => $"{x.Key}-{x.Value}"));
}
}
string referenceOutputFile = provider.Utility.GetReferenceOutputFileName(extension, tag);
if (!(bool.TryParse(Environment.GetEnvironmentVariable("CI"), out bool isCi) && isCi))
{
provider.Utility.SaveTestOutputFile(image, extension, tag: tag);
}
if (!File.Exists(referenceOutputFile))
{
throw new Exception("Reference output file missing: " + referenceOutputFile);
}
using (Image<Rgba32> referenceImage = Image.Load<Rgba32>(referenceOutputFile, ReferenceDecoder.Instance))
{
ImageComparer.VerifySimilarity(referenceImage, image, imageTheshold, segmentThreshold, scalingFactor);
}
return image;
}
}
}

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

@ -52,7 +52,7 @@ namespace ImageSharp.Tests
where TPixel : struct, IPixel<TPixel>
{
string path = TestFile.GetPath(TestImages.Png.Splash);
using (Image<TPixel> image = Image.Load<TPixel>(path, ReferencePngDecoder.Instance))
using (Image<TPixel> image = Image.Load<TPixel>(path, ReferenceDecoder.Instance))
{
image.DebugSave(dummyProvider);
}

Loading…
Cancel
Save