Browse Source

extended diffusion + dither tests

af/merge-core
Anton Firszov 7 years ago
parent
commit
6285ef69ee
  1. 66
      tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
  2. 2
      tests/Images/External

66
tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Dithering; using SixLabors.ImageSharp.Processing.Dithering;
using SixLabors.ImageSharp.Processing.Processors.Dithering; using SixLabors.ImageSharp.Processing.Processors.Dithering;
@ -39,6 +40,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
KnownDitherers.OrderedDither3x3, KnownDitherers.OrderedDither3x3,
KnownDitherers.BayerDither2x2 KnownDitherers.BayerDither2x2
}; };
private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f);
private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4; private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4;
@ -49,16 +51,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
public void ApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider) public void ApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> source = provider.GetImage()) provider.RunRectangleConstrainedValidatingProcessorTest(
using (Image<TPixel> image = source.Clone()) (x, rect) => x.Diffuse(DefaultErrorDiffuser, .5F, rect),
{ comparer: ValidatorComparer);
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);
}
} }
[Theory] [Theory]
@ -66,28 +61,19 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
public void ApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider) public void ApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> source = provider.GetImage()) provider.RunRectangleConstrainedValidatingProcessorTest(
using (Image<TPixel> image = source.Clone()) (x, rect) => x.Dither(DefaultDitherer, rect),
{ comparer: ValidatorComparer);
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);
}
} }
[Theory] [Theory]
[WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)] [WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
public void DiffusionFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) public void DiffusionFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) // Increased tolerance because of compatibility issues on .NET 4.6.2:
{ var comparer = ImageComparer.TolerantPercentage(1f);
image.Mutate(x => x.Diffuse(DefaultErrorDiffuser, 0.5f)); provider.RunValidatingProcessorTest(x => x.Diffuse(DefaultErrorDiffuser, 0.5f), comparer: comparer);
image.DebugSave(provider);
}
} }
[Theory] [Theory]
@ -97,11 +83,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
IErrorDiffuser diffuser) IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) provider.RunValidatingProcessorTest(
{ x => x.Diffuse(diffuser, 0.5f),
image.Mutate(x => x.Diffuse(diffuser, .5F)); testOutputDetails: diffuser.GetType().Name,
image.DebugSave(provider, diffuser.GetType().Name); comparer: ValidatorComparer,
} appendPixelTypeToFileName: false);
} }
[Theory] [Theory]
@ -109,11 +95,9 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
public void DitherFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider) public void DitherFilter_ShouldNotDependOnSinglePixelType<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) provider.RunValidatingProcessorTest(
{ x => x.Dither(DefaultDitherer),
image.Mutate(x => x.Dither(DefaultDitherer)); comparer: ValidatorComparer);
image.DebugSave(provider);
}
} }
[Theory] [Theory]
@ -123,11 +107,11 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
IOrderedDither ditherer) IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel> where TPixel : struct, IPixel<TPixel>
{ {
using (Image<TPixel> image = provider.GetImage()) provider.RunValidatingProcessorTest(
{ x => x.Dither(ditherer),
image.Mutate(x => x.Dither(ditherer)); testOutputDetails: ditherer.GetType().Name,
image.DebugSave(provider, ditherer.GetType().Name); comparer: ValidatorComparer,
} appendPixelTypeToFileName: false);
} }
} }
} }

2
tests/Images/External

@ -1 +1 @@
Subproject commit 2a3247c6da18b8a96cc71e1f2862ac03f2a42315 Subproject commit 0c524009f4d4b0edefddd944defdc408c3971536
Loading…
Cancel
Save