diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs
index efd6c3b40e..a056bc474e 100644
--- a/tests/ImageSharp.Tests/FileTestBase.cs
+++ b/tests/ImageSharp.Tests/FileTestBase.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.Collections.Generic;
namespace SixLabors.ImageSharp.Tests
@@ -8,6 +9,7 @@ namespace SixLabors.ImageSharp.Tests
///
/// The test base class for reading and writing to files.
///
+ [Obsolete("See: https://github.com/SixLabors/ImageSharp/issues/868")]
public abstract class FileTestBase
{
///
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
index 9774cb50cf..368feefb91 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Dithering/DitherTests.cs
@@ -2,129 +2,116 @@
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
-using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
+using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Dithering;
using SixLabors.ImageSharp.Processing.Processors.Dithering;
+using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
using SixLabors.Primitives;
+
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Binarization
{
- public class DitherTests : FileTestBase
+ public class DitherTests
{
- public static readonly string[] CommonTestImages =
- {
- TestImages.Png.CalliphoraPartial, TestImages.Png.Bike
- };
-
- public static readonly TheoryData OrderedDitherers = new TheoryData
- {
- { "Bayer8x8", KnownDitherers.BayerDither8x8 },
- { "Bayer4x4", KnownDitherers.BayerDither4x4 },
- { "Ordered3x3", KnownDitherers.OrderedDither3x3 },
- { "Bayer2x2", KnownDitherers.BayerDither2x2 }
- };
-
- public static readonly TheoryData ErrorDiffusers = new TheoryData
- {
- { "Atkinson", KnownDiffusers.Atkinson },
- { "Burks", KnownDiffusers.Burks },
- { "FloydSteinberg", KnownDiffusers.FloydSteinberg },
- { "JarvisJudiceNinke", KnownDiffusers.JarvisJudiceNinke },
- { "Sierra2", KnownDiffusers.Sierra2 },
- { "Sierra3", KnownDiffusers.Sierra3 },
- { "SierraLite", KnownDiffusers.SierraLite },
- { "StevensonArce", KnownDiffusers.StevensonArce },
- { "Stucki", KnownDiffusers.Stucki },
- };
-
+ public const PixelTypes CommonNonDefaultPixelTypes =
+ PixelTypes.Rgba32 | PixelTypes.Bgra32 | PixelTypes.Rgb24 | PixelTypes.RgbaVector;
+
+ public static readonly string[] CommonTestImages = { TestImages.Png.CalliphoraPartial, TestImages.Png.Bike };
+
+ public static readonly TheoryData ErrorDiffusers = new TheoryData
+ {
+ KnownDiffusers.Atkinson,
+ KnownDiffusers.Burks,
+ KnownDiffusers.FloydSteinberg,
+ KnownDiffusers.JarvisJudiceNinke,
+ KnownDiffusers.Sierra2,
+ KnownDiffusers.Sierra3,
+ KnownDiffusers.SierraLite,
+ KnownDiffusers.StevensonArce,
+ KnownDiffusers.Stucki,
+ };
+
+ public static readonly TheoryData OrderedDitherers = new TheoryData
+ {
+ KnownDitherers.BayerDither8x8,
+ KnownDitherers.BayerDither4x4,
+ KnownDitherers.OrderedDither3x3,
+ KnownDitherers.BayerDither2x2
+ };
+ private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f);
+
private static IOrderedDither DefaultDitherer => KnownDitherers.BayerDither4x4;
private static IErrorDiffuser DefaultErrorDiffuser => KnownDiffusers.Atkinson;
[Theory]
- [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), DefaultPixelType)]
- [WithTestPatternImages(nameof(OrderedDitherers), 100, 100, DefaultPixelType)]
- public void DitherFilter_WorksWithAllDitherers(TestImageProvider provider, string name, IOrderedDither ditherer)
+ [WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)]
+ public void ApplyDiffusionFilterInBox(TestImageProvider provider)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Dither(ditherer));
- image.DebugSave(provider, name);
- }
+ provider.RunRectangleConstrainedValidatingProcessorTest(
+ (x, rect) => x.Diffuse(DefaultErrorDiffuser, .5F, rect),
+ comparer: ValidatorComparer);
}
[Theory]
- [WithFileCollection(nameof(CommonTestImages), nameof(ErrorDiffusers), DefaultPixelType)]
- [WithTestPatternImages(nameof(ErrorDiffusers), 100, 100, DefaultPixelType)]
- public void DiffusionFilter_WorksWithAllErrorDiffusers(TestImageProvider provider, string name, IErrorDiffuser diffuser)
+ [WithFile(TestImages.Png.CalliphoraPartial, PixelTypes.Rgba32)]
+ public void ApplyDitherFilterInBox(TestImageProvider provider)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Diffuse(diffuser, .5F));
- image.DebugSave(provider, name);
- }
+ provider.RunRectangleConstrainedValidatingProcessorTest(
+ (x, rect) => x.Dither(DefaultDitherer, rect),
+ comparer: ValidatorComparer);
}
[Theory]
[WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
- public void DitherFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider)
+ public void DiffusionFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Dither(DefaultDitherer));
- 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]
- [WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
- public void DiffusionFilter_ShouldNotDependOnSinglePixelType(TestImageProvider provider)
+ [WithFileCollection(nameof(CommonTestImages), nameof(ErrorDiffusers), PixelTypes.Rgba32)]
+ public void DiffusionFilter_WorksWithAllErrorDiffusers(
+ TestImageProvider provider,
+ IErrorDiffuser diffuser)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Diffuse(DefaultErrorDiffuser, 0.5f));
- image.DebugSave(provider);
- }
+ provider.RunValidatingProcessorTest(
+ x => x.Diffuse(diffuser, 0.5f),
+ testOutputDetails: diffuser.GetType().Name,
+ comparer: ValidatorComparer,
+ appendPixelTypeToFileName: false);
}
[Theory]
- [WithFile(TestImages.Png.CalliphoraPartial, DefaultPixelType)]
- public void ApplyDitherFilterInBox(TestImageProvider provider)
+ [WithFile(TestImages.Png.Filter0, CommonNonDefaultPixelTypes)]
+ public void DitherFilter_ShouldNotDependOnSinglePixelType(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.RunValidatingProcessorTest(
+ x => x.Dither(DefaultDitherer),
+ comparer: ValidatorComparer);
}
[Theory]
- [WithFile(TestImages.Png.CalliphoraPartial, DefaultPixelType)]
- public void ApplyDiffusionFilterInBox(TestImageProvider provider)
+ [WithFileCollection(nameof(CommonTestImages), nameof(OrderedDitherers), PixelTypes.Rgba32)]
+ public void DitherFilter_WorksWithAllDitherers(
+ TestImageProvider provider,
+ IOrderedDither ditherer)
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.RunValidatingProcessorTest(
+ x => x.Dither(ditherer),
+ testOutputDetails: ditherer.GetType().Name,
+ comparer: ValidatorComparer,
+ appendPixelTypeToFileName: false);
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs
index 792c7b0802..d7f77c9565 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs
@@ -10,35 +10,30 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
- public class BackgroundColorTest : FileTestBase
+ [GroupOutput("Effects")]
+ public class BackgroundColorTest
{
+ public static readonly string[] InputImages =
+ {
+ TestImages.Png.Splash,
+ TestImages.Png.Ducky
+ };
+
[Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyBackgroundColorFilter(TestImageProvider provider)
+ [WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
+ public void FullImage(TestImageProvider provider)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.BackgroundColor(NamedColors.HotPink));
- image.DebugSave(provider);
- }
+ provider.RunValidatingProcessorTest(x => x.BackgroundColor(NamedColors.HotPink));
}
[Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyBackgroundColorFilterInBox(TestImageProvider provider)
+ [WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
+ public void InBox(TestImageProvider provider)
where TPixel : struct, IPixel
{
- using (Image source = provider.GetImage())
- using (var image = source.Clone())
- {
- var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
-
- image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds));
- image.DebugSave(provider);
-
- ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
- }
+ provider.RunRectangleConstrainedValidatingProcessorTest(
+ (x, rect) => x.BackgroundColor(NamedColors.HotPink, rect));
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs
index d4429aaf3d..ea2273cd5d 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs
@@ -10,40 +10,40 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
- public class OilPaintTest : FileTestBase
+ [GroupOutput("Effects")]
+ public class OilPaintTest
{
public static readonly TheoryData OilPaintValues = new TheoryData
{
- { 15, 10 }, { 6, 5 }
+ { 15, 10 },
+ { 6, 5 }
};
+ public static readonly string[] InputImages =
+ {
+ TestImages.Png.CalliphoraPartial,
+ TestImages.Bmp.Car
+ };
[Theory]
- [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)]
- public void ApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize)
+ [WithFileCollection(nameof(InputImages), nameof(OilPaintValues), PixelTypes.Rgba32)]
+ public void FullImage(TestImageProvider provider, int levels, int brushSize)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.OilPaint(levels, brushSize));
- image.DebugSave(provider, string.Join("-", levels, brushSize));
- }
+ provider.RunValidatingProcessorTest(
+ x => x.OilPaint(levels, brushSize),
+ $"{levels}-{brushSize}",
+ appendPixelTypeToFileName: false);
}
[Theory]
- [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)]
- public void ApplyOilPaintFilterInBox(TestImageProvider provider, int levels, int brushSize)
+ [WithFileCollection(nameof(InputImages), nameof(OilPaintValues), PixelTypes.Rgba32)]
+ [WithTestPatternImages(nameof(OilPaintValues), 100, 100, PixelTypes.Rgba32)]
+ public void InBox(TestImageProvider provider, int levels, int brushSize)
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.OilPaint(levels, brushSize, bounds));
- image.DebugSave(provider, string.Join("-", levels, brushSize));
-
- ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
- }
+ provider.RunRectangleConstrainedValidatingProcessorTest(
+ (x, rect) => x.OilPaint(levels, brushSize, rect),
+ $"{levels}-{brushSize}");
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs
index cb9a0ba0cf..726f4b707b 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs
@@ -4,82 +4,32 @@
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
-
using SixLabors.Primitives;
+
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Effects
{
- public class PixelateTest : FileTestBase
+ [GroupOutput("Effects")]
+ public class PixelateTest
{
- public static readonly TheoryData PixelateValues
- = new TheoryData
- {
- 4 ,
- 8
- };
+ public static readonly TheoryData PixelateValues = new TheoryData { 4, 8 };
[Theory]
- [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
- public void ImageShouldApplyPixelateFilter(TestImageProvider provider, int value)
+ [WithFile(TestImages.Png.Ducky, nameof(PixelateValues), PixelTypes.Rgba32)]
+ public void FullImage(TestImageProvider provider, int value)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Pixelate(value));
- image.DebugSave(provider, value);
-
- // Test the neigbouring pixels
- for (int y = 0; y < image.Height; y += value)
- {
- for (int x = 0; x < image.Width; x += value)
- {
- TPixel source = image[x, y];
- for (int pixY = y; pixY < y + value && pixY < image.Height; pixY++)
- {
- for (int pixX = x; pixX < x + value && pixX < image.Width; pixX++)
- {
- Assert.Equal(source, image[pixX, pixY]);
- }
- }
- }
- }
- }
+ provider.RunValidatingProcessorTest(x => x.Pixelate(value), value, appendPixelTypeToFileName: false);
}
[Theory]
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
- public void ImageShouldApplyPixelateFilterInBox(TestImageProvider provider, int value)
+ [WithFile(TestImages.Png.CalliphoraPartial, nameof(PixelateValues), PixelTypes.Rgba32)]
+ public void InBox(TestImageProvider provider, int value)
where TPixel : struct, IPixel
{
- using (Image source = provider.GetImage())
- using (var image = source.Clone())
- {
- var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
-
- image.Mutate(x => x.Pixelate(value, bounds));
- image.DebugSave(provider, value);
-
- for (int y = 0; y < image.Height; y++)
- {
- for (int x = 0; x < image.Width; x++)
- {
- int tx = x;
- int ty = y;
- TPixel sourceColor = source[tx, ty];
- if (bounds.Contains(tx, ty))
- {
- int sourceX = tx - ((tx - bounds.Left) % value) + (value / 2);
- int sourceY = ty - ((ty - bounds.Top) % value) + (value / 2);
-
- sourceColor = image[sourceX, sourceY];
- }
- Assert.Equal(sourceColor, image[tx, ty]);
- }
- }
-
- ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
- }
+ provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => x.Pixelate(value, rect), value);
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs
index 479ee346a5..113c13b8ae 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs
@@ -10,59 +10,14 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
{
- public class GlowTest : FileTestBase
+ [GroupOutput("Overlays")]
+ public class GlowTest : OverlayTestBase
{
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyGlowFilter(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Glow());
- image.DebugSave(provider);
- }
- }
+ protected override void Apply(IImageProcessingContext ctx, T color) => ctx.Glow(color);
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyGlowFilterColor(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Glow(NamedColors.Orange));
- image.DebugSave(provider);
- }
- }
+ protected override void Apply(IImageProcessingContext ctx, float radiusX, float radiusY) =>
+ ctx.Glow(radiusX);
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyGlowFilterRadius(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Glow(image.Width / 4F));
- image.DebugSave(provider);
- }
- }
-
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyGlowFilterInBox(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image source = provider.GetImage())
- using (var image = source.Clone())
- {
- var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
-
- image.Mutate(x => x.Glow(bounds));
- image.DebugSave(provider);
-
- ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
- }
- }
+ protected override void Apply(IImageProcessingContext ctx, Rectangle rect) => ctx.Glow(rect);
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs
new file mode 100644
index 0000000000..d2abcd7312
--- /dev/null
+++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/OverlayTestBase.cs
@@ -0,0 +1,70 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using System.Reflection;
+
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
+using SixLabors.Primitives;
+
+using Xunit;
+
+namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
+{
+ [GroupOutput("Overlays")]
+ public abstract class OverlayTestBase
+ {
+ public static string[] ColorNames = { "Blue", "White" };
+
+ public static string[] InputImages = { TestImages.Png.Ducky, TestImages.Png.Splash };
+
+ private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.05f);
+
+ [Theory]
+ [WithFileCollection(nameof(InputImages), nameof(ColorNames), PixelTypes.Rgba32)]
+ public void FullImage_ApplyColor(TestImageProvider provider, string colorName)
+ where TPixel : struct, IPixel
+ {
+ provider.Utility.TestGroupName = this.GetType().Name;
+ var f = (FieldInfo)typeof(NamedColors).GetMember(colorName)[0];
+ TPixel color = (TPixel)f.GetValue(null);
+
+ provider.RunValidatingProcessorTest(x => this.Apply(x, color), colorName, ValidatorComparer, appendPixelTypeToFileName: false);
+ }
+
+ [Theory]
+ [WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
+ public void FullImage_ApplyRadius(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ provider.Utility.TestGroupName = this.GetType().Name;
+ provider.RunValidatingProcessorTest(
+ x =>
+ {
+ Size size = x.GetCurrentSize();
+ this.Apply(x, size.Width / 4f, size.Height / 4f);
+ },
+ comparer: ValidatorComparer,
+ appendPixelTypeToFileName: false);
+ }
+
+ [Theory]
+ [WithFileCollection(nameof(InputImages), PixelTypes.Rgba32)]
+ public void InBox(TestImageProvider provider)
+ where TPixel : struct, IPixel
+ {
+ provider.Utility.TestGroupName = this.GetType().Name;
+ provider.RunRectangleConstrainedValidatingProcessorTest((x, rect) => this.Apply(x, rect));
+ }
+
+ protected abstract void Apply(IImageProcessingContext ctx, T color)
+ where T : struct, IPixel;
+
+ protected abstract void Apply(IImageProcessingContext ctx, float radiusX, float radiusY)
+ where T : struct, IPixel;
+
+ protected abstract void Apply(IImageProcessingContext ctx, Rectangle rect)
+ where T : struct, IPixel;
+ }
+}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs
index 3a378a0951..ad04a827db 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs
@@ -1,68 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
-using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
-using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
-
using SixLabors.Primitives;
-using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Overlays
{
- public class VignetteTest : FileTestBase
+ [GroupOutput("Overlays")]
+ public class VignetteTest : OverlayTestBase
{
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyVignetteFilter(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Vignette());
- image.DebugSave(provider);
- }
- }
-
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyVignetteFilterColor(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Vignette(NamedColors.Orange));
- image.DebugSave(provider);
- }
- }
-
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyVignetteFilterRadius(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F));
- image.DebugSave(provider);
- }
- }
-
- [Theory]
- [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
- public void ImageShouldApplyVignetteFilterInBox(TestImageProvider provider)
- where TPixel : struct, IPixel
- {
- using (Image source = provider.GetImage())
- using (var image = source.Clone())
- {
- var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
+ protected override void Apply(IImageProcessingContext ctx, T color) => ctx.Vignette(color);
- image.Mutate(x => x.Vignette(bounds));
- image.DebugSave(provider);
+ protected override void Apply(IImageProcessingContext ctx, float radiusX, float radiusY) =>
+ ctx.Vignette(radiusX, radiusY);
- ImageComparer.Tolerant().VerifySimilarityIgnoreRegion(source, image, bounds);
- }
- }
+ protected override void Apply(IImageProcessingContext ctx, Rectangle rect) => ctx.Vignette(rect);
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs
index 28b01061ea..6dc9b36309 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs
@@ -6,27 +6,16 @@ using SixLabors.ImageSharp.Metadata.Profiles.Exif;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder;
+using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
+
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
- public class AutoOrientTests : FileTestBase
+ [GroupOutput("Transforms")]
+ public class AutoOrientTests
{
- public static readonly string[] FlipFiles = { TestImages.Bmp.F };
-
- public static readonly TheoryData OrientationValues
- = new TheoryData
- {
- { RotateMode.None, FlipMode.None, 0 },
- { RotateMode.None, FlipMode.None, 1 },
- { RotateMode.None, FlipMode.Horizontal, 2 },
- { RotateMode.Rotate180, FlipMode.None, 3 },
- { RotateMode.Rotate180, FlipMode.Horizontal, 4 },
- { RotateMode.Rotate90, FlipMode.Horizontal, 5 },
- { RotateMode.Rotate270, FlipMode.None, 6 },
- { RotateMode.Rotate90, FlipMode.Vertical, 7 },
- { RotateMode.Rotate90, FlipMode.None, 8 },
- };
+ public const string FlipTestFile = TestImages.Bmp.F;
public static readonly TheoryData InvalidOrientationValues
= new TheoryData
@@ -38,27 +27,38 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{ ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) }
};
+ public static readonly TheoryData ExifOrientationValues = new TheoryData()
+ {
+ 0,
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ 6,
+ 7,
+ 8
+ };
+
[Theory]
- [WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)]
- public void ImageShouldAutoRotate(TestImageProvider provider, RotateMode rotateType, FlipMode flipType, ushort orientation)
+ [WithFile(FlipTestFile, nameof(ExifOrientationValues), PixelTypes.Rgba32)]
+ public void AutoOrient_WorksForAllExifOrientations(TestImageProvider provider, ushort orientation)
where TPixel : struct, IPixel
{
using (Image image = provider.GetImage())
{
image.Metadata.ExifProfile = new ExifProfile();
image.Metadata.ExifProfile.SetValue(ExifTag.Orientation, orientation);
-
- image.Mutate(x => x.RotateFlip(rotateType, flipType));
- image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"));
-
+
image.Mutate(x => x.AutoOrient());
- image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"));
+ image.DebugSave(provider, orientation, appendPixelTypeToFileName: false);
+ image.CompareToReferenceOutput(provider, orientation, appendPixelTypeToFileName: false);
}
}
[Theory]
- [WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)]
- public void ImageShouldAutoRotateInvalidValues(TestImageProvider provider, ExifDataType dataType, byte[] orientation)
+ [WithFile(FlipTestFile, nameof(InvalidOrientationValues), PixelTypes.Rgba32)]
+ public void AutoOrient_WorksWithCorruptExifData(TestImageProvider provider, ExifDataType dataType, byte[] orientation)
where TPixel : struct, IPixel
{
var profile = new ExifProfile();
@@ -72,11 +72,19 @@ namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
bytes[18] = (byte)dataType;
// Change the number of components
bytes[20] = 1;
+
+ byte[] orientationCodeData = new byte[8];
+ Array.Copy(orientation, orientationCodeData, orientation.Length);
+
+ ulong orientationCode = BitConverter.ToUInt64(orientationCodeData, 0);
using (Image image = provider.GetImage())
+ using (Image reference = image.Clone())
{
image.Metadata.ExifProfile = new ExifProfile(bytes);
image.Mutate(x => x.AutoOrient());
+ image.DebugSave(provider, $"{dataType}-{orientationCode}", appendPixelTypeToFileName: false);
+ ImageComparer.Exact.VerifySimilarity(image, reference);
}
}
}
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
index c01c3b1bd3..50217e892d 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
@@ -13,7 +13,7 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
[GroupOutput("Transforms")]
- public class CropTest : FileTestBase
+ public class CropTest
{
[Theory]
[WithTestPatternImages(70, 30, PixelTypes.Rgba32, 0, 0, 70, 30)]
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs
index 7285270217..d20e6fa359 100644
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs
@@ -7,25 +7,24 @@ using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
{
- public class EntropyCropTest : FileTestBase
+ [GroupOutput("Transforms")]
+ public class EntropyCropTest
{
- public static readonly TheoryData EntropyCropValues
- = new TheoryData
- {
- .25F,
- .75F
- };
+ public static readonly TheoryData EntropyCropValues = new TheoryData { .25F, .75F };
+
+ public static readonly string[] InputImages =
+ {
+ TestImages.Png.Ducky,
+ TestImages.Jpeg.Baseline.Jpeg400,
+ TestImages.Jpeg.Baseline.MultiScanBaselineCMYK
+ };
[Theory]
- [WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)]
- public void ImageShouldEntropyCrop(TestImageProvider provider, float value)
+ [WithFileCollection(nameof(InputImages), nameof(EntropyCropValues), PixelTypes.Rgba32)]
+ public void EntropyCrop(TestImageProvider provider, float value)
where TPixel : struct, IPixel
{
- using (Image image = provider.GetImage())
- {
- image.Mutate(x => x.EntropyCrop(value));
- image.DebugSave(provider, value);
- }
+ provider.RunValidatingProcessorTest(x => x.EntropyCrop(value), value, appendPixelTypeToFileName: false);
}
}
}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs
deleted file mode 100644
index 29c51543fc..0000000000
--- a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs
+++ /dev/null
@@ -1,72 +0,0 @@
-// Copyright (c) Six Labors and contributors.
-// Licensed under the Apache License, Version 2.0.
-
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-using SixLabors.ImageSharp.Processing;
-using SixLabors.ImageSharp.Processing.Processors.Transforms;
-using SixLabors.ImageSharp.PixelFormats;
-using Xunit;
-
-namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
-{
- public class SkewTest : FileTestBase
- {
- public static readonly TheoryData SkewValues
- = new TheoryData
- {
- { 20, 10 },
- { -20, -10 }
- };
-
- public static readonly List ResamplerNames
- = new List
- {
- nameof(KnownResamplers.Bicubic),
- nameof(KnownResamplers.Box),
- nameof(KnownResamplers.CatmullRom),
- nameof(KnownResamplers.Hermite),
- nameof(KnownResamplers.Lanczos2),
- nameof(KnownResamplers.Lanczos3),
- nameof(KnownResamplers.Lanczos5),
- nameof(KnownResamplers.Lanczos8),
- nameof(KnownResamplers.MitchellNetravali),
- nameof(KnownResamplers.NearestNeighbor),
- nameof(KnownResamplers.Robidoux),
- nameof(KnownResamplers.RobidouxSharp),
- nameof(KnownResamplers.Spline),
- nameof(KnownResamplers.Triangle),
- nameof(KnownResamplers.Welch),
- };
-
- [Theory]
- [WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)]
- public void ImageShouldSkew(TestImageProvider provider, float x, float y)
- where TPixel : struct, IPixel
- {
- using (Image image = provider.GetImage())
- {
- image.Mutate(i => i.Skew(x, y));
- image.DebugSave(provider, string.Join("_", x, y));
- }
- }
-
- [Theory]
- [WithTestPatternImages(nameof(SkewValues), 100, 50, DefaultPixelType)]
- public void ImageShouldSkewWithSampler(TestImageProvider provider, float x, float y)
- where TPixel : struct, IPixel
- {
- foreach (string resamplerName in ResamplerNames)
- {
- IResampler sampler = TestUtils.GetResampler(resamplerName);
- using (Image image = provider.GetImage())
- {
- image.Mutate(i => i.Skew(x, y, sampler));
- image.DebugSave(provider, string.Join("_", x, y, resamplerName));
- }
- }
- }
- }
-}
\ No newline at end of file
diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTests.cs
new file mode 100644
index 0000000000..ad77027f0f
--- /dev/null
+++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTests.cs
@@ -0,0 +1,67 @@
+// Copyright (c) Six Labors and contributors.
+// Licensed under the Apache License, Version 2.0.
+
+using SixLabors.ImageSharp.PixelFormats;
+using SixLabors.ImageSharp.Processing;
+using SixLabors.ImageSharp.Processing.Processors.Transforms;
+using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
+
+using Xunit;
+
+namespace SixLabors.ImageSharp.Tests.Processing.Processors.Transforms
+{
+ [GroupOutput("Transforms")]
+ public class SkewTests
+ {
+ private const PixelTypes CommonPixelTypes = PixelTypes.Bgra32 | PixelTypes.Rgb24;
+
+ public static readonly string[] ResamplerNames = new[]
+ {
+ nameof(KnownResamplers.Bicubic),
+ nameof(KnownResamplers.Box),
+ nameof(KnownResamplers.CatmullRom),
+ nameof(KnownResamplers.Hermite),
+ nameof(KnownResamplers.Lanczos2),
+ nameof(KnownResamplers.Lanczos3),
+ nameof(KnownResamplers.Lanczos5),
+ nameof(KnownResamplers.Lanczos8),
+ nameof(KnownResamplers.MitchellNetravali),
+ nameof(KnownResamplers.NearestNeighbor),
+ nameof(KnownResamplers.Robidoux),
+ nameof(KnownResamplers.RobidouxSharp),
+ nameof(KnownResamplers.Spline),
+ nameof(KnownResamplers.Triangle),
+ nameof(KnownResamplers.Welch),
+ };
+
+ public static readonly TheoryData SkewValues = new TheoryData
+ {
+ { 20, 10 },
+ { -20, -10 }
+ };
+
+ private static readonly ImageComparer ValidatorComparer = ImageComparer.TolerantPercentage(0.01f);
+
+ [Theory]
+ [WithTestPatternImages(nameof(SkewValues), 100, 50, CommonPixelTypes)]
+ public void Skew_IsNotBoundToSinglePixelType(TestImageProvider provider, float x, float y)
+ where TPixel : struct, IPixel
+ {
+ provider.RunValidatingProcessorTest(ctx => ctx.Skew(x, y), $"{x}_{y}", ValidatorComparer);
+ }
+
+ [Theory]
+ [WithFile(TestImages.Png.Ducky, nameof(ResamplerNames), PixelTypes.Rgba32)]
+ public void Skew_WorksWithAllResamplers(TestImageProvider provider, string resamplerName)
+ where TPixel : struct, IPixel
+ {
+ IResampler sampler = TestUtils.GetResampler(resamplerName);
+
+ provider.RunValidatingProcessorTest(
+ x => x.Skew(21, 32, sampler),
+ resamplerName,
+ comparer: ValidatorComparer,
+ appendPixelTypeToFileName: false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/tests/Images/External b/tests/Images/External
index 2a3247c6da..854ba68b05 160000
--- a/tests/Images/External
+++ b/tests/Images/External
@@ -1 +1 @@
-Subproject commit 2a3247c6da18b8a96cc71e1f2862ac03f2a42315
+Subproject commit 854ba68b05162bdd87c0c9bbdcdb1c848aa6ddbe