Browse Source

Oilpainting

af/merge-core
James Jackson-South 9 years ago
parent
commit
d76fdedee7
  1. 33
      src/ImageSharp/Processing/Effects/OilPainting.cs
  2. 49
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
  3. 24
      tests/ImageSharp.Tests/FileTestBase.cs
  4. 37
      tests/ImageSharp.Tests/ImageComparer.cs
  5. 4
      tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs
  6. 8
      tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs
  7. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs
  8. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs
  9. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs
  10. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs
  11. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs
  12. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs
  13. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs
  14. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs
  15. 4
      tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs
  16. 4
      tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs
  17. 4
      tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs
  18. 4
      tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs
  19. 4
      tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs
  20. 55
      tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs
  21. 66
      tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs
  22. 4
      tests/ImageSharp.Tests/TestUtilities/TestImageExtensions.cs

33
src/ImageSharp/Processing/Effects/OilPainting.cs

@ -16,6 +16,35 @@ namespace ImageSharp
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Alters the colors of the image recreating an oil painting effect with levels and brushSize
/// set to <value>10</value> and <value>15</value> respectively.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> OilPaint<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
return OilPaint(source, 10, 15);
}
/// <summary>
/// Alters the colors of the image recreating an oil painting effect with levels and brushSize
/// set to <value>10</value> and <value>15</value> respectively.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> OilPaint<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
return OilPaint(source, 10, 15, rectangle);
}
/// <summary>
/// Alters the colors of the image recreating an oil painting effect.
/// </summary>
@ -24,8 +53,8 @@ namespace ImageSharp
/// <param name="levels">The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image.</param>
/// <param name="brushSize">The number of neighboring pixels used in calculating each individual pixel value.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> OilPaint<TPixel>(this Image<TPixel> source, int levels = 10, int brushSize = 15)
where TPixel : struct, IPixel<TPixel>
public static Image<TPixel> OilPaint<TPixel>(this Image<TPixel> source, int levels, int brushSize)
where TPixel : struct, IPixel<TPixel>
{
return OilPaint(source, levels, brushSize, source.Bounds);
}

49
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<TPixel> 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;
}
}

24
tests/ImageSharp.Tests/FileTestBase.cs

@ -12,30 +12,42 @@ namespace ImageSharp.Tests
/// </summary>
public abstract class FileTestBase : TestBase
{
/// <summary>
/// A collection made up of one file for each image format
/// </summary>
public static IEnumerable<string> DefaultFiles =
new[]
{
TestImages.Bmp.Car,
TestImages.Jpeg.Baseline.Calliphora,
TestImages.Png.Splash,
TestImages.Gif.Trans
};
/// <summary>
/// A collection of all the bmp test images
/// </summary>
public static IEnumerable<string> AllBmpFiles => TestImages.Bmp.All;
public static IEnumerable<string> AllBmpFiles = TestImages.Bmp.All;
/// <summary>
/// A collection of all the jpeg test images
/// </summary>
public static IEnumerable<string> AllJpegFiles => TestImages.Jpeg.All;
public static IEnumerable<string> AllJpegFiles = TestImages.Jpeg.All;
/// <summary>
/// A collection of all the png test images
/// </summary>
public static IEnumerable<string> AllPngFiles => TestImages.Png.All;
public static IEnumerable<string> AllPngFiles = TestImages.Png.All;
/// <summary>
/// A collection of all the gif test images
/// </summary>
public static IEnumerable<string> AllGifFiles => TestImages.Gif.All;
public static IEnumerable<string> AllGifFiles = TestImages.Gif.All;
/// <summary>
/// The standard pixel formats enumerations
/// The standard pixel format enumeration
/// </summary>
public const PixelTypes StandardPixelTypes = PixelTypes.StandardImageClass | PixelTypes.Rgba32;
public const PixelTypes StandardPixelType = PixelTypes.StandardImageClass;
public static class Extensions
{

37
tests/ImageSharp.Tests/ImageComparer.cs

@ -1,4 +1,9 @@
namespace ImageSharp.Tests
// <copyright file="ImageComparer.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using ImageSharp;
@ -12,9 +17,9 @@
/// </summary>
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
/// <summary>
/// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold
@ -25,15 +30,15 @@
/// <param name="actual">The actual image</param>
/// <param name="imageTheshold">
/// The threshold for the percentage difference where the images are asumed to be the same.
/// The default/undefined value is <see cref="ImageComparer.DefaultImageThreshold"/>
/// The default/undefined value is <see cref="DefaultImageThreshold"/>
/// </param>
/// <param name="segmentThreshold">
/// The threashold of the individual segments before it acumulates towards the overall difference.
/// The default undefined value is <see cref="ImageComparer.DefaultSegmentThreshold"/>
/// The threshold of the individual segments before it acumulates towards the overall difference.
/// The default undefined value is <see cref="DefaultSegmentThreshold"/>
/// </param>
/// <param name="scalingFactor">
/// This is a sampling factor we sample a grid of average pixels <paramref name="scalingFactor"/> width by <paramref name="scalingFactor"/> high
/// The default undefined value is <see cref="ImageComparer.DefaultScalingFactor"/>
/// The default undefined value is <see cref="DefaultScalingFactor"/>
/// </param>
public static void CheckSimilarity<TPixelA, TPixelB>(Image<TPixelA> expected, Image<TPixelB> actual, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA>
@ -52,8 +57,8 @@
/// <param name="source">The source image</param>
/// <param name="target">The target image</param>
/// <param name="segmentThreshold">
/// The threashold of the individual segments before it acumulates towards the overall difference.
/// The default undefined value is <see cref="ImageComparer.DefaultSegmentThreshold"/>
/// The threshold of the individual segments before it acumulates towards the overall difference.
/// The default undefined value is <see cref="DefaultSegmentThreshold"/>
/// </param>
/// <param name="scalingFactor">
/// This is a sampling factor we sample a grid of average pixels <paramref name="scalingFactor"/> width by <paramref name="scalingFactor"/> high
@ -74,14 +79,14 @@
if (b > segmentThreshold) { diffPixels++; }
}
return (float)diffPixels / (float)(scalingFactor * scalingFactor);
return diffPixels / (float)(scalingFactor * scalingFactor);
}
private static Fast2DArray<byte> GetDifferences<TPixelA, TPixelB>(Image<TPixelA> source, Image<TPixelB> target, int scalingFactor)
where TPixelA : struct, IPixel<TPixelA>
where TPixelB : struct, IPixel<TPixelB>
{
Fast2DArray<byte> differences = new Fast2DArray<byte>(scalingFactor, scalingFactor);
var differences = new Fast2DArray<byte>(scalingFactor, scalingFactor);
Fast2DArray<byte> firstGray = source.GetGrayScaleValues(scalingFactor);
Fast2DArray<byte> 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<byte> GetGrayScaleValues<TPixelA>(this Image<TPixelA> source, int scalingFactor)
where TPixelA : struct, IPixel<TPixelA>
{
byte[] buffer = new byte[4];
byte[] buffer = new byte[3];
using (Image<TPixelA> img = new Image<TPixelA>(source).Resize(scalingFactor, scalingFactor).Grayscale())
{
using (PixelAccessor<TPixelA> pixels = img.Lock())
{
Fast2DArray<byte> grayScale = new Fast2DArray<byte>(scalingFactor, scalingFactor);
var grayScale = new Fast2DArray<byte>(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];
}
}

4
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<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{

8
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<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
{
@ -44,7 +44,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), nameof(Ditherers), StandardPixelType)]
public void ImageShouldApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
{
@ -64,7 +64,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelType)]
public void ImageShouldApplyDiffusionFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel>
{
@ -76,7 +76,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), nameof(ErrorDiffusers), StandardPixelType)]
public void ImageShouldApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelType)]
public void ImageShouldApplyBlackWhiteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{

4
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.
/// </summary>
[Theory]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelTypes)]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, StandardPixelType)]
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelType)]
public void ImageShouldApplyKodachromeFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -26,7 +26,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelType)]
public void ImageShouldApplyLomographFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelType)]
public void ImageShouldApplyPolaroidFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -24,7 +24,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelTypes)]
[WithFileCollection(nameof(AllBmpFiles), StandardPixelType)]
public void ImageShouldApplySepiaFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{

4
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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
@ -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<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{

55
tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs

@ -0,0 +1,55 @@
// <copyright file="OilPaintTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using ImageSharp.PixelFormats;
using Xunit;
public class OilPaintTest : FileTestBase
{
public static readonly TheoryData<int, int> OilPaintValues
= new TheoryData<int, int>
{
{ 15, 10 },
{ 6, 5 }
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), StandardPixelType)]
public void ImageShouldApplyOilPaintFilter<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = new Image<TPixel>(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<TPixel>.HotPink, bounds);
source.Fill(NamedColors<TPixel>.HotPink, bounds);
// TODO: Why does the png box fail without the additional parameter.
ImageComparer.CheckSimilarity(source, image, 0.001F);
}
}
}
}

66
tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs

@ -1,66 +0,0 @@
// <copyright file="OilPaintTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
{
using System;
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class OilPaintTest : FileTestBase
{
public static readonly TheoryData<Tuple<int, int>> OilPaintValues
= new TheoryData<Tuple<int, int>>
{
new Tuple<int, int>(15, 10),
new Tuple<int, int>(6, 5)
};
[Theory]
[MemberData(nameof(OilPaintValues))]
public void ImageShouldApplyOilPaintFilter(Tuple<int, int> value)
{
string path = this.CreateOutputDirectory("OilPaint");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> 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<int, int> value)
{
string path = this.CreateOutputDirectory("OilPaint");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> 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);
}
}
}
}
}
}
}

4
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();
}

Loading…
Cancel
Save