Browse Source

lower default tolerance TolerantImageComparer.DefaultImageThreshold for travis

af/merge-core
Anton Firszov 8 years ago
parent
commit
88f2158e9d
  1. 7
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
  2. 21
      tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
  3. 7
      tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
  4. 5
      tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

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

@ -15,8 +15,13 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison
{
public static ImageComparer Exact { get; } = Tolerant(0, 0);
/// <summary>
/// Returns an instance of <see cref="TolerantImageComparer"/>.
/// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'.
/// Negative value for 'imageThreshold' indicates default threshold (see <see cref="TolerantImageComparer.DefaultImageThreshold"/>).
/// </summary>
public static ImageComparer Tolerant(
float imageThreshold = TolerantImageComparer.DefaultImageThreshold,
float imageThreshold = -1,
int perPixelManhattanThreshold = 0)
{
return new TolerantImageComparer(imageThreshold, perPixelManhattanThreshold);

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

@ -12,10 +12,19 @@
public class TolerantImageComparer : ImageComparer
{
public const float DefaultImageThreshold = 1.0f / (100 * 100 * 255);
public static readonly float DefaultImageThreshold = GetDefaultImageThreshold();
/// <summary>
/// Negative value for 'imageThreshold' indicates default threshold (see <see cref="DefaultImageThreshold"/>).
/// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'.
/// </summary>
public TolerantImageComparer(float imageThreshold, int perPixelManhattanThreshold = 0)
{
if (imageThreshold < 0)
{
imageThreshold = DefaultImageThreshold;
}
this.ImageThreshold = imageThreshold;
this.PerPixelManhattanThreshold = perPixelManhattanThreshold;
}
@ -107,5 +116,15 @@
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int Diff(byte a, byte b) => Math.Abs(a - b);
private static float GetDefaultImageThreshold()
{
// 1% of all pixels in a 100*100 pixel area are allowed to have a difference of 1 unit
float t = 1.0f / (100 * 100 * 255);
// but not with Mono System.Drawing!
// TODO: We may need a runtime-specific check here, instead of the OS specific one!
return TestEnvironment.IsWindows ? t : 4 * t;
}
}
}

7
tests/ImageSharp.Tests/TestUtilities/TestUtils.cs

@ -10,6 +10,7 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Tests
{
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
/// <summary>
@ -154,7 +155,8 @@ namespace SixLabors.ImageSharp.Tests
internal static void RunValidatingProcessorTest<TPixel>(
this TestImageProvider<TPixel> provider,
Action<IImageProcessingContext<TPixel>> process,
object testOutputDetails = null)
object testOutputDetails = null,
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
@ -171,7 +173,8 @@ namespace SixLabors.ImageSharp.Tests
internal static void RunRectangleConstrainedValidatingProcessorTest<TPixel>(
this TestImageProvider<TPixel> provider,
Action<IImageProcessingContext<TPixel>, Rectangle> process,
object testOutputDetails = null)
object testOutputDetails = null,
ImageComparer comparer = null)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())

5
tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs

@ -68,7 +68,10 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image<TPixel> clone = image.Clone())
{
ImagingTestCaseUtility.ModifyPixel(clone, 3, 1, 2);
// Mono System.Drawing is trolling us! See TolerantImageComparer.GetDefaultImageThreshold()!
byte tooBigToSucceed = TestEnvironment.IsWindows ? (byte)2 : (byte)6;
ImagingTestCaseUtility.ModifyPixel(clone, 3, 1, tooBigToSucceed);
var comparer = ImageComparer.Tolerant();

Loading…
Cancel
Save