Browse Source

Merge pull request #232 from JimBobSquarePants/chore/cleanup-tests

Cleanup Processing tests
af/merge-core
James Jackson-South 9 years ago
committed by GitHub
parent
commit
89f563be26
  1. 2
      src/ImageSharp/Image/ImageBase{TPixel}.cs
  2. 2
      src/ImageSharp/Image/ImageProcessingExtensions.cs
  3. 2
      src/ImageSharp/Image/Image{TPixel}.cs
  4. 2
      src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs
  5. 2
      src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs
  6. 42
      src/ImageSharp/Processing/ColorMatrix/Grayscale.cs
  7. 2
      src/ImageSharp/Processing/ColorMatrix/Hue.cs
  8. 2
      src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs
  9. 2
      src/ImageSharp/Processing/ColorMatrix/Lomograph.cs
  10. 2
      src/ImageSharp/Processing/ColorMatrix/Polaroid.cs
  11. 2
      src/ImageSharp/Processing/ColorMatrix/Saturation.cs
  12. 2
      src/ImageSharp/Processing/ColorMatrix/Sepia.cs
  13. 2
      src/ImageSharp/Processing/Convolution/DetectEdges.cs
  14. 2
      src/ImageSharp/Processing/Convolution/GaussianBlur.cs
  15. 2
      src/ImageSharp/Processing/Convolution/GaussianSharpen.cs
  16. 33
      src/ImageSharp/Processing/Effects/OilPainting.cs
  17. 4
      src/ImageSharp/Processing/Overlays/Glow.cs
  18. 4
      src/ImageSharp/Processing/Overlays/Vignette.cs
  19. 49
      src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs
  20. 7
      src/ImageSharp/Processing/Transforms/AutoOrient.cs
  21. 2
      src/ImageSharp/Processing/Transforms/Flip.cs
  22. 18
      src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs
  23. 2
      src/ImageSharp/Processing/Transforms/Pad.cs
  24. 24
      src/ImageSharp/Processing/Transforms/Resize.cs
  25. 2
      src/ImageSharp/Processing/Transforms/Rotate.cs
  26. 2
      src/ImageSharp/Processing/Transforms/RotateFlip.cs
  27. 2
      tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs
  28. 1
      tests/ImageSharp.Sandbox46/Program.cs
  29. 4
      tests/ImageSharp.Tests/Drawing/BlendedShapes.cs
  30. 2
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  31. 2
      tests/ImageSharp.Tests/Drawing/Paths/Extensions.cs
  32. 2
      tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs
  33. 2
      tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs
  34. 2
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs
  35. 2
      tests/ImageSharp.Tests/Drawing/Text/OutputText.cs
  36. 48
      tests/ImageSharp.Tests/FileTestBase.cs
  37. 22
      tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs
  38. 2
      tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
  39. 2
      tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs
  40. 16
      tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
  41. 12
      tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs
  42. 2
      tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs
  43. 4
      tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs
  44. 4
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  45. 2
      tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs
  46. 6
      tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs
  47. 71
      tests/ImageSharp.Tests/ImageComparer.cs
  48. 51
      tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs
  49. 92
      tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs
  50. 43
      tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs
  51. 57
      tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs
  52. 30
      tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs
  53. 50
      tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs
  54. 43
      tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs
  55. 45
      tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs
  56. 43
      tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs
  57. 50
      tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs
  58. 43
      tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs
  59. 50
      tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs
  60. 59
      tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs
  61. 30
      tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs
  62. 30
      tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs
  63. 50
      tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs
  64. 43
      tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs
  65. 50
      tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs
  66. 50
      tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs
  67. 43
      tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs
  68. 50
      tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs
  69. 84
      tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs
  70. 67
      tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs
  71. 67
      tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs
  72. 30
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
  73. 26
      tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs
  74. 33
      tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs
  75. 37
      tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs
  76. 35
      tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs
  77. 17
      tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs
  78. 273
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs
  79. 39
      tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs
  80. 55
      tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs
  81. 33
      tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs
  82. 57
      tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs
  83. 47
      tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs
  84. 57
      tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs
  85. 47
      tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs
  86. 57
      tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs
  87. 57
      tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs
  88. 64
      tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs
  89. 56
      tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs
  90. 31
      tests/ImageSharp.Tests/Processors/Filters/CropTest.cs
  91. 67
      tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs
  92. 104
      tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs
  93. 40
      tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs
  94. 42
      tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs
  95. 80
      tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs
  96. 57
      tests/ImageSharp.Tests/Processors/Filters/HueTest.cs
  97. 46
      tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs
  98. 47
      tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs
  99. 48
      tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs
  100. 66
      tests/ImageSharp.Tests/Processors/Filters/OilPaintTest.cs

2
src/ImageSharp/Image/ImageBase{TPixel}.cs

@ -11,7 +11,7 @@ namespace ImageSharp
using ImageSharp.Memory;
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
/// <summary>
/// The base class of all images. Encapsulates the basic properties and methods required to manipulate

2
src/ImageSharp/Image/ImageProcessingExtensions.cs

@ -7,7 +7,7 @@ namespace ImageSharp
{
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.

2
src/ImageSharp/Image/Image{TPixel}.cs

@ -15,7 +15,7 @@ namespace ImageSharp
using Formats;
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
/// <summary>
/// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes.

2
src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

42
src/ImageSharp/Processing/ColorMatrix/Grayscale.cs

@ -5,11 +5,9 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>
@ -17,6 +15,18 @@ namespace ImageSharp
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image.
/// </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> Grayscale<TPixel>(this Image<TPixel> source)
where TPixel : struct, IPixel<TPixel>
{
return Grayscale(source, GrayscaleMode.Bt709);
}
/// <summary>
/// Applies Grayscale toning to the image.
/// </summary>
@ -24,23 +34,41 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode = GrayscaleMode.Bt709)
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode)
where TPixel : struct, IPixel<TPixel>
{
return Grayscale(source, source.Bounds, mode);
return Grayscale(source, mode, source.Bounds);
}
/// <summary>
/// Applies Grayscale toning to the image.
/// Applies <see cref="GrayscaleMode.Bt709"/> Grayscale toning to the image.
/// </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> Grayscale<TPixel>(this Image<TPixel> source, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
IImageProcessor<TPixel> processor = new GrayscaleBt709Processor<TPixel>();
source.ApplyProcessor(processor, rectangle);
return source;
}
/// <summary>
/// Applies Grayscale toning to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="mode">The formula to apply to perform the operation.</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> Grayscale<TPixel>(this Image<TPixel> source, Rectangle rectangle, GrayscaleMode mode = GrayscaleMode.Bt709)
public static Image<TPixel> Grayscale<TPixel>(this Image<TPixel> source, GrayscaleMode mode, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
IImageProcessor<TPixel> processor = mode == GrayscaleMode.Bt709

2
src/ImageSharp/Processing/ColorMatrix/Hue.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/Lomograph.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/Polaroid.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/Saturation.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/ColorMatrix/Sepia.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/Convolution/DetectEdges.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/Convolution/GaussianBlur.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/Convolution/GaussianSharpen.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

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

4
src/ImageSharp/Processing/Overlays/Glow.cs

@ -5,8 +5,6 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing.Processors;
@ -158,7 +156,7 @@ namespace ImageSharp
public static Image<TPixel> Glow<TPixel>(this Image<TPixel> source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
GlowProcessor<TPixel> processor = new GlowProcessor<TPixel>(color, options) { Radius = radius, };
var processor = new GlowProcessor<TPixel>(color, options) { Radius = radius, };
source.ApplyProcessor(processor, rectangle);
return source;
}

4
src/ImageSharp/Processing/Overlays/Vignette.cs

@ -5,8 +5,6 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing.Processors;
@ -162,7 +160,7 @@ namespace ImageSharp
public static Image<TPixel> Vignette<TPixel>(this Image<TPixel> source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
VignetteProcessor<TPixel> processor = new VignetteProcessor<TPixel>(color, options) { RadiusX = radiusX, RadiusY = radiusY };
var processor = new VignetteProcessor<TPixel>(color, options) { RadiusX = radiusX, RadiusY = radiusY };
source.ApplyProcessor(processor, rectangle);
return source;
}

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

7
src/ImageSharp/Processing/Transforms/AutoOrient.cs

@ -5,12 +5,9 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing;
using Processing.Processors;
using ImageSharp.Processing;
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
@ -80,7 +77,7 @@ namespace ImageSharp
return Orientation.Unknown;
}
Orientation orientation = (Orientation)value.Value;
var orientation = (Orientation)value.Value;
source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft);

2
src/ImageSharp/Processing/Transforms/Flip.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

18
src/ImageSharp/Processing/Transforms/Options/ResizeHelper.cs

@ -399,6 +399,10 @@ namespace ImageSharp.Processing
return new Rectangle(0, 0, source.Width, source.Height);
}
// Fractional variants for preserving aspect ratio.
float percentHeight = MathF.Abs(height / (float)source.Height);
float percentWidth = MathF.Abs(width / (float)source.Width);
float sourceRatio = (float)source.Height / source.Width;
// Find the shortest distance to go.
@ -419,8 +423,18 @@ namespace ImageSharp.Processing
}
else
{
destinationWidth = width;
destinationHeight = height;
if (height > width)
{
destinationWidth = width;
destinationHeight = Convert.ToInt32(source.Height * percentWidth);
height = destinationHeight;
}
else
{
destinationHeight = height;
destinationWidth = Convert.ToInt32(source.Width * percentHeight);
width = destinationWidth;
}
}
// Replace the size to match the rectangle.

2
src/ImageSharp/Processing/Transforms/Pad.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

24
src/ImageSharp/Processing/Transforms/Resize.cs

@ -5,11 +5,9 @@
namespace ImageSharp
{
using System;
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>
@ -58,6 +56,21 @@ namespace ImageSharp
return Resize(source, size.Width, size.Height, new BicubicResampler(), false);
}
/// <summary>
/// Resizes an image to the given <see cref="Size"/>.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to resize.</param>
/// <param name="size">The target image size.</param>
/// <param name="compand">Whether to compress and expand the image color-space to gamma correct the image during processing.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static Image<TPixel> Resize<TPixel>(this Image<TPixel> source, Size size, bool compand)
where TPixel : struct, IPixel<TPixel>
{
return Resize(source, size.Width, size.Height, new BicubicResampler(), compand);
}
/// <summary>
/// Resizes an image to the given width and height.
/// </summary>
@ -140,7 +153,7 @@ namespace ImageSharp
/// <param name="compand">Whether to compress and expand the image color-space to gamma correct the image during processing.</param>
/// <returns>The <see cref="Image{TPixel}"/></returns>
/// <remarks>Passing zero for one of height or width will automatically preserve the aspect ratio of the original image</remarks>
public static Image<TPixel> Resize<TPixel>(this Image<TPixel> source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand = false)
public static Image<TPixel> Resize<TPixel>(this Image<TPixel> source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand)
where TPixel : struct, IPixel<TPixel>
{
if (width == 0 && height > 0)
@ -158,8 +171,7 @@ namespace ImageSharp
Guard.MustBeGreaterThan(width, 0, nameof(width));
Guard.MustBeGreaterThan(height, 0, nameof(height));
ResizeProcessor<TPixel> processor =
new ResizeProcessor<TPixel>(sampler, width, height, targetRectangle) { Compand = compand };
var processor = new ResizeProcessor<TPixel>(sampler, width, height, targetRectangle) { Compand = compand };
source.ApplyProcessor(processor, sourceRectangle);
return source;

2
src/ImageSharp/Processing/Transforms/Rotate.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
using Processing.Processors;
/// <summary>

2
src/ImageSharp/Processing/Transforms/RotateFlip.cs

@ -9,7 +9,7 @@ namespace ImageSharp
using ImageSharp.PixelFormats;
using Processing;
using ImageSharp.Processing;
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.

2
tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs

@ -9,7 +9,7 @@ namespace ImageSharp.Benchmarks
using BenchmarkDotNet.Attributes;
using Processing;
using ImageSharp.Processing;
using CoreImage = ImageSharp.Image;

1
tests/ImageSharp.Sandbox46/Program.cs

@ -10,6 +10,7 @@ namespace ImageSharp.Sandbox46
using ImageSharp.Tests;
using ImageSharp.Tests.Colors;
using ImageSharp.Tests.Processing.Transforms;
using Xunit.Abstractions;

4
tests/ImageSharp.Tests/Drawing/BlendedShapes.cs

@ -18,7 +18,7 @@ namespace ImageSharp.Tests.Drawing
.Select(x=> new object[] { x });
[Theory]
[WithBlankImages(nameof(modes), 100, 100, PixelTypes.StandardImageClass)]
[WithBlankImages(nameof(modes), 100, 100, PixelTypes.Rgba32)]
public void DrawBlendedValues<TPixel>(TestImageProvider<TPixel> provider, PixelBlenderMode mode)
where TPixel : struct, IPixel<TPixel>
{
@ -34,7 +34,7 @@ namespace ImageSharp.Tests.Drawing
}
[Theory]
[WithBlankImages(nameof(modes), 100, 100, PixelTypes.StandardImageClass)]
[WithBlankImages(nameof(modes), 100, 100, PixelTypes.Rgba32)]
public void DrawBlendedValues_transparent<TPixel>(TestImageProvider<TPixel> provider, PixelBlenderMode mode)
where TPixel : struct, IPixel<TPixel>
{

2
tests/ImageSharp.Tests/Drawing/DrawImageTest.cs

@ -12,7 +12,7 @@ namespace ImageSharp.Tests
public class DrawImageTest : FileTestBase
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass;
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32;
public static readonly string[] TestFiles = {
TestImages.Jpeg.Baseline.Calliphora,

2
tests/ImageSharp.Tests/Drawing/Paths/Extensions.cs

@ -5,7 +5,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using System.IO;
using ImageSharp;
using ImageSharp.Drawing.Brushes;
using Processing;
using ImageSharp.Processing;
using System.Collections.Generic;
using Xunit;
using ImageSharp.Drawing;

2
tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs

@ -4,7 +4,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using System;
using System.IO;
using ImageSharp;
using Processing;
using ImageSharp.Processing;
using System.Collections.Generic;
using ImageSharp.PixelFormats;

2
tests/ImageSharp.Tests/Drawing/Paths/ShapePathTests.cs

@ -5,7 +5,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using System.IO;
using ImageSharp;
using ImageSharp.Drawing.Brushes;
using Processing;
using ImageSharp.Processing;
using System.Collections.Generic;
using Xunit;
using ImageSharp.Drawing;

2
tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

@ -5,7 +5,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using System.IO;
using ImageSharp;
using ImageSharp.Drawing.Brushes;
using Processing;
using ImageSharp.Processing;
using System.Collections.Generic;
using Xunit;
using ImageSharp.Drawing;

2
tests/ImageSharp.Tests/Drawing/Text/OutputText.cs

@ -5,7 +5,7 @@ namespace ImageSharp.Tests.Drawing.Text
using System.IO;
using ImageSharp;
using ImageSharp.Drawing.Brushes;
using Processing;
using ImageSharp.Processing;
using System.Collections.Generic;
using Xunit;
using ImageSharp.Drawing;

48
tests/ImageSharp.Tests/FileTestBase.cs

@ -12,6 +12,54 @@ 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;
/// <summary>
/// A collection of all the jpeg test images
/// </summary>
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;
/// <summary>
/// A collection of all the gif test images
/// </summary>
public static IEnumerable<string> AllGifFiles = TestImages.Gif.All;
/// <summary>
/// The standard pixel format enumeration
/// </summary>
public const PixelTypes DefaultPixelType = PixelTypes.Rgba32;
public static class Extensions
{
public const string Bmp = "bmp";
public const string Jpeg = "jpg";
public const string Png = "png";
public const string Gif = "gif";
}
/// <summary>
/// The collection of image files to test against.
/// </summary>

22
tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs

@ -13,22 +13,16 @@ namespace ImageSharp.Tests
public class GeneralFormatTests : FileTestBase
{
[Fact]
public void ResolutionShouldChange()
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ResolutionShouldChange<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
string path = this.CreateOutputDirectory("Resolution");
foreach (TestFile file in Files)
using (Image<TPixel> image = provider.GetImage())
{
using (Image<Rgba32> image = file.CreateImage())
{
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.MetaData.VerticalResolution = 150;
image.MetaData.HorizontalResolution = 150;
image.Save(output);
}
}
image.MetaData.VerticalResolution = 150;
image.MetaData.HorizontalResolution = 150;
image.DebugSave(provider, null, Extensions.Bmp);
}
}

2
tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

@ -14,7 +14,7 @@ namespace ImageSharp.Tests
public class GifDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
public static readonly string[] TestFiles = { TestImages.Gif.Giphy, TestImages.Gif.Rings, TestImages.Gif.Trans };

2
tests/ImageSharp.Tests/Formats/Gif/GifEncoderTests.cs

@ -13,7 +13,7 @@ namespace ImageSharp.Tests
public class GifEncoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
[Theory]
[WithTestPatternImages(100, 100, PixelTypes)]

16
tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs

@ -26,7 +26,7 @@ namespace ImageSharp.Tests
public static string[] ProgressiveTestJpegs = TestImages.Jpeg.Progressive.All;
[Theory]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
[WithFileCollection(nameof(BaselineTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void OpenBaselineJpeg_SaveBmp<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -37,7 +37,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32)]
[WithFileCollection(nameof(ProgressiveTestJpegs), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void OpenProgressiveJpeg_SaveBmp<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -48,11 +48,11 @@ namespace ImageSharp.Tests
}
[Theory]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio420, 75)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio420, 100)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 75)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 100)]
[WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.StandardImageClass, JpegSubsample.Ratio444, 100)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 75)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio420, 100)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 75)]
[WithSolidFilledImages(16, 16, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)]
[WithSolidFilledImages(8, 8, 255, 0, 0, PixelTypes.Rgba32, JpegSubsample.Ratio444, 100)]
public void DecodeGenerated_SaveBmp<TPixel>(
TestImageProvider<TPixel> provider,
JpegSubsample subsample,
@ -79,7 +79,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithSolidFilledImages(42, 88, 255, 0, 0, PixelTypes.StandardImageClass)]
[WithSolidFilledImages(42, 88, 255, 0, 0, PixelTypes.Rgba32)]
public void DecodeGenerated_MetadataOnly<TPixel>(
TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>

12
tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs

@ -28,10 +28,10 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)]
[WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio420)]
[WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)]
[WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.StandardImageClass, 75, JpegSubsample.Ratio444)]
[WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.Rgba32, 75, JpegSubsample.Ratio420)]
[WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.Rgba32, 75, JpegSubsample.Ratio420)]
[WithFile(TestImages.Jpeg.Baseline.Snake, PixelTypes.Rgba32, 75, JpegSubsample.Ratio444)]
[WithFile(TestImages.Jpeg.Baseline.Lake, PixelTypes.Rgba32, 75, JpegSubsample.Ratio444)]
public void LoadResizeSave<TPixel>(TestImageProvider<TPixel> provider, int quality, JpegSubsample subsample)
where TPixel : struct, IPixel<TPixel>
{
@ -49,8 +49,8 @@ namespace ImageSharp.Tests
}
[Theory]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.StandardImageClass | PixelTypes.Argb32, JpegSubsample.Ratio444, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32, JpegSubsample.Ratio420, 75)]
[WithFileCollection(nameof(AllBmpFiles), PixelTypes.Rgba32 | PixelTypes.Rgba32 | PixelTypes.Argb32, JpegSubsample.Ratio444, 75)]
public void OpenBmp_SaveJpeg<TPixel>(TestImageProvider<TPixel> provider, JpegSubsample subSample, int quality)
where TPixel : struct, IPixel<TPixel>
{

2
tests/ImageSharp.Tests/Formats/Jpg/JpegProfilingBenchmarks.cs

@ -72,7 +72,7 @@ namespace ImageSharp.Tests
Image<Rgba32>[] testImages =
testFiles.Select(
tf => TestImageProvider<Rgba32>.File(tf, pixelTypeOverride: PixelTypes.StandardImageClass).GetImage())
tf => TestImageProvider<Rgba32>.File(tf, pixelTypeOverride: PixelTypes.Rgba32).GetImage())
.ToArray();
using (MemoryStream ms = new MemoryStream())

4
tests/ImageSharp.Tests/Formats/Jpg/JpegUtilsTests.cs

@ -40,7 +40,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.StandardImageClass | PixelTypes.Argb32)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void CopyStretchedRGBTo_FromOrigo<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -62,7 +62,7 @@ namespace ImageSharp.Tests
}
[Theory]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.StandardImageClass | PixelTypes.Argb32)]
[WithMemberFactory(nameof(CreateTestImage), PixelTypes.Rgba32| PixelTypes.Rgba32 | PixelTypes.Argb32)]
public void CopyStretchedRGBTo_WithOffset<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

4
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -13,12 +13,12 @@ namespace ImageSharp.Tests
public class PngDecoderTests
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
public static readonly string[] TestFiles =
{
TestImages.Png.Splash, TestImages.Png.Indexed, TestImages.Png.Interlaced, TestImages.Png.FilterVar,
TestImages.Png.ChunkLength1, TestImages.Png.ChunkLength2
TestImages.Png.Bad.ChunkLength1, TestImages.Png.Bad.ChunkLength2
};
[Theory]

2
tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

@ -18,7 +18,7 @@ namespace ImageSharp.Tests
public class PngEncoderTests : FileTestBase
{
private const PixelTypes PixelTypes = Tests.PixelTypes.StandardImageClass | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
private const PixelTypes PixelTypes = Tests.PixelTypes.Rgba32 | Tests.PixelTypes.RgbaVector | Tests.PixelTypes.Argb32;
[Theory]
[WithTestPatternImages(100, 100, PixelTypes, PngColorType.RgbWithAlpha)]

6
tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Tests.Formats.Png
public class PngSmokeTests
{
[Theory]
[WithTestPatternImages(300, 300, PixelTypes.StandardImageClass)]
[WithTestPatternImages(300, 300, PixelTypes.Rgba32)]
public void GeneralTest<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -41,7 +41,7 @@ namespace ImageSharp.Tests.Formats.Png
}
[Theory]
[WithTestPatternImages(100, 100, PixelTypes.StandardImageClass)]
[WithTestPatternImages(100, 100, PixelTypes.Rgba32)]
public void CanSaveIndexedPng<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
@ -105,7 +105,7 @@ namespace ImageSharp.Tests.Formats.Png
//}
[Theory]
[WithTestPatternImages(300, 300, PixelTypes.StandardImageClass)]
[WithTestPatternImages(300, 300, PixelTypes.Rgba32)]
public void Resize<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{

71
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,41 @@
/// </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>
/// Fills the bounded area with a solid color and does a visual comparison between 2 images asserting the difference outwith
/// that area is less then a configurable threshold.
/// </summary>
/// <typeparam name="TPixelA">The color of the expected image</typeparam>
/// <typeparam name="TPixelB">The color type fo the the actual image</typeparam>
/// <param name="expected">The expected image</param>
/// <param name="actual">The actual image</param>
/// <param name="bounds">The bounds within the image has been altered</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="DefaultImageThreshold"/>
/// </param>
/// <param name="segmentThreshold">
/// 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="DefaultScalingFactor"/>
/// </param>
public static void EnsureProcessorChangesAreConstrained<TPixelA, TPixelB>(Image<TPixelA> expected, Image<TPixelB> actual, Rectangle bounds, float imageTheshold = DefaultImageThreshold, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA>
where TPixelB : struct, IPixel<TPixelB>
{
// Draw identical shapes over the bounded and compare to ensure changes are constrained.
expected.Fill(NamedColors<TPixelA>.HotPink, bounds);
actual.Fill(NamedColors<TPixelB>.HotPink, bounds);
CheckSimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor);
}
/// <summary>
/// Does a visual comparison between 2 images and then asserts the difference is less then a configurable threshold
@ -25,15 +62,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,14 +89,14 @@
/// <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
/// The default undefined value is <see cref="ImageComparer.DefaultScalingFactor"/>
/// </param>
/// <returns>Returns a number from 0 - 1 which represents the diference focter between the images.</returns>
/// <returns>Returns a number from 0 - 1 which represents the difference focter between the images.</returns>
public static float PercentageDifference<TPixelA, TPixelB>(this Image<TPixelA> source, Image<TPixelB> target, byte segmentThreshold = DefaultSegmentThreshold, int scalingFactor = DefaultScalingFactor)
where TPixelA : struct, IPixel<TPixelA>
where TPixelB : struct, IPixel<TPixelB>
@ -74,14 +111,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 +126,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 +137,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];
}
}

51
tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs

@ -0,0 +1,51 @@
// <copyright file="BinaryThresholdTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Binarization
{
using ImageSharp.PixelFormats;
using Xunit;
public class BinaryThresholdTest : FileTestBase
{
public static readonly TheoryData<float> BinaryThresholdValues
= new TheoryData<float>
{
.25F,
.75F
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)]
public void ImageShouldApplyBinaryThresholdFilter<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.BinaryThreshold(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)]
public void ImageShouldApplyBinaryThresholdInBox<TPixel>(TestImageProvider<TPixel> provider, float value)
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.BinaryThreshold(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

92
tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs

@ -0,0 +1,92 @@
// <copyright file="DitherTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Binarization
{
using ImageSharp.Dithering;
using ImageSharp.Dithering.Ordered;
using ImageSharp.PixelFormats;
using Xunit;
public class DitherTest : FileTestBase
{
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither>
{
{ "Ordered", new Ordered() },
{ "Bayer", new Bayer() }
};
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser>
{
{ "Atkinson", new Atkinson() },
{ "Burks", new Burks() },
{ "FloydSteinberg", new FloydSteinberg() },
{ "JarvisJudiceNinke", new JarvisJudiceNinke() },
{ "Sierra2", new Sierra2() },
{ "Sierra3", new Sierra3() },
{ "SierraLite", new SierraLite() },
{ "Stucki", new Stucki() },
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)]
public void ImageShouldApplyDitherFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Dither(ditherer)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)]
public void ImageShouldApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
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.Dither(ditherer, bounds)
.DebugSave(provider, name, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)]
public void ImageShouldApplyDiffusionFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Dither(diffuser, .5F)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)]
public void ImageShouldApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
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.Dither(diffuser,.5F, bounds)
.DebugSave(provider, name, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs

@ -0,0 +1,43 @@
// <copyright file="BlackWhiteTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class BlackWhiteTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBlackWhiteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.BlackWhite()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBlackWhiteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.BlackWhite(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

57
tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs

@ -0,0 +1,57 @@
// <copyright file="ColorBlindnessTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class ColorBlindnessTest : FileTestBase
{
public static readonly TheoryData<ColorBlindness> ColorBlindnessFilters
= new TheoryData<ColorBlindness>
{
ColorBlindness.Achromatomaly,
ColorBlindness.Achromatopsia,
ColorBlindness.Deuteranomaly,
ColorBlindness.Deuteranopia,
ColorBlindness.Protanomaly,
ColorBlindness.Protanopia,
ColorBlindness.Tritanomaly,
ColorBlindness.Tritanopia
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)]
public void ImageShouldApplyColorBlindnessFilter<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.ColorBlindness(colorBlindness)
.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)]
public void ImageShouldApplyColorBlindnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
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.ColorBlindness(colorBlindness, bounds)
.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

30
tests/ImageSharp.Tests/Processors/Filters/GrayscaleTest.cs → tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs

@ -3,21 +3,27 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using Xunit;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.PixelFormats;
using Xunit;
public class GrayscaleTest : FileTestBase
{
public static readonly TheoryData<GrayscaleMode> GrayscaleModeTypes
= new TheoryData<GrayscaleMode>
{
GrayscaleMode.Bt601,
GrayscaleMode.Bt709
};
/// <summary>
/// Use test patterns over loaded images to save decode time.
/// </summary>
[Theory]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt601)]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)]
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{
@ -37,22 +43,18 @@ namespace ImageSharp.Tests
}
[Theory]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt709)]
[WithTestPatternImages(50, 50, PixelTypes.StandardImageClass, GrayscaleMode.Bt601)]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)]
public void ImageShouldApplyGrayscaleFilterInBox<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source))
using (var image = new Image<TPixel>(source))
{
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Grayscale(rect, value)
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Grayscale(value, bounds)
.DebugSave(provider, value.ToString());
// Let's draw identical shapes over the greyed areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);
source.Fill(NamedColors<TPixel>.HotPink, rect);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

50
tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs

@ -0,0 +1,50 @@
// <copyright file="HueTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class HueTest : FileTestBase
{
public static readonly TheoryData<int> HueValues
= new TheoryData<int>
{
180,
-180
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)]
public void ImageShouldApplyHueFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Hue(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)]
public void ImageShouldApplyHueFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
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.Hue(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs

@ -0,0 +1,43 @@
// <copyright file="KodachromeTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class KodachromeTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyKodachromeFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Kodachrome()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyKodachromeFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Kodachrome(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

45
tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs

@ -0,0 +1,45 @@
// <copyright file="LomographTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class LomographTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyLomographFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Lomograph()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyLomographFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Lomograph(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs

@ -0,0 +1,43 @@
// <copyright file="PolaroidTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class PolaroidTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyPolaroidFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Polaroid()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyPolaroidFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Polaroid(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs

@ -0,0 +1,50 @@
// <copyright file="SaturationTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class SaturationTest : FileTestBase
{
public static readonly TheoryData<int> SaturationValues
= new TheoryData<int>
{
50 ,
-50 ,
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)]
public void ImageShouldApplySaturationFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Saturation(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)]
public void ImageShouldApplySaturationFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
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.Saturation(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs

@ -0,0 +1,43 @@
// <copyright file="SepiaTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using Xunit;
public class SepiaTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplySepiaFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Sepia()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplySepiaFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Sepia(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs

@ -0,0 +1,50 @@
// <copyright file="BoxBlurTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using Xunit;
public class BoxBlurTest : FileTestBase
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
{
3,
5
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)]
public void ImageShouldApplyBoxBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.BoxBlur(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)]
public void ImageShouldApplyBoxBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
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.BoxBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

59
tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs

@ -0,0 +1,59 @@
// <copyright file="DetectEdgesTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class DetectEdgesTest : FileTestBase
{
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters
= new TheoryData<EdgeDetection>
{
EdgeDetection.Kayyali,
EdgeDetection.Kirsch,
EdgeDetection.Lapacian3X3,
EdgeDetection.Lapacian5X5,
EdgeDetection.LaplacianOfGaussian,
EdgeDetection.Prewitt,
EdgeDetection.RobertsCross,
EdgeDetection.Robinson,
EdgeDetection.Scharr,
EdgeDetection.Sobel
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilter<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.DetectEdges(detector)
.DebugSave(provider, detector.ToString(), Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilterInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
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.DetectEdges(detector, bounds)
.DebugSave(provider, detector.ToString(), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

30
tests/ImageSharp.Tests/Processors/Filters/GaussianBlurTest.cs → tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs

@ -3,49 +3,47 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Convolution
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class GaussianBlurTest
public class GaussianBlurTest : FileTestBase
{
public static readonly TheoryData<int> GaussianBlurValues
= new TheoryData<int>
{
3 ,
5 ,
3,
5
};
[Theory]
[WithTestPatternImages(nameof(GaussianBlurValues), 320, 240, PixelTypes.StandardImageClass)]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)]
public void ImageShouldApplyGaussianBlurFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.GaussianBlur(value)
.DebugSave(provider, value.ToString());
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithTestPatternImages(nameof(GaussianBlurValues), 320, 240, PixelTypes.StandardImageClass)]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)]
public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source))
using (var image = new Image<TPixel>(source))
{
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.GaussianBlur(value, rect)
.DebugSave(provider, value.ToString());
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.GaussianBlur(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// lets draw identical shapes over the blured areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);
source.Fill(NamedColors<TPixel>.HotPink, rect);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

30
tests/ImageSharp.Tests/Processors/Filters/GaussianSharpenTest.cs → tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs

@ -3,10 +3,10 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Convolution
{
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class GaussianSharpenTest : FileTestBase
@ -14,38 +14,36 @@ namespace ImageSharp.Tests
public static readonly TheoryData<int> GaussianSharpenValues
= new TheoryData<int>
{
3 ,
5 ,
3,
5
};
[Theory]
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.GaussianSharpen(value)
.DebugSave(provider, value.ToString());
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithTestPatternImages(nameof(GaussianSharpenValues), 320, 240, PixelTypes.StandardImageClass)]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (Image<TPixel> image = new Image<TPixel>(source))
using (var image = new Image<TPixel>(source))
{
Rectangle rect = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.GaussianSharpen(value, rect)
.DebugSave(provider, value.ToString());
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.GaussianSharpen(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
// lets draw identical shapes over the Sharpened areas and ensure that it didn't change the outer area
image.Fill(NamedColors<TPixel>.HotPink, rect);
source.Fill(NamedColors<TPixel>.HotPink, rect);
ImageComparer.CheckSimilarity(image, source);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}

50
tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs

@ -0,0 +1,50 @@
// <copyright file="AlphaTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class AlphaTest : FileTestBase
{
public static readonly TheoryData<float> AlphaValues
= new TheoryData<float>
{
20/100F,
80/100F
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)]
public void ImageShouldApplyAlphaFilter<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Alpha(value)
.DebugSave(provider, value, Extensions.Png);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)]
public void ImageShouldApplyAlphaFilterInBox<TPixel>(TestImageProvider<TPixel> provider, float value)
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.Alpha(value, bounds)
.DebugSave(provider, value, Extensions.Png);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs

@ -0,0 +1,43 @@
// <copyright file="BackgroundColorTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class BackgroundColorTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.BackgroundColor(NamedColors<TPixel>.HotPink)
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.BackgroundColor(NamedColors<TPixel>.HotPink, bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs

@ -0,0 +1,50 @@
// <copyright file="BrightnessTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class BrightnessTest : FileTestBase
{
public static readonly TheoryData<int> BrightnessValues
= new TheoryData<int>
{
50,
-50
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)]
public void ImageShouldApplyBrightnessFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Brightness(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)]
public void ImageShouldApplyBrightnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
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.Brightness(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ;
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs

@ -0,0 +1,50 @@
// <copyright file="ContrastTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class ContrastTest : FileTestBase
{
public static readonly TheoryData<int> ContrastValues
= new TheoryData<int>
{
50,
-50
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)]
public void ImageShouldApplyContrastFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Contrast(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)]
public void ImageShouldApplyContrastFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
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.Contrast(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs

@ -0,0 +1,43 @@
// <copyright file="InvertTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class InvertTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyInvertFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Invert()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyInvertFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Invert(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

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

@ -0,0 +1,50 @@
// <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), DefaultPixelType)]
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), DefaultPixelType)]
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);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F);
}
}
}
}

84
tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs

@ -0,0 +1,84 @@
// <copyright file="PixelateTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using Xunit;
public class PixelateTest : FileTestBase
{
public static readonly TheoryData<int> PixelateValues
= new TheoryData<int>
{
4 ,
8
};
[Theory]
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
public void ImageShouldApplyPixelateFilter<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Pixelate(value)
.DebugSave(provider, value, Extensions.Bmp);
// 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]);
}
}
}
}
}
}
[Theory]
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
public void ImageShouldApplyPixelateFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> source = provider.GetImage())
using (var image = new Image<TPixel>(source))
{
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Pixelate(value, bounds)
.DebugSave(provider, value, Extensions.Bmp);
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.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

67
tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs

@ -0,0 +1,67 @@
// <copyright file="GlowTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Overlays
{
using ImageSharp.PixelFormats;
using Xunit;
public class GlowTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Glow()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Glow(NamedColors<TPixel>.Orange)
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Glow(image.Width / 4F)
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Glow(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

67
tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs

@ -0,0 +1,67 @@
// <copyright file="VignetteTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Overlays
{
using ImageSharp.PixelFormats;
using Xunit;
public class VignetteTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Vignette()
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Vignette(NamedColors<TPixel>.Orange)
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Vignette(image.Width / 4F, image.Height / 4F)
.DebugSave(provider, null, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
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.Vignette(bounds)
.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

30
tests/ImageSharp.Tests/Processors/Filters/AutoOrientTests.cs → tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -1,19 +1,19 @@
// <copyright file="RotateFlipTest.cs" company="James Jackson-South">
// <copyright file="AutoOrientTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Transforms
{
using System.IO;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Processing;
using Xunit;
public class AutoOrientTests : FileTestBase
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues
= new TheoryData<RotateType, FlipType, ushort>
{
@ -29,23 +29,19 @@ namespace ImageSharp.Tests
};
[Theory]
[MemberData(nameof(OrientationValues))]
public void ImageShouldFlip(RotateType rotateType, FlipType flipType, ushort orientation)
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation)
where TPixel : struct, IPixel<TPixel>
{
string path = this.CreateOutputDirectory("AutoOrient");
TestFile file = TestFile.Create(TestImages.Bmp.F);
using (Image<Rgba32> image = file.CreateImage())
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile();
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
using (FileStream before = File.OpenWrite($"{path}/before-{file.FileName}"))
using (FileStream after = File.OpenWrite($"{path}/after-{file.FileName}"))
{
image.RotateFlip(rotateType, flipType).Save(before).AutoOrient().Save(after);
}
image.RotateFlip(rotateType, flipType)
.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp)
.AutoOrient()
.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp);
}
}
}

26
tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs

@ -0,0 +1,26 @@
// <copyright file="CropTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using Xunit;
public class CropTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldCrop<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Crop(image.Width / 2, image.Height / 2)
.DebugSave(provider, null, Extensions.Bmp);
}
}
}
}

33
tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs

@ -0,0 +1,33 @@
// <copyright file="EntropyCropTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using Xunit;
public class EntropyCropTest : FileTestBase
{
public static readonly TheoryData<float> EntropyCropValues
= new TheoryData<float>
{
.25F,
.75F
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)]
public void ImageShouldEntropyCrop<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.EntropyCrop(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
}
}

37
tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs

@ -0,0 +1,37 @@
// <copyright file="FlipTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class FlipTests : FileTestBase
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<FlipType> FlipValues
= new TheoryData<FlipType>
{
{ FlipType.None },
{ FlipType.Vertical },
{ FlipType.Horizontal },
};
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)]
public void ImageShouldFlip<TPixel>(TestImageProvider<TPixel> provider, FlipType flipType)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Flip(flipType)
.DebugSave(provider, flipType, Extensions.Bmp);
}
}
}
}

35
tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs

@ -0,0 +1,35 @@
// <copyright file="PadTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using Xunit;
public class PadTest : FileTestBase
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldPad<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Pad(image.Width + 50, image.Height + 50)
.DebugSave(provider, null, Extensions.Bmp);
// Check pixels are empty
for (int y = 0; y < 25; y++)
{
for (int x = 0; x < 25; x++)
{
Assert.Equal(image[x, y], default(TPixel));
}
}
}
}
}
}

17
tests/ImageSharp.Tests/Processors/Filters/ResizeProfilingBenchmarks.cs → tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs

@ -1,9 +1,13 @@
namespace ImageSharp.Tests
// <copyright file="ResizeProfilingBenchmarks.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using System.IO;
using System.Text;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
@ -27,7 +31,7 @@ namespace ImageSharp.Tests
this.Measure(this.ExecutionCount,
() =>
{
using (Image<Rgba32> image = new Image<Rgba32>(width, height))
using (var image = new Image<Rgba32>(width, height))
{
image.Resize(width / 4, height / 4);
}
@ -37,11 +41,11 @@ namespace ImageSharp.Tests
// [Fact]
public void PrintWeightsData()
{
ResizeProcessor<Rgba32> proc = new ResizeProcessor<Rgba32>(new BicubicResampler(), 200, 200);
var proc = new ResizeProcessor<Rgba32>(new BicubicResampler(), 200, 200);
ResamplingWeightedProcessor<Rgba32>.WeightsBuffer weights = proc.PrecomputeWeights(200, 500);
StringBuilder bld = new StringBuilder();
var bld = new StringBuilder();
foreach (ResamplingWeightedProcessor<Rgba32>.WeightsWindow window in weights.Weights)
{
@ -51,12 +55,13 @@ namespace ImageSharp.Tests
bld.Append(value);
bld.Append("| ");
}
bld.AppendLine();
}
File.WriteAllText("BicubicWeights.MD", bld.ToString());
//this.Output.WriteLine(bld.ToString());
// this.Output.WriteLine(bld.ToString());
}
}
}

273
tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs

@ -0,0 +1,273 @@
// <copyright file="ResizeTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class ResizeTests : FileTestBase
{
public static readonly string[] ResizeFiles = { TestImages.Jpeg.Baseline.Calliphora };
public static readonly TheoryData<string, IResampler> ReSamplers =
new TheoryData<string, IResampler>
{
{ "Bicubic", new BicubicResampler() },
{ "Triangle", new TriangleResampler() },
{ "NearestNeighbor", new NearestNeighborResampler() },
{ "Box", new BoxResampler() },
{ "Lanczos3", new Lanczos3Resampler() },
{ "Lanczos5", new Lanczos5Resampler() },
{ "MitchellNetravali", new MitchellNetravaliResampler() },
{ "Lanczos8", new Lanczos8Resampler() },
{ "Hermite", new HermiteResampler() },
{ "Spline", new SplineResampler() },
{ "Robidoux", new RobidouxResampler() },
{ "RobidouxSharp", new RobidouxSharpResampler() },
{ "Welch", new WelchResampler() }
};
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResize<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Resize(image.Width / 2, image.Height / 2, sampler, true)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeFromSourceRectangle<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4);
var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWidthAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Resize(image.Width / 3, 0, sampler, false)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeHeightAndKeepAspect<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Resize(0, image.Height / 3, sampler, false)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithCropWidthMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(image.Width / 2, image.Height)
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithCropHeightMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(image.Width, image.Height / 2)
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithPadMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(image.Width + 200, image.Height),
Mode = ResizeMode.Pad
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithBoxPadMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(image.Width + 200, image.Height + 200),
Mode = ResizeMode.BoxPad
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithMaxMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(300, 300),
Mode = ResizeMode.Max
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithMinMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size((int)MathF.Round(image.Width * .75F), (int)MathF.Round(image.Height * .95F)),
Mode = ResizeMode.Min
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(ResizeFiles), nameof(ReSamplers), DefaultPixelType)]
public void ImageShouldResizeWithStretchMode<TPixel>(TestImageProvider<TPixel> provider, string name, IResampler sampler)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
var options = new ResizeOptions
{
Sampler = sampler,
Size = new Size(image.Width / 2, image.Height),
Mode = ResizeMode.Stretch
};
image.Resize(options)
.DebugSave(provider, name, Extensions.Bmp);
}
}
[Theory]
[InlineData(-2, 0)]
[InlineData(-1, 0)]
[InlineData(0, 1)]
[InlineData(1, 0)]
[InlineData(2, 0)]
public static void BicubicWindowOscillatesCorrectly(float x, float expected)
{
var sampler = new BicubicResampler();
float result = sampler.GetValue(x);
Assert.Equal(result, expected);
}
[Theory]
[InlineData(-2, 0)]
[InlineData(-1, 0)]
[InlineData(0, 1)]
[InlineData(1, 0)]
[InlineData(2, 0)]
public static void TriangleWindowOscillatesCorrectly(float x, float expected)
{
var sampler = new TriangleResampler();
float result = sampler.GetValue(x);
Assert.Equal(result, expected);
}
[Theory]
[InlineData(-2, 0)]
[InlineData(-1, 0)]
[InlineData(0, 1)]
[InlineData(1, 0)]
[InlineData(2, 0)]
public static void Lanczos3WindowOscillatesCorrectly(float x, float expected)
{
var sampler = new Lanczos3Resampler();
float result = sampler.GetValue(x);
Assert.Equal(result, expected);
}
[Theory]
[InlineData(-4, 0)]
[InlineData(-2, 0)]
[InlineData(0, 1)]
[InlineData(2, 0)]
[InlineData(4, 0)]
public static void Lanczos5WindowOscillatesCorrectly(float x, float expected)
{
var sampler = new Lanczos5Resampler();
float result = sampler.GetValue(x);
Assert.Equal(result, expected);
}
}
}

39
tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs

@ -0,0 +1,39 @@
// <copyright file="RotateFlipTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateFlipTests : FileTestBase
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType> RotateFlipValues
= new TheoryData<RotateType, FlipType>
{
{ RotateType.None, FlipType.Vertical },
{ RotateType.None, FlipType.Horizontal },
{ RotateType.Rotate90, FlipType.None },
{ RotateType.Rotate180, FlipType.None },
{ RotateType.Rotate270, FlipType.None },
};
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(RotateFlipValues), DefaultPixelType)]
public void ImageShouldRotateFlip<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.RotateFlip(rotateType, flipType)
.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp);
}
}
}
}

55
tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs

@ -0,0 +1,55 @@
// <copyright file="RotateTests.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class RotateTests : FileTestBase
{
public static readonly TheoryData<float> RotateFloatValues
= new TheoryData<float>
{
170,
-170
};
public static readonly TheoryData<RotateType> RotateEnumValues
= new TheoryData<RotateType>
{
RotateType.None,
RotateType.Rotate90,
RotateType.Rotate180,
RotateType.Rotate270
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), DefaultPixelType)]
public void ImageShouldRotate<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Rotate(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), DefaultPixelType)]
public void ImageShouldRotateEnum<TPixel>(TestImageProvider<TPixel> provider, RotateType value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Rotate(value)
.DebugSave(provider, value, Extensions.Bmp);
}
}
}
}

33
tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs

@ -0,0 +1,33 @@
// <copyright file="SkewTest.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using Xunit;
public class SkewTest : FileTestBase
{
public static readonly TheoryData<float, float> SkewValues
= new TheoryData<float, float>
{
{ 20, 10 },
{ -20, -10 }
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)]
public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Skew(x, y)
.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp);
}
}
}
}

57
tests/ImageSharp.Tests/Processors/Filters/AlphaTest.cs

@ -1,57 +0,0 @@
// <copyright file="AlphaTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class AlphaTest : FileTestBase
{
public static readonly TheoryData<float> AlphaValues
= new TheoryData<float>
{
20/100f ,
80/100f
};
[Theory]
[MemberData(nameof(AlphaValues))]
public void ImageShouldApplyAlphaFilter(float value)
{
string path = this.CreateOutputDirectory("Alpha");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Alpha(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(AlphaValues))]
public void ImageShouldApplyAlphaFilterInBox(float value)
{
string path = this.CreateOutputDirectory("Alpha");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Alpha(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

47
tests/ImageSharp.Tests/Processors/Filters/BackgroundColorTest.cs

@ -1,47 +0,0 @@
// <copyright file="BackgroundColorTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BackgroundColorTest : FileTestBase
{
[Fact]
public void ImageShouldApplyBackgroundColorFilter()
{
string path = this.CreateOutputDirectory("BackgroundColor");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.BackgroundColor(Rgba32.HotPink).Save(output);
}
}
}
[Fact]
public void ImageShouldApplyBackgroundColorFilterInBox()
{
string path = this.CreateOutputDirectory("BackgroundColor");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BackgroundColor(Rgba32.HotPink, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

57
tests/ImageSharp.Tests/Processors/Filters/BinaryThresholdTest.cs

@ -1,57 +0,0 @@
// <copyright file="BinaryThresholdTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BinaryThresholdTest : FileTestBase
{
public static readonly TheoryData<float> BinaryThresholdValues
= new TheoryData<float>
{
.25f ,
.75f ,
};
[Theory]
[MemberData(nameof(BinaryThresholdValues))]
public void ImageShouldApplyBinaryThresholdFilter(float value)
{
string path = this.CreateOutputDirectory("BinaryThreshold");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BinaryThreshold(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(BinaryThresholdValues))]
public void ImageShouldApplyBinaryThresholdInBox(float value)
{
string path = this.CreateOutputDirectory("BinaryThreshold");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BinaryThreshold(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

47
tests/ImageSharp.Tests/Processors/Filters/BlackWhiteTest.cs

@ -1,47 +0,0 @@
// <copyright file="BlackWhiteTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BlackWhiteTest : FileTestBase
{
[Fact]
public void ImageShouldApplyBlackWhiteFilter()
{
string path = this.CreateOutputDirectory("BlackWhite");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.BlackWhite().Save(output);
}
}
}
[Fact]
public void ImageShouldApplyBlackWhiteFilterInBox()
{
string path = this.CreateOutputDirectory("BlackWhite");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BlackWhite(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

57
tests/ImageSharp.Tests/Processors/Filters/BoxBlurTest.cs

@ -1,57 +0,0 @@
// <copyright file="BoxBlurTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BoxBlurTest : FileTestBase
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
{
3 ,
5 ,
};
[Theory]
[MemberData(nameof(BoxBlurValues))]
public void ImageShouldApplyBoxBlurFilter(int value)
{
string path = this.CreateOutputDirectory("BoxBlur");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BoxBlur(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(BoxBlurValues))]
public void ImageShouldApplyBoxBlurFilterInBox(int value)
{
string path = this.CreateOutputDirectory("BoxBlur");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.BoxBlur(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

57
tests/ImageSharp.Tests/Processors/Filters/BrightnessTest.cs

@ -1,57 +0,0 @@
// <copyright file="BrightnessTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class BrightnessTest : FileTestBase
{
public static readonly TheoryData<int> BrightnessValues
= new TheoryData<int>
{
50 ,
-50 ,
};
[Theory]
[MemberData(nameof(BrightnessValues))]
public void ImageShouldApplyBrightnessFilter(int value)
{
string path = this.CreateOutputDirectory("Brightness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Brightness(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(BrightnessValues))]
public void ImageShouldApplyBrightnessFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Brightness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Brightness(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

64
tests/ImageSharp.Tests/Processors/Filters/ColorBlindnessTest.cs

@ -1,64 +0,0 @@
// <copyright file="ColorBlindnessTest.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 Processing;
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class ColorBlindnessTest : FileTestBase
{
public static readonly TheoryData<ColorBlindness> ColorBlindnessFilters
= new TheoryData<ColorBlindness>
{
ColorBlindness.Achromatomaly,
ColorBlindness.Achromatopsia,
ColorBlindness.Deuteranomaly,
ColorBlindness.Deuteranopia,
ColorBlindness.Protanomaly,
ColorBlindness.Protanopia,
ColorBlindness.Tritanomaly,
ColorBlindness.Tritanopia
};
[Theory]
[MemberData(nameof(ColorBlindnessFilters))]
public void ImageShouldApplyColorBlindnessFilter(ColorBlindness colorBlindness)
{
string path = this.CreateOutputDirectory("ColorBlindness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(colorBlindness);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.ColorBlindness(colorBlindness).Save(output);
}
}
}
[Theory]
[MemberData(nameof(ColorBlindnessFilters))]
public void ImageShouldApplyBrightnessFilterInBox(ColorBlindness colorBlindness)
{
string path = this.CreateOutputDirectory("ColorBlindness");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(colorBlindness + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.ColorBlindness(colorBlindness, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

56
tests/ImageSharp.Tests/Processors/Filters/ContrastTest.cs

@ -1,56 +0,0 @@
// <copyright file="ContrastTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class ContrastTest : FileTestBase
{
public static readonly TheoryData<int> ContrastValues
= new TheoryData<int>
{
50 ,
-50 ,
};
[Theory]
[MemberData(nameof(ContrastValues))]
public void ImageShouldApplyContrastFilter(int value)
{
string path = this.CreateOutputDirectory("Contrast");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Contrast(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(ContrastValues))]
public void ImageShouldApplyContrastFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Contrast");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Contrast(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

31
tests/ImageSharp.Tests/Processors/Filters/CropTest.cs

@ -1,31 +0,0 @@
// <copyright file="CropTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class CropTest : FileTestBase
{
[Fact]
public void ImageShouldApplyCropSampler()
{
string path = this.CreateOutputDirectory("Crop");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Crop(image.Width / 2, image.Height / 2).Save(output);
}
}
}
}
}

67
tests/ImageSharp.Tests/Processors/Filters/DetectEdgesTest.cs

@ -1,67 +0,0 @@
// <copyright file="DetectEdgesTest.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 Processing;
using System.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class DetectEdgesTest : FileTestBase
{
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters
= new TheoryData<EdgeDetection>
{
EdgeDetection.Kayyali,
EdgeDetection.Kirsch,
EdgeDetection.Lapacian3X3,
EdgeDetection.Lapacian5X5,
EdgeDetection.LaplacianOfGaussian,
EdgeDetection.Prewitt,
EdgeDetection.RobertsCross,
EdgeDetection.Robinson,
EdgeDetection.Scharr,
EdgeDetection.Sobel
};
[Theory]
[MemberData(nameof(DetectEdgesFilters))]
public void ImageShouldApplyDetectEdgesFilter(EdgeDetection detector)
{
string path = this.CreateOutputDirectory("DetectEdges");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(detector);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.DetectEdges(detector).Save(output);
}
}
}
[Theory]
[MemberData(nameof(DetectEdgesFilters))]
public void ImageShouldApplyDetectEdgesFilterInBox(EdgeDetection detector)
{
string path = this.CreateOutputDirectory("DetectEdges");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(detector + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.DetectEdges(detector, new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2))
.Save(output);
}
}
}
}
}

104
tests/ImageSharp.Tests/Processors/Filters/DitherTest.cs

@ -1,104 +0,0 @@
// <copyright file="DitherTest.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.IO;
using ImageSharp.Dithering;
using ImageSharp.Dithering.Ordered;
using ImageSharp.PixelFormats;
using Xunit;
public class DitherTest : FileTestBase
{
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither>
{
{ "Ordered", new Ordered() },
{ "Bayer", new Bayer() }
};
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser>
{
{ "Atkinson", new Atkinson() },
{ "Burks", new Burks() },
{ "FloydSteinberg", new FloydSteinberg() },
{ "JarvisJudiceNinke", new JarvisJudiceNinke() },
{ "Sierra2", new Sierra2() },
{ "Sierra3", new Sierra3() },
{ "SierraLite", new SierraLite() },
{ "Stucki", new Stucki() },
};
[Theory]
[MemberData(nameof(Ditherers))]
public void ImageShouldApplyDitherFilter(string name, IOrderedDither ditherer)
{
string path = this.CreateOutputDirectory("Dither", "Dither");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(name);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Dither(ditherer).Save(output);
}
}
}
[Theory]
[MemberData(nameof(Ditherers))]
public void ImageShouldApplyDitherFilterInBox(string name, IOrderedDither ditherer)
{
string path = this.CreateOutputDirectory("Dither", "Dither");
foreach (TestFile file in Files)
{
string filename = file.GetFileName($"{name}-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Dither(ditherer, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
[Theory]
[MemberData(nameof(ErrorDiffusers))]
public void ImageShouldApplyDiffusionFilter(string name, IErrorDiffuser diffuser)
{
string path = this.CreateOutputDirectory("Dither", "Diffusion");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(name);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Dither(diffuser, .5F).Save(output);
}
}
}
[Theory]
[MemberData(nameof(ErrorDiffusers))]
public void ImageShouldApplyDiffusionFilterInBox(string name, IErrorDiffuser diffuser)
{
string path = this.CreateOutputDirectory("Dither", "Diffusion");
foreach (TestFile file in Files)
{
string filename = file.GetFileName($"{name}-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Dither(diffuser, .5F, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

40
tests/ImageSharp.Tests/Processors/Filters/EntropyCropTest.cs

@ -1,40 +0,0 @@
// <copyright file="EntropyCropTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class EntropyCropTest : FileTestBase
{
public static readonly TheoryData<float> EntropyCropValues
= new TheoryData<float>
{
.25f ,
.75f ,
};
[Theory]
[MemberData(nameof(EntropyCropValues))]
public void ImageShouldApplyEntropyCropSampler(float value)
{
string path = this.CreateOutputDirectory("EntropyCrop");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.EntropyCrop(value).Save(output);
}
}
}
}
}

42
tests/ImageSharp.Tests/Processors/Filters/FlipTests.cs

@ -1,42 +0,0 @@
// <copyright file="RotateFlipTest.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.IO;
using ImageSharp.PixelFormats;
using Processing;
using Xunit;
public class FlipTests : FileTestBase
{
public static readonly TheoryData<FlipType> FlipValues
= new TheoryData<FlipType>
{
{ FlipType.None },
{ FlipType.Vertical },
{ FlipType.Horizontal },
};
[Theory]
[MemberData(nameof(FlipValues))]
public void ImageShouldFlip(FlipType flipType)
{
string path = this.CreateOutputDirectory("Flip");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(flipType);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Flip(flipType).Save(output);
}
}
}
}
}

80
tests/ImageSharp.Tests/Processors/Filters/GlowTest.cs

@ -1,80 +0,0 @@
// <copyright file="GlowTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class GlowTest : FileTestBase
{
[Fact]
public void ImageShouldApplyGlowFilter()
{
string path = this.CreateOutputDirectory("Glow");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Glow().Save(output);
}
}
}
[Fact]
public void ImageShouldApplyGlowFilterColor()
{
string path = this.CreateOutputDirectory("Glow");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("Color");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Glow(Rgba32.HotPink).Save(output);
}
}
}
[Fact]
public void ImageShouldApplyGlowFilterRadius()
{
string path = this.CreateOutputDirectory("Glow");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("Radius");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Glow(image.Width / 4F).Save(output);
}
}
}
[Fact]
public void ImageShouldApplyGlowFilterInBox()
{
string path = this.CreateOutputDirectory("Glow");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Glow(new Rectangle(image.Width / 8, image.Height / 8, image.Width / 2, image.Height / 2))
.Save(output);
}
}
}
}
}

57
tests/ImageSharp.Tests/Processors/Filters/HueTest.cs

@ -1,57 +0,0 @@
// <copyright file="HueTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class HueTest : FileTestBase
{
public static readonly TheoryData<int> HueValues
= new TheoryData<int>
{
180 ,
-180 ,
};
[Theory]
[MemberData(nameof(HueValues))]
public void ImageShouldApplyHueFilter(int value)
{
string path = this.CreateOutputDirectory("Hue");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value);
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Hue(value).Save(output);
}
}
}
[Theory]
[MemberData(nameof(HueValues))]
public void ImageShouldApplyHueFilterInBox(int value)
{
string path = this.CreateOutputDirectory("Hue");
foreach (TestFile file in Files)
{
string filename = file.GetFileName(value + "-InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Hue(value, new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

46
tests/ImageSharp.Tests/Processors/Filters/InvertTest.cs

@ -1,46 +0,0 @@
// <copyright file="InvertTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class InvertTest : FileTestBase
{
[Fact]
public void ImageShouldApplyInvertFilter()
{
string path = this.CreateOutputDirectory("Invert");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Invert().Save(output);
}
}
}
[Fact]
public void ImageShouldApplyInvertFilterInBox()
{
string path = this.CreateOutputDirectory("Invert");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Invert(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

47
tests/ImageSharp.Tests/Processors/Filters/KodachromeTest.cs

@ -1,47 +0,0 @@
// <copyright file="KodachromeTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class KodachromeTest : FileTestBase
{
[Fact]
public void ImageShouldApplyKodachromeFilter()
{
string path = this.CreateOutputDirectory("Kodachrome");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Kodachrome().Save(output);
}
}
}
[Fact]
public void ImageShouldApplyKodachromeFilterInBox()
{
string path = this.CreateOutputDirectory("Kodachrome");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Kodachrome(new Rectangle(10, 10, image.Width / 2, image.Height / 2)).Save(output);
}
}
}
}
}

48
tests/ImageSharp.Tests/Processors/Filters/LomographTest.cs

@ -1,48 +0,0 @@
// <copyright file="LomographTest.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.IO;
using ImageSharp.PixelFormats;
using Xunit;
public class LomographTest : FileTestBase
{
[Fact]
public void ImageShouldApplyLomographFilter()
{
string path = this.CreateOutputDirectory("Lomograph");
foreach (TestFile file in Files)
{
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{file.FileName}"))
{
image.Lomograph().Save(output);
}
}
}
[Fact]
public void ImageShouldApplyLomographFilterInBox()
{
string path = this.CreateOutputDirectory("Lomograph");
foreach (TestFile file in Files)
{
string filename = file.GetFileName("InBox");
using (Image<Rgba32> image = file.CreateImage())
using (FileStream output = File.OpenWrite($"{path}/{filename}"))
{
image.Lomograph(new Rectangle(image.Width / 4, image.Width / 4, image.Width / 2, image.Height / 2))
.Save(output);
}
}
}
}
}

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

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save