diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 86a66eab0..3daeecfc7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.BinaryThreshold(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTests.cs index 7c858babc..0bb45253e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTests.cs @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.Dither(DefaultDitherer, bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } @@ -124,7 +124,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.Dither(DefaultErrorDiffuser, .5F, bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs index d796a62aa..c3250ccfc 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.BlackWhite(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs index cdfbf4abd..122ff5a64 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); image.DebugSave(provider, colorBlindness.ToString()); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index 93c053bdd..ced24f596 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -54,7 +54,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Grayscale(value, bounds)); image.DebugSave(provider, value.ToString()); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs index 1cc146af2..5a1ea16a7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Hue(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs index dec41da54..ebf163ab8 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Kodachrome(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs index 5f662a761..48a58580a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Lomograph(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs index de6642254..2e61e3f02 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Polaroid(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs index 5cbb1ba81..2532a7fe7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Saturation(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs index fbdaee82c..28b1f6256 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Sepia(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index c6150c5ba..94af7aa37 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.BoxBlur(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index b97ab7f60..3508d544b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.GaussianBlur(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 5d9db0b81..4775444a5 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.GaussianSharpen(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs index 66514e540..7f2840f2c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Alpha(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index bea9bfffc..2dd44b3a7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs index 2d039e901..9bfed05b9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Brightness(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs index 8ae054c38..f1e33db88 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Contrast(value, bounds)); image.DebugSave(provider, value); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs index ec93a9211..593023677 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -36,7 +36,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Invert(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index 1a45c6eb5..608fcf10c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); image.DebugSave(provider, string.Join("-", levels, brushSize)); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index ef7cfe0ad..b3f1ee3a2 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects } } - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index 0b0d5e0a2..5693b6d75 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays image.Mutate(x => x.Glow(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index f968b50f9..0d9c3e89b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -60,7 +60,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays image.Mutate(x => x.Vignette(bounds)); image.DebugSave(provider); - ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index ff9756e03..1b6f7a14a 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -43,7 +43,7 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison { result.Add(report); } - + if (expected.Frames.Count != actual.Frames.Count) { throw new Exception("Frame count does not match!"); @@ -82,29 +82,46 @@ namespace SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison } } - /// - /// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith - /// that area is less then a configurable threshold. - /// - /// The color of the expected image - /// The color type fo the the actual image - /// The to use - /// The expected image - /// The actual image - /// The bounds within the image has been altered - public static void EnsureProcessorChangesAreConstrained( + public static void VerifySimilarityIgnoreRegion( this ImageComparer comparer, Image expected, Image actual, - Rectangle bounds) + Rectangle ignoredRegion) where TPixelA : struct, IPixel where TPixelB : struct, IPixel { - // Draw identical shapes over the bounded and compare to ensure changes are constrained. - expected.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); - actual.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); + if (expected.Size() != actual.Size()) + { + throw new ImageDimensionsMismatchException(expected.Size(), actual.Size()); + } + + if (expected.Frames.Count != actual.Frames.Count) + { + throw new ImagesSimilarityException("Image frame count does not match!"); + } - comparer.VerifySimilarity(expected, actual); + IEnumerable reports = comparer.CompareImages(expected, actual); + if (reports.Any()) + { + List cleanedReports = new List(reports.Count()); + foreach (var r in reports) + { + var outsideChanges = r.Differences.Where(x => !( + ignoredRegion.X <= x.Position.X && + x.Position.X <= ignoredRegion.Right && + ignoredRegion.Y <= x.Position.Y && + x.Position.Y <= ignoredRegion.Bottom)); + if (outsideChanges.Any()) + { + cleanedReports.Add(new ImageSimilarityReport(r.ExpectedImage, r.ActualImage, outsideChanges, null)); + } + } + + if (cleanedReports.Any()) + { + throw new ImagePixelsAreDifferentException(cleanedReports); + } + } } } } \ No newline at end of file