From 6285ef69eea7b388db2fb74d540bd4ad2a978656 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Sat, 4 May 2019 17:49:28 +0200 Subject: [PATCH] extended diffusion + dither tests --- .../Processors/Dithering/DitherTests.cs | 66 +++++++------------ tests/Images/External | 2 +- 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs index fbe7bb182..368feefb9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Dithering; using SixLabors.ImageSharp.Processing.Processors.Dithering; @@ -39,6 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization KnownDitherers.OrderedDither3x3, KnownDitherers.BayerDither2x2 }; + private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f); private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; @@ -49,16 +51,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public void ApplyDiffusionFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image source = provider.GetImage()) - using (Image image = source.Clone()) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Mutate(x => x.Diffuse(DefaultErrorDiffuser, .5F, bounds)); - image.DebugSave(provider); - - ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); - } + provider.RunRectangleConstrainedValidatingProcessorTest( + (x, rect) => x.Diffuse(DefaultErrorDiffuser, .5F, rect), + comparer: ValidatorComparer); } [Theory] @@ -66,28 +61,19 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public void ApplyDitherFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image source = provider.GetImage()) - using (Image image = source.Clone()) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - - image.Mutate(x => x.Dither(DefaultDitherer, bounds)); - image.DebugSave(provider); - - ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds); - } + provider.RunRectangleConstrainedValidatingProcessorTest( + (x, rect) => x.Dither(DefaultDitherer, rect), + comparer: ValidatorComparer); } [Theory] [WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)] - public void DiffusionFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider) + public void DiffusionFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Diffuse(DefaultErrorDiffuser, 0.5f)); - image.DebugSave(provider); - } + // Increased tolerance because of compatibility issues on .NET 4.6.2: + var comparer = ImageComparer.TolerantPercentage(1f); + provider.RunValidatingProcessorTest(x => x.Diffuse(DefaultErrorDiffuser, 0.5f), comparer: comparer); } [Theory] @@ -97,11 +83,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization IErrorDiffuser diffuser) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Diffuse(diffuser, .5F)); - image.DebugSave(provider, diffuser.GetType().Name); - } + provider.RunValidatingProcessorTest( + x => x.Diffuse(diffuser, 0.5f), + testOutputDetails: diffuser.GetType().Name, + comparer: ValidatorComparer, + appendPixelTypeToFileName: false); } [Theory] @@ -109,11 +95,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization public void DitherFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Dither(DefaultDitherer)); - image.DebugSave(provider); - } + provider.RunValidatingProcessorTest( + x => x.Dither(DefaultDitherer), + comparer: ValidatorComparer); } [Theory] @@ -123,11 +107,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization IOrderedDither ditherer) where TPixel : struct, IPixel { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Dither(ditherer)); - image.DebugSave(provider, ditherer.GetType().Name); - } + provider.RunValidatingProcessorTest( + x => x.Dither(ditherer), + testOutputDetails: ditherer.GetType().Name, + comparer: ValidatorComparer, + appendPixelTypeToFileName: false); } } } \ No newline at end of file diff --git a/tests/Images/External b/tests/Images/External index 2a3247c6d..0c524009f 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit 2a3247c6da18b8a96cc71e1f2862ac03f2a42315 +Subproject commit 0c524009f4d4b0edefddd944defdc408c3971536