diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index d4528b55b..fd65542e0 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -16,6 +16,35 @@ namespace ImageSharp /// public static partial class ImageExtensions { + /// + /// Alters the colors of the image recreating an oil painting effect with levels and brushSize + /// set to 10 and 15 respectively. + /// + /// The pixel format. + /// The image this method extends. + /// The . + public static Image OilPaint(this Image source) + where TPixel : struct, IPixel + { + return OilPaint(source, 10, 15); + } + + /// + /// Alters the colors of the image recreating an oil painting effect with levels and brushSize + /// set to 10 and 15 respectively. + /// + /// The pixel format. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The . + public static Image OilPaint(this Image source, Rectangle rectangle) + where TPixel : struct, IPixel + { + return OilPaint(source, 10, 15, rectangle); + } + /// /// Alters the colors of the image recreating an oil painting effect. /// @@ -24,8 +53,8 @@ namespace ImageSharp /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static Image OilPaint(this Image source, int levels = 10, int brushSize = 15) - where TPixel : struct, IPixel + public static Image OilPaint(this Image source, int levels, int brushSize) + where TPixel : struct, IPixel { return OilPaint(source, levels, brushSize, source.Bounds); } diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index a43f77a1c..37cc8a9d9 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -97,17 +97,7 @@ namespace ImageSharp.Processing.Processors int fyr = fy - radius; int offsetY = y + fyr; - // Skip the current row - if (offsetY < minY) - { - continue; - } - - // Outwith the current bounds so break. - if (offsetY >= maxY) - { - break; - } + offsetY = offsetY.Clamp(0, maxY); Span sourceOffsetRow = source.GetRowSpan(offsetY); @@ -115,34 +105,25 @@ namespace ImageSharp.Processing.Processors { int fxr = fx - radius; int offsetX = x + fxr; + offsetX = offsetX.Clamp(0, maxX); - // Skip the column - if (offsetX < 0) - { - continue; - } + var vector = sourceOffsetRow[offsetX].ToVector4(); - if (offsetX < maxX) - { - // ReSharper disable once AccessToDisposedClosure - var vector = sourceOffsetRow[offsetX].ToVector4(); + float sourceRed = vector.X; + float sourceBlue = vector.Z; + float sourceGreen = vector.Y; - float sourceRed = vector.X; - float sourceBlue = vector.Z; - float sourceGreen = vector.Y; + int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1)); - int currentIntensity = (int)MathF.Round((sourceBlue + sourceGreen + sourceRed) / 3F * (levels - 1)); + intensityBin[currentIntensity] += 1; + blueBin[currentIntensity] += sourceBlue; + greenBin[currentIntensity] += sourceGreen; + redBin[currentIntensity] += sourceRed; - intensityBin[currentIntensity] += 1; - blueBin[currentIntensity] += sourceBlue; - greenBin[currentIntensity] += sourceGreen; - redBin[currentIntensity] += sourceRed; - - if (intensityBin[currentIntensity] > maxIntensity) - { - maxIntensity = intensityBin[currentIntensity]; - maxIndex = currentIntensity; - } + if (intensityBin[currentIntensity] > maxIntensity) + { + maxIntensity = intensityBin[currentIntensity]; + maxIndex = currentIntensity; } } diff --git a/tests/ImageSharp.Tests/FileTestBase.cs b/tests/ImageSharp.Tests/FileTestBase.cs index 654cdf64e..ff0801e8a 100644 --- a/tests/ImageSharp.Tests/FileTestBase.cs +++ b/tests/ImageSharp.Tests/FileTestBase.cs @@ -12,30 +12,42 @@ namespace ImageSharp.Tests /// public abstract class FileTestBase : TestBase { + /// + /// A collection made up of one file for each image format + /// + public static IEnumerable DefaultFiles = + new[] + { + TestImages.Bmp.Car, + TestImages.Jpeg.Baseline.Calliphora, + TestImages.Png.Splash, + TestImages.Gif.Trans + }; + /// /// A collection of all the bmp test images /// - public static IEnumerable AllBmpFiles => TestImages.Bmp.All; + public static IEnumerable AllBmpFiles = TestImages.Bmp.All; /// /// A collection of all the jpeg test images /// - public static IEnumerable AllJpegFiles => TestImages.Jpeg.All; + public static IEnumerable AllJpegFiles = TestImages.Jpeg.All; /// /// A collection of all the png test images /// - public static IEnumerable AllPngFiles => TestImages.Png.All; + public static IEnumerable AllPngFiles = TestImages.Png.All; /// /// A collection of all the gif test images /// - public static IEnumerable AllGifFiles => TestImages.Gif.All; + public static IEnumerable AllGifFiles = TestImages.Gif.All; /// - /// The standard pixel formats enumerations + /// The standard pixel format enumeration /// - public const PixelTypes StandardPixelTypes = PixelTypes.StandardImageClass | PixelTypes.Rgba32; + public const PixelTypes StandardPixelType = PixelTypes.StandardImageClass; public static class Extensions { diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index d339dc83d..3e40cc2d7 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -1,4 +1,9 @@ -namespace ImageSharp.Tests +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests { using System; using ImageSharp; @@ -12,9 +17,9 @@ /// public static class ImageComparer { - const int DefaultScalingFactor = 32; // this is means the images get scaled into a 32x32 image to sample pixels - const int DefaultSegmentThreshold = 3; // the greyscale difference between 2 segements my be > 3 before it influances the overall difference - const float DefaultImageThreshold = 0.000f; // after segment threasholds the images must have no differences + const int DefaultScalingFactor = 32; // This is means the images get scaled into a 32x32 image to sample pixels + const int DefaultSegmentThreshold = 3; // The greyscale difference between 2 segements my be > 3 before it influences the overall difference + const float DefaultImageThreshold = 0.000F; // After segment thresholds the images must have no differences /// /// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold @@ -25,15 +30,15 @@ /// The actual image /// /// The threshold for the percentage difference where the images are asumed to be the same. - /// The default/undefined value is + /// The default/undefined value is /// /// - /// The threashold of the individual segments before it acumulates towards the overall difference. - /// 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 + /// The default undefined value is /// public static void CheckSimilarity(Image expected, Image actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor) where TPixelA : struct, IPixel @@ -52,8 +57,8 @@ /// The source image /// The target image /// - /// The threashold of the individual segments before it acumulates towards the overall difference. - /// 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 @@ -74,14 +79,14 @@ if (b > segmentThreshold) { diffPixels++; } } - return (float)diffPixels / (float)(scalingFactor * scalingFactor); + return diffPixels / (float)(scalingFactor * scalingFactor); } private static Fast2DArray GetDifferences(Image source, Image target, int scalingFactor) where TPixelA : struct, IPixel where TPixelB : struct, IPixel { - Fast2DArray differences = new Fast2DArray(scalingFactor, scalingFactor); + var differences = new Fast2DArray(scalingFactor, scalingFactor); Fast2DArray firstGray = source.GetGrayScaleValues(scalingFactor); Fast2DArray secondGray = target.GetGrayScaleValues(scalingFactor); @@ -89,7 +94,7 @@ { for (int x = 0; x < scalingFactor; x++) { - var diff = firstGray[x, y] - secondGray[x, y]; + int diff = firstGray[x, y] - secondGray[x, y]; differences[x, y] = (byte)Math.Abs(diff); } } @@ -100,18 +105,18 @@ private static Fast2DArray GetGrayScaleValues(this Image source, int scalingFactor) where TPixelA : struct, IPixel { - byte[] buffer = new byte[4]; + byte[] buffer = new byte[3]; using (Image img = new Image(source).Resize(scalingFactor, scalingFactor).Grayscale()) { using (PixelAccessor pixels = img.Lock()) { - Fast2DArray grayScale = new Fast2DArray(scalingFactor, scalingFactor); + 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[1]; + grayScale[x, y] = buffer[0]; } } diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index 7286375ba..a4da02ade 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.Binarization }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(BinaryThresholdValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(BinaryThresholdValues), StandardPixelType)] public void ImageShouldApplyBinaryThresholdFilter(TestImageProvider provider, float value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Binarization } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(BinaryThresholdValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(BinaryThresholdValues), StandardPixelType)] public void ImageShouldApplyBinaryThresholdInBox(TestImageProvider provider, float value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs index c88227b2c..a6585e026 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelType)] public void ImageShouldApplyDitherFilter(TestImageProvider provider, string name, IOrderedDither ditherer) where TPixel : struct, IPixel { @@ -44,7 +44,7 @@ namespace ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelType)] public void ImageShouldApplyDitherFilterInBox(TestImageProvider provider, string name, IOrderedDither ditherer) where TPixel : struct, IPixel { @@ -64,7 +64,7 @@ namespace ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelType)] public void ImageShouldApplyDiffusionFilter(TestImageProvider provider, string name, IErrorDiffuser diffuser) where TPixel : struct, IPixel { @@ -76,7 +76,7 @@ namespace ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelType)] public void ImageShouldApplyDiffusionFilterInBox(TestImageProvider provider, string name, IErrorDiffuser diffuser) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs index e3083cbe1..97582b27f 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix public class BlackWhiteTest : FileTestBase { [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyBlackWhiteFilter(TestImageProvider provider) where TPixel : struct, IPixel { @@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyBlackWhiteFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs index 24df04fdf..7c6e58da3 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs @@ -26,7 +26,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(ColorBlindnessFilters), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(ColorBlindnessFilters), StandardPixelType)] public void ImageShouldApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindness colorBlindness) where TPixel : struct, IPixel { @@ -38,7 +38,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(ColorBlindnessFilters), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(ColorBlindnessFilters), StandardPixelType)] public void ImageShouldApplyColorBlindnessFilterInBox(TestImageProvider provider, ColorBlindness colorBlindness) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs index c68b7c5c3..f0a23429d 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs @@ -23,7 +23,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix /// Use test patterns over loaded images to save decode time. /// [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelTypes)] + [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelType)] public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) where TPixel : struct, IPixel { @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelTypes)] + [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelType)] public void ImageShouldApplyGrayscaleFilterInBox(TestImageProvider provider, GrayscaleMode value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs index 9b6510631..0666d505a 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(HueValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(HueValues), StandardPixelType)] public void ImageShouldApplyHueFilter(TestImageProvider provider, int value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(HueValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(HueValues), StandardPixelType)] public void ImageShouldApplyHueFilterInBox(TestImageProvider provider, int value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs index ece3eb41a..23fd634e2 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix public class KodachromeTest : FileTestBase { [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyKodachromeFilter(TestImageProvider provider) where TPixel : struct, IPixel { @@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyKodachromeFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs index 2ea686fd9..b0af0e6c3 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs @@ -14,7 +14,7 @@ namespace ImageSharp.Tests public class LomographTest : FileTestBase { [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyLomographFilter(TestImageProvider provider) where TPixel : struct, IPixel { @@ -26,7 +26,7 @@ namespace ImageSharp.Tests } [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyLomographFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs index 1803fb581..ff6640753 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix public class PolaroidTest : FileTestBase { [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyPolaroidFilter(TestImageProvider provider) where TPixel : struct, IPixel { @@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplyPolaroidFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs index 506f29503..924b9d5d4 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(SaturationValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(SaturationValues), StandardPixelType)] public void ImageShouldApplySaturationFilter(TestImageProvider provider, int value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(SaturationValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(SaturationValues), StandardPixelType)] public void ImageShouldApplySaturationFilterInBox(TestImageProvider provider, int value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs index b129ffe56..cd5baa1ce 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs @@ -12,7 +12,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix public class SepiaTest : FileTestBase { [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplySepiaFilter(TestImageProvider provider) where TPixel : struct, IPixel { @@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix } [Theory] - [WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), StandardPixelType)] public void ImageShouldApplySepiaFilterInBox(TestImageProvider provider) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index f19e6cd0c..9e276fcb3 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.Convolution }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelType)] public void ImageShouldApplyBoxBlurFilter(TestImageProvider provider, int value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Convolution } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(BoxBlurValues), StandardPixelType)] public void ImageShouldApplyBoxBlurFilterInBox(TestImageProvider provider, int value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index 4e5a230ec..3155a9956 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Tests.Processing.Convolution }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelType)] public void ImageShouldApplyDetectEdgesFilter(TestImageProvider provider, EdgeDetection detector) where TPixel : struct, IPixel { @@ -40,7 +40,7 @@ namespace ImageSharp.Tests.Processing.Convolution } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(DetectEdgesFilters), StandardPixelType)] public void ImageShouldApplyDetectEdgesFilterInBox(TestImageProvider provider, EdgeDetection detector) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index d80daf1d6..8bdc588be 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.Convolution }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelType)] public void ImageShouldApplyGaussianBlurFilter(TestImageProvider provider, int value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Convolution } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianBlurValues), StandardPixelType)] public void ImageShouldApplyGaussianBlurFilterInBox(TestImageProvider provider, int value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index 1632e2c2f..0497459d7 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -19,7 +19,7 @@ namespace ImageSharp.Tests.Processing.Convolution }; [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelType)] public void ImageShouldApplyGaussianSharpenFilter(TestImageProvider provider, int value) where TPixel : struct, IPixel { @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Convolution } [Theory] - [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelTypes)] + [WithFileCollection(nameof(AllBmpFiles), nameof(GaussianSharpenValues), StandardPixelType)] public void ImageShouldApplyGaussianSharpenFilterInBox(TestImageProvider provider, int value) where TPixel : struct, IPixel { diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs new file mode 100644 index 000000000..3d4725f88 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -0,0 +1,55 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class OilPaintTest : FileTestBase + { + public static readonly TheoryData OilPaintValues + = new TheoryData + { + { 15, 10 }, + { 6, 5 } + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), StandardPixelType)] + public void ImageShouldApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.OilPaint(levels, brushSize) + .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), StandardPixelType)] + public void ImageShouldApplyOilPaintFilterInBox(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.OilPaint(levels, brushSize, bounds) + .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + + // Draw identical shapes over the bounded and compare to ensure changes are constrained. + image.Fill(NamedColors.HotPink, bounds); + source.Fill(NamedColors.HotPink, bounds); + + // TODO: Why does the png box fail without the additional parameter. + ImageComparer.CheckSimilarity(source, image, 0.001F); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs b/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs deleted file mode 100644 index 5facee346..000000000 --- a/tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Tests -{ - using System; - using System.IO; - - using ImageSharp.PixelFormats; - - using Xunit; - - public class OilPaintTest : FileTestBase - { - public static readonly TheoryData> OilPaintValues - = new TheoryData> - { - new Tuple(15, 10), - new Tuple(6, 5) - }; - - [Theory] - [MemberData(nameof(OilPaintValues))] - public void ImageShouldApplyOilPaintFilter(Tuple value) - { - string path = this.CreateOutputDirectory("OilPaint"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value); - using (Image image = file.CreateImage()) - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - if (image.Width > value.Item2 && image.Height > value.Item2) - { - image.OilPaint(value.Item1, value.Item2).Save(output); - } - } - } - } - - [Theory] - [MemberData(nameof(OilPaintValues))] - public void ImageShouldApplyOilPaintFilterInBox(Tuple value) - { - string path = this.CreateOutputDirectory("OilPaint"); - - foreach (TestFile file in Files) - { - string filename = file.GetFileName(value + "-InBox"); - using (Image image = file.CreateImage()) - { - if (image.Width > value.Item2 && image.Height > value.Item2) - { - using (FileStream output = File.OpenWrite($"{path}/{filename}")) - { - image.OilPaint(value.Item1, value.Item2, new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2)).Save(output); - } - } - } - } - } - } -} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs index f55cfbf16..d31150a92 100644 --- a/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs +++ b/tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs @@ -40,7 +40,9 @@ namespace ImageSharp.Tests } else if (settings != null) { - if (settings.GetType().GetTypeInfo().IsPrimitive) + Type type = settings.GetType(); + TypeInfo info = type.GetTypeInfo(); + if (info.IsPrimitive || info.IsEnum || type == typeof(decimal)) { tag = settings.ToString(); }