diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs
index 0e81957019..fd91349f57 100644
--- a/src/ImageSharp/ApplyProcessors.cs
+++ b/src/ImageSharp/ApplyProcessors.cs
@@ -87,14 +87,21 @@ namespace ImageSharp
}
///
- /// Queues up a simple operation that provides access to the mutatable image.
+ /// Applies all the ImageProcessors agains the operation
///
/// The pixel format.
/// The image to rotate, flip, or both.
- /// The operations to perform on the source.
+ /// The operations to perform on the source.
/// returns the current optinoatins class to allow chaining of oprations.
- public static IImageOperations Run(this IImageOperations source, Action> operation)
+ public static IImageOperations ApplyProcessors(this IImageOperations source, params IImageProcessor[] operations)
where TPixel : struct, IPixel
- => source.ApplyProcessor(new DelegateImageProcessor(operation));
+ {
+ foreach (var p in operations)
+ {
+ source = source.ApplyProcessor(p);
+ }
+
+ return source;
+ }
}
}
diff --git a/src/ImageSharp/Numerics/ValueSize.cs b/src/ImageSharp/Numerics/ValueSize.cs
index 5d81e2f952..af7454c191 100644
--- a/src/ImageSharp/Numerics/ValueSize.cs
+++ b/src/ImageSharp/Numerics/ValueSize.cs
@@ -5,12 +5,13 @@
namespace ImageSharp
{
+ using System;
using SixLabors.Primitives;
///
/// Represents a value in relation to a value on the image
///
- internal struct ValueSize
+ internal struct ValueSize : IEquatable
{
///
/// Initializes a new instance of the struct.
@@ -120,5 +121,11 @@ namespace ImageSharp
{
return $"{this.Value} - {this.Type}";
}
+
+ ///
+ public bool Equals(ValueSize other)
+ {
+ return this.Type == other.Type && this.Value == other.Value;
+ }
}
}
diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs
index 614eabca79..ce5e8c205c 100644
--- a/src/ImageSharp/Processing/Binarization/Dither.cs
+++ b/src/ImageSharp/Processing/Binarization/Dither.cs
@@ -25,7 +25,21 @@ namespace ImageSharp
/// The ordered ditherer.
/// The component index to test the threshold against. Must range from 0 to 3.
/// The .
- public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, int index = 0)
+ public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither)
+ where TPixel : struct, IPixel
+ {
+ source.ApplyProcessor(new OrderedDitherProcessor(dither, 0));
+ return source;
+ }
+ ///
+ /// Dithers the image reducing it to two colors using ordered dithering.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The ordered ditherer.
+ /// The component index to test the threshold against. Must range from 0 to 3.
+ /// The .
+ public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, int index)
where TPixel : struct, IPixel
{
source.ApplyProcessor(new OrderedDitherProcessor(dither, index));
@@ -43,7 +57,25 @@ namespace ImageSharp
///
/// The component index to test the threshold against. Must range from 0 to 3.
/// The .
- public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle, int index = 0)
+ public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle)
+ where TPixel : struct, IPixel
+ {
+ source.ApplyProcessor(new OrderedDitherProcessor(dither, 0), rectangle);
+ return source;
+ }
+
+ ///
+ /// Dithers the image reducing it to two colors using ordered dithering.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The ordered ditherer.
+ ///
+ /// The structure that specifies the portion of the image object to alter.
+ ///
+ /// The component index to test the threshold against. Must range from 0 to 3.
+ /// The .
+ public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle, int index)
where TPixel : struct, IPixel
{
source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle);
diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs
index f000a6aa4e..1a89ac1a0e 100644
--- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs
+++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs
@@ -24,7 +24,18 @@ namespace ImageSharp
/// The image this method extends.
/// The 'radius' value representing the size of the area to sample.
/// The .
- public static IImageOperations BoxBlur(this IImageOperations source, int radius = 7)
+ public static IImageOperations BoxBlur(this IImageOperations source)
+ where TPixel : struct, IPixel
+ => source.ApplyProcessor(new BoxBlurProcessor(7));
+
+ ///
+ /// Applies a box blur to the image.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The 'radius' value representing the size of the area to sample.
+ /// The .
+ public static IImageOperations BoxBlur(this IImageOperations source, int radius)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new BoxBlurProcessor(radius));
diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs
index 14bcf20598..b4382f902b 100644
--- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs
+++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs
@@ -55,7 +55,19 @@ namespace ImageSharp
/// The filter for detecting edges.
/// Whether to convert the image to Grayscale first. Defaults to true.
/// The .
- public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, bool grayscale = true)
+ public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter)
+ where TPixel : struct, IPixel
+ => DetectEdges(source, GetProcessor(filter, true));
+
+ ///
+ /// Detects any edges within the image.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The filter for detecting edges.
+ /// Whether to convert the image to Grayscale first. Defaults to true.
+ /// The .
+ public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, bool grayscale)
where TPixel : struct, IPixel
=> DetectEdges(source, GetProcessor(filter, grayscale));
diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs
index 7d551ceb8d..91f5635050 100644
--- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs
+++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs
@@ -25,7 +25,17 @@ namespace ImageSharp
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
/// The .
- public static IImageOperations GaussianBlur(this IImageOperations source, float sigma = 3f)
+ public static IImageOperations GaussianBlur(this IImageOperations source)
+ where TPixel : struct, IPixel
+ => source.ApplyProcessor(new GaussianBlurProcessor(3f));
+ ///
+ /// Applies a Gaussian blur to the image.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The 'sigma' value representing the weight of the blur.
+ /// The .
+ public static IImageOperations GaussianBlur(this IImageOperations source, float sigma)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new GaussianBlurProcessor(sigma));
diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs
index 58c5ad12ac..1fd003d128 100644
--- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs
+++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs
@@ -25,7 +25,18 @@ namespace ImageSharp
/// The image this method extends.
/// The 'sigma' value representing the weight of the blur.
/// The .
- public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma = 3f)
+ public static IImageOperations GaussianSharpen(this IImageOperations source)
+ where TPixel : struct, IPixel
+ => source.ApplyProcessor(new GaussianSharpenProcessor(3f));
+
+ ///
+ /// Applies a Gaussian sharpening filter to the image.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The 'sigma' value representing the weight of the blur.
+ /// The .
+ public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new GaussianSharpenProcessor(sigma));
diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs
index 52ec736f5d..a6efb711bf 100644
--- a/src/ImageSharp/Processing/Delegate.cs
+++ b/src/ImageSharp/Processing/Delegate.cs
@@ -26,5 +26,6 @@ namespace ImageSharp
public static IImageOperations Run(this IImageOperations source, Action> operation)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new DelegateProcessor(operation));
+
}
}
diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs
index cd0551ad39..8447f5ba17 100644
--- a/src/ImageSharp/Processing/Effects/Pixelate.cs
+++ b/src/ImageSharp/Processing/Effects/Pixelate.cs
@@ -24,7 +24,18 @@ namespace ImageSharp
/// The image this method extends.
/// The size of the pixels.
/// The .
- public static IImageOperations Pixelate(this IImageOperations source, int size = 4)
+ public static IImageOperations Pixelate(this IImageOperations source)
+ where TPixel : struct, IPixel
+ => source.ApplyProcessor(new PixelateProcessor(4));
+
+ ///
+ /// Pixelates an image with the given pixel size.
+ ///
+ /// The pixel format.
+ /// The image this method extends.
+ /// The size of the pixels.
+ /// The .
+ public static IImageOperations Pixelate(this IImageOperations source, int size)
where TPixel : struct, IPixel
=> source.ApplyProcessor(new PixelateProcessor(size));
diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs
index 535b758493..175d3ea3a2 100644
--- a/src/ImageSharp/Processing/Overlays/Vignette.cs
+++ b/src/ImageSharp/Processing/Overlays/Vignette.cs
@@ -106,7 +106,7 @@ namespace ImageSharp
/// The .
public static IImageOperations Vignette(this IImageOperations source, TPixel color, GraphicsOptions options)
where TPixel : struct, IPixel
- => source.VignetteInternal(color, 0, 0, options);
+ => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options);
///
/// Applies a radial vignette effect to an image.
@@ -133,7 +133,7 @@ namespace ImageSharp
/// The .
public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle, GraphicsOptions options)
where TPixel : struct, IPixel
- => source.Vignette(NamedColors.Black, 0, 0, rectangle, options);
+ => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options);
///
/// Applies a radial vignette effect to an image.
diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs
index 3adfb83114..ffc8eb6b19 100644
--- a/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/ColorMatrix/SaturationProcessor.cs
@@ -26,6 +26,7 @@ namespace ImageSharp.Processing.Processors
///
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;
}
+ ///
+ /// Gets the amount to apply.
+ ///
+ public int Amount { get; }
+
///
public override Matrix4x4 Matrix { get; }
}
diff --git a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
index 0a2162fb05..93a9254802 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/BoxBlurProcessor.cs
@@ -31,11 +31,17 @@ namespace ImageSharp.Processing.Processors
///
public BoxBlurProcessor(int radius = 7)
{
+ this.Radius = radius;
this.kernelSize = (radius * 2) + 1;
this.KernelX = this.CreateBoxKernel(true);
this.KernelY = this.CreateBoxKernel(false);
}
+ ///
+ /// Gets the Radius
+ ///
+ public int Radius { get; }
+
///
/// Gets the horizontal gradient operator.
///
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
index ef6ddaa6a7..dcafd0d91e 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianBlurProcessor.cs
@@ -72,6 +72,11 @@ namespace ImageSharp.Processing.Processors
this.KernelY = this.CreateGaussianKernel(false);
}
+ ///
+ /// Gets the sigma
+ ///
+ public float Sigma => this.sigma;
+
///
/// Gets the horizontal gradient operator.
///
diff --git a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
index 594dda8cab..84a7f9b09c 100644
--- a/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Convolution/GaussianSharpenProcessor.cs
@@ -74,6 +74,11 @@ namespace ImageSharp.Processing.Processors
this.KernelY = this.CreateGaussianKernel(false);
}
+ ///
+ /// Gets the sigma
+ ///
+ public float Sigma => this.sigma;
+
///
/// Gets the horizontal gradient operator.
///
diff --git a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
index 96fcf4d630..96a2b704f7 100644
--- a/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Effects/BackgroundColorProcessor.cs
@@ -32,6 +32,11 @@ namespace ImageSharp.Processing.Processors
this.options = options;
}
+ ///
+ /// Gets the Graphics options to alter how processor is applied.
+ ///
+ public GraphicsOptions GraphicsOptions => this.options;
+
///
/// Gets the background color value.
///
diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
index 5a816da14d..5da6a96dcf 100644
--- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs
@@ -37,6 +37,11 @@ namespace ImageSharp.Processing.Processors
this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode);
}
+ ///
+ /// Gets the Graphics options to alter how processor is applied.
+ ///
+ public GraphicsOptions GraphicsOptions => this.options;
+
///
/// Gets or sets the glow color to apply.
///
diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
index 6a46692d23..07c45f4f03 100644
--- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
+++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs
@@ -51,6 +51,11 @@ namespace ImageSharp.Processing.Processors
this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode);
}
+ ///
+ /// Gets the Graphics options to alter how processor is applied.
+ ///
+ public GraphicsOptions GraphicsOptions => this.options;
+
///
/// Gets or sets the vignette color to apply.
///
diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
index 16f74f218b..a52065ea9b 100644
--- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs
+++ b/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;
}
///
/// Gets the threshold value.
///
- public float Value { get; }
+ public float Threshold { get; }
///
protected override void OnApply(ImageBase source, Rectangle sourceRectangle)
@@ -45,7 +45,7 @@ namespace ImageSharp.Processing.Processors
new SobelProcessor().Apply(temp, sourceRectangle);
// Apply threshold binarization filter.
- new BinaryThresholdProcessor(this.Value).Apply(temp, sourceRectangle);
+ new BinaryThresholdProcessor(this.Threshold).Apply(temp, sourceRectangle);
// Search for the first white pixels
Rectangle rectangle = ImageMaths.GetFilteredBoundingRectangle(temp, 0);
diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs
index d6bea7108a..398db976e5 100644
--- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs
+++ b/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 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(null);
}
public T Verify(int index = 0)
{
+ Assert.InRange(index, 0, this.operations.applied.Count - 1);
+
+ var operation = this.operations.applied[index];
+
+ return Assert.IsType(operation.Processor);
+ }
+ public T Verify(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(operation.Processor);
}
}
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
index b80173bcf8..c1e22e49c6 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
+++ b/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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(brush, path);
+ var processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(brush, path, noneDefault);
+ var processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(color, path);
+ var processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(color, path, noneDefault);
+ var processor = this.Verify>();
Assert.Equal(noneDefault, processor.Options);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
index 8fe18713d8..11ead13c18 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
+++ b/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 processor = Assert.IsType>(img.ProcessorApplications[i].processor);
+ FillRegionProcessor processor = this.Verify>(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 processor = Assert.IsType>(img.ProcessorApplications[i].processor);
+ FillRegionProcessor processor = this.Verify>(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 processor = Assert.IsType>(img.ProcessorApplications[i].processor);
+ FillRegionProcessor processor = this.Verify>(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 processor = Assert.IsType>(img.ProcessorApplications[i].processor);
+ FillRegionProcessor processor = this.Verify>(i);
Assert.Equal(noneDefault, processor.Options);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
index 2fd9a89b3c..d833bf47be 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
+++ b/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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ FillRegionProcessor processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.FillPolygon(brush, path, noneDefault);
+ FillRegionProcessor processor = this.Verify>();
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 processor = this.Verify>();
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(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 processor = this.Verify>();
- Assert.NotEmpty(img.ProcessorApplications);
- FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor);
Assert.Equal(noneDefault, processor.Options);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
index 56c7d51093..687c63068d 100644
--- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
+++ b/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 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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(brush, rectangle);
+ FillRegionProcessor processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(brush, rectangle, noneDefault);
+ FillRegionProcessor processor = this.Verify>();
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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
-
+ this.operations.Fill(color, rectangle);
+ FillRegionProcessor processor = this.Verify>();
+
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType(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 processor = Assert.IsType>(img.ProcessorApplications[0].processor);
+ this.operations.Fill(color, rectangle, noneDefault);
+ FillRegionProcessor processor = this.Verify>();
Assert.Equal(noneDefault, processor.Options);
diff --git a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs b/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs
deleted file mode 100644
index 1670b33520..0000000000
--- a/tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs
+++ /dev/null
@@ -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;
-
- ///
- /// Watches but does not actually run the processors against the image.
- ///
- ///
- public class ProcessorWatchingImage : Image
- {
- public List ProcessorApplications { get; } = new List();
-
- public ProcessorWatchingImage(int width, int height)
- : base(Configuration.CreateDefaultInstance(), width, height)
- {
- }
-
- public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle)
- {
- this.ProcessorApplications.Add(new ProcessorDetails
- {
- processor = processor,
- rectangle = rectangle
- });
- }
-
- public struct ProcessorDetails
- {
- public IImageProcessor processor;
- public Rectangle rectangle;
- }
- }
-}
diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs
index 067ea122d8..705c99d08e 100644
--- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs
+++ b/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>(this.img.ProcessorApplications[0].processor);
+ this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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 processor =
- Assert.IsType>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(2);
SolidBrush brush = Assert.IsType>(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>(this.img.ProcessorApplications[0].processor);
- FillRegionProcessor processor =
- Assert.IsType>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(2);
SolidBrush brush = Assert.IsType>(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>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(this.img.ProcessorApplications[0].processor);
+ var processor = this.Verify>(0);
+ this.Verify>(1);
+ this.Verify>(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>(0);
+ this.Verify>(1);
+ this.Verify>(2);
+ this.Verify>(3);
+ this.Verify>(4);
+ this.Verify>(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>(0);
+ this.Verify