diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
index d23ab0202..d65653016 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs
+++ b/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);
+ ///
+ /// Returns an instance of .
+ /// 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 ).
+ ///
public static ImageComparer Tolerant(
- float imageThreshold = TolerantImageComparer.DefaultImageThreshold,
+ float imageThreshold = -1,
int perPixelManhattanThreshold = 0)
{
return new TolerantImageComparer(imageThreshold, perPixelManhattanThreshold);
diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
index d20bd72ac..db0048558 100644
--- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs
+++ b/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();
+ ///
+ /// Negative value for 'imageThreshold' indicates default threshold (see ).
+ /// Individual manhattan pixel difference is only added to total image difference when the individual difference is over 'perPixelManhattanThreshold'.
+ ///
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;
+ }
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs b/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
index 7ba890e71..83fa9bc71 100644
--- a/tests/ImageSharp.Tests/TestUtilities/TestUtils.cs
+++ b/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;
///
@@ -154,7 +155,8 @@ namespace SixLabors.ImageSharp.Tests
internal static void RunValidatingProcessorTest(
this TestImageProvider provider,
Action> process,
- object testOutputDetails = null)
+ object testOutputDetails = null,
+ ImageComparer comparer = null)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
@@ -171,7 +173,8 @@ namespace SixLabors.ImageSharp.Tests
internal static void RunRectangleConstrainedValidatingProcessorTest(
this TestImageProvider provider,
Action, Rectangle> process,
- object testOutputDetails = null)
+ object testOutputDetails = null,
+ ImageComparer comparer = null)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs
index f131f51f2..59e6ec5fb 100644
--- a/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs
+++ b/tests/ImageSharp.Tests/TestUtilities/Tests/ImageComparerTests.cs
@@ -68,7 +68,10 @@ namespace SixLabors.ImageSharp.Tests
{
using (Image 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();