From f9cd6b63646d5fa16bbcd29877009599b9a7154e Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Tue, 15 Aug 2017 20:08:09 +0200 Subject: [PATCH] replaced old comparer everywhere --- .../Formats/Png/PngSmokeTests.cs | 3 +- .../Binarization/BinaryThresholdTest.cs | 2 +- .../Processors/Binarization/DitherTest.cs | 4 +- .../Processors/ColorMatrix/BlackWhiteTest.cs | 2 +- .../ColorMatrix/ColorBlindnessTest.cs | 2 +- .../Processors/ColorMatrix/GrayscaleTest.cs | 2 +- .../Processors/ColorMatrix/HueTest.cs | 2 +- .../Processors/ColorMatrix/KodachromeTest.cs | 2 +- .../Processors/ColorMatrix/LomographTest.cs | 2 +- .../Processors/ColorMatrix/PolaroidTest.cs | 2 +- .../Processors/ColorMatrix/SaturationTest.cs | 2 +- .../Processors/ColorMatrix/SepiaTest.cs | 2 +- .../Processors/Convolution/BoxBlurTest.cs | 2 +- .../Processors/Convolution/DetectEdgesTest.cs | 2 +- .../Convolution/GaussianBlurTest.cs | 2 +- .../Convolution/GaussianSharpenTest.cs | 2 +- .../Processors/Effects/AlphaTest.cs | 2 +- .../Processors/Effects/BackgroundColorTest.cs | 2 +- .../Processors/Effects/BrightnessTest.cs | 2 +- .../Processors/Effects/ContrastTest.cs | 2 +- .../Processors/Effects/InvertTest.cs | 2 +- .../Processors/Effects/OilPaintTest.cs | 2 +- .../Processors/Effects/PixelateTest.cs | 2 +- .../Processors/Overlays/GlowTest.cs | 2 +- .../Processors/Overlays/VignetteTest.cs | 2 +- .../ImageComparison/ImageComparer.cs | 29 ++- .../PercentageImageComparer_Old.cs | 224 ------------------ .../ImageComparison/TolerantImageComparer.cs | 6 +- 28 files changed, 57 insertions(+), 255 deletions(-) delete mode 100644 tests/ImageSharp.Tests/TestUtilities/ImageComparison/PercentageImageComparer_Old.cs diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index c60712dd3..a2944fb98 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -37,7 +37,6 @@ namespace ImageSharp.Tests.Formats.Png { ImageComparer.Tolerant().VerifySimilarity(image, img2); // img2.Save(provider.Utility.GetTestOutputFileName("bmp", "_loaded"), new BmpEncoder()); - PercentageImageComparer_Old.VerifySimilarity(image, img2); } } } @@ -123,7 +122,7 @@ namespace ImageSharp.Tests.Formats.Png ms.Position = 0; using (Image img2 = Image.Load(ms, new PngDecoder())) { - PercentageImageComparer_Old.VerifySimilarity(image, img2); + ImageComparer.Tolerant().VerifySimilarity(image, img2); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 353dbb917..1e3bf3740 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -46,7 +46,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.BinaryThreshold(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs index 8cfd1195f..fa1e2f1a7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs @@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.Dither(ditherer, bounds)); image.DebugSave(provider, name); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization image.Mutate(x => x.Dither(diffuser, .5F, bounds)); image.DebugSave(provider, name); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs index e91c9b98a..61827d08d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.BlackWhite(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs index 0d295f683..a236f3099 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); image.DebugSave(provider, colorBlindness.ToString()); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index f32012653..6e41badf2 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -56,7 +56,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Grayscale(value, bounds)); image.DebugSave(provider, value.ToString()); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs index 8aaf4fd5c..6d9c297b4 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Hue(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs index 77b23902f..6cefe2e44 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Kodachrome(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs index a27d761cc..45f7d186a 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -40,7 +40,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Lomograph(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs index 06d27c0c2..5b7137af6 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Polaroid(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs index 7ab55662a..e5a8939e4 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Saturation(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs index c3e9fe6dd..b117e4a04 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix image.Mutate(x => x.Sepia(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index 7847a6fc0..313a0231c 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.BoxBlur(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 1ccecd33c..b303ef7f4 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -58,7 +58,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution image.DebugSave(provider, grayscale: true); // TODO: We don't need this any longer after switching to ReferenceImages - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 3a8882ee4..f58b5857e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.GaussianBlur(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 61df672ce..9537d1a97 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution image.Mutate(x => x.GaussianSharpen(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs index e67a6dd67..721e11890 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Alpha(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index 29da7b625..ee58d5bfb 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs index 7c7160f9a..c0a127501 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Brightness(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); ; + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs index f6f8fa5f8..b95902b37 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Contrast(value, bounds)); image.DebugSave(provider, value); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs index 6a7bd0a36..daf526747 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.Invert(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index b1528e8ac..eb7652d9f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); image.DebugSave(provider, string.Join("-", levels, brushSize)); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index cbeb53823..a26d940e8 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -79,7 +79,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects } } - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index 05a287a0e..6288ced1f 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays image.Mutate(x => x.Glow(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index 656bf9554..b7f1d3b7e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays image.Mutate(x => x.Vignette(bounds)); image.DebugSave(provider); - PercentageImageComparer_Old.EnsureProcessorChangesAreConstrained(source, image, bounds); + ImageComparer.Tolerant().EnsureProcessorChangesAreConstrained(source, image, bounds); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs index d2781ca70..b13905ef5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/ImageComparer.cs @@ -13,10 +13,10 @@ namespace ImageSharp.Tests.TestUtilities.ImageComparison public static ImageComparer Exact { get; } = ExactImageComparer.Instance; public static ImageComparer Tolerant( - float imageThresholdInPercents = 0.01f, + float imageThreshold = TolerantImageComparer.DefaultImageThreshold, int pixelThresholdInPixelByteSum = 0) { - return new TolerantImageComparer(imageThresholdInPercents, pixelThresholdInPixelByteSum); + return new TolerantImageComparer(imageThreshold, pixelThresholdInPixelByteSum); } public abstract ImageSimilarityReport CompareImagesOrFrames( @@ -78,5 +78,30 @@ namespace ImageSharp.Tests.TestUtilities.ImageComparison throw new ImagePixelsAreDifferentException(reports); } } + + /// + /// 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( + this ImageComparer comparer, + Image expected, + Image actual, + Rectangle bounds) + 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)); + + comparer.VerifySimilarity(expected, actual); + } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PercentageImageComparer_Old.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PercentageImageComparer_Old.cs deleted file mode 100644 index 85a78f804..000000000 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/PercentageImageComparer_Old.cs +++ /dev/null @@ -1,224 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests.TestUtilities.ImageComparison -{ - using System; - - using ImageSharp.Memory; - using ImageSharp.PixelFormats; - - using SixLabors.Primitives; - - /// - /// Class to perform simple image comparisons. - /// - public class PercentageImageComparer_Old : ImageComparer - { - public float ImageThreshold { get; } - - public byte SegmentThreshold { get; } - - public int ScaleIntoSize { get; } - - - public PercentageImageComparer_Old( - float imageThreshold = DefaultImageThreshold, - byte segmentThreshold = DefaultSegmentThreshold, - int scaleIntoSize = DefaultScaleIntoSize) - { - this.ImageThreshold = imageThreshold; - this.SegmentThreshold = segmentThreshold; - this.ScaleIntoSize = scaleIntoSize; - } - - /// - /// This is means the images get scaled into a 32x32 image to sample pixels - /// - public const int DefaultScaleIntoSize = 32; - - /// - /// The greyscale difference between 2 segements my be > 3 before it influences the overall difference - /// - public const int DefaultSegmentThreshold = 3; - - /// - /// After segment thresholds the images must have no differences - /// - public const float DefaultImageThreshold = 0.000F; - - /// - /// 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 expected image - /// The actual image - /// The bounds within the image has been altered - /// - /// The threshold for the percentage difference where the images are asumed to be the same. - /// The default/undefined value is - /// - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - public static void EnsureProcessorChangesAreConstrained( - Image expected, - Image actual, - Rectangle bounds, - float imageTheshold = DefaultImageThreshold, - byte segmentThreshold = DefaultSegmentThreshold, - int scaleIntoSize = DefaultScaleIntoSize) - 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)); - - VerifySimilarity(expected, actual, imageTheshold, segmentThreshold, scaleIntoSize); - } - - /// - /// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold - /// - /// The color of the expected image - /// The color type fo the the actual image - /// The expected image - /// The actual image - /// - /// The threshold for the percentage difference where the images are asumed to be the same. - /// The default/undefined value is - /// - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - public static void VerifySimilarity( - Image expected, - Image actual, - float imageTheshold = DefaultImageThreshold, - byte segmentThreshold = DefaultSegmentThreshold, - int scaleIntoSize = DefaultScaleIntoSize) - where TPixelA : struct, IPixel where TPixelB : struct, IPixel - { - var comparer = new PercentageImageComparer_Old(imageTheshold, segmentThreshold, scaleIntoSize); - comparer.CompareImages(expected, actual); - } - - /// - /// Does a visual comparison between 2 images and then and returns the percentage diffence between the 2 - /// - /// The color of the source image - /// The color type for the target image - /// The source image - /// The target image - /// - /// The threshold of the individual segments before it acumulates towards the overall difference. - /// The default undefined value is - /// - /// - /// This is a sampling factor we sample a grid of average pixels width by high - /// The default undefined value is - /// - /// Returns a number from 0 - 1 which represents the difference focter between the images. - public static float PercentageDifference( - Image source, - Image target, - byte segmentThreshold = DefaultSegmentThreshold, - int scalingFactor = DefaultScaleIntoSize) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - // code adapted from https://www.codeproject.com/Articles/374386/Simple-image-comparison-in-NET - Fast2DArray differences = GetDifferences(source, target, scalingFactor); - - int diffPixels = 0; - - foreach (byte b in differences.Data) - { - if (b > segmentThreshold) { diffPixels++; } - } - - return diffPixels / (float)(scalingFactor * scalingFactor); - } - - private static Fast2DArray GetDifferences(Image source, Image target, int scalingFactor) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - var differences = new Fast2DArray(scalingFactor, scalingFactor); - Fast2DArray firstGray = GetGrayScaleValues(source, scalingFactor); - Fast2DArray secondGray = GetGrayScaleValues(target, scalingFactor); - - for (int y = 0; y < scalingFactor; y++) - { - for (int x = 0; x < scalingFactor; x++) - { - int diff = firstGray[x, y] - secondGray[x, y]; - differences[x, y] = (byte)Math.Abs(diff); - } - } - - return differences; - } - - private static Fast2DArray GetGrayScaleValues(Image source, int scalingFactor) - where TPixelA : struct, IPixel - { - byte[] buffer = new byte[3]; - using (Image img = source.Clone(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) - { - using (PixelAccessor pixels = img.Lock()) - { - var grayScale = new Fast2DArray(scalingFactor, scalingFactor); - for (int y = 0; y < scalingFactor; y++) - { - for (int x = 0; x < scalingFactor; x++) - { - pixels[x, y].ToXyzBytes(buffer, 0); - grayScale[x, y] = buffer[0]; - } - } - - return grayScale; - } - } - } - - public override ImageSimilarityReport CompareImagesOrFrames(ImageBase expected, ImageBase actual) - { - throw new NotImplementedException(); - } - - public void CompareImages(Image expected, Image actual) - where TPixelA : struct, IPixel - where TPixelB : struct, IPixel - { - if (expected.Size() != actual.Size()) - { - throw new ImageDimensionsMismatchException(expected.Size(), actual.Size()); - } - - float percentage = PercentageDifference(expected, actual, this.SegmentThreshold, this.ScaleIntoSize); - - if (percentage > this.ImageThreshold) - { - throw new ImagesSimilarityException( - $"The percentage difference of images {percentage} is larger than expected maximum {this.ImageThreshold}!"); - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs index d1e20f88c..27feb046f 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageComparison/TolerantImageComparer.cs @@ -51,7 +51,7 @@ Rgba32[] aBuffer = new Rgba32[width]; Rgba32[] bBuffer = new Rgba32[width]; - double totalDifference = 0.0; + float totalDifference = 0.0f; var differences = new List(); @@ -78,7 +78,9 @@ } } - if (totalDifference > this.ImageThreshold) + float normalizedDifference = totalDifference / ((float)actual.Width * (float)actual.Height); + + if (normalizedDifference > this.ImageThreshold) { return new ImageSimilarityReport(expected, actual, differences); }