Browse Source

test extensions methods

af/merge-core
Scott Williams 9 years ago
parent
commit
3fa5141ad9
  1. 15
      src/ImageSharp/ApplyProcessors.cs
  2. 9
      src/ImageSharp/Numerics/ValueSize.cs
  3. 36
      src/ImageSharp/Processing/Binarization/Dither.cs
  4. 13
      src/ImageSharp/Processing/Convolution/BoxBlur.cs
  5. 14
      src/ImageSharp/Processing/Convolution/DetectEdges.cs
  6. 12
      src/ImageSharp/Processing/Convolution/GaussianBlur.cs
  7. 13
      src/ImageSharp/Processing/Convolution/GaussianSharpen.cs
  8. 1
      src/ImageSharp/Processing/Delegate.cs
  9. 13
      src/ImageSharp/Processing/Effects/Pixelate.cs
  10. 4
      src/ImageSharp/Processing/Overlays/Vignette.cs
  11. 6
      src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs
  12. 6
      src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
  13. 5
      src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
  14. 5
      src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
  15. 5
      src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
  16. 5
      src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
  17. 5
      src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
  18. 6
      src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
  19. 16
      tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs
  20. 37
      tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
  21. 32
      tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
  22. 33
      tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
  23. 40
      tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
  24. 40
      tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs
  25. 137
      tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs
  26. 138
      tests/ImageSharp.Tests/Drawing/Text/DrawText.cs
  27. 13
      tests/ImageSharp.Tests/ImageOperationTests.cs
  28. 43
      tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs
  29. 112
      tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs
  30. 34
      tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs
  31. 57
      tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs
  32. 60
      tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs
  33. 41
      tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs
  34. 34
      tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs
  35. 34
      tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs
  36. 34
      tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs
  37. 42
      tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs
  38. 34
      tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs
  39. 48
      tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs
  40. 79
      tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs
  41. 48
      tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs
  42. 48
      tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs
  43. 25
      tests/ImageSharp.Tests/Processing/DelegateTest.cs
  44. 41
      tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs
  45. 56
      tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs
  46. 41
      tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs
  47. 41
      tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs
  48. 34
      tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs
  49. 64
      tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs
  50. 80
      tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs
  51. 76
      tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs
  52. 81
      tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs
  53. 51
      tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs
  54. 92
      tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs
  55. 43
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs
  56. 57
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs
  57. 61
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs
  58. 50
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs
  59. 43
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs
  60. 45
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs
  61. 43
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs
  62. 50
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs
  63. 43
      tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs
  64. 50
      tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs
  65. 59
      tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs
  66. 50
      tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs
  67. 50
      tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs
  68. 50
      tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs
  69. 43
      tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs
  70. 50
      tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs
  71. 50
      tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs
  72. 43
      tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs
  73. 50
      tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs
  74. 84
      tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs
  75. 67
      tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs
  76. 67
      tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs
  77. 84
      tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs
  78. 26
      tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs
  79. 33
      tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs
  80. 37
      tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs
  81. 35
      tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs
  82. 2
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs
  83. 273
      tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs
  84. 39
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs
  85. 55
      tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs
  86. 33
      tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs
  87. 73
      tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs
  88. 33
      tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs
  89. 26
      tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs
  90. 32
      tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs
  91. 24
      tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs
  92. 262
      tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs
  93. 44
      tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs
  94. 64
      tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs
  95. 35
      tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs
  96. 10
      tests/ImageSharp.Tests/TestFile.cs
  97. 28
      tests/ImageSharp.Tests/TestUtilities/TestType.cs

15
src/ImageSharp/ApplyProcessors.cs

@ -87,14 +87,21 @@ namespace ImageSharp
}
/// <summary>
/// Queues up a simple operation that provides access to the mutatable image.
/// Applies all the ImageProcessors agains the operation
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image to rotate, flip, or both.</param>
/// <param name="operation">The operations to perform on the source.</param>
/// <param name="operations">The operations to perform on the source.</param>
/// <returns>returns the current optinoatins class to allow chaining of oprations.</returns>
public static IImageOperations<TPixel> Run<TPixel>(this IImageOperations<TPixel> source, Action<Image<TPixel>> operation)
public static IImageOperations<TPixel> ApplyProcessors<TPixel>(this IImageOperations<TPixel> source, params IImageProcessor<TPixel>[] operations)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DelegateImageProcessor<TPixel>(operation));
{
foreach (var p in operations)
{
source = source.ApplyProcessor(p);
}
return source;
}
}
}

9
src/ImageSharp/Numerics/ValueSize.cs

@ -5,12 +5,13 @@
namespace ImageSharp
{
using System;
using SixLabors.Primitives;
/// <summary>
/// Represents a value in relation to a value on the image
/// </summary>
internal struct ValueSize
internal struct ValueSize : IEquatable<ValueSize>
{
/// <summary>
/// Initializes a new instance of the <see cref="ValueSize"/> struct.
@ -120,5 +121,11 @@ namespace ImageSharp
{
return $"{this.Value} - {this.Type}";
}
/// <inheritdoc/>
public bool Equals(ValueSize other)
{
return this.Type == other.Type && this.Value == other.Value;
}
}
}

36
src/ImageSharp/Processing/Binarization/Dither.cs

@ -25,7 +25,21 @@ namespace ImageSharp
/// <param name="dither">The ordered ditherer.</param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither, int index = 0)
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, 0));
return source;
}
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither, int index)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, index));
@ -43,7 +57,25 @@ namespace ImageSharp
/// </param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither, Rectangle rectangle, int index = 0)
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, 0), rectangle);
return source;
}
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <param name="index">The component index to test the threshold against. Must range from 0 to 3.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Dither<TPixel>(this IImageOperations<TPixel> source, IOrderedDither dither, Rectangle rectangle, int index)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new OrderedDitherProcessor<TPixel>(dither, index), rectangle);

13
src/ImageSharp/Processing/Convolution/BoxBlur.cs

@ -24,7 +24,18 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> BoxBlur<TPixel>(this IImageOperations<TPixel> source, int radius = 7)
public static IImageOperations<TPixel> BoxBlur<TPixel>(this IImageOperations<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BoxBlurProcessor<TPixel>(7));
/// <summary>
/// Applies a box blur to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="radius">The 'radius' value representing the size of the area to sample.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> BoxBlur<TPixel>(this IImageOperations<TPixel> source, int radius)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new BoxBlurProcessor<TPixel>(radius));

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

@ -55,7 +55,19 @@ namespace ImageSharp
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> DetectEdges<TPixel>(this IImageOperations<TPixel> source, EdgeDetection filter, bool grayscale = true)
public static IImageOperations<TPixel> DetectEdges<TPixel>(this IImageOperations<TPixel> source, EdgeDetection filter)
where TPixel : struct, IPixel<TPixel>
=> DetectEdges(source, GetProcessor<TPixel>(filter, true));
/// <summary>
/// Detects any edges within the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="filter">The filter for detecting edges.</param>
/// <param name="grayscale">Whether to convert the image to Grayscale first. Defaults to true.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> DetectEdges<TPixel>(this IImageOperations<TPixel> source, EdgeDetection filter, bool grayscale)
where TPixel : struct, IPixel<TPixel>
=> DetectEdges(source, GetProcessor<TPixel>(filter, grayscale));

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

@ -25,7 +25,17 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> GaussianBlur<TPixel>(this IImageOperations<TPixel> source, float sigma = 3f)
public static IImageOperations<TPixel> GaussianBlur<TPixel>(this IImageOperations<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianBlurProcessor<TPixel>(3f));
/// <summary>
/// Applies a Gaussian blur to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> GaussianBlur<TPixel>(this IImageOperations<TPixel> source, float sigma)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianBlurProcessor<TPixel>(sigma));

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

@ -25,7 +25,18 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> GaussianSharpen<TPixel>(this IImageOperations<TPixel> source, float sigma = 3f)
public static IImageOperations<TPixel> GaussianSharpen<TPixel>(this IImageOperations<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianSharpenProcessor<TPixel>(3f));
/// <summary>
/// Applies a Gaussian sharpening filter to the image.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="sigma">The 'sigma' value representing the weight of the blur.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> GaussianSharpen<TPixel>(this IImageOperations<TPixel> source, float sigma)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new GaussianSharpenProcessor<TPixel>(sigma));

1
src/ImageSharp/Processing/Delegate.cs

@ -26,5 +26,6 @@ namespace ImageSharp
public static IImageOperations<TPixel> Run<TPixel>(this IImageOperations<TPixel> source, Action<Image<TPixel>> operation)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DelegateProcessor<TPixel>(operation));
}
}

13
src/ImageSharp/Processing/Effects/Pixelate.cs

@ -24,7 +24,18 @@ namespace ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Pixelate<TPixel>(this IImageOperations<TPixel> source, int size = 4)
public static IImageOperations<TPixel> Pixelate<TPixel>(this IImageOperations<TPixel> source)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PixelateProcessor<TPixel>(4));
/// <summary>
/// Pixelates an image with the given pixel size.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="size">The size of the pixels.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Pixelate<TPixel>(this IImageOperations<TPixel> source, int size)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new PixelateProcessor<TPixel>(size));

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

@ -106,7 +106,7 @@ namespace ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Vignette<TPixel>(this IImageOperations<TPixel> source, TPixel color, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.VignetteInternal(color, 0, 0, options);
=> source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options);
/// <summary>
/// Applies a radial vignette effect to an image.
@ -133,7 +133,7 @@ namespace ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageOperations<TPixel> Vignette<TPixel>(this IImageOperations<TPixel> source, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.Vignette(NamedColors<TPixel>.Black, 0, 0, rectangle, options);
=> source.VignetteInternal(NamedColors<TPixel>.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options);
/// <summary>
/// Applies a radial vignette effect to an image.

6
src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs

@ -26,6 +26,7 @@ namespace ImageSharp.Processing.Processors
/// </exception>
public SaturationProcessor(int saturation)
{
this.Amount = saturation;
Guard.MustBeBetweenOrEqualTo(saturation, -100, 100, nameof(saturation));
float saturationFactor = saturation / 100F;
@ -58,6 +59,11 @@ namespace ImageSharp.Processing.Processors
this.Matrix = matrix4X4;
}
/// <summary>
/// Gets the amount to apply.
/// </summary>
public int Amount { get; }
/// <inheritdoc/>
public override Matrix4x4 Matrix { get; }
}

6
src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs

@ -31,11 +31,17 @@ namespace ImageSharp.Processing.Processors
/// </param>
public BoxBlurProcessor(int radius = 7)
{
this.Radius = radius;
this.kernelSize = (radius * 2) + 1;
this.KernelX = this.CreateBoxKernel(true);
this.KernelY = this.CreateBoxKernel(false);
}
/// <summary>
/// Gets the Radius
/// </summary>
public int Radius { get; }
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>

5
src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs

@ -72,6 +72,11 @@ namespace ImageSharp.Processing.Processors
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
/// Gets the sigma
/// </summary>
public float Sigma => this.sigma;
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>

5
src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs

@ -74,6 +74,11 @@ namespace ImageSharp.Processing.Processors
this.KernelY = this.CreateGaussianKernel(false);
}
/// <summary>
/// Gets the sigma
/// </summary>
public float Sigma => this.sigma;
/// <summary>
/// Gets the horizontal gradient operator.
/// </summary>

5
src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs

@ -32,6 +32,11 @@ namespace ImageSharp.Processing.Processors
this.options = options;
}
/// <summary>
/// Gets the Graphics options to alter how processor is applied.
/// </summary>
public GraphicsOptions GraphicsOptions => this.options;
/// <summary>
/// Gets the background color value.
/// </summary>

5
src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs

@ -37,6 +37,11 @@ namespace ImageSharp.Processing.Processors
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.options.BlenderMode);
}
/// <summary>
/// Gets the Graphics options to alter how processor is applied.
/// </summary>
public GraphicsOptions GraphicsOptions => this.options;
/// <summary>
/// Gets or sets the glow color to apply.
/// </summary>

5
src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs

@ -51,6 +51,11 @@ namespace ImageSharp.Processing.Processors
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.options.BlenderMode);
}
/// <summary>
/// Gets the Graphics options to alter how processor is applied.
/// </summary>
public GraphicsOptions GraphicsOptions => this.options;
/// <summary>
/// Gets or sets the vignette color to apply.
/// </summary>

6
src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs

@ -28,13 +28,13 @@ namespace ImageSharp.Processing.Processors
public EntropyCropProcessor(float threshold)
{
Guard.MustBeBetweenOrEqualTo(threshold, 0, 1, nameof(threshold));
this.Value = threshold;
this.Threshold = threshold;
}
/// <summary>
/// Gets the threshold value.
/// </summary>
public float Value { get; }
public float Threshold { get; }
/// <inheritdoc/>
protected override void OnApply(ImageBase<TPixel> source, Rectangle sourceRectangle)
@ -45,7 +45,7 @@ namespace ImageSharp.Processing.Processors
new SobelProcessor<TPixel>().Apply(temp, sourceRectangle);
// Apply threshold binarization filter.
new BinaryThresholdProcessor<TPixel>(this.Value).Apply(temp, sourceRectangle);
new BinaryThresholdProcessor<TPixel>(this.Threshold).Apply(temp, sourceRectangle);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);

16
tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using ImageSharp.Processing;
using SixLabors.Primitives;
using Xunit;
namespace ImageSharp.Tests
@ -9,16 +10,31 @@ namespace ImageSharp.Tests
public abstract class BaseImageOperationsExtensionTest
{
protected readonly FakeImageOperationsProvider.FakeImageOperations<Rgba32> operations;
protected readonly Rectangle rect;
protected readonly GraphicsOptions options;
public BaseImageOperationsExtensionTest()
{
this.options = new GraphicsOptions(false) { };
this.rect = new Rectangle(91, 123, 324, 56); // make this random?
this.operations = new FakeImageOperationsProvider.FakeImageOperations<Rgba32>(null);
}
public T Verify<T>(int index = 0)
{
Assert.InRange(index, 0, this.operations.applied.Count - 1);
var operation = this.operations.applied[index];
return Assert.IsType<T>(operation.Processor);
}
public T Verify<T>(Rectangle rect, int index = 0)
{
Assert.InRange(index, 0, this.operations.applied.Count - 1);
var operation = this.operations.applied[index];
Assert.Equal(rect, operation.Rectangle);
return Assert.IsType<T>(operation.Processor);
}
}

37
tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using ImageSharp.Drawing.Processors;
using ImageSharp.PixelFormats;
public class FillPath : IDisposable
public class FillPath : BaseImageOperationsExtensionTest
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
@ -22,25 +22,12 @@ namespace ImageSharp.Tests.Drawing.Paths
new Vector2(20,10),
new Vector2(30,10),
}));
private ProcessorWatchingImage img;
public FillPath()
{
this.img = new ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
img.Dispose();
}
[Fact]
public void CorrectlySetsBrushAndPath()
{
img.Mutate(x => x.Fill(brush, path));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(brush, path);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -56,10 +43,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushPathOptions()
{
img.Mutate(x => x.Fill(brush, path, noneDefault));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(brush, path, noneDefault);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
@ -73,10 +58,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorAndPath()
{
img.Mutate(x => x.Fill(color, path));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(color, path);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -91,10 +74,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
img.Mutate(x => x.Fill(color, path, noneDefault));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(color, path, noneDefault);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);

32
tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using ImageSharp.Drawing.Processors;
using ImageSharp.PixelFormats;
public class FillPathCollection : IDisposable
public class FillPathCollection : BaseImageOperationsExtensionTest
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
@ -30,29 +30,20 @@ namespace ImageSharp.Tests.Drawing.Paths
}));
IPathCollection pathCollection;
private ProcessorWatchingImage img;
public FillPathCollection()
{
this.pathCollection = new PathCollection(path1, path2);
this.img = new ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
img.Dispose();
}
[Fact]
public void CorrectlySetsBrushAndPath()
{
img.Mutate(x => x.Fill(brush, pathCollection));
this.operations.Fill(brush, pathCollection);
Assert.Equal(2, img.ProcessorApplications.Count);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[i].processor);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -69,12 +60,11 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushPathOptions()
{
img.Mutate(x => x.Fill(brush, pathCollection, noneDefault));
this.operations.Fill(brush, pathCollection, noneDefault);
Assert.Equal(2, img.ProcessorApplications.Count);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[i].processor);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(noneDefault, processor.Options);
@ -89,12 +79,11 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorAndPath()
{
img.Mutate(x => x.Fill(color, pathCollection));
this.operations.Fill(color, pathCollection);
Assert.Equal(2, img.ProcessorApplications.Count);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[i].processor);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -110,12 +99,11 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
img.Mutate(x => x.Fill(color, pathCollection, noneDefault));
this.operations.Fill(color, pathCollection, noneDefault);
Assert.Equal(2, img.ProcessorApplications.Count);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[i].processor);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(noneDefault, processor.Options);

33
tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs

@ -11,7 +11,7 @@ namespace ImageSharp.Tests.Drawing.Paths
using ImageSharp.Drawing.Processors;
using ImageSharp.PixelFormats;
public class FillPolygon : IDisposable
public class FillPolygon : BaseImageOperationsExtensionTest
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
@ -22,25 +22,14 @@ namespace ImageSharp.Tests.Drawing.Paths
new Vector2(20,10),
new Vector2(30,10),
};
private ProcessorWatchingImage img;
public FillPolygon()
{
this.img = new Paths.ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
img.Dispose();
}
[Fact]
public void CorrectlySetsBrushAndPath()
{
img.Mutate(x => x.FillPolygon(brush, path));
this.operations.FillPolygon(brush, path);
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -54,10 +43,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushPathAndOptions()
{
img.Mutate(x => x.FillPolygon(brush, path, noneDefault));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.FillPolygon(brush, path, noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
@ -71,10 +58,9 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorAndPath()
{
img.Mutate(x => x.FillPolygon(color, path));
this.operations.FillPolygon(color, path);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -89,10 +75,9 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
img.Mutate(x => x.FillPolygon(color, path, noneDefault));
this.operations.FillPolygon(color, path, noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);

40
tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs

@ -10,32 +10,18 @@ namespace ImageSharp.Tests.Drawing.Paths
using ImageSharp.Drawing.Processors;
using ImageSharp.PixelFormats;
public class FillRectangle : IDisposable
public class FillRectangle : BaseImageOperationsExtensionTest
{
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
SixLabors.Primitives.Rectangle rectangle = new SixLabors.Primitives.Rectangle(10, 10, 77, 76);
private ProcessorWatchingImage img;
public FillRectangle()
{
this.img = new Paths.ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
img.Dispose();
}
[Fact]
public void CorrectlySetsBrushAndRectangle()
{
img.Mutate(x => x.Fill(brush, rectangle));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(brush, rectangle);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -52,10 +38,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushRectangleAndOptions()
{
img.Mutate(x => x.Fill(brush, rectangle, noneDefault));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(brush, rectangle, noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
@ -72,11 +56,9 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorAndRectangle()
{
img.Mutate(x => x.Fill(color, rectangle));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(color, rectangle);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
@ -93,10 +75,8 @@ namespace ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsColorRectangleAndOptions()
{
img.Mutate(x => x.Fill(color, rectangle, noneDefault));
Assert.NotEmpty(img.ProcessorApplications);
FillRegionProcessor<Rgba32> processor = Assert.IsType<FillRegionProcessor<Rgba32>>(img.ProcessorApplications[0].processor);
this.operations.Fill(color, rectangle, noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);

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

@ -1,40 +0,0 @@

namespace ImageSharp.Tests.Drawing.Paths
{
using System;
using System.IO;
using ImageSharp;
using ImageSharp.Processing;
using System.Collections.Generic;
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
/// <summary>
/// Watches but does not actually run the processors against the image.
/// </summary>
/// <seealso cref="ImageSharp.Image{Rgba32}" />
public class ProcessorWatchingImage : Image<Rgba32>
{
public List<ProcessorDetails> ProcessorApplications { get; } = new List<ProcessorDetails>();
public ProcessorWatchingImage(int width, int height)
: base(Configuration.CreateDefaultInstance(), width, height)
{
}
public override void ApplyProcessor(IImageProcessor<Rgba32> processor, Rectangle rectangle)
{
this.ProcessorApplications.Add(new ProcessorDetails
{
processor = processor,
rectangle = rectangle
});
}
public struct ProcessorDetails
{
public IImageProcessor<Rgba32> processor;
public Rectangle rectangle;
}
}
}

137
tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Tests.Drawing.Text
using Xunit;
public class DrawText_Path : IDisposable
public class DrawText_Path : BaseImageOperationsExtensionTest
{
Rgba32 color = Rgba32.HotPink;
@ -30,8 +30,6 @@ namespace ImageSharp.Tests.Drawing.Text
new LinearLineSegment(
new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), }));
private ProcessorWatchingImage img;
private readonly FontCollection FontCollection;
private readonly Font Font;
@ -40,69 +38,62 @@ namespace ImageSharp.Tests.Drawing.Text
{
this.FontCollection = new FontCollection();
this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12);
this.img = new ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
this.img.Dispose();
}
[Fact]
public void FillsForEachACharachterWhenBrushSetAndNotPen()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
Brushes.Solid(Rgba32.Red),
null,
path,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenColorSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count);
FillRegionProcessor<Rgba32> processor =
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(Rgba32.Red, brush.Color);
@ -111,13 +102,11 @@ namespace ImageSharp.Tests.Drawing.Text
[Fact]
public void FillsForEachACharachterWhenColorSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, path));
this.operations.DrawText("123", this.Font, Rgba32.Red, path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
FillRegionProcessor<Rgba32> processor =
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(Rgba32.Red, brush.Color);
@ -126,99 +115,103 @@ namespace ImageSharp.Tests.Drawing.Text
[Fact]
public void DrawForEachACharachterWhenPenSetAndNotBrush()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
null,
Pens.Dash(Rgba32.Red, 1),
path,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path));
this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path));
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
Brushes.Solid(Rgba32.Red),
Pens.Dash(Rgba32.Red, 1),
path,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(6, this.img.ProcessorApplications.Count);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
this.Verify<FillRegionProcessor<Rgba32>>(3);
this.Verify<FillRegionProcessor<Rgba32>>(4);
this.Verify<FillRegionProcessor<Rgba32>>(5);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(6, this.img.ProcessorApplications.Count);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
this.Verify<FillRegionProcessor<Rgba32>>(3);
this.Verify<FillRegionProcessor<Rgba32>>(4);
this.Verify<FillRegionProcessor<Rgba32>>(5);
}
[Fact]
public void BrushAppliesBeforPen()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"1",
this.Font,
Brushes.Solid(Rgba32.Red),
Pens.Dash(Rgba32.Red, 1),
path,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(2, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
}
[Fact]
public void BrushAppliesBeforPenDefaultOptions()
{
this.img.Mutate(x => x.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path));
this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(2, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
}
}
}

138
tests/ImageSharp.Tests/Drawing/Text/DrawText.cs

@ -20,7 +20,7 @@ namespace ImageSharp.Tests.Drawing.Text
using Xunit;
public class DrawText : IDisposable
public class DrawText : BaseImageOperationsExtensionTest
{
Rgba32 color = Rgba32.HotPink;
@ -30,8 +30,6 @@ namespace ImageSharp.Tests.Drawing.Text
new LinearLineSegment(
new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(20, 10), new Vector2(20, 10), new Vector2(30, 10), }));
private ProcessorWatchingImage img;
private readonly FontCollection FontCollection;
private readonly Font Font;
@ -40,69 +38,62 @@ namespace ImageSharp.Tests.Drawing.Text
{
this.FontCollection = new FontCollection();
this.Font = this.FontCollection.Install(TestFontUtilities.GetPath("SixLaborsSampleAB.woff")).CreateFont(12);
this.img = new ProcessorWatchingImage(10, 10);
}
public void Dispose()
{
this.img.Dispose();
}
[Fact]
public void FillsForEachACharachterWhenBrushSetAndNotPen()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
Brushes.Solid(Rgba32.Red),
null,
Vector2.Zero,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenBrushSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void FillsForEachACharachterWhenColorSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count);
FillRegionProcessor<Rgba32> processor =
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(Rgba32.Red, brush.Color);
@ -111,13 +102,11 @@ namespace ImageSharp.Tests.Drawing.Text
[Fact]
public void FillsForEachACharachterWhenColorSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero));
this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
FillRegionProcessor<Rgba32> processor =
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(Rgba32.Red, brush.Color);
@ -126,99 +115,104 @@ namespace ImageSharp.Tests.Drawing.Text
[Fact]
public void DrawForEachACharachterWhenPenSetAndNotBrush()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
null,
Pens.Dash(Rgba32.Red, 1),
Vector2.Zero,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero));
this.operations.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSet()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)));
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero));
this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(3, this.img.ProcessorApplications.Count); // 3 fills where applied
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"123",
this.Font,
Brushes.Solid(Rgba32.Red),
Pens.Dash(Rgba32.Red, 1),
Vector2.Zero,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(6, this.img.ProcessorApplications.Count);
this.Verify<FillRegionProcessor<Rgba32>>(3);
this.Verify<FillRegionProcessor<Rgba32>>(4);
this.Verify<FillRegionProcessor<Rgba32>>(5);
}
[Fact]
public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions()
{
this.img.Mutate(x => x.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero));
this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(6, this.img.ProcessorApplications.Count);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
this.Verify<FillRegionProcessor<Rgba32>>(2);
this.Verify<FillRegionProcessor<Rgba32>>(3);
this.Verify<FillRegionProcessor<Rgba32>>(4);
this.Verify<FillRegionProcessor<Rgba32>>(5);
}
[Fact]
public void BrushAppliesBeforPen()
{
this.img.Mutate(x => x.DrawText(
this.operations.DrawText(
"1",
this.Font,
Brushes.Solid(Rgba32.Red),
Pens.Dash(Rgba32.Red, 1),
Vector2.Zero,
new TextGraphicsOptions(true)));
new TextGraphicsOptions(true));
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(2, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
}
[Fact]
public void BrushAppliesBeforPenDefaultOptions()
{
this.img.Mutate(x => x.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero));
this.operations.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero);
Assert.NotEmpty(this.img.ProcessorApplications);
Assert.Equal(2, this.img.ProcessorApplications.Count);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[0].processor);
Assert.IsType<FillRegionProcessor<Rgba32>>(this.img.ProcessorApplications[1].processor);
var processor = this.Verify<FillRegionProcessor<Rgba32>>(0);
this.Verify<FillRegionProcessor<Rgba32>>(1);
}
}
}

13
tests/ImageSharp.Tests/ImageOperationTests.cs

@ -104,17 +104,4 @@ namespace ImageSharp.Tests
this.image.Dispose();
}
}
public class RunImageOperation : BaseImageOperationsExtensionTest
{
[Fact]
public void Run_CreatedDelegateProcessor()
{
Action<Image<Rgba32>> action = (i) => { };
this.operations.Run(action);
DelegateImageProcessor<Rgba32> processor = this.Verify<DelegateImageProcessor<Rgba32>>();
Assert.Equal(action, processor.Action);
}
}
}

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

@ -6,46 +6,27 @@
namespace ImageSharp.Tests.Processing.Binarization
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class BinaryThresholdTest : FileTestBase
public class BinaryThresholdTest : BaseImageOperationsExtensionTest
{
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>
[Fact]
public void BinaryThreshold_CorrectProcessor()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.BinaryThreshold(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
this.operations.BinaryThreshold(.23f);
var p = this.Verify<BinaryThresholdProcessor<Rgba32>>();
Assert.Equal(.23f, p.Threshold);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)]
public void ImageShouldApplyBinaryThresholdInBox<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BinaryThreshold_rect_CorrectProcessor()
{
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.Mutate(x => x.BinaryThreshold(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.BinaryThreshold(.93f, this.rect);
var p = this.Verify<BinaryThresholdProcessor<Rgba32>>(this.rect);
Assert.Equal(.93f, p.Threshold);
}
}
}

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

@ -8,85 +8,73 @@ namespace ImageSharp.Tests.Processing.Binarization
using ImageSharp.Dithering;
using ImageSharp.Dithering.Ordered;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using Moq;
using SixLabors.Primitives;
using Xunit;
public class DitherTest : FileTestBase
public class DitherTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<string, IOrderedDither> Ditherers = new TheoryData<string, IOrderedDither>
{
{ "Ordered", new Ordered() },
{ "Bayer", new Bayer() }
};
private readonly IOrderedDither orderedDither;
private readonly IErrorDiffuser errorDiffuser;
public static readonly TheoryData<string, IErrorDiffuser> ErrorDiffusers = new TheoryData<string, IErrorDiffuser>
public DitherTest()
{
{ "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>
this.orderedDither = new Mock<IOrderedDither>().Object;
this.errorDiffuser = new Mock<IErrorDiffuser>().Object;
}
[Fact]
public void Dither_CorrectProcessor()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Dither(ditherer));
image.DebugSave(provider, name, Extensions.Bmp);
}
this.operations.Dither(orderedDither);
var p = this.Verify<OrderedDitherProcessor<Rgba32>>();
Assert.Equal(this.orderedDither, p.Dither);
Assert.Equal(0, p.Index);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)]
public void ImageShouldApplyDitherFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IOrderedDither ditherer)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Dither_rect_CorrectProcessor()
{
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.Mutate(x => x.Dither(ditherer, bounds));
image.DebugSave(provider, name, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Dither(orderedDither, this.rect);
var p = this.Verify<OrderedDitherProcessor<Rgba32>>(this.rect);
Assert.Equal(this.orderedDither, p.Dither);
Assert.Equal(0, p.Index);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)]
public void ImageShouldApplyDiffusionFilter<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Dither_index_CorrectProcessor()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Dither(diffuser, .5F));
image.DebugSave(provider, name, Extensions.Bmp);
}
this.operations.Dither(orderedDither, 2);
var p = this.Verify<OrderedDitherProcessor<Rgba32>>();
Assert.Equal(this.orderedDither, p.Dither);
Assert.Equal(2, p.Index);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)]
public void ImageShouldApplyDiffusionFilterInBox<TPixel>(TestImageProvider<TPixel> provider, string name, IErrorDiffuser diffuser)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Dither_index_rect_CorrectProcessor()
{
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);
this.operations.Dither(orderedDither, this.rect, 2);
var p = this.Verify<OrderedDitherProcessor<Rgba32>>(this.rect);
Assert.Equal(this.orderedDither, p.Dither);
Assert.Equal(2, p.Index);
}
image.Mutate(x => x.Dither(diffuser, .5F, bounds));
image.DebugSave(provider, name, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
[Fact]
public void Dither_ErrorDifuser_CorrectProcessor()
{
this.operations.Dither(errorDiffuser, 4);
var p = this.Verify<ErrorDiffusionDitherProcessor<Rgba32>>();
Assert.Equal(this.errorDiffuser, p.Diffuser);
Assert.Equal(4, p.Threshold);
}
[Fact]
public void Dither_ErrorDifuser_rect_CorrectProcessor()
{
this.operations.Dither(this.errorDiffuser, 3, this.rect);
var p = this.Verify<ErrorDiffusionDitherProcessor<Rgba32>>(this.rect);
Assert.Equal(this.errorDiffuser, p.Diffuser);
Assert.Equal(3, p.Threshold);
}
}
}

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

@ -6,38 +6,24 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class BlackWhiteTest : FileTestBase
public class BlackWhiteTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBlackWhiteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BlackWhite_CorrectProcessor()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.BlackWhite());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.BlackWhite();
var p = this.Verify<BlackWhiteProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBlackWhiteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BlackWhite_rect_CorrectProcessor()
{
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.Mutate(x => x.BlackWhite(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.BlackWhite( this.rect);
var p = this.Verify<BlackWhiteProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -5,53 +5,42 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using System.Collections.Generic;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
public class ColorBlindnessTest : FileTestBase
public class ColorBlindnessTest : BaseImageOperationsExtensionTest
{
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
public static IEnumerable<object[]> TheoryData = new[] {
new object[]{ new TestType<AchromatomalyProcessor<Rgba32>>(), ColorBlindness.Achromatomaly },
new object[]{ new TestType<AchromatopsiaProcessor<Rgba32>>(), ColorBlindness.Achromatopsia },
new object[]{ new TestType<DeuteranomalyProcessor<Rgba32>>(), ColorBlindness.Deuteranomaly },
new object[]{ new TestType<DeuteranopiaProcessor<Rgba32>>(), ColorBlindness.Deuteranopia },
new object[]{ new TestType<ProtanomalyProcessor<Rgba32>>(), ColorBlindness.Protanomaly },
new object[]{ new TestType<ProtanopiaProcessor<Rgba32>>(), ColorBlindness.Protanopia },
new object[]{ new TestType<TritanomalyProcessor<Rgba32>>(), ColorBlindness.Tritanomaly },
new object[]{ new TestType<TritanopiaProcessor<Rgba32>>(), ColorBlindness.Tritanopia }
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)]
public void ImageShouldApplyColorBlindnessFilter<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(TheoryData))]
public void ColorBlindness_CorrectProcessor<T>(TestType<T> testType, ColorBlindness colorBlindness)
where T : IImageProcessor<Rgba32>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.ColorBlindness(colorBlindness));
image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
}
this.operations.ColorBlindness(colorBlindness);
var p = this.Verify<T>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)]
public void ImageShouldApplyColorBlindnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, ColorBlindness colorBlindness)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(TheoryData))]
public void ColorBlindness_rect_CorrectProcessor<T>(TestType<T> testType, ColorBlindness colorBlindness)
where T : IImageProcessor<Rgba32>
{
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.Mutate(x => x.ColorBlindness(colorBlindness, bounds));
image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.ColorBlindness(colorBlindness, this.rect);
var p = this.Verify<T>(this.rect);
}
}
}

60
tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs

@ -5,57 +5,45 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using System.Collections;
using System.Collections.Generic;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
public class GrayscaleTest : FileTestBase
public class GrayscaleTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<GrayscaleMode> GrayscaleModeTypes
= new TheoryData<GrayscaleMode>
{
GrayscaleMode.Bt601,
GrayscaleMode.Bt709
};
public static IEnumerable<object[]> ModeTheoryData = new[] {
new object[]{ new TestType<GrayscaleBt709Processor<Rgba32>>(), GrayscaleMode.Bt709 }
};
/// <summary>
/// Use test patterns over loaded images to save decode time.
/// </summary>
[Theory]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)]
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(ModeTheoryData))]
public void Grayscale_mode_CorrectProcessor<T>(TestType<T> testType, GrayscaleMode mode)
where T : IImageProcessor<Rgba32>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Grayscale(value));
byte[] data = new byte[3];
for (int i = 0; i < image.Pixels.Length; i++)
{
image.Pixels[i].ToXyzBytes(data, 0);
Assert.Equal(data[0], data[1]);
Assert.Equal(data[1], data[2]);
}
this.operations.Grayscale(mode);
var p = this.Verify<T>();
image.DebugSave(provider, value.ToString());
}
}
[Theory]
[WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)]
public void ImageShouldApplyGrayscaleFilterInBox<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(ModeTheoryData))]
public void Grayscale_mode_rect_CorrectProcessor<T>(TestType<T> testType, GrayscaleMode mode)
where T : IImageProcessor<Rgba32>
{
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.Mutate(x => x.Grayscale(value, bounds));
image.DebugSave(provider, value.ToString());
this.operations.Grayscale(mode, this.rect);
this.Verify<T>(this.rect);
}
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
[Fact]
public void Grayscale_rect_CorrectProcessor()
{
this.operations.Grayscale(this.rect);
this.Verify<GrayscaleBt709Processor<Rgba32>>(this.rect);
}
}
}

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

@ -6,45 +6,28 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class HueTest : FileTestBase
public class HueTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> HueValues
= new TheoryData<int>
[Fact]
public void Hue_amount_HueProcessorDefaultsSet()
{
180,
-180
};
this.operations.Hue(34f);
var processor = this.Verify<HueProcessor<Rgba32>>();
[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.Mutate(x => x.Hue(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(34f, processor.Angle);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)]
public void ImageShouldApplyHueFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Hue_amount_rect_HueProcessorDefaultsSet()
{
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.Mutate(x => x.Hue(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
this.operations.Hue(5f, this.rect);
var processor = this.Verify<HueProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(5f, processor.Angle);
}
}
}

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

@ -6,38 +6,24 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class KodachromeTest : FileTestBase
public class KodachromeTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyKodachromeFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Kodachrome_amount_KodachromeProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Kodachrome());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Kodachrome();
var processor = this.Verify<KodachromeProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyKodachromeFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Kodachrome_amount_rect_KodachromeProcessorDefaultsSet()
{
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.Mutate(x => x.Kodachrome(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Kodachrome(this.rect);
var processor = this.Verify<KodachromeProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -8,38 +8,24 @@ namespace ImageSharp.Tests
using System.IO;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class LomographTest : FileTestBase
public class LomographTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyLomographFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Lomograph_amount_LomographProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Lomograph());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Lomograph();
var processor = this.Verify<LomographProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyLomographFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Lomograph_amount_rect_LomographProcessorDefaultsSet()
{
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.Mutate(x => x.Lomograph(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Lomograph(this.rect);
var processor = this.Verify<LomographProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -6,38 +6,24 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class PolaroidTest : FileTestBase
public class PolaroidTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyPolaroidFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Polaroid_amount_PolaroidProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Polaroid());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Polaroid();
var processor = this.Verify<PolaroidProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyPolaroidFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Polaroid_amount_rect_PolaroidProcessorDefaultsSet()
{
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.Mutate(x => x.Polaroid(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Polaroid(this.rect);
var processor = this.Verify<PolaroidProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -6,45 +6,29 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class SaturationTest : FileTestBase
public class SaturationTest : BaseImageOperationsExtensionTest
{
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>
[Fact]
public void Saturation_amount_SaturationProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Saturation(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
this.operations.Saturation(34);
var processor = this.Verify<SaturationProcessor<Rgba32>>();
Assert.Equal(34, processor.Amount);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)]
public void ImageShouldApplySaturationFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Saturation_amount_rect_SaturationProcessorDefaultsSet()
{
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.Mutate(x => x.Saturation(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
this.operations.Saturation(5, this.rect);
var processor = this.Verify<SaturationProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(5, processor.Amount);
}
}
}

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

@ -6,38 +6,24 @@
namespace ImageSharp.Tests.Processing.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class SepiaTest : FileTestBase
public class SepiaTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplySepiaFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Sepia_amount_SepiaProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Sepia());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Sepia();
var processor = this.Verify<SepiaProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplySepiaFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Sepia_amount_rect_SepiaProcessorDefaultsSet()
{
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.Mutate(x => x.Sepia(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Sepia(this.rect);
var processor = this.Verify<SepiaProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -6,45 +6,37 @@
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class BoxBlurTest : FileTestBase
public class BoxBlurTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> BoxBlurValues
= new TheoryData<int>
[Fact]
public void BoxBlur_BoxBlurProcessorDefaultsSet()
{
3,
5
};
this.operations.BoxBlur();
var processor = this.Verify<BoxBlurProcessor<Rgba32>>();
[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.Mutate(x => x.BoxBlur(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(7, processor.Radius);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)]
public void ImageShouldApplyBoxBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BoxBlur_amount_BoxBlurProcessorDefaultsSet()
{
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);
this.operations.BoxBlur(34);
var processor = this.Verify<BoxBlurProcessor<Rgba32>>();
Assert.Equal(34, processor.Radius);
}
image.Mutate(x => x.BoxBlur(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
[Fact]
public void BoxBlur_amount_rect_BoxBlurProcessorDefaultsSet()
{
this.operations.BoxBlur(5, this.rect);
var processor = this.Verify<BoxBlurProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(5, processor.Radius);
}
}
}

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

@ -5,55 +5,68 @@
namespace ImageSharp.Tests.Processing.Convolution
{
using System.Collections.Generic;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
public class DetectEdgesTest : FileTestBase
public class DetectEdgesTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<EdgeDetection> DetectEdgesFilters
= new TheoryData<EdgeDetection>
[Fact]
public void DetectEdges_SobelProcessorDefaultsSet()
{
this.operations.DetectEdges();
var processor = this.Verify<SobelProcessor<Rgba32>>();
Assert.True(processor.Grayscale);
}
[Fact]
public void DetectEdges_Rect_SobelProcessorDefaultsSet()
{
EdgeDetection.Kayyali,
EdgeDetection.Kirsch,
EdgeDetection.Lapacian3X3,
EdgeDetection.Lapacian5X5,
EdgeDetection.LaplacianOfGaussian,
EdgeDetection.Prewitt,
EdgeDetection.RobertsCross,
EdgeDetection.Robinson,
EdgeDetection.Scharr,
EdgeDetection.Sobel
this.operations.DetectEdges(this.rect);
var processor = this.Verify<SobelProcessor<Rgba32>>(this.rect);
Assert.True(processor.Grayscale);
}
public static IEnumerable<object[]> EdgeDetectionTheoryData => new[] {
new object[]{ new TestType<KayyaliProcessor<Rgba32>>(), EdgeDetection.Kayyali },
new object[]{ new TestType<KirschProcessor<Rgba32>>(), EdgeDetection.Kirsch },
new object[]{ new TestType<Laplacian3X3Processor<Rgba32>>(), EdgeDetection.Lapacian3X3 },
new object[]{ new TestType<Laplacian5X5Processor<Rgba32>>(), EdgeDetection.Lapacian5X5 },
new object[]{ new TestType<LaplacianOfGaussianProcessor<Rgba32>>(), EdgeDetection.LaplacianOfGaussian },
new object[]{ new TestType<PrewittProcessor<Rgba32>>(), EdgeDetection.Prewitt },
new object[]{ new TestType<RobertsCrossProcessor<Rgba32>>(), EdgeDetection.RobertsCross },
new object[]{ new TestType<RobinsonProcessor<Rgba32>>(), EdgeDetection.Robinson },
new object[]{ new TestType<ScharrProcessor<Rgba32>>(), EdgeDetection.Scharr },
new object[]{ new TestType<SobelProcessor<Rgba32>>(), EdgeDetection.Sobel },
};
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilter<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(EdgeDetectionTheoryData))]
public void DetectEdges_filter_SobelProcessorDefaultsSet<TProcessor>(TestType<TProcessor> type, EdgeDetection filter)
where TProcessor : IEdgeDetectorProcessor<Rgba32>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.DetectEdges(detector));
image.DebugSave(provider, detector.ToString(), Extensions.Bmp);
}
this.operations.DetectEdges(filter);
var processor = this.Verify<TProcessor>();
Assert.True(processor.Grayscale);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)]
public void ImageShouldApplyDetectEdgesFilterInBox<TPixel>(TestImageProvider<TPixel> provider, EdgeDetection detector)
where TPixel : struct, IPixel<TPixel>
[MemberData(nameof(EdgeDetectionTheoryData))]
public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet<TProcessor>(TestType<TProcessor> type, EdgeDetection filter)
where TProcessor : IEdgeDetectorProcessor<Rgba32>
{
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.Mutate(x => x.DetectEdges(detector, bounds));
image.DebugSave(provider, detector.ToString(), Extensions.Bmp);
var grey = (int)filter % 2 == 0;
this.operations.DetectEdges(filter, grey);
var processor = this.Verify<TProcessor>();
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(grey, processor.Grayscale);
}
}
}

48
tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs

@ -6,45 +6,37 @@
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class GaussianBlurTest : FileTestBase
public class GaussianBlurTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> GaussianBlurValues
= new TheoryData<int>
[Fact]
public void GaussianBlur_GaussianBlurProcessorDefaultsSet()
{
3,
5
};
this.operations.GaussianBlur();
var processor = this.Verify<GaussianBlurProcessor<Rgba32>>();
[Theory]
[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.Mutate(x => x.GaussianBlur(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(3f, processor.Sigma);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)]
public void ImageShouldApplyGaussianBlurFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void GaussianBlur_amount_GaussianBlurProcessorDefaultsSet()
{
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);
this.operations.GaussianBlur(0.2f);
var processor = this.Verify<GaussianBlurProcessor<Rgba32>>();
Assert.Equal(.2f, processor.Sigma);
}
image.Mutate(x => x.GaussianBlur(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
[Fact]
public void GaussianBlur_amount_rect_GaussianBlurProcessorDefaultsSet()
{
this.operations.GaussianBlur(0.6f, this.rect);
var processor = this.Verify<GaussianBlurProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(.6f, processor.Sigma);
}
}
}

48
tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs

@ -6,45 +6,37 @@
namespace ImageSharp.Tests.Processing.Convolution
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class GaussianSharpenTest : FileTestBase
public class GaussianSharpenTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> GaussianSharpenValues
= new TheoryData<int>
[Fact]
public void GaussianSharpen_GaussianSharpenProcessorDefaultsSet()
{
3,
5
};
this.operations.GaussianSharpen();
var processor = this.Verify<GaussianSharpenProcessor<Rgba32>>();
[Theory]
[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.Mutate(x => x.GaussianSharpen(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(3f, processor.Sigma);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void GaussianSharpen_amount_GaussianSharpenProcessorDefaultsSet()
{
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);
this.operations.GaussianSharpen(0.2f);
var processor = this.Verify<GaussianSharpenProcessor<Rgba32>>();
Assert.Equal(.2f, processor.Sigma);
}
image.Mutate(x => x.GaussianSharpen(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
[Fact]
public void GaussianSharpen_amount_rect_GaussianSharpenProcessorDefaultsSet()
{
this.operations.GaussianSharpen(0.6f, this.rect);
var processor = this.Verify<GaussianSharpenProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(.6f, processor.Sigma);
}
}
}

25
tests/ImageSharp.Tests/Processing/DelegateTest.cs

@ -0,0 +1,25 @@
// <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
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using Xunit;
public class DelegateTest : BaseImageOperationsExtensionTest
{
[Fact]
public void Run_CreatedDelegateProcessor()
{
Action<Image<Rgba32>> action = (i) => { };
this.operations.Run(action);
DelegateProcessor<Rgba32> processor = this.Verify<DelegateProcessor<Rgba32>>();
Assert.Equal(action, processor.Action);
}
}
}

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

@ -6,45 +6,28 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class AlphaTest : FileTestBase
public class AlphaTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<float> AlphaValues
= new TheoryData<float>
[Fact]
public void Alpha_amount_AlphaProcessorDefaultsSet()
{
20/100F,
80/100F
};
this.operations.Alpha(0.2f);
var processor = this.Verify<AlphaProcessor<Rgba32>>();
[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.Mutate(x => x.Alpha(value));
image.DebugSave(provider, value, Extensions.Png);
}
Assert.Equal(.2f, processor.Value);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)]
public void ImageShouldApplyAlphaFilterInBox<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Alpha_amount_rect_AlphaProcessorDefaultsSet()
{
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.Mutate(x => x.Alpha(value, bounds));
image.DebugSave(provider, value, Extensions.Png);
this.operations.Alpha(0.6f, this.rect);
var processor = this.Verify<AlphaProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(.6f, processor.Value);
}
}
}

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

@ -6,38 +6,50 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class BackgroundColorTest : FileTestBase
public class BackgroundColorTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.BackgroundColor(Rgba32.BlanchedAlmond);
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
}
[Fact]
public void BackgroundColor_amount_rect_BackgroundColorProcessorDefaultsSet()
{
this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.rect);
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>(this.rect);
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyBackgroundColorFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet()
{
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);
this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.options);
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>();
Assert.Equal(this.options, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
}
image.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink, bounds));
image.DebugSave(provider, null, Extensions.Bmp);
[Fact]
public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet()
{
this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.rect, this.options);
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(this.options, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
}
}
}

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

@ -6,45 +6,28 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class BrightnessTest : FileTestBase
public class BrightnessTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> BrightnessValues
= new TheoryData<int>
[Fact]
public void Brightness_amount_BrightnessProcessorDefaultsSet()
{
50,
-50
};
this.operations.Brightness(23);
var processor = this.Verify<BrightnessProcessor<Rgba32>>();
[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.Mutate(x => x.Brightness(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(23, processor.Value);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)]
public void ImageShouldApplyBrightnessFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Brightness_amount_rect_BrightnessProcessorDefaultsSet()
{
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.Mutate(x => x.Brightness(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
this.operations.Brightness(23, this.rect);
var processor = this.Verify<BrightnessProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ;
}
Assert.Equal(23, processor.Value);
}
}
}

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

@ -6,45 +6,28 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class ContrastTest : FileTestBase
public class ContrastTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> ContrastValues
= new TheoryData<int>
[Fact]
public void Contrast_amount_ContrastProcessorDefaultsSet()
{
50,
-50
};
this.operations.Contrast(23);
var processor = this.Verify<ContrastProcessor<Rgba32>>();
[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.Mutate(x => x.Contrast(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
Assert.Equal(23, processor.Value);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)]
public void ImageShouldApplyContrastFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Contrast_amount_rect_ContrastProcessorDefaultsSet()
{
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.Mutate(x => x.Contrast(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
this.operations.Contrast(23, this.rect);
var processor = this.Verify<ContrastProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(23, processor.Value);
}
}
}

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

@ -6,38 +6,24 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class InvertTest : FileTestBase
public class InvertTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyInvertFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Invert_InvertProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Invert());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Invert();
var processor = this.Verify<InvertProcessor<Rgba32>>();
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyInvertFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Pixelate_rect_PixelateProcessorDefaultsSet()
{
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.Mutate(x => x.Invert(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
this.operations.Invert(this.rect);
var processor = this.Verify<InvertProcessor<Rgba32>>(this.rect);
}
}
}

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

@ -3,48 +3,52 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class OilPaintTest : FileTestBase
public class OilPaintTest : BaseImageOperationsExtensionTest
{
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>
[Fact]
public void OilPaint_OilPaintingProcessorDefaultsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.OilPaint(levels, brushSize));
image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp);
}
this.operations.OilPaint();
var processor = this.Verify<OilPaintingProcessor<Rgba32>>();
Assert.Equal(10, processor.Levels);
Assert.Equal(15, processor.BrushSize);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)]
public void ImageShouldApplyOilPaintFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int levels, int brushSize)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void OilPaint_rect_OilPaintingProcessorDefaultsSet()
{
this.operations.OilPaint(this.rect);
var processor = this.Verify<OilPaintingProcessor<Rgba32>>(this.rect);
Assert.Equal(10, processor.Levels);
Assert.Equal(15, processor.BrushSize);
}
[Fact]
public void OilPaint_Levels_Brsuh_OilPaintingProcessorDefaultsSet()
{
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);
this.operations.OilPaint(34, 65);
var processor = this.Verify<OilPaintingProcessor<Rgba32>>();
image.Mutate(x => x.OilPaint(levels, brushSize, bounds));
image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp);
Assert.Equal(34, processor.Levels);
Assert.Equal(65, processor.BrushSize);
}
[Fact]
public void OilPaint_Levels_Brsuh_rect_OilPaintingProcessorDefaultsSet()
{
this.operations.OilPaint(54, 43, this.rect);
var processor = this.Verify<OilPaintingProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F);
}
Assert.Equal(54, processor.Levels);
Assert.Equal(43, processor.BrushSize);
}
}
}

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

@ -6,79 +6,37 @@
namespace ImageSharp.Tests.Processing.Effects
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class PixelateTest : FileTestBase
public class PixelateTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<int> PixelateValues
= new TheoryData<int>
[Fact]
public void Pixelate_PixelateProcessorDefaultsSet()
{
4 ,
8
};
this.operations.Pixelate();
var processor = this.Verify<PixelateProcessor<Rgba32>>();
[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.Mutate(x => x.Pixelate(value));
image.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]);
}
}
}
}
}
Assert.Equal(4, processor.Size);
}
[Theory]
[WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)]
public void ImageShouldApplyPixelateFilterInBox<TPixel>(TestImageProvider<TPixel> provider, int value)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Pixelate_Size_PixelateProcessorDefaultsSet()
{
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.Mutate(x => x.Pixelate(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
this.operations.Pixelate(12);
var processor = this.Verify<PixelateProcessor<Rgba32>>();
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);
Assert.Equal(12, processor.Size);
}
sourceColor = image[sourceX, sourceY];
}
Assert.Equal(sourceColor, image[tx, ty]);
}
}
[Fact]
public void Pixelate_Size_rect_PixelateProcessorDefaultsSet()
{
this.operations.Pixelate(23, this.rect);
var processor = this.Verify<PixelateProcessor<Rgba32>>(this.rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(23, processor.Size);
}
}
}

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

@ -5,63 +5,57 @@
namespace ImageSharp.Tests.Processing.Overlays
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class GlowTest : FileTestBase
public class GlowTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Glow_GlowProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Glow();
var p = this.Verify<GlowProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Glow_Color_GlowProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow(NamedColors<TPixel>.Orange));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Glow(Rgba32.Aquamarine);
var p = this.Verify<GlowProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Aquamarine, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Glow_Radux_GlowProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Glow(image.Width / 4F));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Glow(3.5f);
var p = this.Verify<GlowProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.GlowColor);
Assert.Equal(ValueSize.Absolute(3.5f), p.Radius);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyGlowFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Glow_Rect_GlowProcessorWithDefaultValues()
{
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.Mutate(x => x.Glow(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
var rect = new Rectangle(12, 123, 43, 65);
this.operations.Glow(rect);
var p = this.Verify<GlowProcessor<Rgba32>>(rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.GlowColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.Radius);
}
}
}

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

@ -5,63 +5,62 @@
namespace ImageSharp.Tests.Processing.Overlays
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using ImageSharp.Tests.TestUtilities;
using SixLabors.Primitives;
using Xunit;
public class VignetteTest : FileTestBase
public class VignetteTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilter<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Vignette_VignetteProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette());
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Vignette();
var p = this.Verify<VignetteProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterColor<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Vignette_Color_VignetteProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette(NamedColors<TPixel>.Orange));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Vignette(Rgba32.Aquamarine);
var p = this.Verify<VignetteProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Aquamarine, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterRadius<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Vignette_Radux_VignetteProcessorWithDefaultValues()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Vignette(3.5f, 12123f);
var p = this.Verify<VignetteProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.VignetteColor);
Assert.Equal(ValueSize.Absolute(3.5f), p.RadiusX);
Assert.Equal(ValueSize.Absolute(12123f), p.RadiusY);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldApplyVignetteFilterInBox<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Vignette_Rect_VignetteProcessorWithDefaultValues()
{
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.Mutate(x => x.Vignette(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
var rect = new Rectangle(12, 123, 43, 65);
this.operations.Vignette(rect);
var p = this.Verify<VignetteProcessor<Rgba32>>(rect);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
Assert.Equal(GraphicsOptions.Default, p.GraphicsOptions);
Assert.Equal(Rgba32.Black, p.VignetteColor);
Assert.Equal(ValueSize.PercentageOfWidth(.5f), p.RadiusX);
Assert.Equal(ValueSize.PercentageOfHeight(.5f), p.RadiusY);
}
}
}

51
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Binarization
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.BinaryThreshold(value));
image.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.Mutate(x => x.BinaryThreshold(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

92
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Binarization
{
using ImageSharp.Dithering;
using ImageSharp.Dithering.Ordered;
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Dither(ditherer));
image.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.Mutate(x => x.Dither(ditherer, bounds));
image.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.Mutate(x => x.Dither(diffuser, .5F));
image.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.Mutate(x => x.Dither(diffuser, .5F, bounds));
image.DebugSave(provider, name, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.BlackWhite());
image.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.Mutate(x => x.BlackWhite(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

57
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using SixLabors.Primitives;
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.Mutate(x => x.ColorBlindness(colorBlindness));
image.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.Mutate(x => x.ColorBlindness(colorBlindness, bounds));
image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

61
tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs

@ -0,0 +1,61 @@
// <copyright file="GrayscaleTest.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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using SixLabors.Primitives;
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(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)]
public void ImageShouldApplyGrayscaleFilterAll<TPixel>(TestImageProvider<TPixel> provider, GrayscaleMode value)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Grayscale(value));
byte[] data = new byte[3];
for (int i = 0; i < image.Pixels.Length; i++)
{
image.Pixels[i].ToXyzBytes(data, 0);
Assert.Equal(data[0], data[1]);
Assert.Equal(data[1], data[2]);
}
image.DebugSave(provider, value.ToString());
}
}
[Theory]
[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 (var image = new Image<TPixel>(source))
{
var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2);
image.Mutate(x => x.Grayscale(value, bounds));
image.DebugSave(provider, value.ToString());
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Hue(value));
image.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.Mutate(x => x.Hue(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Kodachrome());
image.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.Mutate(x => x.Kodachrome(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

45
tests/ImageSharp.Tests/Processing/Processors/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.Processing.Processors.ColorMatrix
{
using System.IO;
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Lomograph());
image.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.Mutate(x => x.Lomograph(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Polaroid());
image.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.Mutate(x => x.Polaroid(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Saturation(value));
image.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.Mutate(x => x.Saturation(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.ColorMatrix
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Sepia());
image.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.Mutate(x => x.Sepia(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Convolution
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.BoxBlur(value));
image.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.Mutate(x => x.BoxBlur(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

59
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Convolution
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using SixLabors.Primitives;
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.Mutate(x => x.DetectEdges(detector));
image.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.Mutate(x => x.DetectEdges(detector, bounds));
image.DebugSave(provider, detector.ToString(), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs

@ -0,0 +1,50 @@
// <copyright file="GaussianBlurTest.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.Processors.Convolution
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
using Xunit;
public class GaussianBlurTest : FileTestBase
{
public static readonly TheoryData<int> GaussianBlurValues
= new TheoryData<int>
{
3,
5
};
[Theory]
[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.Mutate(x => x.GaussianBlur(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[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 (var image = new Image<TPixel>(source))
{
var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2);
image.Mutate(x => x.GaussianBlur(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs

@ -0,0 +1,50 @@
// <copyright file="GaussianSharpenTest.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.Processors.Convolution
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
using Xunit;
public class GaussianSharpenTest : FileTestBase
{
public static readonly TheoryData<int> GaussianSharpenValues
= new TheoryData<int>
{
3,
5
};
[Theory]
[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.Mutate(x => x.GaussianSharpen(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)]
public void ImageShouldApplyGaussianSharpenFilterInBox<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.Mutate(x => x.GaussianSharpen(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Alpha(value));
image.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.Mutate(x => x.Alpha(value, bounds));
image.DebugSave(provider, value, Extensions.Png);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink));
image.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.Mutate(x => x.BackgroundColor(NamedColors<TPixel>.HotPink, bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Brightness(value));
image.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.Mutate(x => x.Brightness(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ;
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Contrast(value));
image.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.Mutate(x => x.Contrast(value, bounds));
image.DebugSave(provider, value, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

43
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Invert());
image.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.Mutate(x => x.Invert(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

50
tests/ImageSharp.Tests/Processing/Processors/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.Processing.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.OilPaint(levels, brushSize));
image.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.Mutate(x => x.OilPaint(levels, brushSize, bounds));
image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F);
}
}
}
}

84
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Effects
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Pixelate(value));
image.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.Mutate(x => x.Pixelate(value, bounds));
image.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/Processors/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.Processors.Overlays
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Glow());
image.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.Mutate(x => x.Glow(NamedColors<TPixel>.Orange));
image.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.Mutate(x => x.Glow(image.Width / 4F));
image.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.Mutate(x => x.Glow(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

67
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Overlays
{
using ImageSharp.PixelFormats;
using SixLabors.Primitives;
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.Mutate(x => x.Vignette());
image.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.Mutate(x => x.Vignette(NamedColors<TPixel>.Orange));
image.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.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F));
image.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.Mutate(x => x.Vignette(bounds));
image.DebugSave(provider, null, Extensions.Bmp);
ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds);
}
}
}
}

84
tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs

@ -0,0 +1,84 @@
// <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.Processing.Processors.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.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>
{
{ RotateType.None, FlipType.None, 0 },
{ RotateType.None, FlipType.None, 1 },
{ RotateType.None, FlipType.Horizontal, 2 },
{ RotateType.Rotate180, FlipType.None, 3 },
{ RotateType.Rotate180, FlipType.Horizontal, 4 },
{ RotateType.Rotate90, FlipType.Horizontal, 5 },
{ RotateType.Rotate270, FlipType.None, 6 },
{ RotateType.Rotate90, FlipType.Vertical, 7 },
{ RotateType.Rotate90, FlipType.None, 8 },
};
public static readonly TheoryData<ExifDataType, byte[]> InvalidOrientationValues
= new TheoryData<ExifDataType, byte[]>
{
{ ExifDataType.Byte, new byte[] { 1 } },
{ ExifDataType.SignedByte, new byte[] { 2 } },
{ ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) },
{ ExifDataType.Long, BitConverter.GetBytes((uint) 4) },
{ ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) }
};
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile();
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
image.Mutate(x => x.RotateFlip(rotateType, flipType));
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp);
image.Mutate(x => x.AutoOrient());
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotateInvalidValues<TPixel>(TestImageProvider<TPixel> provider, ExifDataType dataType, byte[] orientation)
where TPixel : struct, IPixel<TPixel>
{
var profile = new ExifProfile();
profile.SetValue(ExifTag.JPEGTables, orientation);
byte[] bytes = profile.ToByteArray();
// Change the tag into ExifTag.Orientation
bytes[16] = 18;
bytes[17] = 1;
// Change the data type
bytes[18] = (byte)dataType;
// Change the number of components
bytes[20] = 1;
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile(bytes);
image.Mutate(x=>x.AutoOrient());
}
}
}
}

26
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(x => x.Crop(image.Width / 2, image.Height / 2));
image.DebugSave(provider, null, Extensions.Bmp);
}
}
}
}

33
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(x => x.EntropyCrop(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
}
}
}

37
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(x => x.Flip(flipType));
image.DebugSave(provider, flipType, Extensions.Bmp);
}
}
}
}

35
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(x => x.Pad(image.Width + 50, image.Height + 50));
image.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(default(TPixel), image[x, y]);
}
}
}
}
}
}

2
tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs → tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs

@ -3,7 +3,7 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Tests.Processing.Transforms
namespace ImageSharp.Tests.Processing.Processors.Transforms
{
using System;
using System.IO;

273
tests/ImageSharp.Tests/Processing/Processors/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.Processors.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using SixLabors.Primitives;
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.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, sampler, true));
image.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.Mutate(x => x.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false));
image.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.Mutate(x => x.Resize(image.Width / 3, 0, sampler, false));
image.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.Mutate(x => x.Resize(0, image.Height / 3, sampler, false));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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/Processors/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.Processors.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.Mutate(x => x.RotateFlip(rotateType, flipType));
image.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp);
}
}
}
}

55
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(x => x.Rotate(value));
image.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.Mutate(x => x.Rotate(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
}
}
}

33
tests/ImageSharp.Tests/Processing/Processors/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.Processors.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.Mutate(i => i.Skew(x, y));
image.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp);
}
}
}
}

73
tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs

@ -8,77 +8,16 @@ namespace ImageSharp.Tests.Processing.Transforms
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using Xunit;
public class AutoOrientTests : FileTestBase
public class AutoOrientTests : BaseImageOperationsExtensionTest
{
public static readonly string[] FlipFiles = { TestImages.Bmp.F };
public static readonly TheoryData<RotateType, FlipType, ushort> OrientationValues
= new TheoryData<RotateType, FlipType, ushort>
{
{ RotateType.None, FlipType.None, 0 },
{ RotateType.None, FlipType.None, 1 },
{ RotateType.None, FlipType.Horizontal, 2 },
{ RotateType.Rotate180, FlipType.None, 3 },
{ RotateType.Rotate180, FlipType.Horizontal, 4 },
{ RotateType.Rotate90, FlipType.Horizontal, 5 },
{ RotateType.Rotate270, FlipType.None, 6 },
{ RotateType.Rotate90, FlipType.Vertical, 7 },
{ RotateType.Rotate90, FlipType.None, 8 },
};
public static readonly TheoryData<ExifDataType, byte[]> InvalidOrientationValues
= new TheoryData<ExifDataType, byte[]>
[Fact]
public void AutoOrient_AutoRotateProcessor()
{
{ ExifDataType.Byte, new byte[] { 1 } },
{ ExifDataType.SignedByte, new byte[] { 2 } },
{ ExifDataType.SignedShort, BitConverter.GetBytes((short) 3) },
{ ExifDataType.Long, BitConverter.GetBytes((uint) 4) },
{ ExifDataType.SignedLong, BitConverter.GetBytes((int) 5) }
};
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(OrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotate<TPixel>(TestImageProvider<TPixel> provider, RotateType rotateType, FlipType flipType, ushort orientation)
where TPixel : struct, IPixel<TPixel>
{
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile();
image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation);
image.Mutate(x => x.RotateFlip(rotateType, flipType));
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp);
image.Mutate(x => x.AutoOrient());
image.DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp);
}
}
[Theory]
[WithFileCollection(nameof(FlipFiles), nameof(InvalidOrientationValues), DefaultPixelType)]
public void ImageShouldAutoRotateInvalidValues<TPixel>(TestImageProvider<TPixel> provider, ExifDataType dataType, byte[] orientation)
where TPixel : struct, IPixel<TPixel>
{
var profile = new ExifProfile();
profile.SetValue(ExifTag.JPEGTables, orientation);
byte[] bytes = profile.ToByteArray();
// Change the tag into ExifTag.Orientation
bytes[16] = 18;
bytes[17] = 1;
// Change the data type
bytes[18] = (byte)dataType;
// Change the number of components
bytes[20] = 1;
using (Image<TPixel> image = provider.GetImage())
{
image.MetaData.ExifProfile = new ExifProfile(bytes);
image.Mutate(x=>x.AutoOrient());
}
this.operations.AutoOrient();
this.Verify<AutoRotateProcessor<Rgba32>>();
}
}
}

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

@ -5,22 +5,35 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
public class CropTest : FileTestBase
public class CropTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldCrop<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[InlineData(10, 10)]
[InlineData(12, 123)]
public void Crop_Width_height_CropProcessorWithRectangleSet(int width, int height)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Crop(image.Width / 2, image.Height / 2));
image.DebugSave(provider, null, Extensions.Bmp);
}
this.operations.Crop(width, height);
var processor = this.Verify<CropProcessor<Rgba32>>();
Assert.Equal(new Rectangle(0, 0, width, height), processor.CropRectangle);
}
[Theory]
[InlineData(10, 10, 2, 6)]
[InlineData(12, 123, 6, 2)]
public void Crop_Rectangle_CropProcessorWithRectangleSet(int x, int y, int width, int height)
{
var rect = new Rectangle(x, y, width, height);
this.operations.Crop(rect);
var processor = this.Verify<CropProcessor<Rgba32>>();
Assert.Equal(rect, processor.CropRectangle);
}
}
}

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

@ -5,29 +5,23 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using Xunit;
public class EntropyCropTest : FileTestBase
public class EntropyCropTest : BaseImageOperationsExtensionTest
{
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>
[InlineData(0.5f)]
[InlineData(.2f)]
public void EntropyCrop_threasholdFloat_EntropyCropProcessorWithThreshold(float threashold)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.EntropyCrop(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
this.operations.EntropyCrop(threashold);
var processor = this.Verify<EntropyCropProcessor<Rgba32>>();
Assert.Equal(threashold, processor.Threshold);
}
}
}

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

@ -5,33 +5,25 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using Xunit;
public class FlipTests : FileTestBase
public class FlipTests : BaseImageOperationsExtensionTest
{
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>
[InlineData(FlipType.None)]
[InlineData(FlipType.Horizontal)]
[InlineData(FlipType.Vertical)]
public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Flip(flipType));
image.DebugSave(provider, flipType, Extensions.Bmp);
}
this.operations.Flip(flip);
var flipProcessor = this.Verify<FlipProcessor<Rgba32>>();
Assert.Equal(flip, flipProcessor.FlipType);
}
}
}
}

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

@ -5,31 +5,17 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using Xunit;
public class PadTest : FileTestBase
public class PadTest : BaseImageOperationsExtensionTest
{
[Theory]
[WithFileCollection(nameof(DefaultFiles), DefaultPixelType)]
public void ImageShouldPad<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
[Fact(Skip = "Skip this is a helper around resize, skip until resize can be refactord")]
public void Pad_width_height_ResizeProcessorWithCorrectOPtionsSet()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Pad(image.Width + 50, image.Height + 50));
image.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(default(TPixel), image[x, y]);
}
}
}
throw new NotImplementedException("Write test here");
}
}
}

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

@ -5,269 +5,19 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using SixLabors.Primitives;
using Xunit;
public class ResizeTests : FileTestBase
public class ResizeTests : BaseImageOperationsExtensionTest
{
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.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, sampler, true));
image.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.Mutate(x => x.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false));
image.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.Mutate(x => x.Resize(image.Width / 3, 0, sampler, false));
image.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.Mutate(x => x.Resize(0, image.Height / 3, sampler, false));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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.Mutate(x => x.Resize(options));
image.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)
[Fact(Skip = "Skip resize tests as they need refactoring to be simpler and just pass data into the resize processor.")]
public void TestMissing()
{
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);
//
throw new NotImplementedException("Write test here");
}
}
}

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

@ -5,35 +5,37 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using System;
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using Xunit;
public class RotateFlipTests : FileTestBase
public class RotateFlipTests : BaseImageOperationsExtensionTest
{
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>
[InlineData(RotateType.None, FlipType.None, 0)]
[InlineData(RotateType.Rotate90, FlipType.None, 90)]
[InlineData(RotateType.Rotate180, FlipType.None, 180)]
[InlineData(RotateType.Rotate270, FlipType.None, 270)]
[InlineData(RotateType.None, FlipType.Horizontal, 0)]
[InlineData(RotateType.Rotate90, FlipType.Horizontal, 90)]
[InlineData(RotateType.Rotate180, FlipType.Horizontal, 180)]
[InlineData(RotateType.Rotate270, FlipType.Horizontal, 270)]
[InlineData(RotateType.None, FlipType.Vertical, 0)]
[InlineData(RotateType.Rotate90, FlipType.Vertical, 90)]
[InlineData(RotateType.Rotate180, FlipType.Vertical, 180)]
[InlineData(RotateType.Rotate270, FlipType.Vertical, 270)]
public void Rotate_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(RotateType angle, FlipType flip, float expectedAngle)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.RotateFlip(rotateType, flipType));
image.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp);
}
this.operations.RotateFlip(angle, flip);
var rotateProcessor = this.Verify<RotateProcessor<Rgba32>>(0);
var flipProcessor = this.Verify<FlipProcessor<Rgba32>>(1);
Assert.Equal(expectedAngle, rotateProcessor.Angle);
Assert.False(rotateProcessor.Expand);
Assert.Equal(flip, flipProcessor.FlipType);
}
}
}

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

@ -7,49 +7,51 @@ namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing;
using ImageSharp.Processing.Processors;
using Xunit;
public class RotateTests : FileTestBase
public class RotateTests : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<float> RotateFloatValues
= new TheoryData<float>
{
170,
-170
};
public static readonly TheoryData<RotateType> RotateEnumValues
= new TheoryData<RotateType>
[Theory]
[InlineData(85.6f)]
[InlineData(21)]
public void Rotate_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(float angle)
{
RotateType.None,
RotateType.Rotate90,
RotateType.Rotate180,
RotateType.Rotate270
};
this.operations.Rotate(angle);
var processor = this.Verify<RotateProcessor<Rgba32>>();
Assert.Equal(angle, processor.Angle);
Assert.True(processor.Expand);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), DefaultPixelType)]
public void ImageShouldRotate<TPixel>(TestImageProvider<TPixel> provider, float value)
where TPixel : struct, IPixel<TPixel>
[InlineData(RotateType.None, 0)]
[InlineData(RotateType.Rotate90, 90)]
[InlineData(RotateType.Rotate180, 180)]
[InlineData(RotateType.Rotate270, 270)]
public void Rotate_RotateType_RotateProcessorWithAnglesConvertedFromEnumAndExpandTrue(RotateType angle, float expectedangle)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Rotate(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
this.operations.Rotate(angle); // is this api needed ???
var processor = this.Verify<RotateProcessor<Rgba32>>();
Assert.Equal(expectedangle, processor.Angle);
Assert.False(processor.Expand);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), DefaultPixelType)]
public void ImageShouldRotateEnum<TPixel>(TestImageProvider<TPixel> provider, RotateType value)
where TPixel : struct, IPixel<TPixel>
[InlineData(85.6f, false)]
[InlineData(21, true)]
[InlineData(21, false)]
public void Rotate_degreesFloat_expand_RotateProcessorWithAnglesSetAndExpandSet(float angle, bool expand)
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x.Rotate(value));
image.DebugSave(provider, value, Extensions.Bmp);
}
this.operations.Rotate(angle, expand);
var processor = this.Verify<RotateProcessor<Rgba32>>();
Assert.Equal(angle, processor.Angle);
Assert.Equal(expand, processor.Expand);
}
}
}

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

@ -6,28 +6,31 @@
namespace ImageSharp.Tests.Processing.Transforms
{
using ImageSharp.PixelFormats;
using ImageSharp.Processing.Processors;
using Xunit;
public class SkewTest : FileTestBase
public class SkewTest : BaseImageOperationsExtensionTest
{
public static readonly TheoryData<float, float> SkewValues
= new TheoryData<float, float>
[Fact]
public void Skew_x_y_CreateSkewProcessorWithAnglesSetAndExpandTrue()
{
{ 20, 10 },
{ -20, -10 }
};
this.operations.Skew(10, 20);
var processor = this.Verify<SkewProcessor<Rgba32>>();
Assert.Equal(10, processor.AngleX);
Assert.Equal(20, processor.AngleY);
Assert.True(processor.Expand);
}
[Theory]
[WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)]
public void ImageShouldSkew<TPixel>(TestImageProvider<TPixel> provider, float x, float y)
where TPixel : struct, IPixel<TPixel>
[Fact]
public void Skew_x_y_expand_CreateSkewProcessorWithAnglesSetAndExpandTrue()
{
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(i => i.Skew(x, y));
image.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp);
}
this.operations.Skew(10, 20, false);
var processor = this.Verify<SkewProcessor<Rgba32>>();
Assert.Equal(10, processor.AngleX);
Assert.Equal(20, processor.AngleY);
Assert.False(processor.Expand);
}
}
}

10
tests/ImageSharp.Tests/TestFile.cs

@ -29,10 +29,13 @@ namespace ImageSharp.Tests
/// </summary>
private static readonly string FormatsDirectory = GetFormatsDirectory();
private Image<Rgba32> _image;
private byte[] _bytes;
/// <summary>
/// The image.
/// </summary>
private readonly Image<Rgba32> image;
private Image<Rgba32> image => this._image ?? (this._image = Image.Load<Rgba32>(this.Bytes));
/// <summary>
/// The file.
@ -46,15 +49,12 @@ namespace ImageSharp.Tests
private TestFile(string file)
{
this.file = file;
this.Bytes = File.ReadAllBytes(file);
this.image = Image.Load<Rgba32>(this.Bytes);
}
/// <summary>
/// Gets the bytes.
/// </summary>
public byte[] Bytes { get; }
public byte[] Bytes => this._bytes ?? (this._bytes = File.ReadAllBytes(this.file));
/// <summary>
/// The file name.

28
tests/ImageSharp.Tests/TestUtilities/TestType.cs

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;
using ImageSharp.PixelFormats;
using Xunit.Abstractions;
namespace ImageSharp.Tests.TestUtilities
{
public class TestType<T> : IXunitSerializable
{
public TestType()
{
}
public void Deserialize(IXunitSerializationInfo info)
{
}
public void Serialize(IXunitSerializationInfo info)
{
}
public override string ToString()
{
return $"Type<{typeof(T).Name}>";
}
}
}
Loading…
Cancel
Save