From f026778e4727a47a4be99f3954ae92775ad3a55b Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 1 Jul 2017 20:09:35 +0100 Subject: [PATCH 01/20] migrate to a Image.Generate/Image.Mutate context api --- samples/AvatarWithRoundedCorner/Program.cs | 17 +-- src/ImageSharp.Drawing/DrawImage.cs | 14 +- src/ImageSharp.Drawing/FillRegion.cs | 14 +- src/ImageSharp.Drawing/Paths/DrawBeziers.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawLines.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPath.cs | 12 +- .../Paths/DrawPathCollection.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPolygon.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawRectangle.cs | 12 +- .../Paths/FillPathBuilder.cs | 8 +- .../Paths/FillPathCollection.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPaths.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPolygon.cs | 8 +- src/ImageSharp.Drawing/Paths/FillRectangle.cs | 8 +- .../Processors/DrawImageProcessor.cs | 2 +- src/ImageSharp.Drawing/Text/DrawText.Path.cs | 21 ++- src/ImageSharp.Drawing/Text/DrawText.cs | 21 ++- .../Text/TextGraphicsOptions.cs | 9 -- src/ImageSharp/ApplyProcessors.cs | 100 ++++++++++++++ src/ImageSharp/Formats/Bmp/ImageExtensions.cs | 19 ++- src/ImageSharp/Formats/Gif/ImageExtensions.cs | 21 +-- .../Formats/Jpeg/ImageExtensions.cs | 21 +-- src/ImageSharp/Formats/Png/ImageExtensions.cs | 21 +-- src/ImageSharp/IImageOperations{TPixel}.cs | 36 +++++ src/ImageSharp/Image/IImageProcessor.cs | 2 +- src/ImageSharp/Image/ImageBase{TPixel}.cs | 10 -- .../Image/ImageProcessingExtensions.cs | 4 +- src/ImageSharp/Image/Image{TPixel}.cs | 8 +- src/ImageSharp/ImageOperations.cs | 62 +++++++++ src/ImageSharp/Numerics/ValueSize.cs | 124 ++++++++++++++++++ .../Binarization/BinaryThreshold.cs | 7 +- .../Processing/Binarization/Dither.cs | 14 +- .../Processing/ColorMatrix/BlackWhite.cs | 7 +- .../Processing/ColorMatrix/ColorBlindness.cs | 48 +++---- .../Processing/ColorMatrix/Grayscale.cs | 20 +-- src/ImageSharp/Processing/ColorMatrix/Hue.cs | 7 +- .../Processing/ColorMatrix/Kodachrome.cs | 7 +- .../Processing/ColorMatrix/Lomograph.cs | 13 +- .../Processing/ColorMatrix/Polaroid.cs | 11 +- .../Processing/ColorMatrix/Saturation.cs | 7 +- .../Processing/ColorMatrix/Sepia.cs | 13 +- .../Processing/Convolution/BoxBlur.cs | 13 +- .../Processing/Convolution/DetectEdges.cs | 80 +++++------ .../Processing/Convolution/GaussianBlur.cs | 13 +- .../Processing/Convolution/GaussianSharpen.cs | 13 +- .../Processing/DelegateImageProcessor.cs | 44 +++++++ src/ImageSharp/Processing/Effects/Alpha.cs | 13 +- .../Processing/Effects/BackgroundColor.cs | 17 +-- .../Processing/Effects/Brightness.cs | 13 +- src/ImageSharp/Processing/Effects/Contrast.cs | 13 +- src/ImageSharp/Processing/Effects/Invert.cs | 13 +- .../Processing/Effects/OilPainting.cs | 26 +--- src/ImageSharp/Processing/Effects/Pixelate.cs | 18 +-- src/ImageSharp/Processing/ImageProcessor.cs | 66 +++++++++- src/ImageSharp/Processing/Overlays/Glow.cs | 79 ++++++----- .../Processing/Overlays/Vignette.cs | 54 ++++---- .../ColorMatrix/PolaroidProcessor.cs | 2 +- .../Effects/OilPaintingProcessor.cs | 5 + .../Processors/Effects/PixelateProcessor.cs | 13 +- .../Processors/Overlays/GlowProcessor.cs | 11 +- .../Processors/Overlays/VignetteProcessor.cs | 28 +++- .../Transforms/AutoRotateProcessor.cs | 103 +++++++++++++++ .../Transforms/ResamplingWeightedProcessor.cs | 12 +- .../Processing/Transforms/AutoOrient.cs | 64 +-------- src/ImageSharp/Processing/Transforms/Crop.cs | 15 +-- .../Processing/Transforms/EntropyCrop.cs | 9 +- src/ImageSharp/Processing/Transforms/Flip.cs | 9 +- src/ImageSharp/Processing/Transforms/Pad.cs | 2 +- .../Processing/Transforms/Resize.cs | 118 ++++++++++++----- .../Processing/Transforms/Rotate.cs | 17 +-- .../Processing/Transforms/RotateFlip.cs | 2 +- src/ImageSharp/Processing/Transforms/Skew.cs | 11 +- src/ImageSharp/Quantizers/Quantize.cs | 45 ++++--- .../Drawing/DrawBeziers.cs | 4 +- .../Drawing/DrawLines.cs | 4 +- .../Drawing/DrawPolygon.cs | 4 +- .../Drawing/FillPolygon.cs | 8 +- .../Drawing/FillRectangle.cs | 6 +- .../Drawing/FillWithPattern.cs | 2 +- tests/ImageSharp.Benchmarks/Samplers/Crop.cs | 2 +- .../Samplers/DetectEdges.cs | 22 ++-- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 2 +- .../ImageSharp.Benchmarks/Samplers/Resize.cs | 2 +- .../ImageSharp.Tests/Drawing/BeziersTests.cs | 12 +- .../ImageSharp.Tests/Drawing/BlendedShapes.cs | 42 +++--- .../ImageSharp.Tests/Drawing/DrawImageTest.cs | 4 +- .../ImageSharp.Tests/Drawing/DrawPathTests.cs | 16 +-- .../Drawing/FillPatternTests.cs | 7 +- .../Drawing/FillRegionProcessorTests.cs | 6 +- .../Drawing/FillSolidBrushTests.cs | 15 ++- .../Drawing/LineComplexPolygonTests.cs | 30 ++--- tests/ImageSharp.Tests/Drawing/LineTests.cs | 88 ++++++------- .../Drawing/Paths/FillPath.cs | 8 +- .../Drawing/Paths/FillPathCollection.cs | 8 +- .../Drawing/Paths/FillPolygon.cs | 8 +- .../Drawing/Paths/FillRectangle.cs | 8 +- .../ImageSharp.Tests/Drawing/PolygonTests.cs | 28 ++-- .../Drawing/RecolorImageTest.cs | 8 +- .../Drawing/SolidBezierTests.cs | 16 +-- .../Drawing/SolidComplexPolygonTests.cs | 18 +-- .../Drawing/SolidPolygonTests.cs | 62 ++++----- .../Drawing/Text/DrawText.Path.cs | 63 +++------ .../ImageSharp.Tests/Drawing/Text/DrawText.cs | 63 +++------ .../Drawing/Text/OutputText.cs | 4 +- .../Formats/GeneralFormatTests.cs | 14 +- .../Formats/Jpg/JpegEncoderTests.cs | 3 +- .../Formats/Png/PngSmokeTests.cs | 2 +- .../Image/PixelAccessorTests.cs | 5 +- tests/ImageSharp.Tests/ImageComparer.cs | 6 +- .../Binarization/BinaryThresholdTest.cs | 8 +- .../Processing/Binarization/DitherTest.cs | 16 +-- .../Processing/ColorMatrix/BlackWhiteTest.cs | 8 +- .../ColorMatrix/ColorBlindnessTest.cs | 8 +- .../Processing/ColorMatrix/GrayscaleTest.cs | 6 +- .../Processing/ColorMatrix/HueTest.cs | 8 +- .../Processing/ColorMatrix/KodachromeTest.cs | 8 +- .../Processing/ColorMatrix/LomographTest.cs | 8 +- .../Processing/ColorMatrix/PolaroidTest.cs | 8 +- .../Processing/ColorMatrix/SaturationTest.cs | 8 +- .../Processing/ColorMatrix/SepiaTest.cs | 8 +- .../Processing/Convolution/BoxBlurTest.cs | 8 +- .../Processing/Convolution/DetectEdgesTest.cs | 8 +- .../Convolution/GaussianBlurTest.cs | 8 +- .../Convolution/GaussianSharpenTest.cs | 8 +- .../Processing/Effects/AlphaTest.cs | 8 +- .../Processing/Effects/BackgroundColorTest.cs | 8 +- .../Processing/Effects/BrightnessTest.cs | 8 +- .../Processing/Effects/ContrastTest.cs | 8 +- .../Processing/Effects/InvertTest.cs | 8 +- .../Processing/Effects/OilPaintTest.cs | 8 +- .../Processing/Effects/PixelateTest.cs | 8 +- .../Processing/Overlays/GlowTest.cs | 16 +-- .../Processing/Overlays/VignetteTest.cs | 16 +-- .../Processing/Transforms/AutoOrientTests.cs | 9 +- .../Processing/Transforms/CropTest.cs | 4 +- .../Processing/Transforms/EntropyCropTest.cs | 4 +- .../Processing/Transforms/FlipTests.cs | 4 +- .../Processing/Transforms/PadTest.cs | 4 +- .../Transforms/ResizeProfilingBenchmarks.cs | 2 +- .../Processing/Transforms/ResizeTests.cs | 44 +++---- .../Processing/Transforms/RotateFlipTests.cs | 4 +- .../Processing/Transforms/RotateTests.cs | 8 +- .../Processing/Transforms/SkewTest.cs | 4 +- .../ImageProviders/SolidProvider.cs | 3 +- .../ImageProviders/TestImageProvider.cs | 10 ++ .../Tests/TestUtilityExtensionsTests.cs | 3 +- 146 files changed, 1504 insertions(+), 1146 deletions(-) create mode 100644 src/ImageSharp/ApplyProcessors.cs create mode 100644 src/ImageSharp/IImageOperations{TPixel}.cs create mode 100644 src/ImageSharp/ImageOperations.cs create mode 100644 src/ImageSharp/Numerics/ValueSize.cs create mode 100644 src/ImageSharp/Processing/DelegateImageProcessor.cs create mode 100644 src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index b164c8d3b..45fe1e3c8 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -23,13 +23,14 @@ namespace AvatarWithRoundedCorner { using (var image = Image.Load(source)) { - image.Resize(new ImageSharp.Processing.ResizeOptions - { - Size = size, - Mode = ImageSharp.Processing.ResizeMode.Crop - }); + image.Mutate(x => x + .Resize(new ImageSharp.Processing.ResizeOptions + { + Size = size, + Mode = ImageSharp.Processing.ResizeMode.Crop + }) + .Run(i=>ApplyRoundedCourners(i, cornerRadius))); - ApplyRoundedCourners(image, cornerRadius); image.Save(destination); } } @@ -38,10 +39,10 @@ namespace AvatarWithRoundedCorner { var corners = BuildCorners(img.Width, img.Height, cornerRadius); // now we have our corners time to draw them - img.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) + img.Mutate(x => x.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) { BlenderMode = ImageSharp.PixelFormats.PixelBlenderMode.Src // enforces that any part of this shape that has color is punched out of the background - }); + })); } public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index 03eb7be28..bd51e4ac0 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The location to draw the blended image. /// The options. /// The . - public static Image DrawImage(this Image source, Image image, Size size, Point location, GraphicsOptions options) + public static IImageOperations DrawImage(this IImageOperations source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) @@ -37,7 +37,7 @@ namespace ImageSharp location = Point.Empty; } - source.ApplyProcessor(new DrawImageProcessor(image, size, location, options), source.Bounds); + source.ApplyProcessor(new DrawImageProcessor(image, size, location, options)); return source; } @@ -49,7 +49,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static Image Blend(this Image source, Image image, float percent) + public static IImageOperations Blend(this IImageOperations source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -66,7 +66,7 @@ namespace ImageSharp /// The blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static Image Blend(this Image source, Image image, PixelBlenderMode blender, float percent) + public static IImageOperations Blend(this IImageOperations source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -83,7 +83,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . - public static Image Blend(this Image source, Image image, GraphicsOptions options) + public static IImageOperations Blend(this IImageOperations source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); @@ -99,7 +99,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static Image DrawImage(this Image source, Image image, float percent, Size size, Point location) + public static IImageOperations DrawImage(this IImageOperations source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -118,7 +118,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static Image DrawImage(this Image source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) + public static IImageOperations DrawImage(this IImageOperations source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index b3ee2ed99..d8bb78e90 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The details how to fill the region of interest. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, GraphicsOptions options) where TPixel : struct, IPixel { return source.Apply(new FillProcessor(brush, options)); @@ -36,7 +36,7 @@ namespace ImageSharp /// The image this method extends. /// The details how to fill the region of interest. /// The . - public static Image Fill(this Image source, IBrush brush) + public static IImageOperations Fill(this IImageOperations source, IBrush brush) where TPixel : struct, IPixel { return source.Fill(brush, GraphicsOptions.Default); @@ -49,7 +49,7 @@ namespace ImageSharp /// The image this method extends. /// The color. /// The . - public static Image Fill(this Image source, TPixel color) + public static IImageOperations Fill(this IImageOperations source, TPixel color) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color)); @@ -64,7 +64,7 @@ namespace ImageSharp /// The region. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, Region region, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Apply(new FillRegionProcessor(brush, region, options)); @@ -78,7 +78,7 @@ namespace ImageSharp /// The brush. /// The region. /// The . - public static Image Fill(this Image source, IBrush brush, Region region) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region) where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); @@ -93,7 +93,7 @@ namespace ImageSharp /// The region. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, Region region, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region, options); @@ -107,7 +107,7 @@ namespace ImageSharp /// The color. /// The region. /// The . - public static Image Fill(this Image source, TPixel color, Region region) + public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region); diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index 59bcf4036..d332f1d05 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawBeziers(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawBeziers(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static Image DrawBeziers(this Image source, IPen pen, PointF[] points) + public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index 3ce0dc4da..db1e46af8 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawLines(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawLines(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The .> - public static Image DrawLines(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawLines(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static Image DrawLines(this Image source, IPen pen, PointF[] points) + public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index 1fba06370..57ce2032a 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, IPath path, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The path. /// The . - public static Image Draw(this Image source, IPen pen, IPath path) + public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path) where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPath path) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path); @@ -86,7 +86,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPath path) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path); diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs index 877737653..f909e98da 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath path in paths) @@ -44,7 +44,7 @@ namespace ImageSharp /// The pen. /// The paths. /// The . - public static Image Draw(this Image source, IPen pen, IPathCollection paths) + public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(pen, paths, GraphicsOptions.Default); @@ -60,7 +60,7 @@ namespace ImageSharp /// The shapes. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths, options); @@ -75,7 +75,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, IPathCollection paths) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths); @@ -91,7 +91,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths, options); @@ -106,7 +106,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, IPathCollection paths) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths); diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index 4fa469a49..b787afcd5 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, PointF[] points) + public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static Image DrawPolygon(this Image source, TPixel color, float thickness, PointF[] points) + public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points, options); @@ -88,7 +88,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static Image DrawPolygon(this Image source, IPen pen, PointF[] points) + public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); @@ -103,7 +103,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image DrawPolygon(this Image source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index b3f0e6fc3..544ca2fe9 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The shape. /// The . - public static Image Draw(this Image source, IPen pen, RectangleF shape) + public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static Image Draw(this Image source, IBrush brush, float thickness, RectangleF shape) + public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape); @@ -86,7 +86,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static Image Draw(this Image source, TPixel color, float thickness, RectangleF shape) + public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape); diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs index abb5ef73a..eae34f034 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, Action path, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path, GraphicsOptions options) where TPixel : struct, IPixel { var pb = new PathBuilder(); @@ -42,7 +42,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static Image Fill(this Image source, IBrush brush, Action path) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path) where TPixel : struct, IPixel { return source.Fill(brush, path, GraphicsOptions.Default); @@ -57,7 +57,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, Action path, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static Image Fill(this Image source, TPixel color, Action path) + public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs index 3ea9fb94b..662245dc3 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shapes. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath s in paths) @@ -43,7 +43,7 @@ namespace ImageSharp /// The brush. /// The paths. /// The . - public static Image Fill(this Image source, IBrush brush, IPathCollection paths) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(brush, paths, GraphicsOptions.Default); @@ -58,7 +58,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths, options); @@ -72,7 +72,7 @@ namespace ImageSharp /// The color. /// The paths. /// The . - public static Image Fill(this Image source, TPixel color, IPathCollection paths) + public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths); diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index f579c4ad0..07342d47b 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static Image Fill(this Image source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static Image Fill(this Image source, IBrush brush, IPath path) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, IPath path, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static Image Fill(this Image source, TPixel color, IPath path) + public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index 6266d3bd6..7feac5b0a 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -27,7 +27,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image FillPolygon(this Image source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -41,7 +41,7 @@ namespace ImageSharp /// The brush. /// The points. /// The . - public static Image FillPolygon(this Image source, IBrush brush, PointF[] points) + public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -56,7 +56,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static Image FillPolygon(this Image source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The color. /// The points. /// The . - public static Image FillPolygon(this Image source, TPixel color, PointF[] points) + public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index bd6460cf9..52512ca1c 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Fill(this Image source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The shape. /// The . - public static Image Fill(this Image source, IBrush brush, RectangleF shape) + public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); @@ -53,7 +53,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static Image Fill(this Image source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The shape. /// The . - public static Image Fill(this Image source, TPixel color, RectangleF shape) + public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 62344b101..07a3ae8c2 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -70,7 +70,7 @@ namespace ImageSharp.Drawing.Processors { if (targetImage.Bounds.Size != this.Size) { - targetImage = disposableImage = new Image(this.Image).Resize(this.Size.Width, this.Size.Height); + targetImage = disposableImage = this.Image.Generate(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Text/DrawText.Path.cs index 523813188..459d5de0d 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.Path.cs @@ -31,7 +31,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, IPath path) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); @@ -50,7 +50,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, path, options); @@ -68,7 +68,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPath path) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); @@ -87,7 +87,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, path, options); @@ -105,7 +105,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, IPath path) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); @@ -124,7 +124,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, path, options); @@ -143,7 +143,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, IPath path) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); @@ -163,16 +163,11 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; float dpiY = DefaultTextDpi; - if (options.UseImageResolution) - { - dpiX = (float)source.MetaData.HorizontalResolution; - dpiY = (float)source.MetaData.VerticalResolution; - } var style = new RendererOptions(font, dpiX, dpiY) { diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 6352836a9..989322a73 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -34,7 +34,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, PointF location) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, location, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, PointF location) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); @@ -90,7 +90,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, PointF location) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); @@ -127,7 +127,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); @@ -146,7 +146,7 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, PointF location) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); @@ -166,16 +166,11 @@ namespace ImageSharp /// /// The . /// - public static Image DrawText(this Image source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; float dpiY = DefaultTextDpi; - if (options.UseImageResolution) - { - dpiX = (float)source.MetaData.HorizontalResolution; - dpiY = (float)source.MetaData.VerticalResolution; - } var style = new RendererOptions(font, dpiX, dpiY, location) { diff --git a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs index 593ac36d4..e360e8aee 100644 --- a/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs +++ b/src/ImageSharp.Drawing/Text/TextGraphicsOptions.cs @@ -29,8 +29,6 @@ namespace ImageSharp.Drawing private PixelBlenderMode blenderMode; - private bool? useImageResolution; - private float wrapTextWidth; private SixLabors.Fonts.HorizontalAlignment? horizontalAlignment; @@ -44,7 +42,6 @@ namespace ImageSharp.Drawing { this.applyKerning = true; this.tabWidth = 4; - this.useImageResolution = false; this.wrapTextWidth = 0; this.horizontalAlignment = HorizontalAlignment.Left; this.verticalAlignment = VerticalAlignment.Top; @@ -89,12 +86,6 @@ namespace ImageSharp.Drawing /// public float TabWidth { get => this.tabWidth ?? 4; set => this.tabWidth = value; } - /// - /// Gets or sets a value indicating whether to use the current image resultion to for point size scaling. - /// If this is [false] the text renders at 72dpi otherwise it renders at Image resolution - /// - public bool UseImageResolution { get => this.useImageResolution ?? false; set => this.useImageResolution = value; } - /// /// Gets or sets a value indicating if greater than zero determine the width at which text should wrap. /// diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs new file mode 100644 index 000000000..2a9c3ccbe --- /dev/null +++ b/src/ImageSharp/ApplyProcessors.cs @@ -0,0 +1,100 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + + using ImageSharp.PixelFormats; + + using ImageSharp.Processing; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Mutates the image by applying the operations to it. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// The operations to perform on the source. + public static void Mutate(this Image source, Action> operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + + // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing + var operationsRunner = new ImageOperations(source); + operations(operationsRunner); + } + + /// + /// Mutates the image by applying the operations to it. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// The operations to perform on the source. + public static void Mutate(this Image source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + + // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing + var operationsRunner = new ImageOperations(source); + operationsRunner.ApplyProcessors(operations); + } + + /// + /// Mutates the image by applying the operations to it. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// The operations to perform on the source. + /// Anew Image which has teh data from the but with the applied. + public static Image Generate(this Image source, Action> operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + var generated = new Image(source); + + // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing + var operationsRunner = new ImageOperations(generated); + operations(operationsRunner); + return generated; + } + + /// + /// Mutates the image by applying the operations to it. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// The operations to perform on the source. + /// Anew Image which has teh data from the but with the applied. + public static Image Generate(this Image source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + Guard.NotNull(operations, nameof(operations)); + var generated = new Image(source); + + // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing + var operationsRunner = new ImageOperations(generated); + operationsRunner.ApplyProcessors(operations); + return generated; + } + + /// + /// Mutates the image by applying the operations to it. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// 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) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DelegateImageProcessor(operation)); + } +} diff --git a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs index aba24f999..96d0ceb9f 100644 --- a/src/ImageSharp/Formats/Bmp/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Bmp/ImageExtensions.cs @@ -24,11 +24,20 @@ namespace ImageSharp /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsBmp(this Image source, Stream stream) + public static void SaveAsBmp(this Image source, Stream stream) where TPixel : struct, IPixel - => source.Save(stream, new BmpEncoder()); + => source.SaveAsBmp(stream, null); + + /// + /// Saves the image to the given stream with the bmp format. + /// + /// The pixel format. + /// The image this method extends. + /// The stream to save the image to. + /// The encoder to save the image with. + /// Thrown if the stream is null. + public static void SaveAsBmp(this Image source, Stream stream, BmpEncoder encoder) + where TPixel : struct, IPixel + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Bitmap)); } } diff --git a/src/ImageSharp/Formats/Gif/ImageExtensions.cs b/src/ImageSharp/Formats/Gif/ImageExtensions.cs index ea9c9b504..717df4423 100644 --- a/src/ImageSharp/Formats/Gif/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Gif/ImageExtensions.cs @@ -24,14 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsGif(this Image source, Stream stream) + public static void SaveAsGif(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsGif(source, stream, null); - } + => source.SaveAsGif(stream, null); /// /// Saves the image to the given stream with the gif format. @@ -41,16 +36,8 @@ namespace ImageSharp /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsGif(this Image source, Stream stream, GifEncoder encoder) + public static void SaveAsGif(this Image source, Stream stream, GifEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new GifEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Gif)); } } diff --git a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs index 8fbf9e5a7..c69007e66 100644 --- a/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Jpeg/ImageExtensions.cs @@ -24,14 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsJpeg(this Image source, Stream stream) + public static void SaveAsJpeg(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsJpeg(source, stream, null); - } + => SaveAsJpeg(source, stream, null); /// /// Saves the image to the given stream with the jpeg format. @@ -41,16 +36,8 @@ namespace ImageSharp /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) + public static void SaveAsJpeg(this Image source, Stream stream, JpegEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new JpegEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Jpeg)); } } diff --git a/src/ImageSharp/Formats/Png/ImageExtensions.cs b/src/ImageSharp/Formats/Png/ImageExtensions.cs index c81738576..697380c19 100644 --- a/src/ImageSharp/Formats/Png/ImageExtensions.cs +++ b/src/ImageSharp/Formats/Png/ImageExtensions.cs @@ -23,14 +23,9 @@ namespace ImageSharp /// The image this method extends. /// The stream to save the image to. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsPng(this Image source, Stream stream) + public static void SaveAsPng(this Image source, Stream stream) where TPixel : struct, IPixel - { - return SaveAsPng(source, stream, null); - } + => SaveAsPng(source, stream, null); /// /// Saves the image to the given stream with the png format. @@ -40,16 +35,8 @@ namespace ImageSharp /// The stream to save the image to. /// The options for the encoder. /// Thrown if the stream is null. - /// - /// The . - /// - public static Image SaveAsPng(this Image source, Stream stream, PngEncoder encoder) + public static void SaveAsPng(this Image source, Stream stream, PngEncoder encoder) where TPixel : struct, IPixel - { - encoder = encoder ?? new PngEncoder(); - encoder.Encode(source, stream); - - return source; - } + => source.Save(stream, encoder ?? source.Configuration.FindEncoder(ImageFormats.Png)); } } diff --git a/src/ImageSharp/IImageOperations{TPixel}.cs b/src/ImageSharp/IImageOperations{TPixel}.cs new file mode 100644 index 000000000..a176c0e28 --- /dev/null +++ b/src/ImageSharp/IImageOperations{TPixel}.cs @@ -0,0 +1,36 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using ImageSharp.Formats; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using SixLabors.Primitives; + + /// + /// The static collection of all the default image formats + /// + /// The pixel format + public interface IImageOperations + where TPixel : struct, IPixel + { + /// + /// Adds the processor to the current setr of image operations to be applied. + /// + /// The processor to apply + /// The area to apply it to + /// returns the current optinoatins class to allow chaining of oprations. + IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle); + + /// + /// Adds the processor to the current setr of image operations to be applied. + /// + /// The processor to apply + /// returns the current optinoatins class to allow chaining of oprations. + IImageOperations ApplyProcessor(IImageProcessor processor); + } +} \ No newline at end of file diff --git a/src/ImageSharp/Image/IImageProcessor.cs b/src/ImageSharp/Image/IImageProcessor.cs index 8687766d5..1e144e835 100644 --- a/src/ImageSharp/Image/IImageProcessor.cs +++ b/src/ImageSharp/Image/IImageProcessor.cs @@ -42,6 +42,6 @@ namespace ImageSharp.Processing /// /// doesnt fit the dimension of the image. /// - void Apply(ImageBase source, Rectangle sourceRectangle); + void Apply(Image source, Rectangle sourceRectangle); } } diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index 20b891f2d..d4a7af9ca 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -194,16 +194,6 @@ namespace ImageSharp return this.Pixels.Slice((y * this.Width) + x, this.Width - x); } - /// - /// Applies the processor. - /// - /// The processor. - /// The rectangle. - public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - processor.Apply(this, rectangle); - } - /// public void Dispose() { diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs index 8eed103d1..44fcba7cf 100644 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ b/src/ImageSharp/Image/ImageProcessingExtensions.cs @@ -22,10 +22,10 @@ namespace ImageSharp /// The image this method extends. /// The processor to apply to the image. /// The . - public static Image Apply(this Image source, IImageProcessor processor) + public static IImageOperations Apply(this IImageOperations source, IImageProcessor processor) where TPixel : struct, IPixel { - source.ApplyProcessor(processor, source.Bounds); + source.ApplyProcessor(processor); return source; } } diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 5e8bcab31..13b865521 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -138,14 +138,10 @@ namespace ImageSharp /// /// The processor to apply to the image. /// The structure that specifies the portion of the image object to draw. - public override void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { // we want to put this on on here as it gives us a really go place to test/verify processor settings - base.ApplyProcessor(processor, rectangle); - foreach (ImageFrame sourceFrame in this.Frames) - { - sourceFrame.ApplyProcessor(processor, rectangle); - } + processor.Apply(this, rectangle); } /// diff --git a/src/ImageSharp/ImageOperations.cs b/src/ImageSharp/ImageOperations.cs new file mode 100644 index 000000000..dde3153d1 --- /dev/null +++ b/src/ImageSharp/ImageOperations.cs @@ -0,0 +1,62 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System.Collections.Generic; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using SixLabors.Primitives; + + /// + /// The static collection of all the default image formats + /// + /// The pixel format + internal class ImageOperations : IImageOperations + where TPixel : struct, IPixel + { + private readonly Image image; + + /// + /// Initializes a new instance of the class. + /// + /// The image. + public ImageOperations(Image image) + { + this.image = image; + } + + /// + public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + // TODO : make this queue, and allow special processors managage the cloing operation for 'generate' + // to allow things like resize to not need to retain an extra copy of image data in memory, and to + // prevent an pixel copy operation + this.image.ApplyProcessor(processor, rectangle); + return this; + } + + /// + public IImageOperations ApplyProcessor(IImageProcessor processor) + { + return this.ApplyProcessor(processor, this.image.Bounds); + } + + /// + /// Applies a bluck colelctino of pressorce at once + /// + /// Processors to apply + /// this + public IImageOperations ApplyProcessors(IEnumerable> processors) + { + foreach (var processor in processors) + { + return this.ApplyProcessor(processor); + } + + return this; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Numerics/ValueSize.cs b/src/ImageSharp/Numerics/ValueSize.cs new file mode 100644 index 000000000..5d81e2f95 --- /dev/null +++ b/src/ImageSharp/Numerics/ValueSize.cs @@ -0,0 +1,124 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using SixLabors.Primitives; + + /// + /// Represents a value in relation to a value on the image + /// + internal struct ValueSize + { + /// + /// Initializes a new instance of the struct. + /// + /// The value. + /// The type. + public ValueSize(float value, ValueSizeType type) + { + if (type != ValueSizeType.Absolute) + { + Guard.MustBeBetweenOrEqualTo(value, 0, 1, nameof(value)); + } + + this.Value = value; + this.Type = type; + } + + /// + /// The different vlaue types + /// + public enum ValueSizeType + { + /// + /// The value is the final return value + /// + Absolute, + + /// + /// The value is a percentage of the Images Width + /// + PercentageOfWidth, + + /// + /// The value is a percentage of the Images height + /// + PercentageOfHeight + } + + /// + /// Gets the value. + /// + public float Value { get; } + + /// + /// Gets the type. + /// + public ValueSizeType Type { get; } + + /// + /// Implicitly converts a float into an absolute value + /// + /// the vlaue to use as the absolute figure. + public static implicit operator ValueSize(float d) + => Absolute(d); + + /// + /// Create a new ValueSize with as a PercentageOfWidth type with value set to percentage. + /// + /// The percentage. + /// a Values size with type PercentageOfWidth + public static ValueSize PercentageOfWidth(float percentage) + { + return new ValueSize(percentage, ValueSizeType.PercentageOfWidth); + } + + /// + /// Create a new ValueSize with as a PercentageOfHeight type with value set to percentage. + /// + /// The percentage. + /// a Values size with type PercentageOfHeight + public static ValueSize PercentageOfHeight(float percentage) + { + return new ValueSize(percentage, ValueSizeType.PercentageOfHeight); + } + + /// + /// Create a new ValueSize with as a Absolute type with value set to value. + /// + /// The value. + /// a Values size with type Absolute( + public static ValueSize Absolute(float value) + { + return new ValueSize(value, ValueSizeType.Absolute); + } + + /// + /// Calculates the specified size. + /// + /// The size. + /// The calucalted value + public float Calculate(Size size) + { + switch (this.Type) + { + case ValueSizeType.PercentageOfWidth: + return this.Value * size.Width; + case ValueSizeType.PercentageOfHeight: + return this.Value * size.Height; + case ValueSizeType.Absolute: + default: + return this.Value; + } + } + + /// + public override string ToString() + { + return $"{this.Value} - {this.Type}"; + } + } +} diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index e37f80c25..a4ee73af4 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -24,10 +24,11 @@ namespace ImageSharp /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static Image BinaryThreshold(this Image source, float threshold) + public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold) where TPixel : struct, IPixel { - return BinaryThreshold(source, threshold, source.Bounds); + source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); + return source; } /// @@ -40,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BinaryThreshold(this Image source, float threshold, Rectangle rectangle) + public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index efaf63b06..614eabca7 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -25,10 +25,11 @@ namespace ImageSharp /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static Image Dither(this Image source, IOrderedDither dither, int index = 0) + public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, int index = 0) where TPixel : struct, IPixel { - return Dither(source, dither, source.Bounds, index); + source.ApplyProcessor(new OrderedDitherProcessor(dither, index)); + return source; } /// @@ -42,7 +43,7 @@ namespace ImageSharp /// /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static Image Dither(this Image source, IOrderedDither dither, Rectangle rectangle, int index = 0) + public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle, int index = 0) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); @@ -57,10 +58,11 @@ namespace ImageSharp /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold) + public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel { - return Dither(source, diffuser, threshold, source.Bounds); + source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold)); + return source; } /// @@ -74,7 +76,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Dither(this Image source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 6a4e3807b..5710991dc 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -24,10 +24,11 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image BlackWhite(this Image source) + public static IImageOperations BlackWhite(this IImageOperations source) where TPixel : struct, IPixel { - return BlackWhite(source, source.Bounds); + source.ApplyProcessor(new BlackWhiteProcessor()); + return source; } /// @@ -39,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BlackWhite(this Image source, Rectangle rectangle) + public static IImageOperations BlackWhite(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 14641afba..4d83ba9a2 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -25,10 +25,11 @@ namespace ImageSharp /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness) + public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness) where TPixel : struct, IPixel { - return ColorBlindness(source, colorBlindness, source.Bounds); + source.ApplyProcessor(GetProcessor(colorBlindness)); + return source; } /// @@ -41,48 +42,35 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image ColorBlindness(this Image source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel { - IImageProcessor processor; + source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); + return source; + } + private static IImageProcessor GetProcessor(ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { switch (colorBlindness) { case ImageSharp.Processing.ColorBlindness.Achromatomaly: - processor = new AchromatomalyProcessor(); - break; - + return new AchromatomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Achromatopsia: - processor = new AchromatopsiaProcessor(); - break; - + return new AchromatopsiaProcessor(); case ImageSharp.Processing.ColorBlindness.Deuteranomaly: - processor = new DeuteranomalyProcessor(); - break; - + return new DeuteranomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Deuteranopia: - processor = new DeuteranopiaProcessor(); - break; - + return new DeuteranopiaProcessor(); case ImageSharp.Processing.ColorBlindness.Protanomaly: - processor = new ProtanomalyProcessor(); - break; - + return new ProtanomalyProcessor(); case ImageSharp.Processing.ColorBlindness.Protanopia: - processor = new ProtanopiaProcessor(); - break; - + return new ProtanopiaProcessor(); case ImageSharp.Processing.ColorBlindness.Tritanomaly: - processor = new TritanomalyProcessor(); - break; - + return new TritanomalyProcessor(); default: - processor = new TritanopiaProcessor(); - break; + return new TritanopiaProcessor(); } - - source.ApplyProcessor(processor, rectangle); - return source; } } } diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 635b6747a..6cdc3343d 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Grayscale(this Image source) + public static IImageOperations Grayscale(this IImageOperations source) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709); @@ -35,10 +35,15 @@ namespace ImageSharp /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode) + public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode) where TPixel : struct, IPixel { - return Grayscale(source, mode, source.Bounds); + IImageProcessor processor = mode == GrayscaleMode.Bt709 + ? (IImageProcessor)new GrayscaleBt709Processor() + : new GrayscaleBt601Processor(); + + source.ApplyProcessor(processor); + return source; } /// @@ -50,13 +55,10 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Grayscale(this Image source, Rectangle rectangle) + public static IImageOperations Grayscale(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { - IImageProcessor processor = new GrayscaleBt709Processor(); - - source.ApplyProcessor(processor, rectangle); - return source; + return Grayscale(source, GrayscaleMode.Bt709, rectangle); } /// @@ -69,7 +71,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Grayscale(this Image source, GrayscaleMode mode, Rectangle rectangle) + public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index d218b3a10..86a533621 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -25,10 +25,11 @@ namespace ImageSharp /// The image this method extends. /// The angle in degrees to adjust the image. /// The . - public static Image Hue(this Image source, float degrees) + public static IImageOperations Hue(this IImageOperations source, float degrees) where TPixel : struct, IPixel { - return Hue(source, degrees, source.Bounds); + source.ApplyProcessor(new HueProcessor(degrees)); + return source; } /// @@ -41,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Hue(this Image source, float degrees, Rectangle rectangle) + public static IImageOperations Hue(this IImageOperations source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index 09eb13190..2f331d647 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -24,10 +24,11 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Kodachrome(this Image source) + public static IImageOperations Kodachrome(this IImageOperations source) where TPixel : struct, IPixel { - return Kodachrome(source, source.Bounds); + source.ApplyProcessor(new KodachromeProcessor()); + return source; } /// @@ -39,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Kodachrome(this Image source, Rectangle rectangle) + public static IImageOperations Kodachrome(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index bca4577e4..e2c8f3674 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -24,10 +24,10 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Lomograph(this Image source) + public static IImageOperations Lomograph(this IImageOperations source) where TPixel : struct, IPixel { - return Lomograph(source, source.Bounds, GraphicsOptions.Default); + return Lomograph(source, GraphicsOptions.Default); } /// @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Lomograph(this Image source, Rectangle rectangle) + public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { return Lomograph(source, rectangle, GraphicsOptions.Default); @@ -52,10 +52,11 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Lomograph(this Image source, GraphicsOptions options) + public static IImageOperations Lomograph(this IImageOperations source, GraphicsOptions options) where TPixel : struct, IPixel { - return Lomograph(source, source.Bounds, options); + source.ApplyProcessor(new LomographProcessor(options)); + return source; } /// @@ -68,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static Image Lomograph(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index b2d8515d6..bfbf6477b 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Polaroid(this Image source) + public static IImageOperations Polaroid(this IImageOperations source) where TPixel : struct, IPixel { return Polaroid(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Polaroid(this Image source, Rectangle rectangle) + public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { return Polaroid(source, rectangle, GraphicsOptions.Default); @@ -52,10 +52,11 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Polaroid(this Image source, GraphicsOptions options) + public static IImageOperations Polaroid(this IImageOperations source, GraphicsOptions options) where TPixel : struct, IPixel { - return Polaroid(source, source.Bounds, options); + source.ApplyProcessor(new PolaroidProcessor(options)); + return source; } /// @@ -68,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static Image Polaroid(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 88f3b1529..5a2650527 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -25,10 +25,11 @@ namespace ImageSharp /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// The . - public static Image Saturation(this Image source, int amount) + public static IImageOperations Saturation(this IImageOperations source, int amount) where TPixel : struct, IPixel { - return Saturation(source, amount, source.Bounds); + source.ApplyProcessor(new SaturationProcessor(amount)); + return source; } /// @@ -41,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Saturation(this Image source, int amount, Rectangle rectangle) + public static IImageOperations Saturation(this IImageOperations source, int amount, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index 000c0ffba..f4dbb26c1 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Sepia(this Image source) + public static IImageOperations Sepia(this IImageOperations source) where TPixel : struct, IPixel - { - return Sepia(source, source.Bounds); - } + => source.ApplyProcessor(new SepiaProcessor()); /// /// Applies sepia toning to the image. @@ -39,11 +37,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Sepia(this Image source, Rectangle rectangle) + public static IImageOperations Sepia(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new SepiaProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new SepiaProcessor(), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index ad5e477dc..f000a6aa4 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// The . - public static Image BoxBlur(this Image source, int radius = 7) + public static IImageOperations BoxBlur(this IImageOperations source, int radius = 7) where TPixel : struct, IPixel - { - return BoxBlur(source, radius, source.Bounds); - } + => source.ApplyProcessor(new BoxBlurProcessor(radius)); /// /// Applies a box blur to the image. @@ -40,11 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BoxBlur(this Image source, int radius, Rectangle rectangle) + public static IImageOperations BoxBlur(this IImageOperations source, int radius, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); - return source; - } + => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index 1cc8b693f..14bcf2059 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -25,10 +25,10 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image DetectEdges(this Image source) + public static IImageOperations DetectEdges(this IImageOperations source) where TPixel : struct, IPixel { - return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true }); + return DetectEdges(source, new SobelProcessor { Grayscale = true }); } /// @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle) + public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); @@ -55,11 +55,9 @@ namespace ImageSharp /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true) + public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, bool grayscale = true) where TPixel : struct, IPixel - { - return DetectEdges(source, filter, source.Bounds, grayscale); - } + => DetectEdges(source, GetProcessor(filter, grayscale)); /// /// Detects any edges within the image. @@ -72,7 +70,41 @@ namespace ImageSharp /// /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + where TPixel : struct, IPixel + => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); + + /// + /// Detects any edges within the image. + /// + /// The pixel format. + /// The image this method extends. + /// The filter for detecting edges. + /// The . + public static IImageOperations DetectEdges(this IImageOperations source, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel + { + return source.ApplyProcessor(filter); + } + + /// + /// Detects any edges within the image. + /// + /// The pixel format. + /// The image this method extends. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The filter for detecting edges. + /// The . + public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle, IEdgeDetectorProcessor filter) + where TPixel : struct, IPixel + { + source.ApplyProcessor(filter, rectangle); + return source; + } + + private static IEdgeDetectorProcessor GetProcessor(EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel { IEdgeDetectorProcessor processor; @@ -120,37 +152,7 @@ namespace ImageSharp break; } - return DetectEdges(source, rectangle, processor); - } - - /// - /// Detects any edges within the image. - /// - /// The pixel format. - /// The image this method extends. - /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, IEdgeDetectorProcessor filter) - where TPixel : struct, IPixel - { - return DetectEdges(source, source.Bounds, filter); - } - - /// - /// Detects any edges within the image. - /// - /// The pixel format. - /// The image this method extends. - /// - /// The structure that specifies the portion of the image object to alter. - /// - /// The filter for detecting edges. - /// The . - public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorProcessor filter) - where TPixel : struct, IPixel - { - source.ApplyProcessor(filter, rectangle); - return source; + return processor; } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index f9658fcb5..7d551ceb8 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -25,11 +25,9 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static Image GaussianBlur(this Image source, float sigma = 3f) + public static IImageOperations GaussianBlur(this IImageOperations source, float sigma = 3f) where TPixel : struct, IPixel - { - return GaussianBlur(source, sigma, source.Bounds); - } + => source.ApplyProcessor(new GaussianBlurProcessor(sigma)); /// /// Applies a Gaussian blur to the image. @@ -41,11 +39,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image GaussianBlur(this Image source, float sigma, Rectangle rectangle) + public static IImageOperations GaussianBlur(this IImageOperations source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); - return source; - } + => source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index bb616cc67..58c5ad12a 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -25,11 +25,9 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static Image GaussianSharpen(this Image source, float sigma = 3f) + public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma = 3f) where TPixel : struct, IPixel - { - return GaussianSharpen(source, sigma, source.Bounds); - } + => source.ApplyProcessor(new GaussianSharpenProcessor(sigma)); /// /// Applies a Gaussian sharpening filter to the image. @@ -41,11 +39,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image GaussianSharpen(this Image source, float sigma, Rectangle rectangle) + public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); - return source; - } + => source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); } } diff --git a/src/ImageSharp/Processing/DelegateImageProcessor.cs b/src/ImageSharp/Processing/DelegateImageProcessor.cs new file mode 100644 index 000000000..e1d1060c6 --- /dev/null +++ b/src/ImageSharp/Processing/DelegateImageProcessor.cs @@ -0,0 +1,44 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Processing +{ + using System; + using System.Threading.Tasks; + + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Allows the application of processors to images. + /// + /// The pixel format. + internal class DelegateImageProcessor : ImageProcessor + where TPixel : struct, IPixel + { + private readonly Action> action; + + /// + /// Initializes a new instance of the class. + /// + /// The action. + public DelegateImageProcessor(Action> action) + { + this.action = action; + } + + /// + protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) + { + this.action?.Invoke((Image)source); + } + + /// + protected override void OnApply(ImageBase source, Rectangle sourceRectangle) + { + // no op, we did all we wanted to do inside BeforeImageApply + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index a0d218651..4978caf86 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The new opacity of the image. Must be between 0 and 1. /// The . - public static Image Alpha(this Image source, float percent) + public static IImageOperations Alpha(this IImageOperations source, float percent) where TPixel : struct, IPixel - { - return Alpha(source, percent, source.Bounds); - } + => source.ApplyProcessor(new AlphaProcessor(percent)); /// /// Alters the alpha component of the image. @@ -40,11 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Alpha(this Image source, float percent, Rectangle rectangle) + public static IImageOperations Alpha(this IImageOperations source, float percent, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new AlphaProcessor(percent), rectangle); - return source; - } + => source.ApplyProcessor(new AlphaProcessor(percent), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index a1e04c8a3..276bfa2a7 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -25,11 +25,9 @@ namespace ImageSharp /// The color to set as the background. /// The options effecting pixel blending. /// The . - public static Image BackgroundColor(this Image source, TPixel color, GraphicsOptions options) + public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return BackgroundColor(source, color, source.Bounds, options); - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); /// /// Replaces the background color of image with the given one. @@ -42,12 +40,9 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); - return source; - } + => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); /// /// Replaces the background color of image with the given one. @@ -56,7 +51,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the background. /// The . - public static Image BackgroundColor(this Image source, TPixel color) + public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color) where TPixel : struct, IPixel { return BackgroundColor(source, color, GraphicsOptions.Default); @@ -72,7 +67,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image BackgroundColor(this Image source, TPixel color, Rectangle rectangle) + public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 165f897b8..9bc27e75d 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// The . - public static Image Brightness(this Image source, int amount) + public static IImageOperations Brightness(this IImageOperations source, int amount) where TPixel : struct, IPixel - { - return Brightness(source, amount, source.Bounds); - } + => source.ApplyProcessor(new BrightnessProcessor(amount)); /// /// Alters the brightness component of the image. @@ -40,11 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Brightness(this Image source, int amount, Rectangle rectangle) + public static IImageOperations Brightness(this IImageOperations source, int amount, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); - return source; - } + => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index 0a55fd067..52eb0d5ec 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// The . - public static Image Contrast(this Image source, int amount) + public static IImageOperations Contrast(this IImageOperations source, int amount) where TPixel : struct, IPixel - { - return Contrast(source, amount, source.Bounds); - } + => source.ApplyProcessor(new ContrastProcessor(amount)); /// /// Alters the contrast component of the image. @@ -40,11 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Contrast(this Image source, int amount, Rectangle rectangle) + public static IImageOperations Contrast(this IImageOperations source, int amount, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new ContrastProcessor(amount), rectangle); - return source; - } + => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index d9a069556..4f8c6a886 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -23,11 +23,9 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Invert(this Image source) + public static IImageOperations Invert(this IImageOperations source) where TPixel : struct, IPixel - { - return Invert(source, source.Bounds); - } + => source.ApplyProcessor(new InvertProcessor()); /// /// Inverts the colors of the image. @@ -38,11 +36,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Invert(this Image source, Rectangle rectangle) + public static IImageOperations Invert(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel - { - source.ApplyProcessor(new InvertProcessor(), rectangle); - return source; - } + => source.ApplyProcessor(new InvertProcessor(), rectangle); } } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index 3b300e919..23d552885 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image OilPaint(this Image source) + public static IImageOperations OilPaint(this IImageOperations source) where TPixel : struct, IPixel { return OilPaint(source, 10, 15); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image OilPaint(this Image source, Rectangle rectangle) + public static IImageOperations OilPaint(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { return OilPaint(source, 10, 15, rectangle); @@ -54,11 +54,9 @@ namespace ImageSharp /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static Image OilPaint(this Image source, int levels, int brushSize) - where TPixel : struct, IPixel - { - return OilPaint(source, levels, brushSize, source.Bounds); - } + public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize) + where TPixel : struct, IPixel + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); /// /// Alters the colors of the image recreating an oil painting effect. @@ -71,18 +69,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image OilPaint(this Image source, int levels, int brushSize, Rectangle rectangle) + public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel - { - Guard.MustBeGreaterThan(levels, 0, nameof(levels)); - - if (brushSize <= 0 || brushSize > source.Height || brushSize > source.Width) - { - throw new ArgumentOutOfRangeException(nameof(brushSize)); - } - - source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); - return source; - } + => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index 07fdd50a3..cd0551ad3 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -24,11 +24,9 @@ namespace ImageSharp /// The image this method extends. /// The size of the pixels. /// The . - public static Image Pixelate(this Image source, int size = 4) + public static IImageOperations Pixelate(this IImageOperations source, int size = 4) where TPixel : struct, IPixel - { - return Pixelate(source, size, source.Bounds); - } + => source.ApplyProcessor(new PixelateProcessor(size)); /// /// Pixelates an image with the given pixel size. @@ -40,16 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Pixelate(this Image source, int size, Rectangle rectangle) + public static IImageOperations Pixelate(this IImageOperations source, int size, Rectangle rectangle) where TPixel : struct, IPixel - { - if (size <= 0 || size > source.Height || size > source.Width) - { - throw new ArgumentOutOfRangeException(nameof(size)); - } - - source.ApplyProcessor(new PixelateProcessor(size), rectangle); - return source; - } + => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/ImageProcessor.cs b/src/ImageSharp/Processing/ImageProcessor.cs index dd2a93bc5..bf88d5ff7 100644 --- a/src/ImageSharp/Processing/ImageProcessor.cs +++ b/src/ImageSharp/Processing/ImageProcessor.cs @@ -25,7 +25,7 @@ namespace ImageSharp.Processing public virtual bool Compand { get; set; } = false; /// - public void Apply(ImageBase source, Rectangle sourceRectangle) + public void Apply(Image source, Rectangle sourceRectangle) { if (this.ParallelOptions == null) { @@ -34,10 +34,50 @@ namespace ImageSharp.Processing try { - this.BeforeApply(source, sourceRectangle); + this.BeforeImageApply(source, sourceRectangle); + this.BeforeApply(source, sourceRectangle); this.OnApply(source, sourceRectangle); + this.AfterApply(source, sourceRectangle); + + foreach (ImageFrame sourceFrame in source.Frames) + { + this.BeforeApply(source, sourceRectangle); + + this.OnApply(source, sourceRectangle); + this.AfterApply(source, sourceRectangle); + } + + this.AfterImageApply(source, sourceRectangle); + } +#if DEBUG + catch (Exception) + { + throw; +#else + catch (Exception ex) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); +#endif + } + } + + /// + /// Applies the processor to just a single ImageBase + /// + /// the source image + /// the target + public void Apply(ImageBase source, Rectangle sourceRectangle) + { + if (this.ParallelOptions == null) + { + this.ParallelOptions = source.Configuration.ParallelOptions; + } + try + { + this.BeforeApply(source, sourceRectangle); + this.OnApply(source, sourceRectangle); this.AfterApply(source, sourceRectangle); } #if DEBUG @@ -52,6 +92,17 @@ namespace ImageSharp.Processing } } + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeImageApply(Image source, Rectangle sourceRectangle) + { + } + /// /// This method is called before the process is applied to prepare the processor. /// @@ -83,5 +134,16 @@ namespace ImageSharp.Processing protected virtual void AfterApply(ImageBase source, Rectangle sourceRectangle) { } + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterImageApply(Image source, Rectangle sourceRectangle) + { + } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index 84f6bf10a..4c58a27d4 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Glow(this Image source) + public static IImageOperations Glow(this IImageOperations source) where TPixel : struct, IPixel { return Glow(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the glow. /// The . - public static Image Glow(this Image source, TPixel color) + public static IImageOperations Glow(this IImageOperations source, TPixel color) where TPixel : struct, IPixel { return Glow(source, color, GraphicsOptions.Default); @@ -47,7 +47,7 @@ namespace ImageSharp /// The image this method extends. /// The the radius. /// The . - public static Image Glow(this Image source, float radius) + public static IImageOperations Glow(this IImageOperations source, float radius) where TPixel : struct, IPixel { return Glow(source, radius, GraphicsOptions.Default); @@ -62,11 +62,9 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Glow(this Image source, Rectangle rectangle) + public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel - { - return Glow(source, rectangle, GraphicsOptions.Default); - } + => source.Glow(rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -79,11 +77,9 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Glow(this Image source, TPixel color, float radius, Rectangle rectangle) + public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel - { - return Glow(source, color, radius, rectangle, GraphicsOptions.Default); - } + => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); /// /// Applies a radial glow effect to an image. @@ -92,11 +88,9 @@ namespace ImageSharp /// The image this method extends. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, GraphicsOptions options) + public static IImageOperations Glow(this IImageOperations source, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds, options); - } + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -106,11 +100,9 @@ namespace ImageSharp /// The color to set as the glow. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, TPixel color, GraphicsOptions options) + public static IImageOperations Glow(this IImageOperations source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, color, source.Bounds.Width * .5F, source.Bounds, options); - } + => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); /// /// Applies a radial glow effect to an image. @@ -120,11 +112,9 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, float radius, GraphicsOptions options) + public static IImageOperations Glow(this IImageOperations source, float radius, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, radius, source.Bounds, options); - } + => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); /// /// Applies a radial glow effect to an image. @@ -136,11 +126,9 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - return Glow(source, NamedColors.Black, 0, rectangle, options); - } + => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); /// /// Applies a radial glow effect to an image. @@ -154,12 +142,37 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static Image Glow(this Image source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - var processor = new GlowProcessor(color, options) { Radius = radius, }; - source.ApplyProcessor(processor, rectangle); - return source; - } + => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); + + /// + /// Applies a radial glow effect to an image. + /// + /// The pixel format. + /// The image this method extends. + /// The color to set as the glow. + /// The the radius. + /// + /// The structure that specifies the portion of the image object to alter. + /// + /// The options effecting things like blending. + /// The . + private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); + + /// + /// Applies a radial glow effect to an image. + /// + /// The pixel format. + /// The image this method extends. + /// The color to set as the glow. + /// The the radius. + /// The options effecting things like blending. + /// The . + private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 75c4611a1..78060570c 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static Image Vignette(this Image source) + public static IImageOperations Vignette(this IImageOperations source) where TPixel : struct, IPixel { return Vignette(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the vignette. /// The . - public static Image Vignette(this Image source, TPixel color) + public static IImageOperations Vignette(this IImageOperations source, TPixel color) where TPixel : struct, IPixel { return Vignette(source, color, GraphicsOptions.Default); @@ -48,7 +48,7 @@ namespace ImageSharp /// The the x-radius. /// The the y-radius. /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY) + public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY) where TPixel : struct, IPixel { return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); @@ -63,7 +63,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Vignette(this Image source, Rectangle rectangle) + public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle) where TPixel : struct, IPixel { return Vignette(source, rectangle, GraphicsOptions.Default); @@ -81,11 +81,9 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static Image Vignette(this Image source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel - { - return Vignette(source, color, radiusX, radiusY, rectangle, GraphicsOptions.Default); - } + => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); /// /// Applies a radial vignette effect to an image. @@ -94,11 +92,9 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, GraphicsOptions options) + public static IImageOperations Vignette(this IImageOperations source, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, options); - } + => source.Vignette(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -108,11 +104,9 @@ namespace ImageSharp /// The color to set as the vignette. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, TPixel color, GraphicsOptions options) + public static IImageOperations Vignette(this IImageOperations source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, color, source.Bounds.Width * .5F, source.Bounds.Height * .5F, source.Bounds, options); - } + => source.Vignette(color, 0, 0, options); /// /// Applies a radial vignette effect to an image. @@ -123,11 +117,9 @@ namespace ImageSharp /// The the y-radius. /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, radiusX, radiusY, source.Bounds, options); - } + => source.Vignette(NamedColors.Black, radiusX, radiusY, options); /// /// Applies a radial vignette effect to an image. @@ -139,11 +131,9 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - return Vignette(source, NamedColors.Black, 0, 0, rectangle, options); - } + => source.Vignette(NamedColors.Black, 0, 0, rectangle, options); /// /// Applies a radial vignette effect to an image. @@ -158,12 +148,16 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static Image Vignette(this Image source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - { - var processor = new VignetteProcessor(color, options) { RadiusX = radiusX, RadiusY = radiusY }; - source.ApplyProcessor(processor, rectangle); - return source; - } + => source.Vignette(color, radiusX, radiusY, rectangle, options); + + private static IImageOperations Vignette(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); + + private static IImageOperations Vignette(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + where TPixel : struct, IPixel + => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs index 9e54574df..5c1bd20b1 100644 --- a/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs +++ b/src/ImageSharp/Processing/Processors/ColorMatrix/PolaroidProcessor.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Processing.Processors protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) { new VignetteProcessor(veryDarkOrange, this.options).Apply(source, sourceRectangle); - new GlowProcessor(lightOrange, this.options) { Radius = source.Width / 4F }.Apply(source, sourceRectangle); + new GlowProcessor(lightOrange, source.Width / 4F, this.options).Apply(source, sourceRectangle); } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs index f484c8eec..383917c45 100644 --- a/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/OilPaintingProcessor.cs @@ -51,6 +51,11 @@ namespace ImageSharp.Processing.Processors /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { + if (this.BrushSize <= 0 || this.BrushSize > source.Height || this.BrushSize > source.Width) + { + throw new ArgumentOutOfRangeException(nameof(this.BrushSize)); + } + int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; diff --git a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs index ff83117c5..a44e85ef3 100644 --- a/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Effects/PixelateProcessor.cs @@ -29,23 +29,28 @@ namespace ImageSharp.Processing.Processors public PixelateProcessor(int size) { Guard.MustBeGreaterThan(size, 0, nameof(size)); - this.Value = size; + this.Size = size; } /// /// Gets or the pixel size. /// - public int Value { get; } + public int Size { get; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { + if (this.Size <= 0 || this.Size > source.Height || this.Size > source.Width) + { + throw new ArgumentOutOfRangeException(nameof(this.Size)); + } + int startY = sourceRectangle.Y; int endY = sourceRectangle.Bottom; int startX = sourceRectangle.X; int endX = sourceRectangle.Right; - int size = this.Value; - int offset = this.Value / 2; + int size = this.Size; + int offset = this.Size / 2; // Align start/end positions. int minX = Math.Max(0, startX); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 8a13eabca..5a816da14 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -27,11 +27,13 @@ namespace ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// The color or the glow. + /// The radius of the glow. /// The options effecting blending and composition. - public GlowProcessor(TPixel color, GraphicsOptions options) + public GlowProcessor(TPixel color, ValueSize radius, GraphicsOptions options) { this.options = options; this.GlowColor = color; + this.Radius = radius; this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); } @@ -43,7 +45,7 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the the radius. /// - public float Radius { get; set; } + public ValueSize Radius { get; set; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) @@ -54,7 +56,10 @@ namespace ImageSharp.Processing.Processors int endX = sourceRectangle.Right; TPixel glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle); - float maxDistance = this.Radius > 0 ? MathF.Min(this.Radius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; + + var finalRadius = this.Radius.Calculate(source.Bounds.Size); + + float maxDistance = finalRadius > 0 ? MathF.Min(finalRadius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; // Align start/end positions. int minX = Math.Max(0, startX); diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 8cb58739b..6a46692d2 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -27,11 +27,26 @@ namespace ImageSharp.Processing.Processors /// Initializes a new instance of the class. /// /// The color of the vignette. + /// The x-radius. + /// The y-radius. /// The options effecting blending and composition. - public VignetteProcessor(TPixel color, GraphicsOptions options) + public VignetteProcessor(TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) { this.VignetteColor = color; + this.RadiusX = radiusX; + this.RadiusY = radiusY; + this.options = options; + this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); + } + /// + /// Initializes a new instance of the class. + /// + /// The color of the vignette. + /// The options effecting blending and composition. + public VignetteProcessor(TPixel color, GraphicsOptions options) + { + this.VignetteColor = color; this.options = options; this.blender = PixelOperations.Instance.GetPixelBlender(this.options.BlenderMode); } @@ -44,12 +59,12 @@ namespace ImageSharp.Processing.Processors /// /// Gets or sets the the x-radius. /// - public float RadiusX { get; set; } + public ValueSize RadiusX { get; set; } /// /// Gets or sets the the y-radius. /// - public float RadiusY { get; set; } + public ValueSize RadiusY { get; set; } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) @@ -60,8 +75,11 @@ namespace ImageSharp.Processing.Processors int endX = sourceRectangle.Right; TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle); - float rX = this.RadiusX > 0 ? MathF.Min(this.RadiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; - float rY = this.RadiusY > 0 ? MathF.Min(this.RadiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; + + var finalradiusX = this.RadiusX.Calculate(source.Bounds.Size); + var finalradiusY = this.RadiusY.Calculate(source.Bounds.Size); + float rX = finalradiusX > 0 ? MathF.Min(finalradiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; + float rY = finalradiusY > 0 ? MathF.Min(finalradiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; float maxDistance = MathF.Sqrt((rX * rX) + (rY * rY)); // Align start/end positions. diff --git a/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs new file mode 100644 index 000000000..f18eb8092 --- /dev/null +++ b/src/ImageSharp/Processing/Processors/Transforms/AutoRotateProcessor.cs @@ -0,0 +1,103 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Processing.Processors +{ + using System; + using System.Threading.Tasks; + + using ImageSharp.Memory; + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Adjusts an image so that its orientation is suitable for viewing. Adjustments are based on EXIF metadata embedded in the image. + /// + /// The pixel format. + internal class AutoRotateProcessor : ImageProcessor + where TPixel : struct, IPixel + { + /// + /// Initializes a new instance of the class. + /// + public AutoRotateProcessor() + { + } + + /// + protected override void OnApply(ImageBase sourceBase, Rectangle sourceRectangle) + { + // can only apply to the origional image + var source = sourceBase as Image; + if (source != null) + { + Orientation orientation = GetExifOrientation(source); + + switch (orientation) + { + case Orientation.TopRight: + new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + break; + + case Orientation.BottomRight: + new RotateProcessor() { Angle = (int)RotateType.Rotate180, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.BottomLeft: + new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); + break; + + case Orientation.LeftTop: + new RotateProcessor() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle); + new FlipProcessor(FlipType.Horizontal).Apply(source, sourceRectangle); + break; + + case Orientation.RightTop: + new RotateProcessor() { Angle = (int)RotateType.Rotate90, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.RightBottom: + new FlipProcessor(FlipType.Vertical).Apply(source, sourceRectangle); + new RotateProcessor() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.LeftBottom: + new RotateProcessor() { Angle = (int)RotateType.Rotate270, Expand = false }.Apply(source, sourceRectangle); + break; + + case Orientation.Unknown: + case Orientation.TopLeft: + default: + break; + } + } + } + + /// + /// Returns the current EXIF orientation + /// + /// The image to auto rotate. + /// The + private static Orientation GetExifOrientation(Image source) + { + if (source.MetaData.ExifProfile == null) + { + return Orientation.Unknown; + } + + ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); + if (value == null) + { + return Orientation.Unknown; + } + + var orientation = (Orientation)value.Value; + + source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); + + return orientation; + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 0186a8fa8..0f1e166fd 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -46,19 +46,19 @@ namespace ImageSharp.Processing.Processors public IResampler Sampler { get; } /// - /// Gets the width. + /// Gets or sets the width. /// - public int Width { get; } + public int Width { get; protected set; } /// - /// Gets the height. + /// Gets or sets the height. /// - public int Height { get; } + public int Height { get; protected set; } /// - /// Gets the resize rectangle. + /// Gets or sets the resize rectangle. /// - public Rectangle ResizeRectangle { get; } + public Rectangle ResizeRectangle { get; protected set; } /// /// Gets or sets the horizontal weights. diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index 07e5d5bc9..fb7bfb4ac 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -20,68 +20,8 @@ namespace ImageSharp /// The pixel format. /// The image to auto rotate. /// The - public static Image AutoOrient(this Image source) + public static IImageOperations AutoOrient(this IImageOperations source) where TPixel : struct, IPixel - { - Orientation orientation = GetExifOrientation(source); - - switch (orientation) - { - case Orientation.TopRight: - return source.Flip(FlipType.Horizontal); - - case Orientation.BottomRight: - return source.Rotate(RotateType.Rotate180); - - case Orientation.BottomLeft: - return source.Flip(FlipType.Vertical); - - case Orientation.LeftTop: - return source.Rotate(RotateType.Rotate90) - .Flip(FlipType.Horizontal); - - case Orientation.RightTop: - return source.Rotate(RotateType.Rotate90); - - case Orientation.RightBottom: - return source.Flip(FlipType.Vertical) - .Rotate(RotateType.Rotate270); - - case Orientation.LeftBottom: - return source.Rotate(RotateType.Rotate270); - - case Orientation.Unknown: - case Orientation.TopLeft: - default: - return source; - } - } - - /// - /// Returns the current EXIF orientation - /// - /// The pixel format. - /// The image to auto rotate. - /// The - private static Orientation GetExifOrientation(Image source) - where TPixel : struct, IPixel - { - if (source.MetaData.ExifProfile == null) - { - return Orientation.Unknown; - } - - ExifValue value = source.MetaData.ExifProfile.GetValue(ExifTag.Orientation); - if (value == null) - { - return Orientation.Unknown; - } - - var orientation = (Orientation)value.Value; - - source.MetaData.ExifProfile.SetValue(ExifTag.Orientation, (ushort)Orientation.TopLeft); - - return orientation; - } + => source.ApplyProcessor(new Processing.Processors.AutoRotateProcessor()); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index 94e9ba1f4..c518ac5ac 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -25,11 +25,9 @@ namespace ImageSharp /// The target image width. /// The target image height. /// The - public static Image Crop(this Image source, int width, int height) + public static IImageOperations Crop(this IImageOperations source, int width, int height) where TPixel : struct, IPixel - { - return Crop(source, new Rectangle(0, 0, width, height)); - } + => Crop(source, new Rectangle(0, 0, width, height)); /// /// Crops an image to the given rectangle. @@ -40,13 +38,8 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to retain. /// /// The - public static Image Crop(this Image source, Rectangle cropRectangle) + public static IImageOperations Crop(this IImageOperations source, Rectangle cropRectangle) where TPixel : struct, IPixel - { - CropProcessor processor = new CropProcessor(cropRectangle); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new CropProcessor(cropRectangle)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index 2f4a8e383..00f404321 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -23,13 +23,8 @@ namespace ImageSharp /// The image to crop. /// The threshold for entropic density. /// The - public static Image EntropyCrop(this Image source, float threshold = .5f) + public static IImageOperations EntropyCrop(this IImageOperations source, float threshold = .5f) where TPixel : struct, IPixel - { - EntropyCropProcessor processor = new EntropyCropProcessor(threshold); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new EntropyCropProcessor(threshold)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 1c8baebf1..6cde1257c 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -24,13 +24,8 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static Image Flip(this Image source, FlipType flipType) + public static IImageOperations Flip(this IImageOperations source, FlipType flipType) where TPixel : struct, IPixel - { - FlipProcessor processor = new FlipProcessor(flipType); - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new FlipProcessor(flipType)); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index 8138fd765..fb064f5ce 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// The new width. /// The new height. /// The . - public static Image Pad(this Image source, int width, int height) + public static IImageOperations Pad(this IImageOperations source, int width, int height) where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index e00faf10e..6ccea5f42 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -24,23 +24,28 @@ namespace ImageSharp /// The resize options. /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, ResizeOptions options) + public static IImageOperations Resize(this IImageOperations source, ResizeOptions options) where TPixel : struct, IPixel { - // Ensure size is populated across both dimensions. - if (options.Size.Width == 0 && options.Size.Height > 0) + return source.Run(img => { - options.Size = new Size((int)MathF.Round(source.Width * options.Size.Height / (float)source.Height), options.Size.Height); - } + // cheat and bound through a run, inside here we should just be mutating, this reallt needs moving over to a processor - if (options.Size.Height == 0 && options.Size.Width > 0) - { - options.Size = new Size(options.Size.Width, (int)MathF.Round(source.Height * options.Size.Width / (float)source.Width)); - } + // Ensure size is populated across both dimensions. + if (options.Size.Width == 0 && options.Size.Height > 0) + { + options.Size = new Size((int)MathF.Round(img.Width * options.Size.Height / (float)img.Height), options.Size.Height); + } + + if (options.Size.Height == 0 && options.Size.Width > 0) + { + options.Size = new Size(options.Size.Width, (int)MathF.Round(img.Height * options.Size.Width / (float)img.Width)); + } - Rectangle targetRectangle = ResizeHelper.CalculateTargetLocationAndBounds(source, options); + Rectangle targetRectangle = ResizeHelper.CalculateTargetLocationAndBounds(img, options); - return Resize(source, options.Size.Width, options.Size.Height, options.Sampler, source.Bounds, targetRectangle, options.Compand); + img.Mutate(x => Resize(x, options.Size.Width, options.Size.Height, options.Sampler, targetRectangle, options.Compand)); + }); } /// @@ -51,7 +56,7 @@ namespace ImageSharp /// The target image size. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, Size size) + public static IImageOperations Resize(this IImageOperations source, Size size) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); @@ -66,7 +71,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, Size size, bool compand) + public static IImageOperations Resize(this IImageOperations source, Size size, bool compand) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), compand); @@ -81,7 +86,7 @@ namespace ImageSharp /// The target image height. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height) + public static IImageOperations Resize(this IImageOperations source, int width, int height) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); @@ -97,7 +102,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, bool compand) + public static IImageOperations Resize(this IImageOperations source, int width, int height, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); @@ -113,7 +118,7 @@ namespace ImageSharp /// The to perform the resampling. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler) + public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); @@ -130,10 +135,10 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, bool compand) + public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel { - return Resize(source, width, height, sampler, source.Bounds, new Rectangle(0, 0, width, height), compand); + return Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); } /// @@ -154,28 +159,69 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static Image Resize(this Image source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) + public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { - if (width == 0 && height > 0) - { - width = (int)MathF.Round(source.Width * height / (float)source.Height); - targetRectangle.Width = width; - } + return source.Run(img => + { + // todo : stop cheeting here and move this stuff into the processors itself + if (width == 0 && height > 0) + { + width = (int)MathF.Round(img.Width * height / (float)img.Height); + targetRectangle.Width = width; + } + + if (height == 0 && width > 0) + { + height = (int)MathF.Round(img.Height * width / (float)img.Width); + targetRectangle.Height = height; + } + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); + }); + } - if (height == 0 && width > 0) + /// + /// Resizes an image to the given width and height with the given sampler and + /// source rectangle. + /// + /// The pixel format. + /// The image to resize. + /// The target image width. + /// The target image height. + /// The to perform the resampling. + /// + /// The structure that specifies the portion of the target image object to draw to. + /// + /// Whether to compress and expand the image color-space to gamma correct the image during processing. + /// The + /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image + public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) + where TPixel : struct, IPixel + { + return source.Run(img => { - height = (int)MathF.Round(source.Height * width / (float)source.Width); - targetRectangle.Height = height; - } - - Guard.MustBeGreaterThan(width, 0, nameof(width)); - Guard.MustBeGreaterThan(height, 0, nameof(height)); - - var processor = new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }; - - source.ApplyProcessor(processor, sourceRectangle); - return source; + // todo : stop cheeting here and move this stuff into the processors itself + if (width == 0 && height > 0) + { + width = (int)MathF.Round(img.Width * height / (float)img.Height); + targetRectangle.Width = width; + } + + if (height == 0 && width > 0) + { + height = (int)MathF.Round(img.Height * width / (float)img.Width); + targetRectangle.Height = height; + } + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand })); + }); } } } diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index af7c06a27..92349dba3 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static Image Rotate(this Image source, float degrees) + public static IImageOperations Rotate(this IImageOperations source, float degrees) where TPixel : struct, IPixel { return Rotate(source, degrees, true); @@ -37,11 +37,9 @@ namespace ImageSharp /// The image to rotate. /// The to perform the rotation. /// The - public static Image Rotate(this Image source, RotateType rotateType) + public static IImageOperations Rotate(this IImageOperations source, RotateType rotateType) where TPixel : struct, IPixel - { - return Rotate(source, (float)rotateType, false); - } + => Rotate(source, (float)rotateType, false); /// /// Rotates an image by the given angle in degrees. @@ -51,13 +49,8 @@ namespace ImageSharp /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static Image Rotate(this Image source, float degrees, bool expand) + public static IImageOperations Rotate(this IImageOperations source, float degrees, bool expand) where TPixel : struct, IPixel - { - RotateProcessor processor = new RotateProcessor { Angle = degrees, Expand = expand }; - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new RotateProcessor { Angle = degrees, Expand = expand }); } } diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index 805deb8d1..fda11d833 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The to perform the rotation. /// The to perform the flip. /// The - public static Image RotateFlip(this Image source, RotateType rotateType, FlipType flipType) + public static IImageOperations RotateFlip(this IImageOperations source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index d42d79225..f38606eda 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static Image Skew(this Image source, float degreesX, float degreesY) + public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY) where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); @@ -39,13 +39,8 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static Image Skew(this Image source, float degreesX, float degreesY, bool expand) + public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel - { - SkewProcessor processor = new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }; - - source.ApplyProcessor(processor, source.Bounds); - return source; - } + => source.ApplyProcessor(new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }); } } diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index a23509278..2b5130f8c 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static Image Quantize(this Image source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageOperations Quantize(this IImageOperations source, Quantization mode = Quantization.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; @@ -54,31 +54,34 @@ namespace ImageSharp /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . - public static Image Quantize(this Image source, IQuantizer quantizer, int maxColors) + public static IImageOperations Quantize(this IImageOperations source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { - QuantizedImage quantized = quantizer.Quantize(source, maxColors); - int palleteCount = quantized.Palette.Length - 1; - - using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) + return source.Run(img => { - Parallel.For( - 0, - pixels.Height, - source.Configuration.ParallelOptions, - y => - { - for (int x = 0; x < pixels.Width; x++) + // TODO : move helper logic into the processor + QuantizedImage quantized = quantizer.Quantize(img, maxColors); + int palleteCount = quantized.Palette.Length - 1; + + using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) + { + Parallel.For( + 0, + pixels.Height, + img.Configuration.ParallelOptions, + y => { - int i = x + (y * pixels.Width); - TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; - pixels[x, y] = color; - } - }); + for (int x = 0; x < pixels.Width; x++) + { + int i = x + (y * pixels.Width); + TPixel color = quantized.Palette[Math.Min(palleteCount, quantized.Pixels[i])]; + pixels[x, y] = color; + } + }); - source.SwapPixelsBuffers(pixels); - return source; - } + img.SwapPixelsBuffers(pixels); + } + }); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs index 66104944e..0a5750fe9 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs @@ -47,7 +47,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.DrawBeziers( + image.Mutate(x => x.DrawBeziers( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { @@ -55,7 +55,7 @@ namespace ImageSharp.Benchmarks new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 500) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs index a6af5a976..3a3b5f30d 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs @@ -45,14 +45,14 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.DrawLines( + image.Mutate(x => x.DrawLines( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs index 3abd3b889..b9a960589 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs @@ -47,14 +47,14 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.DrawPolygon( + image.Mutate(x => x.DrawPolygon( Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs index b7d1b96b7..b0981b94d 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs @@ -55,13 +55,13 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.FillPolygon( + image.Mutate(x => x.FillPolygon( Rgba32.HotPink, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(550, 50), new Vector2(200, 400) - }); + })); using (MemoryStream ms = new MemoryStream()) { @@ -75,9 +75,9 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.Fill( + image.Mutate(x => x.Fill( Rgba32.HotPink, - this.shape); + this.shape)); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index 0738812a1..6219a97f6 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -39,7 +39,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140)); + image.Mutate(x => x.Fill(Rgba32.HotPink, new CoreRectangle(10, 10, 190, 140))); return new CoreSize(image.Width, image.Height); } @@ -50,13 +50,13 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.FillPolygon( + image.Mutate(x => x.FillPolygon( Rgba32.HotPink, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), - new Vector2(10, 150) }); + new Vector2(10, 150) })); return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs index aa97efe00..fec6332d2 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs @@ -40,7 +40,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink)); + image.Mutate(x => x.Fill(CoreBrushes.BackwardDiagonal(Rgba32.HotPink))); using (MemoryStream ms = new MemoryStream()) { diff --git a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs index cb13378a1..ee8fdcf25 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Crop.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Crop.cs @@ -41,7 +41,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.Crop(100, 100); + image.Mutate(x => x.Crop(100, 100)); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs index 1f69030a0..380a0abb0 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/DetectEdges.cs @@ -38,17 +38,17 @@ namespace ImageSharp.Benchmarks [Benchmark(Description = "ImageSharp DetectEdges")] public void ImageProcessorCoreDetectEdges() { - this.image.DetectEdges(EdgeDetection.Kayyali); - this.image.DetectEdges(EdgeDetection.Kayyali); - this.image.DetectEdges(EdgeDetection.Kirsch); - this.image.DetectEdges(EdgeDetection.Lapacian3X3); - this.image.DetectEdges(EdgeDetection.Lapacian5X5); - this.image.DetectEdges(EdgeDetection.LaplacianOfGaussian); - this.image.DetectEdges(EdgeDetection.Prewitt); - this.image.DetectEdges(EdgeDetection.RobertsCross); - this.image.DetectEdges(EdgeDetection.Robinson); - this.image.DetectEdges(EdgeDetection.Scharr); - this.image.DetectEdges(EdgeDetection.Sobel); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kayyali)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Kirsch)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian3X3)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Lapacian5X5)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.LaplacianOfGaussian)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Prewitt)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.RobertsCross)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Robinson)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Scharr)); + this.image.Mutate(x => x.DetectEdges(EdgeDetection.Sobel)); } } } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 2aa8df96c..53cdb1b93 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -26,7 +26,7 @@ namespace ImageSharp.Benchmarks [GlobalSetup] public void Setup() { - this.bulk = new GlowProcessor(NamedColors.Beige, GraphicsOptions.Default) { Radius = 800 * .5f, }; + this.bulk = new GlowProcessor(NamedColors.Beige, 800 * .5f, GraphicsOptions.Default); this.parallel = new GlowProcessorParallel(NamedColors.Beige) { Radius = 800 * .5f, }; } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs index 387340069..db2216770 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Resize.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Resize.cs @@ -41,7 +41,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(2000, 2000)) { - image.Resize(400, 400); + image.Mutate(x => x.Resize(400, 400)); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs index 7ddc2de5a..1b3aeacb1 100644 --- a/tests/ImageSharp.Tests/Drawing/BeziersTests.cs +++ b/tests/ImageSharp.Tests/Drawing/BeziersTests.cs @@ -24,15 +24,15 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "BezierLine"); using (Image image = new Image(500, 500)) { - image.BackgroundColor(Rgba32.Blue) + image.Mutate(x => x.BackgroundColor(Rgba32.Blue) .DrawBeziers(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[] { new Vector2(10, 400), new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -63,7 +63,7 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image.BackgroundColor(Rgba32.Blue) + image.Mutate(x => x.BackgroundColor(Rgba32.Blue) .DrawBeziers(color, 10, new SixLabors.Primitives.PointF[]{ @@ -71,8 +71,8 @@ namespace ImageSharp.Tests.Drawing new Vector2(30, 10), new Vector2(240, 30), new Vector2(300, 400) - }) - .Save($"{path}/Opacity.png"); + })); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs index 40a1cb3d3..e1ff00ca2 100644 --- a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs +++ b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs @@ -27,11 +27,12 @@ namespace ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) - { - BlenderMode = mode - }); + img.Mutate(x=>x + .Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)) + .Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + { + BlenderMode = mode + })); img.DebugSave(provider, new { mode }); } } @@ -45,15 +46,15 @@ namespace ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); - img.Fill(NamedColors.Transparent, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + })); + img.Mutate(x => x.Fill(NamedColors.Transparent, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } @@ -67,20 +68,20 @@ namespace ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY)); - img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x=>x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY))); + img.Mutate(x => x.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); var c = NamedColors.Red.ToVector4(); c.W *= 0.5f; TPixel pixel = default(TPixel); pixel.PackFromVector4(c); - img.Fill(pixel, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x => x.Fill(pixel, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } @@ -96,16 +97,11 @@ namespace ImageSharp.Tests.Drawing { var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); - img.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY)); - //img.Fill(NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true) - //{ - // BlenderMode = mode - //}); - - img.Fill(NamedColors.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) + img.Mutate(x => x.Fill(NamedColors.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY))); + img.Mutate(x => x.Fill(NamedColors.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true) { BlenderMode = mode - }); + })); img.DebugSave(provider, new { mode }); } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 728ed749a..29e3d94fb 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -40,8 +40,8 @@ namespace ImageSharp.Tests using (Image image = provider.GetImage()) using (Image blend = Image.Load(TestFile.Create(TestImages.Bmp.Car).Bytes)) { - image.DrawImage(blend, mode, .75f, new Size(image.Width / 2, image.Height / 2), new Point(image.Width / 4, image.Height / 4)) - .DebugSave(provider, new { mode }); + image.Mutate(x => x.DrawImage(blend, mode, .75f, new Size(image.Width / 2, image.Height / 2), new Point(image.Width / 4, image.Height / 4))); + image.DebugSave(provider, new { mode }); } } } diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index da5028f04..c609aa991 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -34,10 +34,10 @@ namespace ImageSharp.Tests.Drawing ShapePath p = new ShapePath(linerSegemnt, bazierSegment); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, p) - .Save($"{path}/Simple.png"); + .Draw(Rgba32.HotPink, 5, p)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -74,10 +74,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(color, 10, p) - .Save($"{path}/Opacity.png"); + .Draw(color, 10, p)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -101,12 +101,12 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Path"); using (var image = new Image(256, 256)) { - image.Fill(Rgba32.Black); + image.Mutate(x => x.Fill(Rgba32.Black)); var pen = Pens.Solid(Rgba32.White, 5f); for (int i = 0; i < 300; i += 20) { - image.DrawLines(pen, new SixLabors.Primitives.PointF[] { new Vector2(100, 2), new Vector2(-10, i) }); + image.Mutate(x => x.DrawLines(pen, new SixLabors.Primitives.PointF[] { new Vector2(100, 2), new Vector2(-10, i) })); } image diff --git a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs index bbabdf0ea..5dd7c5521 100644 --- a/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillPatternTests.cs @@ -21,9 +21,9 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "PatternBrush"); using (Image image = new Image(20, 20)) { - image + image.Mutate(x => x .Fill(background) - .Fill(brush); + .Fill(brush)); image.Save($"{path}/{name}.png"); @@ -51,7 +51,8 @@ namespace ImageSharp.Tests.Drawing } } } - image.Resize(80, 80).Save($"{path}/{name}x4.png"); + image.Mutate(x => x.Resize(80, 80)); + image.Save($"{path}/{name}x4.png"); } } diff --git a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs index b04a41385..d0e93e734 100644 --- a/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs @@ -71,18 +71,16 @@ namespace ImageSharp.Tests.Drawing processor.Apply(img, bounds); } - - [Fact] public void DrawOffCanvas() { using (var img = new Image(10, 10)) { - img.DrawLines(new Pen(Rgba32.Black, 10), new SixLabors.Primitives.PointF[] { + img.Mutate(x => x.DrawLines(new Pen(Rgba32.Black, 10), new SixLabors.Primitives.PointF[] { new Vector2(-10, 5), new Vector2(20, 5), - }); + })); } } } diff --git a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs index ce127cfe0..f2f6ad06a 100644 --- a/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs +++ b/tests/ImageSharp.Tests/Drawing/FillSolidBrushTests.cs @@ -24,8 +24,9 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { + image.Mutate(x => x + .Fill(Rgba32.HotPink)); image - .Fill(Rgba32.HotPink) .Save($"{path}/DefaultBack.png"); using (PixelAccessor sourcePixels = image.Lock()) @@ -43,10 +44,10 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Fill", "SolidBrush"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink) - .Save($"{path}/Simple.png"); + .Fill(Rgba32.HotPink)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -65,10 +66,10 @@ namespace ImageSharp.Tests.Drawing { Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(color) - .Save($"{path}/Opacity.png"); + .Fill(color)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index e058572fb..fea7ee818 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -34,10 +34,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/Simple.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -81,10 +81,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/SimpleVanishHole.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleVanishHole.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -129,10 +129,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1)) - .Save($"{path}/SimpleOverlapping.png"); + .Draw(Rgba32.HotPink, 5, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleOverlapping.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -172,10 +172,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(Pens.Dash(Rgba32.HotPink, 5), simplePath.Clip(hole1)) - .Save($"{path}/Dashed.png"); + .Draw(Pens.Dash(Rgba32.HotPink, 5), simplePath.Clip(hole1))); + image.Save($"{path}/Dashed.png"); } } @@ -197,10 +197,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Draw(color, 5, simplePath.Clip(hole1)) - .Save($"{path}/Opacity.png"); + .Draw(color, 5, simplePath.Clip(hole1))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index f47d56696..693bbc28f 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -23,15 +23,15 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[]{ new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -50,7 +50,7 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 5, new SixLabors.Primitives.PointF[] { @@ -58,8 +58,8 @@ namespace ImageSharp.Tests.Drawing new Vector2(200, 150), new Vector2(50, 300) }, - new GraphicsOptions(false)) - .Save($"{path}/Simple_noantialias.png"); + new GraphicsOptions(false))); + image.Save($"{path}/Simple_noantialias.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -78,17 +78,17 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.Dash(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Dashed.png"); - } + })); + image.Save($"{path}/Dashed.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDotted() @@ -96,17 +96,17 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.Dot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Dot.png"); - } + })); + image.Save($"{path}/Dot.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDashDot() @@ -114,17 +114,17 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.DashDot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/DashDot.png"); - } + })); + image.Save($"{path}/DashDot.png"); } + } [Fact] public void ImageShouldBeOverlayedByPathDashDotDot() @@ -132,15 +132,15 @@ namespace ImageSharp.Tests.Drawing string path = this.CreateOutputDirectory("Drawing", "Lines"); Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Pens.DashDotDot(Rgba32.HotPink, 5), new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/DashDotDot.png"); - } + })); + image.Save($"{path}/DashDotDot.png"); + } [Fact] public void ImageShouldBeOverlayedPathWithOpacity() @@ -151,27 +151,27 @@ namespace ImageSharp.Tests.Drawing Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(color, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Opacity.png"); + })); + image.Save($"{path}/Opacity.png"); - //shift background color towards forground color by the opacity amount - Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); + //shift background color towards forground color by the opacity amount + Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); - using (PixelAccessor sourcePixels = image.Lock()) - { - Assert.Equal(mergedColor, sourcePixels[11, 11]); + using (PixelAccessor sourcePixels = image.Lock()) + { + Assert.Equal(mergedColor, sourcePixels[11, 11]); - Assert.Equal(mergedColor, sourcePixels[199, 149]); + Assert.Equal(mergedColor, sourcePixels[199, 149]); - Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - } + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } + } [Fact] public void ImageShouldBeOverlayedByPathOutline() @@ -180,27 +180,27 @@ namespace ImageSharp.Tests.Drawing Image image = new Image(500, 500); - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .DrawLines(Rgba32.HotPink, 10, new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 10), new Vector2(200, 150), new Vector2(10, 150) - }) - .Save($"{path}/Rectangle.png"); + })); + image.Save($"{path}/Rectangle.png"); - using (PixelAccessor sourcePixels = image.Lock()) - { - Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); + using (PixelAccessor sourcePixels = image.Lock()) + { + Assert.Equal(Rgba32.HotPink, sourcePixels[11, 11]); - Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); + Assert.Equal(Rgba32.HotPink, sourcePixels[198, 10]); - Assert.Equal(Rgba32.Blue, sourcePixels[10, 50]); + Assert.Equal(Rgba32.Blue, sourcePixels[10, 50]); - Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); - } + Assert.Equal(Rgba32.Blue, sourcePixels[50, 50]); } - } + } +} diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 3a2b66c3c..b80173bcf 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndPath() { - img.Fill(brush, path); + img.Mutate(x => x.Fill(brush, path)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -56,7 +56,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - img.Fill(brush, path, noneDefault); + img.Mutate(x => x.Fill(brush, path, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -73,7 +73,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorAndPath() { - img.Fill(color, path); + img.Mutate(x => x.Fill(color, path)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -91,7 +91,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - img.Fill(color, path, noneDefault); + img.Mutate(x => x.Fill(color, path, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index 24efa976e..8fe18713d 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -47,7 +47,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndPath() { - img.Fill(brush, pathCollection); + img.Mutate(x => x.Fill(brush, pathCollection)); Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) @@ -69,7 +69,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - img.Fill(brush, pathCollection, noneDefault); + img.Mutate(x => x.Fill(brush, pathCollection, noneDefault)); Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) @@ -89,7 +89,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorAndPath() { - img.Fill(color, pathCollection); + img.Mutate(x => x.Fill(color, pathCollection)); Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) @@ -110,7 +110,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - img.Fill(color, pathCollection, noneDefault); + img.Mutate(x => x.Fill(color, pathCollection, noneDefault)); Assert.Equal(2, img.ProcessorApplications.Count); for (var i = 0; i < 2; i++) diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index b46d3d0d9..2fd9a89b3 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndPath() { - img.FillPolygon(brush, path); + img.Mutate(x => x.FillPolygon(brush, path)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -54,7 +54,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathAndOptions() { - img.FillPolygon(brush, path, noneDefault); + img.Mutate(x => x.FillPolygon(brush, path, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -71,7 +71,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorAndPath() { - img.FillPolygon(color, path); + img.Mutate(x => x.FillPolygon(color, path)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -89,7 +89,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - img.FillPolygon(color, path, noneDefault); + img.Mutate(x => x.FillPolygon(color, path, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 7e6a3deee..56c7d5109 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -32,7 +32,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushAndRectangle() { - img.Fill(brush, rectangle); + img.Mutate(x => x.Fill(brush, rectangle)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushRectangleAndOptions() { - img.Fill(brush, rectangle, noneDefault); + img.Mutate(x => x.Fill(brush, rectangle, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -72,7 +72,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorAndRectangle() { - img.Fill(color, rectangle); + img.Mutate(x => x.Fill(color, rectangle)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); @@ -93,7 +93,7 @@ namespace ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorRectangleAndOptions() { - img.Fill(color, rectangle, noneDefault); + img.Mutate(x => x.Fill(color, rectangle, noneDefault)); Assert.NotEmpty(img.ProcessorApplications); FillRegionProcessor processor = Assert.IsType>(img.ProcessorApplications[0].processor); diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index 501b10e4a..827cde5a8 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -25,15 +25,15 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .DrawPolygon(Rgba32.HotPink, 5, - new SixLabors.Primitives.PointF[] { + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .DrawPolygon(Rgba32.HotPink, 5, + new SixLabors.Primitives.PointF[] { new Vector2(10, 10), new Vector2(200, 150), new Vector2(50, 300) - }) - .Save($"{path}/Simple.png"); + })); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -62,10 +62,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .DrawPolygon(color, 10, simplePath) - .Save($"{path}/Opacity.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .DrawPolygon(color, 10, simplePath)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -90,10 +90,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Draw(Rgba32.HotPink, 10, new Rectangle(10, 10, 190, 140)) - .Save($"{path}/Rectangle.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Draw(Rgba32.HotPink, 10, new Rectangle(10, 10, 190, 140))); + image.Save($"{path}/Rectangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { diff --git a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs index 9c62e860a..53b7d950f 100644 --- a/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs @@ -27,8 +27,8 @@ namespace ImageSharp.Tests { using (Image image = file.CreateImage()) { - image.Fill(brush) - .Save($"{path}/{file.FileName}"); + image.Mutate(x => x.Fill(brush)); + image.Save($"{path}/{file.FileName}"); } } } @@ -45,8 +45,8 @@ namespace ImageSharp.Tests using (Image image = file.CreateImage()) { int imageHeight = image.Height; - image.Fill(brush, new Rectangle(0, imageHeight / 2 - imageHeight / 4, image.Width, imageHeight / 2)) - .Save($"{path}/Shaped_{file.FileName}"); + image.Mutate(x => x.Fill(brush, new Rectangle(0, imageHeight / 2 - imageHeight / 4, image.Width, imageHeight / 2))); + image.Save($"{path}/Shaped_{file.FileName}"); } } } diff --git a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs index ba904cb3f..aa9ffb187 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs @@ -28,10 +28,10 @@ namespace ImageSharp.Tests.Drawing }; using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new Polygon(new CubicBezierLineSegment(simplePath))) - .Save($"{path}/Simple.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Fill(Rgba32.HotPink, new Polygon(new CubicBezierLineSegment(simplePath)))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -60,10 +60,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .BackgroundColor(Rgba32.Blue) - .Fill(color, new Polygon(new CubicBezierLineSegment(simplePath))) - .Save($"{path}/Opacity.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .Fill(color, new Polygon(new CubicBezierLineSegment(simplePath)))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs index c3af3d5c2..70369a6a8 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs @@ -34,10 +34,10 @@ namespace ImageSharp.Tests.Drawing // var clipped = new Rectangle(10, 10, 100, 100).Clip(new Rectangle(20, 0, 20, 20)); using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, clipped) - .Save($"{path}/Simple.png"); + .Fill(Rgba32.HotPink, clipped)); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -66,10 +66,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, simplePath.Clip(hole1)) - .Save($"{path}/SimpleOverlapping.png"); + .Fill(Rgba32.HotPink, simplePath.Clip(hole1))); + image.Save($"{path}/SimpleOverlapping.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -98,10 +98,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(color, simplePath.Clip(hole1)) - .Save($"{path}/Opacity.png"); + .Fill(color, simplePath.Clip(hole1))); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 793bcfc9f..469669acf 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -31,9 +31,9 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true)) - .Save($"{path}/Simple.png"); + image.Mutate(x => x + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true))); + image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -54,9 +54,9 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image - .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true)) - .Save($"{path}/Pattern.png"); + image.Mutate(x => x + .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true))); + image.Save($"{path}/Pattern.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -77,10 +77,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false)) - .Save($"{path}/Simple_NoAntialias.png"); + .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false))); + image.Save($"{path}/Simple_NoAntialias.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -110,10 +110,10 @@ namespace ImageSharp.Tests.Drawing { ImageBrush brush = new ImageBrush(brushImage); - image - .BackgroundColor(Rgba32.Blue) - .FillPolygon(brush, simplePath) - .Save($"{path}/Image.png"); + image.Mutate(x => x + .BackgroundColor(Rgba32.Blue) + .FillPolygon(brush, simplePath)); + image.Save($"{path}/Image.png"); } } @@ -130,10 +130,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .FillPolygon(color, simplePath) - .Save($"{path}/Opacity.png"); + .FillPolygon(color, simplePath)); + image.Save($"{path}/Opacity.png"); //shift background color towards forground color by the opacity amount Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f)); @@ -152,10 +152,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(500, 500)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new SixLabors.Shapes.RectangularePolygon(10, 10, 190, 140)) - .Save($"{path}/Rectangle.png"); + .Fill(Rgba32.HotPink, new SixLabors.Shapes.RectangularePolygon(10, 10, 190, 140))); + image.Save($"{path}/Rectangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -179,10 +179,10 @@ namespace ImageSharp.Tests.Drawing using (Image image = new Image(100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 3, 30)) - .Save($"{path}/Triangle.png"); + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 3, 30))); + image.Save($"{path}/Triangle.png"); using (PixelAccessor sourcePixels = image.Lock()) { @@ -202,10 +202,10 @@ namespace ImageSharp.Tests.Drawing config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI)) - .Save($"{path}/Septagon.png"); + .Fill(Rgba32.HotPink, new RegularPolygon(50, 50, 7, 30, -(float)Math.PI))); + image.Save($"{path}/Septagon.png"); } } @@ -218,11 +218,11 @@ namespace ImageSharp.Tests.Drawing config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 100, 100)) { - image + image.Mutate(x => x .BackgroundColor(Rgba32.Blue) .Fill(Rgba32.HotPink, new EllipsePolygon(50, 50, 30, 50) - .Rotate((float)(Math.PI / 3))) - .Save($"{path}/ellipse.png"); + .Rotate((float)(Math.PI / 3)))); + image.Save($"{path}/ellipse.png"); } } @@ -235,7 +235,7 @@ namespace ImageSharp.Tests.Drawing config.ParallelOptions.MaxDegreeOfParallelism = 1; using (Image image = new Image(config, 200, 200)) { - image + image.Mutate(x => x .Fill(Rgba32.Blue) .FillPolygon(Rgba32.HotPink, new SixLabors.Primitives.PointF[] { @@ -245,8 +245,8 @@ namespace ImageSharp.Tests.Drawing new Vector2( 120, 64 ), new Vector2( 120, 120 ), new Vector2( 8, 120 ) - }) - .Save($"{path}/clipped-corner.png"); + })); + image.Save($"{path}/clipped-corner.png"); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs index 05a1f1e36..067ea122d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs @@ -51,13 +51,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPen() { - this.img.DrawText( + this.img.Mutate(x => x.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 @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, path); + this.img.Mutate(x => x.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 @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.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 @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), path); + this.img.Mutate(x => x.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 @@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, path, new TextGraphicsOptions(true))); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); @@ -111,7 +111,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Rgba32.Red, path); + this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, path)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); @@ -126,13 +126,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrush() { - this.img.DrawText( + this.img.Mutate(x => x.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 @@ -142,7 +142,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), path); + this.img.Mutate(x => x.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 @@ -152,7 +152,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.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 @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), path); + this.img.Mutate(x => x.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 @@ -172,13 +172,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { - this.img.DrawText( + this.img.Mutate(x => x.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); @@ -187,7 +187,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); + this.img.Mutate(x => x.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); @@ -196,13 +196,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void BrushAppliesBeforPen() { - this.img.DrawText( + this.img.Mutate(x => x.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); @@ -213,39 +213,12 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), path); + this.img.Mutate(x => x.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>(this.img.ProcessorApplications[0].processor); Assert.IsType>(this.img.ProcessorApplications[1].processor); } - - [Fact] - public void GlyphHeightChangesBasedOnuseImageResolutionFlag() - { - this.img.MetaData.VerticalResolution = 1; - this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) { - UseImageResolution = false - }); - - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), path, new TextGraphicsOptions(true) - { - UseImageResolution = true - }); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); - - ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); - ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); - - // magic numbers based on the font used at well known resolutions - Assert.Equal(7.44, ownRegion.Shape.Bounds.Height, 2); - Assert.Equal(0.1, imgRegion.Shape.Bounds.Height, 2); - } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 1c8c9f1d1..d03af5456 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -51,13 +51,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPen() { - this.img.DrawText( + this.img.Mutate(x => x.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 @@ -67,7 +67,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetAndNotPenDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), null, Vector2.Zero); + this.img.Mutate(x => x.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 @@ -77,7 +77,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.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 @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero); + this.img.Mutate(x => x.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 @@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSet() { - this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true))); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); @@ -111,7 +111,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSetDefaultOptions() { - this.img.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero); + this.img.Mutate(x => x.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero)); Assert.NotEmpty(this.img.ProcessorApplications); Assert.Equal(3, this.img.ProcessorApplications.Count); @@ -126,13 +126,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrush() { - this.img.DrawText( + this.img.Mutate(x => x.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 @@ -142,7 +142,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndNotBrushDefaultOptions() { - this.img.DrawText("123", this.Font, null, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.img.Mutate(x => x.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 @@ -152,7 +152,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSet() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.img.Mutate(x => x.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 @@ -162,7 +162,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetDefaultOptions() { - this.img.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.img.Mutate(x => x.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 @@ -172,13 +172,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { - this.img.DrawText( + this.img.Mutate(x => x.DrawText( "123", 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(6, this.img.ProcessorApplications.Count); @@ -187,7 +187,7 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSetDefaultOptions() { - this.img.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.img.Mutate(x => x.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); @@ -196,13 +196,13 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void BrushAppliesBeforPen() { - this.img.DrawText( + this.img.Mutate(x => x.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); @@ -213,39 +213,12 @@ namespace ImageSharp.Tests.Drawing.Text [Fact] public void BrushAppliesBeforPenDefaultOptions() { - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), Vector2.Zero); + this.img.Mutate(x => x.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>(this.img.ProcessorApplications[0].processor); Assert.IsType>(this.img.ProcessorApplications[1].processor); } - - [Fact] - public void GlyphHeightChangesBasedOnuseImageResolutionFlag() - { - this.img.MetaData.VerticalResolution = 1; - this.img.MetaData.HorizontalResolution = 1; - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) { - UseImageResolution = false - }); - - this.img.DrawText("1", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true) - { - UseImageResolution = true - }); - - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(2, this.img.ProcessorApplications.Count); - FillRegionProcessor ownResolution = Assert.IsType>(this.img.ProcessorApplications[0].processor); - FillRegionProcessor imgResolution = Assert.IsType>(this.img.ProcessorApplications[1].processor); - - ShapeRegion ownRegion = Assert.IsType(ownResolution.Region); - ShapeRegion imgRegion = Assert.IsType(imgResolution.Region); - - // magic numbers based on the font used at well known resolutions - Assert.Equal(7.44, ownRegion.Shape.Bounds.Height, 2); - Assert.Equal(0.1, imgRegion.Shape.Bounds.Height, 2); - } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs index ce2a5becf..af401264d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/OutputText.cs @@ -34,8 +34,8 @@ namespace ImageSharp.Tests.Drawing.Text //draws 2 overlapping triangle glyphs twice 1 set on each line using (Image img = new Image(100, 200)) { - img.Fill(Rgba32.DarkBlue) - .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0)); + img.Mutate(x => x.Fill(Rgba32.DarkBlue) + .DrawText("AB\nAB", new Font(this.Font, 50), Rgba32.Red, new Vector2(0, 0))); img.Save($"{this.CreateOutputDirectory("Drawing", "Text")}/AB.png"); } } diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 4ef8fe061..1f669ba24 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -50,7 +50,7 @@ namespace ImageSharp.Tests { using (Image image = file.CreateImage()) { - image.Save($"{path}/{file.FileName}"); + image.Save($"{path}/{file.FileName}"); } } } @@ -68,8 +68,8 @@ namespace ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { - image.Quantize(Quantization.Octree) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Octree)); + image.Save(output, mimeType); } } @@ -78,8 +78,8 @@ namespace ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { - image.Quantize(Quantization.Wu) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Wu)); + image.Save(output, mimeType); } } @@ -87,8 +87,8 @@ namespace ImageSharp.Tests { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { - image.Quantize(Quantization.Palette) - .Save(output, mimeType); + image.Mutate(x => x.Quantize(Quantization.Palette)); + image.Save(output, mimeType); } } } diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs index 86faeee23..49802a8d2 100644 --- a/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegEncoderTests.cs @@ -36,8 +36,9 @@ namespace ImageSharp.Tests public void LoadResizeSave(TestImageProvider provider, int quality, JpegSubsample subsample) where TPixel : struct, IPixel { - using (Image image = provider.GetImage().Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max })) + using (Image image = provider.GetImage(x=>x.Resize(new ResizeOptions { Size = new Size(150, 100), Mode = ResizeMode.Max }))) { + image.MetaData.ExifProfile = null; // Reduce the size of the file JpegEncoder options = new JpegEncoder { Subsample = subsample, Quality = quality }; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs index bac340a71..43ca2a1b6 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs +++ b/tests/ImageSharp.Tests/Formats/Png/PngSmokeTests.cs @@ -113,7 +113,7 @@ namespace ImageSharp.Tests.Formats.Png using (MemoryStream ms = new MemoryStream()) { // image.Save(provider.Utility.GetTestOutputFileName("png")); - image.Resize(100, 100); + image.Mutate(x=>x.Resize(100, 100)); // image.Save(provider.Utility.GetTestOutputFileName("png", "resize")); image.Save(ms, new PngEncoder()); diff --git a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs index b59023340..4ffc33580 100644 --- a/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs +++ b/tests/ImageSharp.Tests/Image/PixelAccessorTests.cs @@ -82,7 +82,7 @@ namespace ImageSharp.Tests { using (Image srcImage = provider.GetImage()) { - srcImage.Fill(NamedColors.Red, new Rectangle(4, 4, 8, 8)); + srcImage.Mutate(x => x.Fill(NamedColors.Red, new Rectangle(4, 4, 8, 8))); using (PixelAccessor srcPixels = srcImage.Lock()) { using (PixelArea area = new PixelArea(8, 8, order)) @@ -100,8 +100,9 @@ namespace ImageSharp.Tests provider.Utility.SourceFileOrDescription = order.ToString(); provider.Utility.SaveTestOutputFile(destImage, "bmp"); - using (Image expectedImage = new Image(8, 8).Fill(NamedColors.Red)) + using (Image expectedImage = new Image(8, 8)) { + expectedImage.Mutate(x => x.Fill(NamedColors.Red)); Assert.True(destImage.IsEquivalentTo(expectedImage)); } } diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index 6cd80e9e8..46d4351de 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -47,8 +47,8 @@ namespace ImageSharp.Tests where TPixelB : struct, IPixel { // Draw identical shapes over the bounded and compare to ensure changes are constrained. - expected.Fill(NamedColors.HotPink, bounds); - actual.Fill(NamedColors.HotPink, bounds); + expected.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); + actual.Mutate(x => x.Fill(NamedColors.HotPink, bounds)); CheckSimilarity(expected, actual, imageTheshold, segmentThreshold, scalingFactor); } @@ -138,7 +138,7 @@ namespace ImageSharp.Tests where TPixelA : struct, IPixel { byte[] buffer = new byte[3]; - using (Image img = new Image(source).Resize(scalingFactor, scalingFactor).Grayscale()) + using (Image img = source.Generate(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) { using (PixelAccessor pixels = img.Lock()) { diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index 642df598a..a8140aac7 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Binarization { using (Image image = provider.GetImage()) { - image.BinaryThreshold(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.BinaryThreshold(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -41,8 +41,8 @@ namespace ImageSharp.Tests.Processing.Binarization { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.BinaryThreshold(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.BinaryThreshold(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs index a06397c86..25b34bfe4 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs @@ -38,8 +38,8 @@ namespace ImageSharp.Tests.Processing.Binarization { using (Image image = provider.GetImage()) { - image.Dither(ditherer) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Dither(ditherer)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -53,8 +53,8 @@ namespace ImageSharp.Tests.Processing.Binarization { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Dither(ditherer, bounds) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Dither(ditherer, bounds)); + image.DebugSave(provider, name, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } @@ -67,8 +67,8 @@ namespace ImageSharp.Tests.Processing.Binarization { using (Image image = provider.GetImage()) { - image.Dither(diffuser, .5F) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Dither(diffuser, .5F)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -82,8 +82,8 @@ namespace ImageSharp.Tests.Processing.Binarization { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Dither(diffuser,.5F, bounds) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Dither(diffuser, .5F, bounds)); + image.DebugSave(provider, name, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs index 4dc70fb0f..90c02be19 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.BlackWhite() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.BlackWhite()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.BlackWhite(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.BlackWhite(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs index bc1c8ad22..9006e3e33 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs @@ -32,8 +32,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.ColorBlindness(colorBlindness) - .DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); + image.Mutate(x => x.ColorBlindness(colorBlindness)); + image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); } } @@ -47,8 +47,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.ColorBlindness(colorBlindness, bounds) - .DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); + image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); + image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs index 9bf55a6d2..6dd0e8248 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Grayscale(value); + image.Mutate(x => x.Grayscale(value)); byte[] data = new byte[3]; for (int i = 0; i < image.Pixels.Length; i++) { @@ -51,8 +51,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix using (var image = new Image(source)) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Grayscale(value, bounds) - .DebugSave(provider, value.ToString()); + image.Mutate(x => x.Grayscale(value, bounds)); + image.DebugSave(provider, value.ToString()); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs index ba1cf2b8f..1fe56a8be 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Hue(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Hue(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Hue(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Hue(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs index 971cdb6d8..779ca0f6b 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Kodachrome() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Kodachrome()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Kodachrome(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Kodachrome(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs index 5b41cdb3b..ebfacb720 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs @@ -20,8 +20,8 @@ namespace ImageSharp.Tests { using (Image image = provider.GetImage()) { - image.Lomograph() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Lomograph()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -35,8 +35,8 @@ namespace ImageSharp.Tests { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Lomograph(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Lomograph(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs index 48f7a6c0a..54836cedf 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Polaroid() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Polaroid()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Polaroid(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Polaroid(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs index a4a4f3bb5..73c3f98b5 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Saturation(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Saturation(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Saturation(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Saturation(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs index af554e30d..ae7865c11 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { using (Image image = provider.GetImage()) { - image.Sepia() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Sepia()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.ColorMatrix { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Sepia(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Sepia(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index ef049a539..58a2665d0 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Convolution { using (Image image = provider.GetImage()) { - image.BoxBlur(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.BoxBlur(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Convolution { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.BoxBlur(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.BoxBlur(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index d5817ab14..9f3a2d79a 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs @@ -34,8 +34,8 @@ namespace ImageSharp.Tests.Processing.Convolution { using (Image image = provider.GetImage()) { - image.DetectEdges(detector) - .DebugSave(provider, detector.ToString(), Extensions.Bmp); + image.Mutate(x => x.DetectEdges(detector)); + image.DebugSave(provider, detector.ToString(), Extensions.Bmp); } } @@ -49,8 +49,8 @@ namespace ImageSharp.Tests.Processing.Convolution { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.DetectEdges(detector, bounds) - .DebugSave(provider, detector.ToString(), Extensions.Bmp); + image.Mutate(x => x.DetectEdges(detector, bounds)); + image.DebugSave(provider, detector.ToString(), Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index fa4e4b0b6..763e806af 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Convolution { using (Image image = provider.GetImage()) { - image.GaussianBlur(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.GaussianBlur(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Convolution { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.GaussianBlur(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.GaussianBlur(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index d15042ee6..6313bc72a 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Convolution { using (Image image = provider.GetImage()) { - image.GaussianSharpen(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.GaussianSharpen(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Convolution { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.GaussianSharpen(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.GaussianSharpen(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs index 34a24e70b..e01e67e18 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.Alpha(value) - .DebugSave(provider, value, Extensions.Png); + image.Mutate(x => x.Alpha(value)); + image.DebugSave(provider, value, Extensions.Png); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Alpha(value, bounds) - .DebugSave(provider, value, Extensions.Png); + image.Mutate(x => x.Alpha(value, bounds)); + image.DebugSave(provider, value, Extensions.Png); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 63efbf3e7..55f11b8b5 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.BackgroundColor(NamedColors.HotPink) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink)); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.BackgroundColor(NamedColors.HotPink, bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs index c3b37705a..081fdf319 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.Brightness(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Brightness(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Brightness(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Brightness(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ; } diff --git a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs index 892eb9362..2c2ef1403 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.Contrast(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Contrast(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Contrast(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Contrast(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs index 3d8b3d1a1..7d79517bc 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.Invert() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Invert()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -33,8 +33,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Invert(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Invert(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 3d0e8f117..002d57d84 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests { using (Image image = provider.GetImage()) { - image.OilPaint(levels, brushSize) - .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + image.Mutate(x => x.OilPaint(levels, brushSize)); + image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); } } @@ -40,8 +40,8 @@ namespace ImageSharp.Tests { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.OilPaint(levels, brushSize, bounds) - .DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); + image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); } diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index 253f1f459..3a6e273d0 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Effects { using (Image image = provider.GetImage()) { - image.Pixelate(value) - .DebugSave(provider, value, Extensions.Bmp); + 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) @@ -56,8 +56,8 @@ namespace ImageSharp.Tests.Processing.Effects { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Pixelate(value, bounds) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Pixelate(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); for (int y = 0; y < image.Height; y++) { diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index d0633dca5..20e521c8d 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Glow() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Glow()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -30,8 +30,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Glow(NamedColors.Orange) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Glow(NamedColors.Orange)); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -42,8 +42,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Glow(image.Width / 4F) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Glow(image.Width / 4F)); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -57,8 +57,8 @@ namespace ImageSharp.Tests.Processing.Overlays { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Glow(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Glow(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index 56fcf0ee0..74c5296fa 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Vignette() - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Vignette()); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -30,8 +30,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Vignette(NamedColors.Orange) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Vignette(NamedColors.Orange)); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -42,8 +42,8 @@ namespace ImageSharp.Tests.Processing.Overlays { using (Image image = provider.GetImage()) { - image.Vignette(image.Width / 4F, image.Height / 4F) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Vignette(image.Width / 4F, image.Height / 4F)); + image.DebugSave(provider, null, Extensions.Bmp); } } @@ -57,8 +57,8 @@ namespace ImageSharp.Tests.Processing.Overlays { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); - image.Vignette(bounds) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Vignette(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index 7bc0c8bb5..6c1d32b33 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs @@ -38,10 +38,11 @@ namespace ImageSharp.Tests.Processing.Transforms image.MetaData.ExifProfile = new ExifProfile(); image.MetaData.ExifProfile.SetValue(ExifTag.Orientation, orientation); - image.RotateFlip(rotateType, flipType) - .DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "1_before"), Extensions.Bmp) - .AutoOrient() - .DebugSave(provider, string.Join("_", rotateType, flipType, orientation, "2_after"), Extensions.Bmp); + 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); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index ca20abf79..b95c9d82a 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Crop(image.Width / 2, image.Height / 2) - .DebugSave(provider, null, Extensions.Bmp); + image.Mutate(x => x.Crop(image.Width / 2, image.Height / 2)); + image.DebugSave(provider, null, Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index 24febd5b2..1c97c70ad 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.EntropyCrop(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.EntropyCrop(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 45ab1e5f8..8e048ae04 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs @@ -29,8 +29,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Flip(flipType) - .DebugSave(provider, flipType, Extensions.Bmp); + image.Mutate(x => x.Flip(flipType)); + image.DebugSave(provider, flipType, Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index 7caa1e7c0..7471330be 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs @@ -18,8 +18,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Pad(image.Width + 50, image.Height + 50) - .DebugSave(provider, null, Extensions.Bmp); + 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++) diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs index a300672e8..7b83f0a8e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs @@ -34,7 +34,7 @@ namespace ImageSharp.Tests.Processing.Transforms { using (var image = new Image(width, height)) { - image.Resize(width / 4, height / 4); + image.Mutate(x => x.Resize(width / 4, height / 4)); } }); } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index fb195254e..0092ae9da 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs @@ -39,8 +39,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Resize(image.Width / 2, image.Height / 2, sampler, true) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(image.Width / 2, image.Height / 2, sampler, true)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -54,8 +54,8 @@ namespace ImageSharp.Tests.Processing.Transforms var sourceRectangle = new Rectangle(image.Width / 8, image.Height / 8, image.Width / 4, image.Height / 4); var destRectangle = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); - image.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(image.Width, image.Height, sampler, sourceRectangle, destRectangle, false)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -66,8 +66,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Resize(image.Width / 3, 0, sampler, false) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(image.Width / 3, 0, sampler, false)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -78,8 +78,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Resize(0, image.Height / 3, sampler, false) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(0, image.Height / 3, sampler, false)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -96,8 +96,8 @@ namespace ImageSharp.Tests.Processing.Transforms Size = new Size(image.Width / 2, image.Height) }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -114,8 +114,8 @@ namespace ImageSharp.Tests.Processing.Transforms Size = new Size(image.Width, image.Height / 2) }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -133,8 +133,8 @@ namespace ImageSharp.Tests.Processing.Transforms Mode = ResizeMode.Pad }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -152,8 +152,8 @@ namespace ImageSharp.Tests.Processing.Transforms Mode = ResizeMode.BoxPad }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -171,8 +171,8 @@ namespace ImageSharp.Tests.Processing.Transforms Mode = ResizeMode.Max }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -190,8 +190,8 @@ namespace ImageSharp.Tests.Processing.Transforms Mode = ResizeMode.Min }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } @@ -209,8 +209,8 @@ namespace ImageSharp.Tests.Processing.Transforms Mode = ResizeMode.Stretch }; - image.Resize(options) - .DebugSave(provider, name, Extensions.Bmp); + image.Mutate(x => x.Resize(options)); + image.DebugSave(provider, name, Extensions.Bmp); } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index f85ef6f13..432b2549b 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs @@ -31,8 +31,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.RotateFlip(rotateType, flipType) - .DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp); + image.Mutate(x => x.RotateFlip(rotateType, flipType)); + image.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 1f1856429..2db86390d 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs @@ -35,8 +35,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Rotate(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Rotate(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } @@ -47,8 +47,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Rotate(value) - .DebugSave(provider, value, Extensions.Bmp); + image.Mutate(x => x.Rotate(value)); + image.DebugSave(provider, value, Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index f2c2d7cbd..63924c535 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs @@ -25,8 +25,8 @@ namespace ImageSharp.Tests.Processing.Transforms { using (Image image = provider.GetImage()) { - image.Skew(x, y) - .DebugSave(provider, string.Join("_", x, y), Extensions.Bmp); + image.Mutate(i => i.Skew(x, y)); + image.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs index 0caded420..08e3e1054 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs @@ -55,7 +55,8 @@ namespace ImageSharp.Tests TPixel color = default(TPixel); color.PackFromRgba32(new Rgba32(this.r, this.g, this.b, this.a)); - return image.Fill(color); + image.Mutate(x => x.Fill(color)); + return image; } public override void Serialize(IXunitSerializationInfo info) diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index 03a685d34..e939d78bb 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -82,6 +82,16 @@ namespace ImageSharp.Tests /// public abstract Image GetImage(); + /// + /// Returns an instance to the test case with the necessary traits. + /// + public Image GetImage(Action> operationsToApply) + { + var img = GetImage(); + img.Mutate(operationsToApply); + return img; + } + public virtual void Deserialize(IXunitSerializationInfo info) { PixelTypes pixelType = info.GetValue("PixelType"); diff --git a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs index 437c295b9..88ab987ed 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Tests/TestUtilityExtensionsTests.cs @@ -67,8 +67,7 @@ namespace ImageSharp.Tests where TPixel : struct, IPixel { Image a = provider.GetImage(); - Image b = provider.GetImage(); - b = b.OilPaint(3, 2); + Image b = provider.GetImage(x=>x.OilPaint(3, 2)); Assert.False(a.IsEquivalentTo(b, compareAlpha)); } From 456e139813f21be2d9b75b7e7ad81c50758e09da Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 4 Jul 2017 18:47:32 +0100 Subject: [PATCH 02/20] fix demo --- samples/AvatarWithRoundedCorner/Program.cs | 52 +++++++++++++--------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 45fe1e3c8..0ceb7566e 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -8,57 +8,69 @@ namespace AvatarWithRoundedCorner using SixLabors.Primitives; using SixLabors.Shapes; - class Program + static class Program { static void Main(string[] args) { System.IO.Directory.CreateDirectory("output"); + using (var img = Image.Load("fb.jpg")) + { + // as generate returns a new IImage make sure we dispose of it + using (Image dest = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 20))) + { + dest.Save("output/fb.png"); + } + + using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 100))) + { + destRound.Save("output/fb-round.png"); + } - GenerateAvatar("fb.jpg", "output/fb.png", new Size(200, 200), 20); - GenerateAvatar("fb.jpg", "output/fb-round.png", new Size(200, 200), 100); - GenerateAvatar("fb.jpg", "output/fb-rounder.png", new Size(200, 200), 150); + using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 150))) + { + destRound.Save("output/fb-rounder.png"); + } + + // the original `img` object has not been altered at all. + } } - private static void GenerateAvatar(string source, string destination, Size size, float cornerRadius) + // lets create our custom image mutating pipeline + private static IImageOperations ConvertToAvatar(this IImageOperations operations, Size size, float cornerRadius) { - using (var image = Image.Load(source)) + return operations.Resize(new ImageSharp.Processing.ResizeOptions { - image.Mutate(x => x - .Resize(new ImageSharp.Processing.ResizeOptions - { - Size = size, - Mode = ImageSharp.Processing.ResizeMode.Crop - }) - .Run(i=>ApplyRoundedCourners(i, cornerRadius))); - - image.Save(destination); - } + Size = size, + Mode = ImageSharp.Processing.ResizeMode.Crop + }).Run(i => ApplyRoundedCourners(i, cornerRadius)); } + // the combination of `IImageOperations.Run()` + this could be replaced with an `IImageProcessor` public static void ApplyRoundedCourners(Image img, float cornerRadius) { var corners = BuildCorners(img.Width, img.Height, cornerRadius); - // now we have our corners time to draw them + + // mutating in here as we already have a cloned original img.Mutate(x => x.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) { BlenderMode = ImageSharp.PixelFormats.PixelBlenderMode.Src // enforces that any part of this shape that has color is punched out of the background })); } - public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) + public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { // first create a square var rect = new SixLabors.Shapes.RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); // then cut out of the square a circle so we are left with a corner - var cornerToptLeft = rect.Clip(new SixLabors.Shapes.EllipsePolygon(cornerRadius-0.5f, cornerRadius - 0.5f, cornerRadius)); + var cornerToptLeft = rect.Clip(new SixLabors.Shapes.EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); // corner is now a corner shape positions top left //lets make 3 more positioned correctly, we cando that by translating the orgional artound the center of the image var center = new Vector2(imageWidth / 2, imageHeight / 2); var angle = Math.PI / 2f; - float rightPos = imageWidth - cornerToptLeft.Bounds.Width +1; + float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; // move it across the widthof the image - the width of the shape From 88e30a01340c2dd2c4cd3f2fa32e2a7b14a56b07 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 4 Jul 2017 19:05:01 +0100 Subject: [PATCH 03/20] fix apply processors to frames --- src/ImageSharp/Processing/ImageProcessor.cs | 6 +++--- .../Formats/Gif/GifDecoderTests.cs | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Processing/ImageProcessor.cs b/src/ImageSharp/Processing/ImageProcessor.cs index bf88d5ff7..a4ed4eb98 100644 --- a/src/ImageSharp/Processing/ImageProcessor.cs +++ b/src/ImageSharp/Processing/ImageProcessor.cs @@ -42,10 +42,10 @@ namespace ImageSharp.Processing foreach (ImageFrame sourceFrame in source.Frames) { - this.BeforeApply(source, sourceRectangle); + this.BeforeApply(sourceFrame, sourceRectangle); - this.OnApply(source, sourceRectangle); - this.AfterApply(source, sourceRectangle); + this.OnApply(sourceFrame, sourceRectangle); + this.AfterApply(sourceFrame, sourceRectangle); } this.AfterImageApply(source, sourceRectangle); diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs index 06bfd8990..f74c7a5a7 100644 --- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs +++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Tests using ImageSharp.Formats; using ImageSharp.PixelFormats; + using SixLabors.Primitives; public class GifDecoderTests { @@ -29,7 +30,20 @@ namespace ImageSharp.Tests imageProvider.Utility.SaveTestOutputFile(image, "gif"); } } - + [Theory] + [WithFileCollection(nameof(TestFiles), PixelTypes)] + public void DecodeResizeAndSave(TestImageProvider imageProvider) + where TPixel : struct, IPixel + { + using (Image image = imageProvider.GetImage()) + { + image.Mutate(x => x.Resize(new Size(image.Width / 2, image.Height / 2))); + + imageProvider.Utility.SaveTestOutputFile(image, "bmp"); + imageProvider.Utility.SaveTestOutputFile(image, "gif"); + } + } + [Fact] public void Decode_IgnoreMetadataIsFalse_CommentsAreRead() { From a61fcc95d9e37a63903aa2def3e59e475edae39d Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Wed, 5 Jul 2017 07:39:19 +0100 Subject: [PATCH 04/20] Rename Generate -> Clone --- samples/AvatarWithRoundedCorner/Program.cs | 6 +++--- .../Processors/DrawImageProcessor.cs | 2 +- src/ImageSharp/ApplyProcessors.cs | 10 +++++----- src/ImageSharp/Image/Image{TPixel}.cs | 9 +++++++++ tests/ImageSharp.Tests/ImageComparer.cs | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 0ceb7566e..d519fc1ed 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -16,17 +16,17 @@ namespace AvatarWithRoundedCorner using (var img = Image.Load("fb.jpg")) { // as generate returns a new IImage make sure we dispose of it - using (Image dest = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 20))) + using (Image dest = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 20))) { dest.Save("output/fb.png"); } - using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 100))) + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 100))) { destRound.Save("output/fb-round.png"); } - using (Image destRound = img.Generate(x => x.ConvertToAvatar(new Size(200, 200), 150))) + using (Image destRound = img.Clone(x => x.ConvertToAvatar(new Size(200, 200), 150))) { destRound.Save("output/fb-rounder.png"); } diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 07a3ae8c2..7154396dd 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -70,7 +70,7 @@ namespace ImageSharp.Drawing.Processors { if (targetImage.Bounds.Size != this.Size) { - targetImage = disposableImage = this.Image.Generate(x => x.Resize(this.Size.Width, this.Size.Height)); + targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 2a9c3ccbe..a092b789b 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -49,13 +49,13 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Clones the current image mutating the clone by applying the operations to it. /// /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Generate(this Image source, Action> operations) + public static Image Clone(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); @@ -68,13 +68,13 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Clones the current image mutating the clone by applying the operations to it. /// /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Generate(this Image source, params IImageProcessor[] operations) + public static Image Clone(this Image source, params IImageProcessor[] operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); @@ -87,7 +87,7 @@ namespace ImageSharp } /// - /// Mutates the image by applying the operations to it. + /// Queues up a simple operation that provides access to the mutatable image. /// /// The pixel format. /// The image to rotate, flip, or both. diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 13b865521..0dcb36905 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -250,6 +250,15 @@ namespace ImageSharp } #endif + /// + /// Clones the current image + /// + /// Returns a new image with all the same metadata as the original. + public Image Clone() + { + return new Image(this); + } + /// public override string ToString() { diff --git a/tests/ImageSharp.Tests/ImageComparer.cs b/tests/ImageSharp.Tests/ImageComparer.cs index 46d4351de..ea6d2e805 100644 --- a/tests/ImageSharp.Tests/ImageComparer.cs +++ b/tests/ImageSharp.Tests/ImageComparer.cs @@ -138,7 +138,7 @@ namespace ImageSharp.Tests where TPixelA : struct, IPixel { byte[] buffer = new byte[3]; - using (Image img = source.Generate(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) + using (Image img = source.Clone(x => x.Resize(scalingFactor, scalingFactor).Grayscale())) { using (PixelAccessor pixels = img.Lock()) { From 001e3ca0153444539a5eae36812c8d89dd8b2a04 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Mon, 10 Jul 2017 23:28:32 +0100 Subject: [PATCH 05/20] Fix stack overflow --- src/ImageSharp/Processing/Overlays/Vignette.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 78060570c..535b75849 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -94,7 +94,7 @@ namespace ImageSharp /// The . public static IImageOperations Vignette(this IImageOperations source, GraphicsOptions options) where TPixel : struct, IPixel - => source.Vignette(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); + => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); /// /// Applies a radial vignette effect to an image. @@ -106,7 +106,7 @@ namespace ImageSharp /// The . public static IImageOperations Vignette(this IImageOperations source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel - => source.Vignette(color, 0, 0, options); + => source.VignetteInternal(color, 0, 0, options); /// /// Applies a radial vignette effect to an image. @@ -119,7 +119,7 @@ namespace ImageSharp /// The . public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel - => source.Vignette(NamedColors.Black, radiusX, radiusY, options); + => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); /// /// Applies a radial vignette effect to an image. @@ -150,13 +150,13 @@ namespace ImageSharp /// The . public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel - => source.Vignette(color, radiusX, radiusY, rectangle, options); + => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); - private static IImageOperations Vignette(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); - private static IImageOperations Vignette(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } From 961e202f10bcef1f5a16116ac5fc223efaff1310 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 11 Jul 2017 18:44:16 +0100 Subject: [PATCH 06/20] initail image operations tests --- src/ImageSharp/ApplyProcessors.cs | 26 +++- src/ImageSharp/Configuration.cs | 7 +- src/ImageSharp/IImageOperationsProvider.cs | 38 ++++++ src/ImageSharp/IImageOperations{TPixel}.cs | 2 +- .../Processing/DelegateImageProcessor.cs | 5 + src/Shared/AssemblyInfo.Common.cs | 4 +- .../BaseImageOperationsExtensionTest.cs | 25 ++++ .../FakeImageOperationsProvider.cs | 77 +++++++++++ tests/ImageSharp.Tests/ImageOperationTests.cs | 120 ++++++++++++++++++ 9 files changed, 297 insertions(+), 7 deletions(-) create mode 100644 src/ImageSharp/IImageOperationsProvider.cs create mode 100644 tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs create mode 100644 tests/ImageSharp.Tests/FakeImageOperationsProvider.cs create mode 100644 tests/ImageSharp.Tests/ImageOperationTests.cs diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index a092b789b..d625b1c24 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -28,7 +28,7 @@ namespace ImageSharp Guard.NotNull(operations, nameof(operations)); // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - var operationsRunner = new ImageOperations(source); + IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); operations(operationsRunner); } @@ -44,7 +44,7 @@ namespace ImageSharp Guard.NotNull(operations, nameof(operations)); // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - var operationsRunner = new ImageOperations(source); + IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); operationsRunner.ApplyProcessors(operations); } @@ -62,7 +62,7 @@ namespace ImageSharp var generated = new Image(source); // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - var operationsRunner = new ImageOperations(generated); + IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); operations(operationsRunner); return generated; } @@ -81,7 +81,7 @@ namespace ImageSharp var generated = new Image(source); // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - var operationsRunner = new ImageOperations(generated); + IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); operationsRunner.ApplyProcessors(operations); return generated; } @@ -96,5 +96,23 @@ namespace ImageSharp public static IImageOperations Run(this IImageOperations source, Action> operation) where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateImageProcessor(operation)); + + /// + /// Queues up a simple operation that provides access to the mutatable image. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// The operations to perform on the source. + /// returns the current optinoatins class to allow chaining of oprations. + internal static IImageOperations ApplyProcessors(this IImageOperations source, params IImageProcessor[] operations) + where TPixel : struct, IPixel + { + foreach (IImageProcessor op in operations) + { + source = source.ApplyProcessor(op); + } + + return source; + } } } diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 226d45132..834019633 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -103,11 +103,16 @@ namespace ImageSharp #if !NETSTANDARD1_1 /// - /// Gets or sets the fielsystem helper for accessing the local file system. + /// Gets or sets the filesystem helper for accessing the local file system. /// internal IFileSystem FileSystem { get; set; } = new LocalFileSystem(); #endif + /// + /// Gets or sets the image operations providers. + /// + internal IImageOperationsProvider ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); + /// /// Registers a new format provider. /// diff --git a/src/ImageSharp/IImageOperationsProvider.cs b/src/ImageSharp/IImageOperationsProvider.cs new file mode 100644 index 000000000..475c63265 --- /dev/null +++ b/src/ImageSharp/IImageOperationsProvider.cs @@ -0,0 +1,38 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using ImageSharp.PixelFormats; + + /// + /// Represents an interface that will create IImageOperations + /// + internal interface IImageOperationsProvider + { + /// + /// Called during Mutate operations to generate the imageoperations provider. + /// + /// The pixel format + /// The source image. + /// A new IImageOPeration + IImageOperations CreateMutator(Image source) + where TPixel : struct, IPixel; + } + + /// + /// The default implmentation of IImageOperationsProvider + /// + internal class DefaultImageOperationsProvider : IImageOperationsProvider + { + /// + public IImageOperations CreateMutator(Image source) + where TPixel : struct, IPixel + { + return new ImageOperations(source); + } + } +} diff --git a/src/ImageSharp/IImageOperations{TPixel}.cs b/src/ImageSharp/IImageOperations{TPixel}.cs index a176c0e28..349cef7f3 100644 --- a/src/ImageSharp/IImageOperations{TPixel}.cs +++ b/src/ImageSharp/IImageOperations{TPixel}.cs @@ -12,7 +12,7 @@ namespace ImageSharp using SixLabors.Primitives; /// - /// The static collection of all the default image formats + /// An interface to queue up image operations. /// /// The pixel format public interface IImageOperations diff --git a/src/ImageSharp/Processing/DelegateImageProcessor.cs b/src/ImageSharp/Processing/DelegateImageProcessor.cs index e1d1060c6..5fbb84114 100644 --- a/src/ImageSharp/Processing/DelegateImageProcessor.cs +++ b/src/ImageSharp/Processing/DelegateImageProcessor.cs @@ -29,6 +29,11 @@ namespace ImageSharp.Processing this.action = action; } + /// + /// Gets the action that will be applied to the image. + /// + internal Action> Action => this.action; + /// protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) { diff --git a/src/Shared/AssemblyInfo.Common.cs b/src/Shared/AssemblyInfo.Common.cs index 252ef3eae..c2aa13de2 100644 --- a/src/Shared/AssemblyInfo.Common.cs +++ b/src/Shared/AssemblyInfo.Common.cs @@ -37,4 +37,6 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("ImageSharp.Drawing")] [assembly: InternalsVisibleTo("ImageSharp.Benchmarks")] [assembly: InternalsVisibleTo("ImageSharp.Tests")] -[assembly: InternalsVisibleTo("ImageSharp.Sandbox46")] \ No newline at end of file +[assembly: InternalsVisibleTo("ImageSharp.Sandbox46")] + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs new file mode 100644 index 000000000..d6bea7108 --- /dev/null +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Text; +using ImageSharp.Processing; +using Xunit; + +namespace ImageSharp.Tests +{ + public abstract class BaseImageOperationsExtensionTest + { + protected readonly FakeImageOperationsProvider.FakeImageOperations operations; + + public BaseImageOperationsExtensionTest() + { + this.operations = new FakeImageOperationsProvider.FakeImageOperations(null); + } + + public T Verify(int index = 0) + { + var operation = this.operations.applied[index]; + + return Assert.IsType(operation.Processor); + } + } +} diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs new file mode 100644 index 000000000..b9a1d80a2 --- /dev/null +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -0,0 +1,77 @@ +namespace ImageSharp.Tests +{ + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using SixLabors.Primitives; + + public class FakeImageOperationsProvider : IImageOperationsProvider + { + private List ImageOperators = new List(); + + public bool HasCreated(Image source) + where TPixel : struct, IPixel + { + return Created(source).Any(); + } + public IEnumerable> Created(Image source) where TPixel : struct, IPixel + { + return this.ImageOperators.OfType>() + .Where(x => x.source == source); + } + + public IEnumerable.AppliedOpperation> AppliedOperations(Image source) where TPixel : struct, IPixel + { + return Created(source) + .SelectMany(x => x.applied); + } + + public IImageOperations CreateMutator(Image source) where TPixel : struct, IPixel + { + var op = new FakeImageOperations(source); + this.ImageOperators.Add(op); + return op; + } + + + public class FakeImageOperations : IImageOperations + where TPixel : struct, IPixel + { + public Image source; + + public List applied = new List(); + + public FakeImageOperations(Image source) + { + this.source = source; + } + + public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + applied.Add(new AppliedOpperation + { + Processor = processor, + Rectangle = rectangle + }); + return this; + } + + public IImageOperations ApplyProcessor(IImageProcessor processor) + { + applied.Add(new AppliedOpperation + { + Processor = processor + }); + return this; + } + public struct AppliedOpperation + { + public Rectangle? Rectangle { get; set; } + public IImageProcessor Processor { get; set; } + } + } + } +} diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs new file mode 100644 index 000000000..61bb18e76 --- /dev/null +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -0,0 +1,120 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + + using ImageSharp.Formats; + using ImageSharp.IO; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using Moq; + using SixLabors.Primitives; + using Xunit; + + /// + /// Tests the configuration class. + /// + public class ImageOperationTests : IDisposable + { + private readonly Image image; + private readonly FakeImageOperationsProvider provider; + private readonly IImageProcessor processor; + + public Configuration Configuration { get; private set; } + + public ImageOperationTests() + { + this.provider = new FakeImageOperationsProvider(); + this.processor = new Mock>().Object; + this.image = new Image(new Configuration() + { + ImageOperationsProvider = this.provider + }, 1, 1); + } + + [Fact] + public void MutateCallsImageOperationsProvider_Func_OriginalImage() + { + this.image.Mutate(x => x.ApplyProcessor(this.processor)); + + Assert.True(this.provider.HasCreated(this.image)); + Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x=>x.Processor)); + } + + [Fact] + public void MutateCallsImageOperationsProvider_ListOfProcessors_OriginalImage() + { + this.image.Mutate(this.processor); + + Assert.True(this.provider.HasCreated(this.image)); + Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_Func_WithDuplicateImage() + { + var returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); + + Assert.True(this.provider.HasCreated(returned)); + Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_ListOfProcessors_WithDuplicateImage() + { + var returned = this.image.Clone(this.processor); + + Assert.True(this.provider.HasCreated(returned)); + Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_Func_NotOnOrigional() + { + var returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); + Assert.False(this.provider.HasCreated(this.image)); + Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOrigional() + { + var returned = this.image.Clone(this.processor); + Assert.False(this.provider.HasCreated(this.image)); + Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.Processor)); + } + + [Fact] + public void ApplyProcessors_ListOfProcessors_AppliesALlProcessorsToOperation() + { + var operations = new FakeImageOperationsProvider.FakeImageOperations(null); + operations.ApplyProcessors(this.processor); + Assert.Contains(this.processor, operations.applied.Select(x => x.Processor)); + } + + public void Dispose() + { + this.image.Dispose(); + } + } + + public class RunImageOperation : BaseImageOperationsExtensionTest + { + [Fact] + public void Run_CreatedDelegateProcessor() + { + Action> action = (i) => { }; + this.operations.Run(action); + + DelegateImageProcessor processor = this.Verify>(); + Assert.Equal(action, processor.Action); + } + } +} \ No newline at end of file From c3f7f8395ebf68de40a8e821a8cf660ec7abec32 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 11 Jul 2017 19:01:01 +0100 Subject: [PATCH 07/20] move methods --- src/ImageSharp/ApplyProcessors.cs | 11 ------- src/ImageSharp/Processing/Delegate.cs | 30 +++++++++++++++++++ .../DelegateProcessor.cs} | 8 ++--- .../{ => Processors}/ImageProcessor.cs | 0 4 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 src/ImageSharp/Processing/Delegate.cs rename src/ImageSharp/Processing/{DelegateImageProcessor.cs => Processors/DelegateProcessor.cs} (81%) rename src/ImageSharp/Processing/{ => Processors}/ImageProcessor.cs (100%) diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index a092b789b..9287c8367 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -85,16 +85,5 @@ namespace ImageSharp operationsRunner.ApplyProcessors(operations); return generated; } - - /// - /// Queues up a simple operation that provides access to the mutatable image. - /// - /// The pixel format. - /// The image to rotate, flip, or both. - /// 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) - where TPixel : struct, IPixel - => source.ApplyProcessor(new DelegateImageProcessor(operation)); } } diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs new file mode 100644 index 000000000..52ec736f5 --- /dev/null +++ b/src/ImageSharp/Processing/Delegate.cs @@ -0,0 +1,30 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + + using ImageSharp.PixelFormats; + + using ImageSharp.Processing; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Queues up a simple operation that provides access to the mutatable image. + /// + /// The pixel format. + /// The image to rotate, flip, or both. + /// 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) + where TPixel : struct, IPixel + => source.ApplyProcessor(new DelegateProcessor(operation)); + } +} diff --git a/src/ImageSharp/Processing/DelegateImageProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs similarity index 81% rename from src/ImageSharp/Processing/DelegateImageProcessor.cs rename to src/ImageSharp/Processing/Processors/DelegateProcessor.cs index e1d1060c6..f0d691777 100644 --- a/src/ImageSharp/Processing/DelegateImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,16 +15,16 @@ namespace ImageSharp.Processing /// Allows the application of processors to images. /// /// The pixel format. - internal class DelegateImageProcessor : ImageProcessor + internal class DelegateProcessor : ImageProcessor where TPixel : struct, IPixel { private readonly Action> action; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The action. - public DelegateImageProcessor(Action> action) + public DelegateProcessor(Action> action) { this.action = action; } diff --git a/src/ImageSharp/Processing/ImageProcessor.cs b/src/ImageSharp/Processing/Processors/ImageProcessor.cs similarity index 100% rename from src/ImageSharp/Processing/ImageProcessor.cs rename to src/ImageSharp/Processing/Processors/ImageProcessor.cs From f7cbb279955090eacecccec6a08a8f026b605140 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 11 Jul 2017 22:13:24 +0100 Subject: [PATCH 08/20] test extensions methods --- src/ImageSharp/ApplyProcessors.cs | 15 +- src/ImageSharp/Numerics/ValueSize.cs | 9 +- .../Processing/Binarization/Dither.cs | 36 ++- .../Processing/Convolution/BoxBlur.cs | 13 +- .../Processing/Convolution/DetectEdges.cs | 14 +- .../Processing/Convolution/GaussianBlur.cs | 12 +- .../Processing/Convolution/GaussianSharpen.cs | 13 +- src/ImageSharp/Processing/Delegate.cs | 1 + src/ImageSharp/Processing/Effects/Pixelate.cs | 13 +- .../Processing/Overlays/Vignette.cs | 4 +- .../ColorMatrix/SaturationProcessor.cs | 6 + .../Convolution/BoxBlurProcessor.cs | 6 + .../Convolution/GaussianBlurProcessor.cs | 5 + .../Convolution/GaussianSharpenProcessor.cs | 5 + .../Effects/BackgroundColorProcessor.cs | 5 + .../Processors/Overlays/GlowProcessor.cs | 5 + .../Processors/Overlays/VignetteProcessor.cs | 5 + .../Transforms/EntropyCropProcessor.cs | 6 +- .../BaseImageOperationsExtensionTest.cs | 16 + .../Drawing/Paths/FillPath.cs | 37 +-- .../Drawing/Paths/FillPathCollection.cs | 32 +- .../Drawing/Paths/FillPolygon.cs | 33 +-- .../Drawing/Paths/FillRectangle.cs | 40 +-- .../Drawing/Paths/ProcessorWatchingImage.cs | 40 --- .../Drawing/Text/DrawText.Path.cs | 137 +++++---- .../ImageSharp.Tests/Drawing/Text/DrawText.cs | 138 +++++---- tests/ImageSharp.Tests/ImageOperationTests.cs | 13 - .../Binarization/BinaryThresholdTest.cs | 43 +-- .../Processing/Binarization/DitherTest.cs | 112 ++++--- .../Processing/ColorMatrix/BlackWhiteTest.cs | 34 +-- .../ColorMatrix/ColorBlindnessTest.cs | 57 ++-- .../Processing/ColorMatrix/GrayscaleTest.cs | 60 ++-- .../Processing/ColorMatrix/HueTest.cs | 41 +-- .../Processing/ColorMatrix/KodachromeTest.cs | 34 +-- .../Processing/ColorMatrix/LomographTest.cs | 34 +-- .../Processing/ColorMatrix/PolaroidTest.cs | 34 +-- .../Processing/ColorMatrix/SaturationTest.cs | 42 +-- .../Processing/ColorMatrix/SepiaTest.cs | 34 +-- .../Processing/Convolution/BoxBlurTest.cs | 48 ++- .../Processing/Convolution/DetectEdgesTest.cs | 79 ++--- .../Convolution/GaussianBlurTest.cs | 48 ++- .../Convolution/GaussianSharpenTest.cs | 48 ++- .../Processing/DelegateTest.cs | 25 ++ .../Processing/Effects/AlphaTest.cs | 41 +-- .../Processing/Effects/BackgroundColorTest.cs | 56 ++-- .../Processing/Effects/BrightnessTest.cs | 41 +-- .../Processing/Effects/ContrastTest.cs | 41 +-- .../Processing/Effects/InvertTest.cs | 34 +-- .../Processing/Effects/OilPaintTest.cs | 64 ++-- .../Processing/Effects/PixelateTest.cs | 80 ++--- .../Processing/Overlays/GlowTest.cs | 76 +++-- .../Processing/Overlays/VignetteTest.cs | 81 +++--- .../Binarization/BinaryThresholdTest.cs | 51 ++++ .../Processors/Binarization/DitherTest.cs | 92 ++++++ .../Processors/ColorMatrix/BlackWhiteTest.cs | 43 +++ .../ColorMatrix/ColorBlindnessTest.cs | 57 ++++ .../Processors/ColorMatrix/GrayscaleTest.cs | 61 ++++ .../Processors/ColorMatrix/HueTest.cs | 50 ++++ .../Processors/ColorMatrix/KodachromeTest.cs | 43 +++ .../Processors/ColorMatrix/LomographTest.cs | 45 +++ .../Processors/ColorMatrix/PolaroidTest.cs | 43 +++ .../Processors/ColorMatrix/SaturationTest.cs | 50 ++++ .../Processors/ColorMatrix/SepiaTest.cs | 43 +++ .../Processors/Convolution/BoxBlurTest.cs | 50 ++++ .../Processors/Convolution/DetectEdgesTest.cs | 59 ++++ .../Convolution/GaussianBlurTest.cs | 50 ++++ .../Convolution/GaussianSharpenTest.cs | 50 ++++ .../Processors/Effects/AlphaTest.cs | 50 ++++ .../Processors/Effects/BackgroundColorTest.cs | 43 +++ .../Processors/Effects/BrightnessTest.cs | 50 ++++ .../Processors/Effects/ContrastTest.cs | 50 ++++ .../Processors/Effects/InvertTest.cs | 43 +++ .../Processors/Effects/OilPaintTest.cs | 50 ++++ .../Processors/Effects/PixelateTest.cs | 84 ++++++ .../Processors/Overlays/GlowTest.cs | 67 +++++ .../Processors/Overlays/VignetteTest.cs | 67 +++++ .../Processors/Transforms/AutoOrientTests.cs | 84 ++++++ .../Processors/Transforms/CropTest.cs | 26 ++ .../Processors/Transforms/EntropyCropTest.cs | 33 +++ .../Processors/Transforms/FlipTests.cs | 37 +++ .../Processors/Transforms/PadTest.cs | 35 +++ .../Transforms/ResizeProfilingBenchmarks.cs | 2 +- .../Processors/Transforms/ResizeTests.cs | 273 ++++++++++++++++++ .../Processors/Transforms/RotateFlipTests.cs | 39 +++ .../Processors/Transforms/RotateTests.cs | 55 ++++ .../Processors/Transforms/SkewTest.cs | 33 +++ .../Processing/Transforms/AutoOrientTests.cs | 73 +---- .../Processing/Transforms/CropTest.cs | 33 ++- .../Processing/Transforms/EntropyCropTest.cs | 26 +- .../Processing/Transforms/FlipTests.cs | 32 +- .../Processing/Transforms/PadTest.cs | 24 +- .../Processing/Transforms/ResizeTests.cs | 262 +---------------- .../Processing/Transforms/RotateFlipTests.cs | 44 +-- .../Processing/Transforms/RotateTests.cs | 64 ++-- .../Processing/Transforms/SkewTest.cs | 35 ++- tests/ImageSharp.Tests/TestFile.cs | 10 +- .../TestUtilities/TestType.cs | 28 ++ 97 files changed, 2941 insertions(+), 1544 deletions(-) delete mode 100644 tests/ImageSharp.Tests/Drawing/Paths/ProcessorWatchingImage.cs create mode 100644 tests/ImageSharp.Tests/Processing/DelegateTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs rename tests/ImageSharp.Tests/Processing/{ => Processors}/Transforms/ResizeProfilingBenchmarks.cs (97%) create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs create mode 100644 tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs create mode 100644 tests/ImageSharp.Tests/TestUtilities/TestType.cs diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 0e8195701..fd91349f5 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 5d81e2f95..af7454c19 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 614eabca7..ce5e8c205 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 f000a6aa4..1a89ac1a0 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 14bcf2059..b4382f902 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 7d551ceb8..91f563505 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 58c5ad12a..1fd003d12 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 52ec736f5..a6efb711b 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 cd0551ad3..8447f5ba1 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 535b75849..175d3ea3a 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 3adfb8311..ffc8eb6b1 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 0a2162fb0..93a925480 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 ef6ddaa6a..dcafd0d91 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 594dda8ca..84a7f9b09 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 96fcf4d63..96a2b704f 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 5a816da14..5da6a96dc 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 6a46692d2..07c45f4f0 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 16f74f218..a52065ea9 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 d6bea7108..398db976e 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 b80173bcf..c1e22e49c 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 8fe18713d..11ead13c1 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 2fd9a89b3..d833bf47b 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 56c7d5109..687c63068 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 1670b3352..000000000 --- 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 067ea122d..705c99d08 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>(1); + this.Verify>(2); + this.Verify>(3); + this.Verify>(4); + this.Verify>(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>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(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>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(1); } } } diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index d03af5456..0adf0141c 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/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>(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, 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>(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), 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>(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), 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>(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, 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 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, 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>(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,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>(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), 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>(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), 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>(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), 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>(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), Vector2.Zero, - new TextGraphicsOptions(true))); + new TextGraphicsOptions(true)); + + var processor = this.Verify>(0); + this.Verify>(1); + this.Verify>(2); - Assert.NotEmpty(this.img.ProcessorApplications); - Assert.Equal(6, this.img.ProcessorApplications.Count); + 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), 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>(0); + this.Verify>(1); + this.Verify>(2); + this.Verify>(3); + this.Verify>(4); + this.Verify>(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>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(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>(this.img.ProcessorApplications[0].processor); - Assert.IsType>(this.img.ProcessorApplications[1].processor); + var processor = this.Verify>(0); + this.Verify>(1); } } } diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs index 61bb18e76..a84b0fcb0 100644 --- a/tests/ImageSharp.Tests/ImageOperationTests.cs +++ b/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> action = (i) => { }; - this.operations.Run(action); - - DelegateImageProcessor processor = this.Verify>(); - Assert.Equal(action, processor.Action); - } - } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs index a8140aac7..b61df2035 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/BinaryThresholdTest.cs +++ b/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 BinaryThresholdValues - = new TheoryData - { - .25F, - .75F - }; - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] - public void ImageShouldApplyBinaryThresholdFilter(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void BinaryThreshold_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.BinaryThreshold(value)); - image.DebugSave(provider, value, Extensions.Bmp); - } + this.operations.BinaryThreshold(.23f); + var p = this.Verify>(); + Assert.Equal(.23f, p.Threshold); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] - public void ImageShouldApplyBinaryThresholdInBox(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void BinaryThreshold_rect_CorrectProcessor() { - - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); + Assert.Equal(.93f, p.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs index 25b34bfe4..bf67826b6 100644 --- a/tests/ImageSharp.Tests/Processing/Binarization/DitherTest.cs +++ b/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 Ditherers = new TheoryData - { - { "Ordered", new Ordered() }, - { "Bayer", new Bayer() } - }; + private readonly IOrderedDither orderedDither; + private readonly IErrorDiffuser errorDiffuser; - public static readonly TheoryData ErrorDiffusers = new TheoryData + 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(TestImageProvider provider, string name, IOrderedDither ditherer) - where TPixel : struct, IPixel + this.orderedDither = new Mock().Object; + this.errorDiffuser = new Mock().Object; + } + [Fact] + public void Dither_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Dither(ditherer)); - image.DebugSave(provider, name, Extensions.Bmp); - } + this.operations.Dither(orderedDither); + var p = this.Verify>(); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(0, p.Index); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(Ditherers), DefaultPixelType)] - public void ImageShouldApplyDitherFilterInBox(TestImageProvider provider, string name, IOrderedDither ditherer) - where TPixel : struct, IPixel + [Fact] + public void Dither_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(0, p.Index); } - - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] - public void ImageShouldApplyDiffusionFilter(TestImageProvider provider, string name, IErrorDiffuser diffuser) - where TPixel : struct, IPixel + [Fact] + public void Dither_index_CorrectProcessor() { - using (Image 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>(); + Assert.Equal(this.orderedDither, p.Dither); + Assert.Equal(2, p.Index); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ErrorDiffusers), DefaultPixelType)] - public void ImageShouldApplyDiffusionFilterInBox(TestImageProvider provider, string name, IErrorDiffuser diffuser) - where TPixel : struct, IPixel + [Fact] + public void Dither_index_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.Dither(orderedDither, this.rect, 2); + var p = this.Verify>(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>(); + 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>(this.rect); + Assert.Equal(this.errorDiffuser, p.Diffuser); + Assert.Equal(3, p.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs index 90c02be19..0608ee511 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/BlackWhiteTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BlackWhite_CorrectProcessor() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.BlackWhite()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.BlackWhite(); + var p = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBlackWhiteFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BlackWhite_rect_CorrectProcessor() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs index 9006e3e33..5f0fe06e4 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/ColorBlindnessTest.cs +++ b/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 ColorBlindnessFilters - = new TheoryData - { - ColorBlindness.Achromatomaly, - ColorBlindness.Achromatopsia, - ColorBlindness.Deuteranomaly, - ColorBlindness.Deuteranopia, - ColorBlindness.Protanomaly, - ColorBlindness.Protanopia, - ColorBlindness.Tritanomaly, - ColorBlindness.Tritanopia + public static IEnumerable TheoryData = new[] { + new object[]{ new TestType>(), ColorBlindness.Achromatomaly }, + new object[]{ new TestType>(), ColorBlindness.Achromatopsia }, + new object[]{ new TestType>(), ColorBlindness.Deuteranomaly }, + new object[]{ new TestType>(), ColorBlindness.Deuteranopia }, + new object[]{ new TestType>(), ColorBlindness.Protanomaly }, + new object[]{ new TestType>(), ColorBlindness.Protanopia }, + new object[]{ new TestType>(), ColorBlindness.Tritanomaly }, + new object[]{ new TestType>(), ColorBlindness.Tritanopia } }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] - public void ImageShouldApplyColorBlindnessFilter(TestImageProvider provider, ColorBlindness colorBlindness) - where TPixel : struct, IPixel + [MemberData(nameof(TheoryData))] + public void ColorBlindness_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + where T : IImageProcessor { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.ColorBlindness(colorBlindness)); - image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); - } + this.operations.ColorBlindness(colorBlindness); + var p = this.Verify(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ColorBlindnessFilters), DefaultPixelType)] - public void ImageShouldApplyColorBlindnessFilterInBox(TestImageProvider provider, ColorBlindness colorBlindness) - where TPixel : struct, IPixel + [MemberData(nameof(TheoryData))] + public void ColorBlindness_rect_CorrectProcessor(TestType testType, ColorBlindness colorBlindness) + where T : IImageProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(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(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs index 6dd0e8248..a4722261e 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/GrayscaleTest.cs +++ b/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 GrayscaleModeTypes - = new TheoryData - { - GrayscaleMode.Bt601, - GrayscaleMode.Bt709 - }; + public static IEnumerable ModeTheoryData = new[] { + new object[]{ new TestType>(), GrayscaleMode.Bt709 } + }; - /// - /// Use test patterns over loaded images to save decode time. - /// [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] - public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) - where TPixel : struct, IPixel + [MemberData(nameof(ModeTheoryData))] + public void Grayscale_mode_CorrectProcessor(TestType testType, GrayscaleMode mode) + where T : IImageProcessor { - using (Image 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(); - image.DebugSave(provider, value.ToString()); - } } [Theory] - [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] - public void ImageShouldApplyGrayscaleFilterInBox(TestImageProvider provider, GrayscaleMode value) - where TPixel : struct, IPixel + [MemberData(nameof(ModeTheoryData))] + public void Grayscale_mode_rect_CorrectProcessor(TestType testType, GrayscaleMode mode) + where T : IImageProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(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(this.rect); + } - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + [Fact] + public void Grayscale_rect_CorrectProcessor() + { + this.operations.Grayscale(this.rect); + this.Verify>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs index 1fe56a8be..413299085 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/HueTest.cs +++ b/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 HueValues - = new TheoryData + [Fact] + public void Hue_amount_HueProcessorDefaultsSet() { - 180, - -180 - }; + this.operations.Hue(34f); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] - public void ImageShouldApplyHueFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Hue_amount_rect_HueProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5f, processor.Angle); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs index 779ca0f6b..dcffd4b4f 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/KodachromeTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Kodachrome_amount_KodachromeProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Kodachrome()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Kodachrome(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyKodachromeFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Kodachrome_amount_rect_KodachromeProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs index ebfacb720..5b468bfde 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/LomographTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Lomograph_amount_LomographProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Lomograph()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Lomograph(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyLomographFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Lomograph_amount_rect_LomographProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs index 54836cedf..245bc47c5 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/PolaroidTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Polaroid_amount_PolaroidProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Polaroid()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Polaroid(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyPolaroidFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Polaroid_amount_rect_PolaroidProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs index 73c3f98b5..58df89db6 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SaturationTest.cs +++ b/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 SaturationValues - = new TheoryData - { - 50 , - -50 , - }; - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] - public void ImageShouldApplySaturationFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Saturation_amount_SaturationProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Saturation(value)); - image.DebugSave(provider, value, Extensions.Bmp); - } + this.operations.Saturation(34); + var processor = this.Verify>(); + + Assert.Equal(34, processor.Amount); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] - public void ImageShouldApplySaturationFilterInBox(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Saturation_amount_rect_SaturationProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5, processor.Amount); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs index ae7865c11..3fa1f081a 100644 --- a/tests/ImageSharp.Tests/Processing/ColorMatrix/SepiaTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Sepia_amount_SepiaProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Sepia()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Sepia(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplySepiaFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Sepia_amount_rect_SepiaProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs index 58a2665d0..e4c185114 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/BoxBlurTest.cs +++ b/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 BoxBlurValues - = new TheoryData + [Fact] + public void BoxBlur_BoxBlurProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.BoxBlur(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] - public void ImageShouldApplyBoxBlurFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void BoxBlur_amount_BoxBlurProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.BoxBlur(34); + var processor = this.Verify>(); + + 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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(5, processor.Radius); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs index 9f3a2d79a..0377953a6 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/DetectEdgesTest.cs +++ b/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 DetectEdgesFilters - = new TheoryData + + [Fact] + public void DetectEdges_SobelProcessorDefaultsSet() + { + this.operations.DetectEdges(); + var processor = this.Verify>(); + + 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>(this.rect); + + Assert.True(processor.Grayscale); + } + public static IEnumerable EdgeDetectionTheoryData => new[] { + new object[]{ new TestType>(), EdgeDetection.Kayyali }, + new object[]{ new TestType>(), EdgeDetection.Kirsch }, + new object[]{ new TestType>(), EdgeDetection.Lapacian3X3 }, + new object[]{ new TestType>(), EdgeDetection.Lapacian5X5 }, + new object[]{ new TestType>(), EdgeDetection.LaplacianOfGaussian }, + new object[]{ new TestType>(), EdgeDetection.Prewitt }, + new object[]{ new TestType>(), EdgeDetection.RobertsCross }, + new object[]{ new TestType>(), EdgeDetection.Robinson }, + new object[]{ new TestType>(), EdgeDetection.Scharr }, + new object[]{ new TestType>(), EdgeDetection.Sobel }, }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilter(TestImageProvider provider, EdgeDetection detector) - where TPixel : struct, IPixel + [MemberData(nameof(EdgeDetectionTheoryData))] + public void DetectEdges_filter_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + where TProcessor : IEdgeDetectorProcessor { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.DetectEdges(detector)); - image.DebugSave(provider, detector.ToString(), Extensions.Bmp); - } + this.operations.DetectEdges(filter); + var processor = this.Verify(); + + Assert.True(processor.Grayscale); } [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(DetectEdgesFilters), DefaultPixelType)] - public void ImageShouldApplyDetectEdgesFilterInBox(TestImageProvider provider, EdgeDetection detector) - where TPixel : struct, IPixel + [MemberData(nameof(EdgeDetectionTheoryData))] + public void DetectEdges_filter_grayscale_SobelProcessorDefaultsSet(TestType type, EdgeDetection filter) + where TProcessor : IEdgeDetectorProcessor { - using (Image source = provider.GetImage()) - using (var image = new Image(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(); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(grey, processor.Grayscale); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs index 763e806af..8b2e4c634 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianBlurTest.cs +++ b/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 GaussianBlurValues - = new TheoryData + [Fact] + public void GaussianBlur_GaussianBlurProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.GaussianBlur(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] - public void ImageShouldApplyGaussianBlurFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void GaussianBlur_amount_GaussianBlurProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.GaussianBlur(0.2f); + var processor = this.Verify>(); + + 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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Sigma); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs index 6313bc72a..e381ad7e9 100644 --- a/tests/ImageSharp.Tests/Processing/Convolution/GaussianSharpenTest.cs +++ b/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 GaussianSharpenValues - = new TheoryData + [Fact] + public void GaussianSharpen_GaussianSharpenProcessorDefaultsSet() { - 3, - 5 - }; + this.operations.GaussianSharpen(); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] - public void ImageShouldApplyGaussianSharpenFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void GaussianSharpen_amount_GaussianSharpenProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.GaussianSharpen(0.2f); + var processor = this.Verify>(); + + 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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Sigma); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/DelegateTest.cs b/tests/ImageSharp.Tests/Processing/DelegateTest.cs new file mode 100644 index 000000000..73011bee1 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/DelegateTest.cs @@ -0,0 +1,25 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing +{ + using System; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using Xunit; + + public class DelegateTest : BaseImageOperationsExtensionTest + { + [Fact] + public void Run_CreatedDelegateProcessor() + { + Action> action = (i) => { }; + this.operations.Run(action); + + DelegateProcessor processor = this.Verify>(); + Assert.Equal(action, processor.Action); + } + } +} diff --git a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs index e01e67e18..960ab4509 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/AlphaTest.cs +++ b/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 AlphaValues - = new TheoryData + [Fact] + public void Alpha_amount_AlphaProcessorDefaultsSet() { - 20/100F, - 80/100F - }; + this.operations.Alpha(0.2f); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] - public void ImageShouldApplyAlphaFilter(TestImageProvider provider, float value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [Fact] + public void Alpha_amount_rect_AlphaProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(.6f, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index 55f11b8b5..8de7b675a 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BackgroundColor_amount_BackgroundColorProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.BackgroundColor(NamedColors.HotPink)); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.BackgroundColor(Rgba32.BlanchedAlmond); + var processor = this.Verify>(); + + 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>(this.rect); + + Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyBackgroundColorFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.options); + var processor = this.Verify>(); + + Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); + } - image.Mutate(x => x.BackgroundColor(NamedColors.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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(this.options, processor.GraphicsOptions); + Assert.Equal(Rgba32.BlanchedAlmond, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs index 081fdf319..e9a9a49b6 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BrightnessTest.cs +++ b/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 BrightnessValues - = new TheoryData + [Fact] + public void Brightness_amount_BrightnessProcessorDefaultsSet() { - 50, - -50 - }; + this.operations.Brightness(23); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] - public void ImageShouldApplyBrightnessFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Brightness_amount_rect_BrightnessProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ; - } + Assert.Equal(23, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs index 2c2ef1403..392c407f3 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/ContrastTest.cs +++ b/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 ContrastValues - = new TheoryData + [Fact] + public void Contrast_amount_ContrastProcessorDefaultsSet() { - 50, - -50 - }; + this.operations.Contrast(23); + var processor = this.Verify>(); - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] - public void ImageShouldApplyContrastFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Contrast_amount_rect_ContrastProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(23, processor.Value); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs index 7d79517bc..794cb65b8 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/InvertTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Invert_InvertProcessorDefaultsSet() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Invert()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Invert(); + var processor = this.Verify>(); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] - public void ImageShouldApplyInvertFilterInBox(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Pixelate_rect_PixelateProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(this.rect); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs index 002d57d84..b96887c76 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/OilPaintTest.cs @@ -3,48 +3,52 @@ // Licensed under the Apache License, Version 2.0. // -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 OilPaintValues - = new TheoryData - { - { 15, 10 }, - { 6, 5 } - }; - - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] - public void ImageShouldApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize) - where TPixel : struct, IPixel + [Fact] + public void OilPaint_OilPaintingProcessorDefaultsSet() { - using (Image 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>(); + + Assert.Equal(10, processor.Levels); + Assert.Equal(15, processor.BrushSize); } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] - public void ImageShouldApplyOilPaintFilterInBox(TestImageProvider provider, int levels, int brushSize) - where TPixel : struct, IPixel + [Fact] + public void OilPaint_rect_OilPaintingProcessorDefaultsSet() + { + this.operations.OilPaint(this.rect); + var processor = this.Verify>(this.rect); + + Assert.Equal(10, processor.Levels); + Assert.Equal(15, processor.BrushSize); + } + [Fact] + public void OilPaint_Levels_Brsuh_OilPaintingProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(source)) - { - var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + this.operations.OilPaint(34, 65); + var processor = this.Verify>(); - 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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); - } + Assert.Equal(54, processor.Levels); + Assert.Equal(43, processor.BrushSize); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs index 3a6e273d0..bcd35af16 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/PixelateTest.cs +++ b/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 PixelateValues - = new TheoryData + [Fact] + public void Pixelate_PixelateProcessorDefaultsSet() { - 4 , - 8 - }; + this.operations.Pixelate(); + var processor = this.Verify>(); - [Theory] - [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] - public void ImageShouldApplyPixelateFilter(TestImageProvider provider, int value) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, int value) - where TPixel : struct, IPixel + [Fact] + public void Pixelate_Size_PixelateProcessorDefaultsSet() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(); - 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>(this.rect); - ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); - } + Assert.Equal(23, processor.Size); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs index 20e521c8d..223129877 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/GlowTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_GlowProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Glow()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Glow(); + var p = this.Verify>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Color_GlowProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Glow(NamedColors.Orange)); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Glow(Rgba32.Aquamarine); + var p = this.Verify>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Radux_GlowProcessorWithDefaultValues() { - using (Image 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>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Glow_Rect_GlowProcessorWithDefaultValues() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs index 74c5296fa..f93ca186f 100644 --- a/tests/ImageSharp.Tests/Processing/Overlays/VignetteTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_VignetteProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Vignette()); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Vignette(); + var p = this.Verify>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Color_VignetteProcessorWithDefaultValues() { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Vignette(NamedColors.Orange)); - image.DebugSave(provider, null, Extensions.Bmp); - } + this.operations.Vignette(Rgba32.Aquamarine); + var p = this.Verify>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Radux_VignetteProcessorWithDefaultValues() { - using (Image 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>(); + + 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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact] + public void Vignette_Rect_VignetteProcessorWithDefaultValues() { - using (Image source = provider.GetImage()) - using (var image = new Image(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>(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); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs new file mode 100644 index 000000000..3e8c99e35 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -0,0 +1,51 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Binarization +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class BinaryThresholdTest : FileTestBase + { + public static readonly TheoryData BinaryThresholdValues + = new TheoryData + { + .25F, + .75F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BinaryThresholdValues), DefaultPixelType)] + public void ImageShouldApplyBinaryThresholdFilter(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BinaryThreshold(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs new file mode 100644 index 000000000..0a4ccaeb1 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs @@ -0,0 +1,92 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 Ditherers = new TheoryData + { + { "Ordered", new Ordered() }, + { "Bayer", new Bayer() } + }; + + public static readonly TheoryData ErrorDiffusers = new TheoryData + { + { "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(TestImageProvider provider, string name, IOrderedDither ditherer) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IOrderedDither ditherer) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.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(TestImageProvider provider, string name, IErrorDiffuser diffuser) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IErrorDiffuser diffuser) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Dither(diffuser, .5F, bounds)); + image.DebugSave(provider, name, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs new file mode 100644 index 000000000..5b4953d60 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BlackWhite()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBlackWhiteFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BlackWhite(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs new file mode 100644 index 000000000..6d2df4c9b --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -0,0 +1,57 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 ColorBlindnessFilters + = new TheoryData + { + 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(TestImageProvider provider, ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, ColorBlindness colorBlindness) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.ColorBlindness(colorBlindness, bounds)); + image.DebugSave(provider, colorBlindness.ToString(), Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs new file mode 100644 index 000000000..3fba626c2 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -0,0 +1,61 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 GrayscaleModeTypes + = new TheoryData + { + GrayscaleMode.Bt601, + GrayscaleMode.Bt709 + }; + + /// + /// Use test patterns over loaded images to save decode time. + /// + [Theory] + [WithTestPatternImages(nameof(GrayscaleModeTypes), 50, 50, DefaultPixelType)] + public void ImageShouldApplyGrayscaleFilterAll(TestImageProvider provider, GrayscaleMode value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, GrayscaleMode value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(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); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs new file mode 100644 index 000000000..1019e2def --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class HueTest : FileTestBase + { + public static readonly TheoryData HueValues + = new TheoryData + { + 180, + -180 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(HueValues), DefaultPixelType)] + public void ImageShouldApplyHueFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Hue(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs new file mode 100644 index 000000000..9e7c2c02f --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Kodachrome()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyKodachromeFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Kodachrome(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs new file mode 100644 index 000000000..d44f7005f --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -0,0 +1,45 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Lomograph()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyLomographFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Lomograph(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs new file mode 100644 index 000000000..29ae45be4 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Polaroid()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyPolaroidFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Polaroid(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs new file mode 100644 index 000000000..df0af2bb6 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.ColorMatrix +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class SaturationTest : FileTestBase + { + public static readonly TheoryData SaturationValues + = new TheoryData + { + 50 , + -50 , + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(SaturationValues), DefaultPixelType)] + public void ImageShouldApplySaturationFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Saturation(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs new file mode 100644 index 000000000..82bd4b26e --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Sepia()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplySepiaFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Sepia(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs new file mode 100644 index 000000000..71b5ee69b --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Convolution +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class BoxBlurTest : FileTestBase + { + public static readonly TheoryData BoxBlurValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BoxBlurValues), DefaultPixelType)] + public void ImageShouldApplyBoxBlurFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BoxBlur(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs new file mode 100644 index 000000000..7a5dbc1fc --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -0,0 +1,59 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 DetectEdgesFilters + = new TheoryData + { + 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(TestImageProvider provider, EdgeDetection detector) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, EdgeDetection detector) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.DetectEdges(detector, bounds)); + image.DebugSave(provider, detector.ToString(), Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs new file mode 100644 index 000000000..5bb372e54 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Convolution +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class GaussianBlurTest : FileTestBase + { + public static readonly TheoryData GaussianBlurValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianBlurValues), DefaultPixelType)] + public void ImageShouldApplyGaussianBlurFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.GaussianBlur(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs new file mode 100644 index 000000000..71eae5b09 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Convolution +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class GaussianSharpenTest : FileTestBase + { + public static readonly TheoryData GaussianSharpenValues + = new TheoryData + { + 3, + 5 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(GaussianSharpenValues), DefaultPixelType)] + public void ImageShouldApplyGaussianSharpenFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.GaussianSharpen(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs new file mode 100644 index 000000000..c29267b10 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Effects +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class AlphaTest : FileTestBase + { + public static readonly TheoryData AlphaValues + = new TheoryData + { + 20/100F, + 80/100F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(AlphaValues), DefaultPixelType)] + public void ImageShouldApplyAlphaFilter(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Alpha(value, bounds)); + image.DebugSave(provider, value, Extensions.Png); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs new file mode 100644 index 000000000..2e2768115 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink)); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyBackgroundColorFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.BackgroundColor(NamedColors.HotPink, bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs new file mode 100644 index 000000000..abd9951ab --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Effects +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class BrightnessTest : FileTestBase + { + public static readonly TheoryData BrightnessValues + = new TheoryData + { + 50, + -50 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(BrightnessValues), DefaultPixelType)] + public void ImageShouldApplyBrightnessFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Brightness(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); ; + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs new file mode 100644 index 000000000..c9d322a97 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Effects +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class ContrastTest : FileTestBase + { + public static readonly TheoryData ContrastValues + = new TheoryData + { + 50, + -50 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(ContrastValues), DefaultPixelType)] + public void ImageShouldApplyContrastFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Contrast(value, bounds)); + image.DebugSave(provider, value, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs new file mode 100644 index 000000000..839b1bb99 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -0,0 +1,43 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Invert()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyInvertFilterInBox(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Invert(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs new file mode 100644 index 000000000..17598c648 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -0,0 +1,50 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Effects +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class OilPaintTest : FileTestBase + { + public static readonly TheoryData OilPaintValues + = new TheoryData + { + { 15, 10 }, + { 6, 5 } + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(OilPaintValues), DefaultPixelType)] + public void ImageShouldApplyOilPaintFilter(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int levels, int brushSize) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.OilPaint(levels, brushSize, bounds)); + image.DebugSave(provider, string.Join("-", levels, brushSize), Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds, 0.001F); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs new file mode 100644 index 000000000..e24b359e3 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -0,0 +1,84 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Effects +{ + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + using Xunit; + + public class PixelateTest : FileTestBase + { + public static readonly TheoryData PixelateValues + = new TheoryData + { + 4 , + 8 + }; + + [Theory] + [WithTestPatternImages(nameof(PixelateValues), 320, 240, PixelTypes.Rgba32)] + public void ImageShouldApplyPixelateFilter(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, int value) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(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); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs new file mode 100644 index 000000000..cab607973 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -0,0 +1,67 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Glow()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilterColor(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Glow(NamedColors.Orange)); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyGlowFilterRadius(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Glow(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs new file mode 100644 index 000000000..6f856c686 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -0,0 +1,67 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Vignette()); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilterColor(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Vignette(NamedColors.Orange)); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldApplyVignetteFilterRadius(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image source = provider.GetImage()) + using (var image = new Image(source)) + { + var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); + + image.Mutate(x => x.Vignette(bounds)); + image.DebugSave(provider, null, Extensions.Bmp); + + ImageComparer.EnsureProcessorChangesAreConstrained(source, image, bounds); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs new file mode 100644 index 000000000..7ab49bc41 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/AutoOrientTests.cs @@ -0,0 +1,84 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 OrientationValues + = new TheoryData + { + { 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 InvalidOrientationValues + = new TheoryData + { + { 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(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, ExifDataType dataType, byte[] orientation) + where TPixel : struct, IPixel + { + 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 image = provider.GetImage()) + { + image.MetaData.ExifProfile = new ExifProfile(bytes); + image.Mutate(x=>x.AutoOrient()); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs new file mode 100644 index 000000000..951fdee5e --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/CropTest.cs @@ -0,0 +1,26 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Transforms +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class CropTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldCrop(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Crop(image.Width / 2, image.Height / 2)); + image.DebugSave(provider, null, Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs new file mode 100644 index 000000000..910925e8f --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/EntropyCropTest.cs @@ -0,0 +1,33 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Transforms +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class EntropyCropTest : FileTestBase + { + public static readonly TheoryData EntropyCropValues + = new TheoryData + { + .25F, + .75F + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)] + public void ImageShouldEntropyCrop(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.EntropyCrop(value)); + image.DebugSave(provider, value, Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs new file mode 100644 index 000000000..1ffccb80a --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/FlipTests.cs @@ -0,0 +1,37 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 FlipValues + = new TheoryData + { + { FlipType.None }, + { FlipType.Vertical }, + { FlipType.Horizontal }, + }; + + [Theory] + [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] + public void ImageShouldFlip(TestImageProvider provider, FlipType flipType) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Flip(flipType)); + image.DebugSave(provider, flipType, Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs new file mode 100644 index 000000000..9a0964538 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/PadTest.cs @@ -0,0 +1,35 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Transforms +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class PadTest : FileTestBase + { + [Theory] + [WithFileCollection(nameof(DefaultFiles), DefaultPixelType)] + public void ImageShouldPad(TestImageProvider provider) + where TPixel : struct, IPixel + { + using (Image 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]); + } + } + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs similarity index 97% rename from tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs rename to tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs index 7b83f0a8e..4e6fd024e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeProfilingBenchmarks.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeProfilingBenchmarks.cs @@ -3,7 +3,7 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Tests.Processing.Transforms +namespace ImageSharp.Tests.Processing.Processors.Transforms { using System; using System.IO; diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs new file mode 100644 index 000000000..813767edc --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/ResizeTests.cs @@ -0,0 +1,273 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 ReSamplers = + new TheoryData + { + { "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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, string name, IResampler sampler) + where TPixel : struct, IPixel + { + using (Image 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); + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs new file mode 100644 index 000000000..b0cafd114 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateFlipTests.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +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 RotateFlipValues + = new TheoryData + { + { 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(TestImageProvider provider, RotateType rotateType, FlipType flipType) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.RotateFlip(rotateType, flipType)); + image.DebugSave(provider, string.Join("_", rotateType, flipType), Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs new file mode 100644 index 000000000..74afd0240 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/RotateTests.cs @@ -0,0 +1,55 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Transforms +{ + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + + using Xunit; + + public class RotateTests : FileTestBase + { + public static readonly TheoryData RotateFloatValues + = new TheoryData + { + 170, + -170 + }; + + public static readonly TheoryData RotateEnumValues + = new TheoryData + { + RotateType.None, + RotateType.Rotate90, + RotateType.Rotate180, + RotateType.Rotate270 + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), DefaultPixelType)] + public void ImageShouldRotate(TestImageProvider provider, float value) + where TPixel : struct, IPixel + { + using (Image 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(TestImageProvider provider, RotateType value) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(x => x.Rotate(value)); + image.DebugSave(provider, value, Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs new file mode 100644 index 000000000..64f4d4905 --- /dev/null +++ b/tests/ImageSharp.Tests/Processing/Processors/Transforms/SkewTest.cs @@ -0,0 +1,33 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Tests.Processing.Processors.Transforms +{ + using ImageSharp.PixelFormats; + + using Xunit; + + public class SkewTest : FileTestBase + { + public static readonly TheoryData SkewValues + = new TheoryData + { + { 20, 10 }, + { -20, -10 } + }; + + [Theory] + [WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] + public void ImageShouldSkew(TestImageProvider provider, float x, float y) + where TPixel : struct, IPixel + { + using (Image image = provider.GetImage()) + { + image.Mutate(i => i.Skew(x, y)); + image.DebugSave(provider, string.Join("_", x, y), Extensions.Bmp); + } + } + } +} \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs index 3799054be..c26c957a0 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/AutoOrientTests.cs +++ b/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 OrientationValues - = new TheoryData - { - { 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 InvalidOrientationValues - = new TheoryData + [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(TestImageProvider provider, RotateType rotateType, FlipType flipType, ushort orientation) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, ExifDataType dataType, byte[] orientation) - where TPixel : struct, IPixel - { - 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 image = provider.GetImage()) - { - image.MetaData.ExifProfile = new ExifProfile(bytes); - image.Mutate(x=>x.AutoOrient()); - } + this.operations.AutoOrient(); + this.Verify>(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs index b95c9d82a..33f3ffb93 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/CropTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [InlineData(10, 10)] + [InlineData(12, 123)] + public void Crop_Width_height_CropProcessorWithRectangleSet(int width, int height) { - using (Image 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>(); + + 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>(); + + Assert.Equal(rect, processor.CropRectangle); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs index 1c97c70ad..11a7dc250 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/EntropyCropTest.cs +++ b/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 EntropyCropValues - = new TheoryData - { - .25F, - .75F - }; [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(EntropyCropValues), DefaultPixelType)] - public void ImageShouldEntropyCrop(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [InlineData(0.5f)] + [InlineData(.2f)] + public void EntropyCrop_threasholdFloat_EntropyCropProcessorWithThreshold(float threashold) { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.EntropyCrop(value)); - image.DebugSave(provider, value, Extensions.Bmp); - } + this.operations.EntropyCrop(threashold); + var processor = this.Verify>(); + + Assert.Equal(threashold, processor.Threshold); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs index 8e048ae04..5234baed7 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/FlipTests.cs +++ b/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 FlipValues - = new TheoryData - { - { FlipType.None }, - { FlipType.Vertical }, - { FlipType.Horizontal }, - }; [Theory] - [WithFileCollection(nameof(FlipFiles), nameof(FlipValues), DefaultPixelType)] - public void ImageShouldFlip(TestImageProvider provider, FlipType flipType) - where TPixel : struct, IPixel + [InlineData(FlipType.None)] + [InlineData(FlipType.Horizontal)] + [InlineData(FlipType.Vertical)] + public void Flip_degreesFloat_RotateProcessorWithAnglesSetAndExpandTrue(FlipType flip) { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Flip(flipType)); - image.DebugSave(provider, flipType, Extensions.Bmp); - } + this.operations.Flip(flip); + var flipProcessor = this.Verify>(); + + Assert.Equal(flip, flipProcessor.FlipType); } } -} \ No newline at end of file +} diff --git a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs index 7471330be..8b8d51f9f 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/PadTest.cs +++ b/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(TestImageProvider provider) - where TPixel : struct, IPixel + [Fact(Skip = "Skip this is a helper around resize, skip until resize can be refactord")] + public void Pad_width_height_ResizeProcessorWithCorrectOPtionsSet() { - using (Image 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"); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs index 0092ae9da..ae35740a9 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/ResizeTests.cs +++ b/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 ReSamplers = - new TheoryData - { - { "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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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(TestImageProvider provider, string name, IResampler sampler) - where TPixel : struct, IPixel - { - using (Image 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"); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs index 432b2549b..91505afa0 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateFlipTests.cs +++ b/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 RotateFlipValues - = new TheoryData - { - { 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(TestImageProvider provider, RotateType rotateType, FlipType flipType) - where TPixel : struct, IPixel + [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 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>(0); + var flipProcessor = this.Verify>(1); + + Assert.Equal(expectedAngle, rotateProcessor.Angle); + Assert.False(rotateProcessor.Expand); + Assert.Equal(flip, flipProcessor.FlipType); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs b/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs index 2db86390d..da2a34d0e 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/RotateTests.cs +++ b/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 RotateFloatValues - = new TheoryData - { - 170, - -170 - }; - public static readonly TheoryData RotateEnumValues - = new TheoryData + [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>(); + + Assert.Equal(angle, processor.Angle); + Assert.True(processor.Expand); + } + [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(RotateFloatValues), DefaultPixelType)] - public void ImageShouldRotate(TestImageProvider provider, float value) - where TPixel : struct, IPixel + [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 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>(); + + Assert.Equal(expectedangle, processor.Angle); + Assert.False(processor.Expand); } + [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(RotateEnumValues), DefaultPixelType)] - public void ImageShouldRotateEnum(TestImageProvider provider, RotateType value) - where TPixel : struct, IPixel + [InlineData(85.6f, false)] + [InlineData(21, true)] + [InlineData(21, false)] + public void Rotate_degreesFloat_expand_RotateProcessorWithAnglesSetAndExpandSet(float angle, bool expand) { - using (Image image = provider.GetImage()) - { - image.Mutate(x => x.Rotate(value)); - image.DebugSave(provider, value, Extensions.Bmp); - } + this.operations.Rotate(angle, expand); + var processor = this.Verify>(); + + Assert.Equal(angle, processor.Angle); + Assert.Equal(expand, processor.Expand); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs b/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs index 63924c535..6e7b2d8e8 100644 --- a/tests/ImageSharp.Tests/Processing/Transforms/SkewTest.cs +++ b/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 SkewValues - = new TheoryData + [Fact] + public void Skew_x_y_CreateSkewProcessorWithAnglesSetAndExpandTrue() { - { 20, 10 }, - { -20, -10 } - }; + this.operations.Skew(10, 20); + var processor = this.Verify>(); + + Assert.Equal(10, processor.AngleX); + Assert.Equal(20, processor.AngleY); + Assert.True(processor.Expand); + } - [Theory] - [WithFileCollection(nameof(DefaultFiles), nameof(SkewValues), DefaultPixelType)] - public void ImageShouldSkew(TestImageProvider provider, float x, float y) - where TPixel : struct, IPixel + [Fact] + public void Skew_x_y_expand_CreateSkewProcessorWithAnglesSetAndExpandTrue() { - using (Image 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>(); + + Assert.Equal(10, processor.AngleX); + Assert.Equal(20, processor.AngleY); + Assert.False(processor.Expand); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index c0f9deebb..f634eb3f4 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -29,10 +29,13 @@ namespace ImageSharp.Tests /// private static readonly string FormatsDirectory = GetFormatsDirectory(); + private Image _image; + private byte[] _bytes; + /// /// The image. /// - private readonly Image image; + private Image image => this._image ?? (this._image = Image.Load(this.Bytes)); /// /// 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(this.Bytes); } /// /// Gets the bytes. /// - public byte[] Bytes { get; } + public byte[] Bytes => this._bytes ?? (this._bytes = File.ReadAllBytes(this.file)); /// /// The file name. diff --git a/tests/ImageSharp.Tests/TestUtilities/TestType.cs b/tests/ImageSharp.Tests/TestUtilities/TestType.cs new file mode 100644 index 000000000..adba1f971 --- /dev/null +++ b/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 : IXunitSerializable + { + public TestType() + { + } + + public void Deserialize(IXunitSerializationInfo info) + { + } + + public void Serialize(IXunitSerializationInfo info) + { + } + + public override string ToString() + { + return $"Type<{typeof(T).Name}>"; + } + } +} From 04b6ad824c657abe8a59babc3466f30516894a81 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 11 Jul 2017 22:18:23 +0100 Subject: [PATCH 09/20] fix warnings --- samples/AvatarWithRoundedCorner/Program.cs | 1 - src/ImageSharp/Processing/Binarization/Dither.cs | 3 +-- src/ImageSharp/Processing/Convolution/BoxBlur.cs | 1 - src/ImageSharp/Processing/Convolution/DetectEdges.cs | 1 - src/ImageSharp/Processing/Convolution/GaussianBlur.cs | 2 +- src/ImageSharp/Processing/Convolution/GaussianSharpen.cs | 1 - src/ImageSharp/Processing/Delegate.cs | 1 - src/ImageSharp/Processing/Effects/Pixelate.cs | 1 - .../General/PixelConversion_ConvertFromRgba32.cs | 2 +- .../General/PixelConversion_ConvertFromVector4.cs | 2 +- .../General/PixelConversion_ConvertToRgba32.cs | 2 +- 11 files changed, 5 insertions(+), 12 deletions(-) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index d519fc1ed..0cd484737 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -68,7 +68,6 @@ namespace AvatarWithRoundedCorner // corner is now a corner shape positions top left //lets make 3 more positioned correctly, we cando that by translating the orgional artound the center of the image var center = new Vector2(imageWidth / 2, imageHeight / 2); - var angle = Math.PI / 2f; float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index ce5e8c205..fc5193c33 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -23,7 +23,6 @@ namespace ImageSharp /// 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) where TPixel : struct, IPixel @@ -31,6 +30,7 @@ namespace ImageSharp source.ApplyProcessor(new OrderedDitherProcessor(dither, 0)); return source; } + /// /// Dithers the image reducing it to two colors using ordered dithering. /// @@ -55,7 +55,6 @@ namespace ImageSharp /// /// 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) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index 1a89ac1a0..cc0931215 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -22,7 +22,6 @@ namespace ImageSharp /// /// 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) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index b4382f902..18006752f 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -53,7 +53,6 @@ namespace ImageSharp /// 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) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index 91f563505..953a576fc 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -23,11 +23,11 @@ namespace ImageSharp /// /// 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) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(3f)); + /// /// Applies a Gaussian blur to the image. /// diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index 1fd003d12..1d0cce222 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -23,7 +23,6 @@ namespace ImageSharp /// /// 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) where TPixel : struct, IPixel diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs index a6efb711b..52ec736f5 100644 --- a/src/ImageSharp/Processing/Delegate.cs +++ b/src/ImageSharp/Processing/Delegate.cs @@ -26,6 +26,5 @@ 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 8447f5ba1..b9403b765 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -22,7 +22,6 @@ namespace ImageSharp /// /// The pixel format. /// The image this method extends. - /// The size of the pixels. /// The . public static IImageOperations Pixelate(this IImageOperations source) where TPixel : struct, IPixel diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs index e096fd828..0f025c9a4 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromRgba32.cs @@ -142,7 +142,7 @@ namespace ImageSharp.Benchmarks.General [Params(32)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.compatibleMemLayoutRunner = new ConversionRunner(this.Count); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs index 721ac121a..357ac307e 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertFromVector4.cs @@ -108,7 +108,7 @@ namespace ImageSharp.Benchmarks.General [Params(32)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.nonVectorRunner = new ConversionRunner(this.Count); diff --git a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs index 0c9a8af3f..88f607789 100644 --- a/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs +++ b/tests/ImageSharp.Benchmarks/General/PixelConversion_ConvertToRgba32.cs @@ -111,7 +111,7 @@ namespace ImageSharp.Benchmarks.General [Params(128)] public int Count { get; set; } - [Setup] + [GlobalSetup] public void Setup() { this.compatibleMemoryLayoutRunner = new ConversionRunner(this.Count); From c12f99354df137bb59920e7d3169c53b679b08bc Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 11 Jul 2017 22:25:54 +0100 Subject: [PATCH 10/20] fix sandbox test --- tests/ImageSharp.Sandbox46/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ImageSharp.Sandbox46/Program.cs b/tests/ImageSharp.Sandbox46/Program.cs index 6f93df16e..b536af71f 100644 --- a/tests/ImageSharp.Sandbox46/Program.cs +++ b/tests/ImageSharp.Sandbox46/Program.cs @@ -11,6 +11,7 @@ namespace ImageSharp.Sandbox46 using ImageSharp.Tests; using ImageSharp.Tests.Colors; using ImageSharp.Tests.PixelFormats; + using ImageSharp.Tests.Processing.Processors.Transforms; using ImageSharp.Tests.Processing.Transforms; using Xunit.Abstractions; From ab30013d635d924ed874a1c9c7a7c9ca7a418d45 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Fri, 14 Jul 2017 21:42:32 +0100 Subject: [PATCH 12/20] Renameing classes + simplifying Image --- samples/AvatarWithRoundedCorner/Program.cs | 2 +- src/ImageSharp.Drawing/DrawImage.cs | 12 +- src/ImageSharp.Drawing/FillRegion.cs | 18 +- src/ImageSharp.Drawing/Paths/DrawBeziers.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawLines.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPath.cs | 12 +- .../Paths/DrawPathCollection.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawPolygon.cs | 12 +- src/ImageSharp.Drawing/Paths/DrawRectangle.cs | 12 +- .../Paths/FillPathBuilder.cs | 8 +- .../Paths/FillPathCollection.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPaths.cs | 8 +- src/ImageSharp.Drawing/Paths/FillPolygon.cs | 8 +- src/ImageSharp.Drawing/Paths/FillRectangle.cs | 8 +- .../Processors/DrawImageProcessor.cs | 4 +- src/ImageSharp.Drawing/Text/DrawText.Path.cs | 16 +- src/ImageSharp.Drawing/Text/DrawText.cs | 16 +- src/ImageSharp/ApplyProcessors.cs | 32 +-- src/ImageSharp/Configuration.cs | 2 +- ...DefaultInternalImageProcessorApplicator.cs | 72 +++++++ ...cs => IImageProcessorApplicatorFactory.cs} | 11 +- ...s => IImageProcessorApplicator{TPixel}.cs} | 22 +- src/ImageSharp/Image/IImageBase.cs | 10 - src/ImageSharp/Image/ImageBase{TPixel}.cs | 30 +-- src/ImageSharp/Image/ImageExtensions.cs | 153 +++++++++++++ src/ImageSharp/Image/ImageFrame{TPixel}.cs | 44 ++-- .../Image/ImageProcessingExtensions.cs | 32 --- src/ImageSharp/Image/Image{TPixel}.cs | 204 ++++-------------- src/ImageSharp/ImageOperations.cs | 62 ------ .../PackedPixelConverterHelper.cs | 9 +- .../Binarization/BinaryThreshold.cs | 4 +- .../Processing/Binarization/Dither.cs | 12 +- .../Processing/ColorMatrix/BlackWhite.cs | 4 +- .../Processing/ColorMatrix/ColorBlindness.cs | 4 +- .../Processing/ColorMatrix/Grayscale.cs | 8 +- src/ImageSharp/Processing/ColorMatrix/Hue.cs | 4 +- .../Processing/ColorMatrix/Kodachrome.cs | 4 +- .../Processing/ColorMatrix/Lomograph.cs | 8 +- .../Processing/ColorMatrix/Polaroid.cs | 8 +- .../Processing/ColorMatrix/Saturation.cs | 4 +- .../Processing/ColorMatrix/Sepia.cs | 4 +- .../Processing/Convolution/BoxBlur.cs | 6 +- .../Processing/Convolution/DetectEdges.cs | 14 +- .../Processing/Convolution/GaussianBlur.cs | 6 +- .../Processing/Convolution/GaussianSharpen.cs | 6 +- src/ImageSharp/Processing/Delegate.cs | 2 +- src/ImageSharp/Processing/Effects/Alpha.cs | 4 +- .../Processing/Effects/BackgroundColor.cs | 8 +- .../Processing/Effects/Brightness.cs | 6 +- src/ImageSharp/Processing/Effects/Contrast.cs | 4 +- src/ImageSharp/Processing/Effects/Invert.cs | 4 +- .../Processing/Effects/OilPainting.cs | 8 +- src/ImageSharp/Processing/Effects/Pixelate.cs | 6 +- src/ImageSharp/Processing/Overlays/Glow.cs | 24 +-- .../Processing/Overlays/Vignette.cs | 24 +-- .../Convolution/Convolution2PassProcessor.cs | 2 +- .../EdgeDetectorCompassProcessor.cs | 4 +- .../Processors/Overlays/GlowProcessor.cs | 2 +- .../Processors/Overlays/VignetteProcessor.cs | 4 +- .../Transforms/EntropyCropProcessor.cs | 2 +- .../Processors/Transforms/RotateProcessor.cs | 3 +- .../Processors/Transforms/SkewProcessor.cs | 3 +- .../Processing/Transforms/AutoOrient.cs | 2 +- src/ImageSharp/Processing/Transforms/Crop.cs | 4 +- .../Processing/Transforms/EntropyCrop.cs | 2 +- src/ImageSharp/Processing/Transforms/Flip.cs | 2 +- src/ImageSharp/Processing/Transforms/Pad.cs | 2 +- .../Processing/Transforms/Resize.cs | 18 +- .../Processing/Transforms/Rotate.cs | 6 +- .../Processing/Transforms/RotateFlip.cs | 2 +- src/ImageSharp/Processing/Transforms/Skew.cs | 4 +- src/ImageSharp/Quantizers/Quantize.cs | 4 +- .../Quantizers/Quantizer{TPixel}.cs | 2 +- tests/ImageSharp.Benchmarks/Samplers/Glow.cs | 4 +- .../BaseImageOperationsExtensionTest.cs | 3 +- .../FakeImageOperationsProvider.cs | 30 ++- .../Formats/GeneralFormatTests.cs | 6 +- tests/ImageSharp.Tests/ImageOperationTests.cs | 4 +- .../Binarization/BinaryThresholdTest.cs | 2 +- .../Processors/Binarization/DitherTest.cs | 4 +- .../Processors/ColorMatrix/BlackWhiteTest.cs | 2 +- .../ColorMatrix/ColorBlindnessTest.cs | 2 +- .../Processors/ColorMatrix/GrayscaleTest.cs | 2 +- .../Processors/ColorMatrix/HueTest.cs | 2 +- .../Processors/ColorMatrix/KodachromeTest.cs | 2 +- .../Processors/ColorMatrix/LomographTest.cs | 2 +- .../Processors/ColorMatrix/PolaroidTest.cs | 2 +- .../Processors/ColorMatrix/SaturationTest.cs | 2 +- .../Processors/ColorMatrix/SepiaTest.cs | 2 +- .../Processors/Convolution/BoxBlurTest.cs | 2 +- .../Processors/Convolution/DetectEdgesTest.cs | 2 +- .../Convolution/GaussianBlurTest.cs | 2 +- .../Convolution/GaussianSharpenTest.cs | 2 +- .../Processors/Effects/AlphaTest.cs | 2 +- .../Processors/Effects/BackgroundColorTest.cs | 2 +- .../Processors/Effects/BrightnessTest.cs | 2 +- .../Processors/Effects/ContrastTest.cs | 2 +- .../Processors/Effects/InvertTest.cs | 2 +- .../Processors/Effects/OilPaintTest.cs | 2 +- .../Processors/Effects/PixelateTest.cs | 2 +- .../Processors/Overlays/GlowTest.cs | 2 +- .../Processors/Overlays/VignetteTest.cs | 2 +- tests/ImageSharp.Tests/TestFile.cs | 2 +- .../TestUtilities/Factories/GenericFactory.cs | 2 +- .../TestUtilities/Factories/ImageFactory.cs | 2 +- .../ImageProviders/TestImageProvider.cs | 2 +- .../ImageProviders/TestPatternProvider.cs | 2 +- 107 files changed, 633 insertions(+), 591 deletions(-) create mode 100644 src/ImageSharp/DefaultInternalImageProcessorApplicator.cs rename src/ImageSharp/{IImageOperationsProvider.cs => IImageProcessorApplicatorFactory.cs} (61%) rename src/ImageSharp/{IImageOperations{TPixel}.cs => IImageProcessorApplicator{TPixel}.cs} (54%) create mode 100644 src/ImageSharp/Image/ImageExtensions.cs delete mode 100644 src/ImageSharp/Image/ImageProcessingExtensions.cs delete mode 100644 src/ImageSharp/ImageOperations.cs diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index 0cd484737..f635ed203 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -36,7 +36,7 @@ namespace AvatarWithRoundedCorner } // lets create our custom image mutating pipeline - private static IImageOperations ConvertToAvatar(this IImageOperations operations, Size size, float cornerRadius) + private static IImageProcessorApplicator ConvertToAvatar(this IImageProcessorApplicator operations, Size size, float cornerRadius) { return operations.Resize(new ImageSharp.Processing.ResizeOptions { diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index bd51e4ac0..a7b1faa15 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The location to draw the blended image. /// The options. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, Size size, Point location, GraphicsOptions options) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) @@ -49,7 +49,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, float percent) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -66,7 +66,7 @@ namespace ImageSharp /// The blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, PixelBlenderMode blender, float percent) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -83,7 +83,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . - public static IImageOperations Blend(this IImageOperations source, Image image, GraphicsOptions options) + public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); @@ -99,7 +99,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, float percent, Size size, Point location) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -118,7 +118,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageOperations DrawImage(this IImageOperations source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) + public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index d8bb78e90..ff86c7240 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -23,10 +23,10 @@ namespace ImageSharp /// The details how to fill the region of interest. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillProcessor(brush, options)); + return source.ApplyProcessor(new FillProcessor(brush, options)); } /// @@ -36,7 +36,7 @@ namespace ImageSharp /// The image this method extends. /// The details how to fill the region of interest. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush) where TPixel : struct, IPixel { return source.Fill(brush, GraphicsOptions.Default); @@ -49,7 +49,7 @@ namespace ImageSharp /// The image this method extends. /// The color. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color)); @@ -64,10 +64,10 @@ namespace ImageSharp /// The region. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel { - return source.Apply(new FillRegionProcessor(brush, region, options)); + return source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); } /// @@ -78,7 +78,7 @@ namespace ImageSharp /// The brush. /// The region. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Region region) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region) where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); @@ -93,7 +93,7 @@ namespace ImageSharp /// The region. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region, options); @@ -107,7 +107,7 @@ namespace ImageSharp /// The color. /// The region. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Region region) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region); diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index d332f1d05..b83edb7a2 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawBeziers(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index db1e46af8..553ec2ca5 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The .> - public static IImageOperations DrawLines(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawLines(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index 57ce2032a..68ba89ff1 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path) where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path); @@ -86,7 +86,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPath path) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path); diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs index f909e98da..086ce9723 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath path in paths) @@ -44,7 +44,7 @@ namespace ImageSharp /// The pen. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(pen, paths, GraphicsOptions.Default); @@ -60,7 +60,7 @@ namespace ImageSharp /// The shapes. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths, options); @@ -75,7 +75,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths); @@ -91,7 +91,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths, options); @@ -106,7 +106,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, IPathCollection paths) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths); diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index b787afcd5..12b687415 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points, options); @@ -88,7 +88,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); @@ -103,7 +103,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations DrawPolygon(this IImageOperations source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index 544ca2fe9..a9832a628 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, IPen pen, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, IBrush brush, float thickness, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape); @@ -86,7 +86,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageOperations Draw(this IImageOperations source, TPixel color, float thickness, RectangleF shape) + public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape); diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs index eae34f034..38d3ad10f 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path, GraphicsOptions options) where TPixel : struct, IPixel { var pb = new PathBuilder(); @@ -42,7 +42,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, Action path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path) where TPixel : struct, IPixel { return source.Fill(brush, path, GraphicsOptions.Default); @@ -57,7 +57,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, Action path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs index 662245dc3..eec3fa795 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shapes. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath s in paths) @@ -43,7 +43,7 @@ namespace ImageSharp /// The brush. /// The paths. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPathCollection paths) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(brush, paths, GraphicsOptions.Default); @@ -58,7 +58,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths, options); @@ -72,7 +72,7 @@ namespace ImageSharp /// The color. /// The paths. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPathCollection paths) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths); diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index 07342d47b..7cd6dbe54 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, IPath path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, IPath path) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index 7feac5b0a..6b6cef8ac 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -27,7 +27,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -41,7 +41,7 @@ namespace ImageSharp /// The brush. /// The points. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, IBrush brush, PointF[] points) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -56,7 +56,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The color. /// The points. /// The . - public static IImageOperations FillPolygon(this IImageOperations source, TPixel color, PointF[] points) + public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index 52512ca1c..9e475137a 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The shape. /// The . - public static IImageOperations Fill(this IImageOperations source, IBrush brush, RectangleF shape) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); @@ -53,7 +53,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The shape. /// The . - public static IImageOperations Fill(this IImageOperations source, TPixel color, RectangleF shape) + public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs index 7154396dd..c5b92b408 100644 --- a/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawImageProcessor.cs @@ -68,13 +68,13 @@ namespace ImageSharp.Drawing.Processors try { - if (targetImage.Bounds.Size != this.Size) + if (targetImage.Size() != this.Size) { targetImage = disposableImage = this.Image.Clone(x => x.Resize(this.Size.Width, this.Size.Height)); } // Align start/end positions. - Rectangle bounds = this.Image.Bounds; + Rectangle bounds = this.Image.Bounds(); int minX = Math.Max(this.Location.X, sourceRectangle.X); int maxX = Math.Min(this.Location.X + bounds.Width, sourceRectangle.Width); maxX = Math.Min(this.Location.X + this.Size.Width, maxX); diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Text/DrawText.Path.cs index 459d5de0d..c109047b2 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.Path.cs @@ -31,7 +31,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); @@ -50,7 +50,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, path, options); @@ -68,7 +68,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); @@ -87,7 +87,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, path, options); @@ -105,7 +105,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); @@ -124,7 +124,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, path, options); @@ -143,7 +143,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); @@ -163,7 +163,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 989322a73..338d06058 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -34,7 +34,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, location, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); @@ -90,7 +90,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); @@ -127,7 +127,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); @@ -146,7 +146,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); @@ -166,7 +166,7 @@ namespace ImageSharp /// /// The . /// - public static IImageOperations DrawText(this IImageOperations source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index fd91349f5..78a5fc079 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -22,14 +22,15 @@ namespace ImageSharp /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. - public static void Mutate(this Image source, Action> operations) + public static void Mutate(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); operations(operationsRunner); + operationsRunner.Apply(); } /// @@ -42,10 +43,11 @@ namespace ImageSharp where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(source); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); operationsRunner.ApplyProcessors(operations); + operationsRunner.Apply(); } /// @@ -55,16 +57,15 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Clone(this Image source, Action> operations) + public static Image Clone(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); - var generated = new Image(source); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); operations(operationsRunner); - return generated; + return operationsRunner.Apply(); } /// @@ -78,12 +79,11 @@ namespace ImageSharp where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); - var generated = new Image(source); + Guard.NotNull(source, nameof(source)); - // TODO: add parameter to Configuration to configure how this is created, create an IImageOperationsFactory that cna be used to switch this out with a fake for testing - IImageOperations operationsRunner = source.Configuration.ImageOperationsProvider.CreateMutator(generated); + IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); operationsRunner.ApplyProcessors(operations); - return generated; + return operationsRunner.Apply(); } /// @@ -93,10 +93,10 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// returns the current optinoatins class to allow chaining of oprations. - public static IImageOperations ApplyProcessors(this IImageOperations source, params IImageProcessor[] operations) + public static IImageProcessorApplicator ApplyProcessors(this IImageProcessorApplicator source, params IImageProcessor[] operations) where TPixel : struct, IPixel { - foreach (var p in operations) + foreach (IImageProcessor p in operations) { source = source.ApplyProcessor(p); } diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index 834019633..b86819430 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -111,7 +111,7 @@ namespace ImageSharp /// /// Gets or sets the image operations providers. /// - internal IImageOperationsProvider ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); + internal IImageProcessorApplicatorFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); /// /// Registers a new format provider. diff --git a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs new file mode 100644 index 000000000..4dda4f070 --- /dev/null +++ b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs @@ -0,0 +1,72 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + using ImageSharp.PixelFormats; + using ImageSharp.Processing; + using SixLabors.Primitives; + + /// + /// The static collection of all the default image formats + /// + /// The pixel format + internal class DefaultInternalImageProcessorApplicator : IInternalImageProcessorApplicator + where TPixel : struct, IPixel + { + private readonly bool mutate; + private readonly Image source; + private Image destination; + + /// + /// Initializes a new instance of the class. + /// + /// The image. + /// The mutate. + public DefaultInternalImageProcessorApplicator(Image source, bool mutate) + { + this.mutate = mutate; + this.source = source; + if (this.mutate) + { + this.destination = source; + } + } + + /// + public Image Apply() + { + if (!this.mutate && this.destination == null) + { + // ensure we have cloned it if we are not mutating as we might have failed to register any Processors + this.destination = this.source.Clone(); + } + + return this.destination; + } + + /// + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + { + if (!this.mutate && this.destination == null) + { + // TODO check if the processor implements a special interface and if it does then allow it to take + // over and crereate the clone on behalf ImageOperations class. + this.destination = this.source.Clone(); + } + + processor.Apply(this.destination, rectangle); + return this; + } + + /// + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) + { + return this.ApplyProcessor(processor, this.source.Bounds()); + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/IImageOperationsProvider.cs b/src/ImageSharp/IImageProcessorApplicatorFactory.cs similarity index 61% rename from src/ImageSharp/IImageOperationsProvider.cs rename to src/ImageSharp/IImageProcessorApplicatorFactory.cs index 475c63265..b79353ef5 100644 --- a/src/ImageSharp/IImageOperationsProvider.cs +++ b/src/ImageSharp/IImageProcessorApplicatorFactory.cs @@ -11,28 +11,29 @@ namespace ImageSharp /// /// Represents an interface that will create IImageOperations /// - internal interface IImageOperationsProvider + internal interface IImageProcessorApplicatorFactory { /// /// Called during Mutate operations to generate the imageoperations provider. /// /// The pixel format /// The source image. + /// A flag to determin with the image operations is allowed to mutate the source image or not. /// A new IImageOPeration - IImageOperations CreateMutator(Image source) + IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel; } /// /// The default implmentation of IImageOperationsProvider /// - internal class DefaultImageOperationsProvider : IImageOperationsProvider + internal class DefaultImageOperationsProvider : IImageProcessorApplicatorFactory { /// - public IImageOperations CreateMutator(Image source) + public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel { - return new ImageOperations(source); + return new DefaultInternalImageProcessorApplicator(source, mutate); } } } diff --git a/src/ImageSharp/IImageOperations{TPixel}.cs b/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs similarity index 54% rename from src/ImageSharp/IImageOperations{TPixel}.cs rename to src/ImageSharp/IImageProcessorApplicator{TPixel}.cs index 349cef7f3..861c5b010 100644 --- a/src/ImageSharp/IImageOperations{TPixel}.cs +++ b/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,7 +15,7 @@ namespace ImageSharp /// An interface to queue up image operations. /// /// The pixel format - public interface IImageOperations + public interface IImageProcessorApplicator where TPixel : struct, IPixel { /// @@ -24,13 +24,27 @@ namespace ImageSharp /// The processor to apply /// The area to apply it to /// returns the current optinoatins class to allow chaining of oprations. - IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle); + IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle); /// /// Adds the processor to the current setr of image operations to be applied. /// /// The processor to apply /// returns the current optinoatins class to allow chaining of oprations. - IImageOperations ApplyProcessor(IImageProcessor processor); + IImageProcessorApplicator ApplyProcessor(IImageProcessor processor); + } + + /// + /// An internal interface to queue up image operations and have a method to apply them to and return a result + /// + /// The pixel format + public interface IInternalImageProcessorApplicator : IImageProcessorApplicator + where TPixel : struct, IPixel + { + /// + /// Adds the processors to the current image + /// + /// returns the current image or a new image depending on withere this is alloed to mutate the source image. + Image Apply(); } } \ No newline at end of file diff --git a/src/ImageSharp/Image/IImageBase.cs b/src/ImageSharp/Image/IImageBase.cs index 0e087aa4a..9e0c10606 100644 --- a/src/ImageSharp/Image/IImageBase.cs +++ b/src/ImageSharp/Image/IImageBase.cs @@ -12,11 +12,6 @@ namespace ImageSharp /// public interface IImageBase { - /// - /// Gets the representing the bounds of the image. - /// - Rectangle Bounds { get; } - /// /// Gets the width in pixels. /// @@ -27,11 +22,6 @@ namespace ImageSharp /// int Height { get; } - /// - /// Gets the pixel ratio made up of the width and height. - /// - double PixelRatio { get; } - /// /// Gets the configuration providing initialization code which allows extending the library. /// diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index d4a7af9ca..95d537518 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -19,7 +19,6 @@ namespace ImageSharp /// images in different pixel formats. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] public abstract class ImageBase : IImageBase where TPixel : struct, IPixel { @@ -105,12 +104,8 @@ namespace ImageSharp // Rent then copy the pixels. Unsafe.CopyBlock gives us a nice speed boost here. this.RentPixels(); - using (PixelAccessor sourcePixels = other.Lock()) - using (PixelAccessor target = this.Lock()) - { - // Check we can do this without crashing - sourcePixels.CopyTo(target); - } + + other.Pixels.CopyTo(this.Pixels); } /// @@ -122,12 +117,6 @@ namespace ImageSharp /// public int Height { get; private set; } - /// - public double PixelRatio => (double)this.Width / this.Height; - - /// - public Rectangle Bounds => new Rectangle(0, 0, this.Width, this.Height); - /// /// Gets the configuration providing initialization code which allows extending the library. /// @@ -194,6 +183,15 @@ namespace ImageSharp return this.Pixels.Slice((y * this.Width) + x, this.Width - x); } + /// + /// Clones the image + /// + /// A new items which is a clone of the original. + public ImageBase Clone() + { + return this.CloneInternal(); + } + /// public void Dispose() { @@ -246,6 +244,12 @@ namespace ImageSharp this.PixelBuffer = newPixels; } + /// + /// Clones the image + /// + /// A new items which is a clone of the original. + protected abstract ImageBase CloneInternal(); + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs new file mode 100644 index 000000000..9c2575a86 --- /dev/null +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -0,0 +1,153 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Text; + using ImageSharp.Formats; + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Extension methods over Image{TPixel} + /// + public static partial class ImageExtensions + { + /// + /// Gets the bounds of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Rectangle Bounds(this ImageBase source) + where TPixel : struct, IPixel + => new Rectangle(0, 0, source.Width, source.Height); + + /// + /// Gets the size of the image. + /// + /// The Pixel format. + /// The source image + /// Returns the bounds of the image + public static Size Size(this ImageBase source) + where TPixel : struct, IPixel + => new Size(source.Width, source.Height); + +#if !NETSTANDARD1_1 + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The file path to save the image to. + /// Thrown if the stream is null. + public static void Save(this Image source, string filePath) + where TPixel : struct, IPixel + { + Guard.NotNullOrEmpty(filePath, nameof(filePath)); + + string ext = Path.GetExtension(filePath).Trim('.'); + IImageFormat format = source.Configuration.FindFormatByFileExtensions(ext); + if (format == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); + foreach (IImageFormat fmt in source.Configuration.ImageFormats) + { + stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); + foreach (KeyValuePair enc in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(filePath, encoder); + } + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The file path to save the image to. + /// The encoder to save the image with. + /// Thrown if the encoder is null. + public static void Save(this Image source, string filePath, IImageEncoder encoder) + where TPixel : struct, IPixel + { + Guard.NotNull(encoder, nameof(encoder)); + using (Stream fs = source.Configuration.FileSystem.Create(filePath)) + { + source.Save(fs, encoder); + } + } +#endif + + /// + /// Saves the image to the given stream using the currently loaded image format. + /// + /// The Pixel format. + /// The source image + /// The stream to save the image to. + /// The format to save the image to. + /// Thrown if the stream is null. + public static void Save(this Image source, Stream stream, IImageFormat format) + where TPixel : struct, IPixel + { + Guard.NotNull(format, nameof(format)); + IImageEncoder encoder = source.Configuration.FindEncoder(format); + + if (encoder == null) + { + var stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); + + foreach (KeyValuePair val in source.Configuration.ImageEncoders) + { + stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); + } + + throw new NotSupportedException(stringBuilder.ToString()); + } + + source.Save(stream, encoder); + } + + /// + /// Returns a Base64 encoded string from the given image. + /// + /// + /// The Pixel format. + /// The source image + /// The format. + /// The + public static string ToBase64String(this Image source, IImageFormat format) + where TPixel : struct, IPixel + { + using (var stream = new MemoryStream()) + { + source.Save(stream, format); + stream.Flush(); + return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; + } + } + } +} diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index 04b9902c6..c8cad1648 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -14,39 +14,49 @@ namespace ImageSharp /// Represents a single frame in a animation. /// /// The pixel format. - public class ImageFrame : ImageBase, IImageFrame + public sealed class ImageFrame : ImageBase, IImageFrame where TPixel : struct, IPixel { /// /// Initializes a new instance of the class. /// - /// The width of the image in pixels. - /// The height of the image in pixels. /// /// The configuration providing initialization code which allows extending the library. /// - public ImageFrame(int width, int height, Configuration configuration = null) + /// The width of the image in pixels. + /// The height of the image in pixels. + public ImageFrame(Configuration configuration, int width, int height) : base(configuration, width, height) { } + /// + /// Initializes a new instance of the class. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + public ImageFrame(int width, int height) + : this(null, width, height) + { + } + /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageFrame image) + internal ImageFrame(ImageBase image) : base(image) { - this.CopyProperties(image); } /// /// Initializes a new instance of the class. /// /// The image to create the frame from. - public ImageFrame(ImageBase image) + private ImageFrame(ImageFrame image) : base(image) { + this.CopyProperties(image); } /// @@ -63,15 +73,19 @@ namespace ImageSharp /// /// Returns a copy of the image frame in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public ImageFrame To(Func scaleFunc = null) + public ImageFrame CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + return this.Clone() as ImageFrame; + } - ImageFrame target = new ImageFrame(this.Width, this.Height, this.Configuration); + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); + + var target = new ImageFrame(this.Configuration, this.Width, this.Height); target.CopyProperties(this); using (PixelAccessor pixels = this.Lock()) @@ -99,11 +113,17 @@ namespace ImageSharp /// Clones the current instance. /// /// The - internal virtual ImageFrame Clone() + public new ImageFrame Clone() { return new ImageFrame(this); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/Image/ImageProcessingExtensions.cs b/src/ImageSharp/Image/ImageProcessingExtensions.cs deleted file mode 100644 index 44fcba7cf..000000000 --- a/src/ImageSharp/Image/ImageProcessingExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using ImageSharp.PixelFormats; - - using ImageSharp.Processing; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Applies the processor to the image. - /// This method does not resize the target image. - /// - /// The pixel format. - /// The image this method extends. - /// The processor to apply to the image. - /// The . - public static IImageOperations Apply(this IImageOperations source, IImageProcessor processor) - where TPixel : struct, IPixel - { - source.ApplyProcessor(processor); - return source; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index 0dcb36905..ae89b777c 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -22,8 +22,7 @@ namespace ImageSharp /// Encapsulates an image, which consists of the pixel data for a graphics image and its attributes. /// /// The pixel format. - [DebuggerDisplay("Image: {Width}x{Height}")] - public class Image : ImageBase, IImage + public sealed class Image : ImageBase, IImage where TPixel : struct, IPixel { /// @@ -51,20 +50,36 @@ namespace ImageSharp { } + /// + /// Initializes a new instance of the class + /// with the height and the width of the image. + /// + /// + /// The configuration providing initialization code which allows extending the library. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The images metadata. + internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) + : base(configuration, width, height) + { + this.MetaData = metadata ?? new ImageMetaData(); + } + /// /// Initializes a new instance of the class /// by making a copy from another image. /// /// The other image, where the clone should be made from. /// is null. - public Image(Image other) + private Image(Image other) : base(other) { foreach (ImageFrame frame in other.Frames) { if (frame != null) { - this.Frames.Add(new ImageFrame(frame)); + this.Frames.Add(frame.Clone()); } } @@ -77,101 +92,22 @@ namespace ImageSharp /// /// The other image, where the clone should be made from. /// is null. - public Image(ImageBase other) + private Image(ImageBase other) : base(other) { } - /// - /// Initializes a new instance of the class - /// with the height and the width of the image. - /// - /// - /// The configuration providing initialization code which allows extending the library. - /// - /// The width of the image in pixels. - /// The height of the image in pixels. - /// The images metadata. - internal Image(Configuration configuration, int width, int height, ImageMetaData metadata) - : base(configuration, width, height) - { - this.MetaData = metadata ?? new ImageMetaData(); - } - /// /// Gets the meta data of the image. /// public ImageMetaData MetaData { get; private set; } = new ImageMetaData(); /// - /// Gets the width of the image in inches. It is calculated as the width of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The width of the image in inches. - public double InchWidth => this.Width / this.MetaData.HorizontalResolution; - - /// - /// Gets the height of the image in inches. It is calculated as the height of the image - /// in pixels multiplied with the density. When the density is equals or less than zero - /// the default value is used. - /// - /// The height of the image in inches. - public double InchHeight => this.Height / this.MetaData.VerticalResolution; - - /// - /// Gets a value indicating whether this image is animated. - /// - /// - /// True if this image is animated; otherwise, false. - /// - public bool IsAnimated => this.Frames.Count > 0; - - /// - /// Gets the other frames for the animation. + /// Gets the other frames associated with this image. /// /// The list of frame images. public IList> Frames { get; } = new List>(); - /// - /// Applies the processor to the image. - /// - /// The processor to apply to the image. - /// The structure that specifies the portion of the image object to draw. - public virtual void ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - // we want to put this on on here as it gives us a really go place to test/verify processor settings - processor.Apply(this, rectangle); - } - - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The stream to save the image to. - /// The format to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(Stream stream, IImageFormat format) - { - Guard.NotNull(format, nameof(format)); - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine("Can't find encoder for provided mime type. Available encoded:"); - - foreach (KeyValuePair val in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {val.Key.Name} : {val.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(stream, encoder); - } - /// /// Saves the image to the given stream using the given image encoder. /// @@ -191,70 +127,11 @@ namespace ImageSharp return this; } -#if !NETSTANDARD1_1 - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The file path to save the image to. - /// Thrown if the stream is null. - /// The - public Image Save(string filePath) - { - Guard.NotNullOrEmpty(filePath, nameof(filePath)); - - string ext = Path.GetExtension(filePath).Trim('.'); - var format = this.Configuration.FindFormatByFileExtensions(ext); - if (format == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find a format that is associated with the file extention '{ext}'. Registered formats with there extensions include:"); - foreach (IImageFormat fmt in this.Configuration.ImageFormats) - { - stringBuilder.AppendLine($" - {fmt.Name} : {string.Join(", ", fmt.FileExtensions)}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - IImageEncoder encoder = this.Configuration.FindEncoder(format); - - if (encoder == null) - { - var stringBuilder = new StringBuilder(); - stringBuilder.AppendLine($"Can't find encoder for file extention '{ext}' using image format '{format.Name}'. Registered encoders include:"); - foreach (KeyValuePair enc in this.Configuration.ImageEncoders) - { - stringBuilder.AppendLine($" - {enc.Key} : {enc.Value.GetType().Name}"); - } - - throw new NotSupportedException(stringBuilder.ToString()); - } - - return this.Save(filePath, encoder); - } - - /// - /// Saves the image to the given stream using the currently loaded image format. - /// - /// The file path to save the image to. - /// The encoder to save the image with. - /// Thrown if the encoder is null. - /// The - public Image Save(string filePath, IImageEncoder encoder) - { - Guard.NotNull(encoder, nameof(encoder)); - using (Stream fs = this.Configuration.FileSystem.Create(filePath)) - { - return this.Save(fs, encoder); - } - } -#endif - /// /// Clones the current image /// /// Returns a new image with all the same metadata as the original. - public Image Clone() + public new Image Clone() { return new Image(this); } @@ -265,32 +142,21 @@ namespace ImageSharp return $"Image<{typeof(TPixel).Name}>: {this.Width}x{this.Height}"; } - /// - /// Returns a Base64 encoded string from the given image. - /// - /// - /// The format. - /// The - public string ToBase64String(IImageFormat format) - { - using (var stream = new MemoryStream()) - { - this.Save(stream, format); - stream.Flush(); - return $"data:{format.DefaultMimeType};base64,{Convert.ToBase64String(stream.ToArray())}"; - } - } - /// /// Returns a copy of the image in the given pixel format. /// - /// A function that allows for the correction of vector scaling between unknown color formats. /// The pixel format. /// The - public Image To(Func scaleFunc = null) + public Image CloneAs() where TPixel2 : struct, IPixel { - scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(scaleFunc); + if (typeof(TPixel2) == typeof(TPixel)) + { + // short circuit when same pixel types + return this.Clone() as Image; + } + + Func scaleFunc = PackedPixelConverterHelper.ComputeScaleFunction(); var target = new Image(this.Configuration, this.Width, this.Height); target.CopyProperties(this); @@ -315,7 +181,7 @@ namespace ImageSharp for (int i = 0; i < this.Frames.Count; i++) { - target.Frames.Add(this.Frames[i].To()); + target.Frames.Add(this.Frames[i].CloneAs()); } return target; @@ -325,7 +191,7 @@ namespace ImageSharp /// Creates a new from this instance /// /// The - internal virtual ImageFrame ToFrame() + internal ImageFrame ToFrame() { return new ImageFrame(this); } @@ -342,6 +208,12 @@ namespace ImageSharp base.Dispose(disposing); } + /// + protected override ImageBase CloneInternal() + { + return this.Clone(); + } + /// /// Copies the properties from the other . /// diff --git a/src/ImageSharp/ImageOperations.cs b/src/ImageSharp/ImageOperations.cs deleted file mode 100644 index dde3153d1..000000000 --- a/src/ImageSharp/ImageOperations.cs +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System.Collections.Generic; - using ImageSharp.PixelFormats; - using ImageSharp.Processing; - using SixLabors.Primitives; - - /// - /// The static collection of all the default image formats - /// - /// The pixel format - internal class ImageOperations : IImageOperations - where TPixel : struct, IPixel - { - private readonly Image image; - - /// - /// Initializes a new instance of the class. - /// - /// The image. - public ImageOperations(Image image) - { - this.image = image; - } - - /// - public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) - { - // TODO : make this queue, and allow special processors managage the cloing operation for 'generate' - // to allow things like resize to not need to retain an extra copy of image data in memory, and to - // prevent an pixel copy operation - this.image.ApplyProcessor(processor, rectangle); - return this; - } - - /// - public IImageOperations ApplyProcessor(IImageProcessor processor) - { - return this.ApplyProcessor(processor, this.image.Bounds); - } - - /// - /// Applies a bluck colelctino of pressorce at once - /// - /// Processors to apply - /// this - public IImageOperations ApplyProcessors(IEnumerable> processors) - { - foreach (var processor in processors) - { - return this.ApplyProcessor(processor); - } - - return this; - } - } -} \ No newline at end of file diff --git a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs index 29ef5675e..2a25ffc16 100644 --- a/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs +++ b/src/ImageSharp/PixelFormats/PackedPixelConverterHelper.cs @@ -21,18 +21,11 @@ namespace ImageSharp.PixelFormats /// /// Returns the correct scaling function for the given types The compute scale function. /// - /// The scale function. /// The source pixel format. /// The target pixel format. /// The - public static Func ComputeScaleFunction(Func scaleFunc) + public static Func ComputeScaleFunction() { - // Custom type with a custom function. - if (scaleFunc != null) - { - return scaleFunc; - } - Type source = typeof(TPixel); Type target = typeof(TPixel2); diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index a4ee73af4..796b4f597 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold) + public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BinaryThreshold(this IImageOperations source, float threshold, Rectangle rectangle) + public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index fc5193c33..177279cea 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The ordered ditherer. /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0)); @@ -39,7 +39,7 @@ 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) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index)); @@ -56,7 +56,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Dither(this IImageOperations source, IOrderedDither dither, Rectangle rectangle) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0), rectangle); @@ -74,7 +74,7 @@ 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) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); @@ -89,7 +89,7 @@ namespace ImageSharp /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold)); @@ -107,7 +107,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Dither(this IImageOperations source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 5710991dc..3d15d1cbc 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations BlackWhite(this IImageOperations source) + public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BlackWhite(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 4d83ba9a2..8a055c33c 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness) + public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations ColorBlindness(this IImageOperations source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 6cdc3343d..7b00ae0d8 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Grayscale(this IImageOperations source) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 @@ -55,7 +55,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Grayscale(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709, rectangle); @@ -71,7 +71,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Grayscale(this IImageOperations source, GrayscaleMode mode, Rectangle rectangle) + public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index 86a533621..cd2adaadb 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The angle in degrees to adjust the image. /// The . - public static IImageOperations Hue(this IImageOperations source, float degrees) + public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Hue(this IImageOperations source, float degrees, Rectangle rectangle) + public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index 2f331d647..b16f241c0 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Kodachrome(this IImageOperations source) + public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Kodachrome(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index e2c8f3674..0a2f80cc4 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Lomograph(this IImageOperations source) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Lomograph(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Lomograph(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Lomograph(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Lomograph(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index bfbf6477b..e579a3251 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Polaroid(this IImageOperations source) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Polaroid(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Polaroid(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Polaroid(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Polaroid(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 5a2650527..768eb97c5 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// The . - public static IImageOperations Saturation(this IImageOperations source, int amount) + public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Saturation(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index f4dbb26c1..5cf64a020 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Sepia(this IImageOperations source) + public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor()); @@ -37,7 +37,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Sepia(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index cc0931215..c25de3571 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations BoxBlur(this IImageOperations source) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(7)); @@ -34,7 +34,7 @@ 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) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BoxBlur(this IImageOperations source, int radius, Rectangle rectangle) + public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index 18006752f..7ececcfe2 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations DetectEdges(this IImageOperations source) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return DetectEdges(source, new SobelProcessor { Grayscale = true }); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); @@ -54,7 +54,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, true)); @@ -66,7 +66,7 @@ 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) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, grayscale)); @@ -81,7 +81,7 @@ namespace ImageSharp /// /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) where TPixel : struct, IPixel => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, IEdgeDetectorProcessor filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { return source.ApplyProcessor(filter); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The filter for detecting edges. /// The . - public static IImageOperations DetectEdges(this IImageOperations source, Rectangle rectangle, IEdgeDetectorProcessor filter) + public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { source.ApplyProcessor(filter, rectangle); diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index 953a576fc..4b1682818 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations GaussianBlur(this IImageOperations source) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(3f)); @@ -35,7 +35,7 @@ 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) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations GaussianBlur(this IImageOperations source, float sigma, Rectangle rectangle) + public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index 1d0cce222..8c8ac6ed2 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations GaussianSharpen(this IImageOperations source) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(3f)); @@ -35,7 +35,7 @@ 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) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations GaussianSharpen(this IImageOperations source, float sigma, Rectangle rectangle) + public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs index 52ec736f5..a5647d69e 100644 --- a/src/ImageSharp/Processing/Delegate.cs +++ b/src/ImageSharp/Processing/Delegate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// 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 IImageProcessorApplicator Run(this IImageProcessorApplicator source, Action> operation) where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateProcessor(operation)); } diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index 4978caf86..b49a697da 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new opacity of the image. Must be between 0 and 1. /// The . - public static IImageOperations Alpha(this IImageOperations source, float percent) + public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Alpha(this IImageOperations source, float percent, Rectangle rectangle) + public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index 276bfa2a7..c4754c8e6 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The color to set as the background. /// The options effecting pixel blending. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); @@ -40,7 +40,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); @@ -51,7 +51,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the background. /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return BackgroundColor(source, color, GraphicsOptions.Default); @@ -67,7 +67,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations BackgroundColor(this IImageOperations source, TPixel color, Rectangle rectangle) + public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 9bc27e75d..59a02d456 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -24,8 +24,8 @@ namespace ImageSharp /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// The . - public static IImageOperations Brightness(this IImageOperations source, int amount) - where TPixel : struct, IPixel + public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount) + where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount)); /// @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Brightness(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index 52eb0d5ec..e94605a75 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// The . - public static IImageOperations Contrast(this IImageOperations source, int amount) + public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Contrast(this IImageOperations source, int amount, Rectangle rectangle) + public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index 4f8c6a886..5e0ceab75 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Invert(this IImageOperations source) + public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor()); @@ -36,7 +36,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Invert(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index 23d552885..e6a8c8373 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations OilPaint(this IImageOperations source) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return OilPaint(source, 10, 15); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations OilPaint(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return OilPaint(source, 10, 15, rectangle); @@ -54,7 +54,7 @@ namespace ImageSharp /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); @@ -69,7 +69,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations OilPaint(this IImageOperations source, int levels, int brushSize, Rectangle rectangle) + public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index b9403b765..c1e631838 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Pixelate(this IImageOperations source) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(4)); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The size of the pixels. /// The . - public static IImageOperations Pixelate(this IImageOperations source, int size) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Pixelate(this IImageOperations source, int size, Rectangle rectangle) + public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index 4c58a27d4..30ff66692 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Glow(this IImageOperations source) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Glow(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the glow. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return Glow(source, color, GraphicsOptions.Default); @@ -47,7 +47,7 @@ namespace ImageSharp /// The image this method extends. /// The the radius. /// The . - public static IImageOperations Glow(this IImageOperations source, float radius) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius) where TPixel : struct, IPixel { return Glow(source, radius, GraphicsOptions.Default); @@ -62,7 +62,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(rectangle, GraphicsOptions.Default); @@ -77,7 +77,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); @@ -88,7 +88,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); @@ -100,7 +100,7 @@ namespace ImageSharp /// The color to set as the glow. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); @@ -112,7 +112,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, float radius, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); @@ -126,7 +126,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); @@ -142,7 +142,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageOperations Glow(this IImageOperations source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); @@ -158,7 +158,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); @@ -171,7 +171,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - private static IImageOperations Glow(this IImageOperations source, TPixel color, ValueSize radius, GraphicsOptions options) + private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 175d3ea3a..81cd773b2 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageOperations Vignette(this IImageOperations source) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source) where TPixel : struct, IPixel { return Vignette(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the vignette. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color) where TPixel : struct, IPixel { return Vignette(source, color, GraphicsOptions.Default); @@ -48,7 +48,7 @@ namespace ImageSharp /// The the x-radius. /// The the y-radius. /// The . - public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY) where TPixel : struct, IPixel { return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); @@ -63,7 +63,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle) where TPixel : struct, IPixel { return Vignette(source, rectangle, GraphicsOptions.Default); @@ -81,7 +81,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -104,7 +104,7 @@ namespace ImageSharp /// The color to set as the vignette. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -117,7 +117,7 @@ namespace ImageSharp /// The the y-radius. /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); @@ -131,7 +131,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); @@ -148,15 +148,15 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageOperations Vignette(this IImageOperations source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); - private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); - private static IImageOperations VignetteInternal(this IImageOperations source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } diff --git a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs index ceb985b0b..e5813f0d5 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/Convolution2PassProcessor.cs @@ -50,7 +50,7 @@ namespace ImageSharp.Processing.Processors using (var firstPassPixels = new PixelAccessor(width, height)) using (PixelAccessor sourcePixels = source.Lock()) { - this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds, this.KernelX); + this.ApplyConvolution(firstPassPixels, sourcePixels, source.Bounds(), this.KernelX); this.ApplyConvolution(sourcePixels, firstPassPixels, sourceRectangle, this.KernelY); } } diff --git a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs index 367c288fc..cc21c3e19 100644 --- a/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Convolution/EdgeDetection/EdgeDetectorCompassProcessor.cs @@ -89,7 +89,7 @@ namespace ImageSharp.Processing.Processors int maxY = Math.Min(source.Height, endY); // we need a clean copy for each pass to start from - using (ImageBase cleanCopy = new Image(source)) + using (ImageBase cleanCopy = source.Clone()) { new ConvolutionProcessor(kernels[0]).Apply(source, sourceRectangle); @@ -116,7 +116,7 @@ namespace ImageSharp.Processing.Processors // ReSharper disable once ForCanBeConvertedToForeach for (int i = 1; i < kernels.Length; i++) { - using (ImageBase pass = new Image(cleanCopy)) + using (ImageBase pass = cleanCopy.Clone()) { new ConvolutionProcessor(kernels[i]).Apply(pass, sourceRectangle); diff --git a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs index 5da6a96dc..2b9c88f2d 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/GlowProcessor.cs @@ -62,7 +62,7 @@ namespace ImageSharp.Processing.Processors TPixel glowColor = this.GlowColor; Vector2 centre = Rectangle.Center(sourceRectangle); - var finalRadius = this.Radius.Calculate(source.Bounds.Size); + var finalRadius = this.Radius.Calculate(source.Size()); float maxDistance = finalRadius > 0 ? MathF.Min(finalRadius, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; diff --git a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs index 07c45f4f0..de50dd84b 100644 --- a/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Overlays/VignetteProcessor.cs @@ -81,8 +81,8 @@ namespace ImageSharp.Processing.Processors TPixel vignetteColor = this.VignetteColor; Vector2 centre = Rectangle.Center(sourceRectangle); - var finalradiusX = this.RadiusX.Calculate(source.Bounds.Size); - var finalradiusY = this.RadiusY.Calculate(source.Bounds.Size); + var finalradiusX = this.RadiusX.Calculate(source.Size()); + var finalradiusY = this.RadiusY.Calculate(source.Size()); float rX = finalradiusX > 0 ? MathF.Min(finalradiusX, sourceRectangle.Width * .5F) : sourceRectangle.Width * .5F; float rY = finalradiusY > 0 ? MathF.Min(finalradiusY, sourceRectangle.Height * .5F) : sourceRectangle.Height * .5F; float maxDistance = MathF.Sqrt((rX * rX) + (rY * rY)); diff --git a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs index a52065ea9..648e86d3c 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/EntropyCropProcessor.cs @@ -39,7 +39,7 @@ namespace ImageSharp.Processing.Processors /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - using (ImageBase temp = new Image(source)) + using (ImageBase temp = source.Clone()) { // Detect the edges. new SobelProcessor().Apply(temp, sourceRectangle); diff --git a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs index e6b1d180f..45d04626e 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/RotateProcessor.cs @@ -45,6 +45,7 @@ namespace ImageSharp.Processing.Processors int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +61,7 @@ namespace ImageSharp.Processing.Processors { var transformedPoint = Point.Rotate(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } diff --git a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs index 9766caa69..757f3fa0b 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/SkewProcessor.cs @@ -45,6 +45,7 @@ namespace ImageSharp.Processing.Processors int height = this.CanvasRectangle.Height; int width = this.CanvasRectangle.Width; Matrix3x2 matrix = this.GetCenteredMatrix(source, this.processMatrix); + Rectangle sourceBounds = source.Bounds(); using (var targetPixels = new PixelAccessor(width, height)) { @@ -60,7 +61,7 @@ namespace ImageSharp.Processing.Processors { var transformedPoint = Point.Skew(new Point(x, y), matrix); - if (source.Bounds.Contains(transformedPoint.X, transformedPoint.Y)) + if (sourceBounds.Contains(transformedPoint.X, transformedPoint.Y)) { targetRow[x] = source[transformedPoint.X, transformedPoint.Y]; } diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index 6f7d1b665..f741e41b1 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image to auto rotate. /// The - public static IImageOperations AutoOrient(this IImageOperations source) + public static IImageProcessorApplicator AutoOrient(this IImageProcessorApplicator source) where TPixel : struct, IPixel => source.ApplyProcessor(new Processing.Processors.AutoRotateProcessor()); } diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index c518ac5ac..aad80fa0f 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The target image width. /// The target image height. /// The - public static IImageOperations Crop(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel => Crop(source, new Rectangle(0, 0, width, height)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to retain. /// /// The - public static IImageOperations Crop(this IImageOperations source, Rectangle cropRectangle) + public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, Rectangle cropRectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new CropProcessor(cropRectangle)); } diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index 00f404321..a0704619c 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to crop. /// The threshold for entropic density. /// The - public static IImageOperations EntropyCrop(this IImageOperations source, float threshold = .5f) + public static IImageProcessorApplicator EntropyCrop(this IImageProcessorApplicator source, float threshold = .5f) where TPixel : struct, IPixel => source.ApplyProcessor(new EntropyCropProcessor(threshold)); } diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 6cde1257c..2f20c3bd8 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static IImageOperations Flip(this IImageOperations source, FlipType flipType) + public static IImageProcessorApplicator Flip(this IImageProcessorApplicator source, FlipType flipType) where TPixel : struct, IPixel => source.ApplyProcessor(new FlipProcessor(flipType)); } diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index fb064f5ce..90a9e281b 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// The new width. /// The new height. /// The . - public static IImageOperations Pad(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Pad(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index 6ccea5f42..4c04991c0 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The resize options. /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, ResizeOptions options) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, ResizeOptions options) where TPixel : struct, IPixel { return source.Run(img => @@ -56,7 +56,7 @@ namespace ImageSharp /// The target image size. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, Size size) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); @@ -71,7 +71,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, Size size, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size, bool compand) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), compand); @@ -86,7 +86,7 @@ namespace ImageSharp /// The target image height. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); @@ -102,7 +102,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); @@ -118,7 +118,7 @@ namespace ImageSharp /// The to perform the resampling. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); @@ -135,7 +135,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); @@ -159,7 +159,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => @@ -199,7 +199,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageOperations Resize(this IImageOperations source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) + public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index 92349dba3..08ac44dad 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static IImageOperations Rotate(this IImageOperations source, float degrees) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees) where TPixel : struct, IPixel { return Rotate(source, degrees, true); @@ -37,7 +37,7 @@ namespace ImageSharp /// The image to rotate. /// The to perform the rotation. /// The - public static IImageOperations Rotate(this IImageOperations source, RotateType rotateType) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, RotateType rotateType) where TPixel : struct, IPixel => Rotate(source, (float)rotateType, false); @@ -49,7 +49,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static IImageOperations Rotate(this IImageOperations source, float degrees, bool expand) + public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new RotateProcessor { Angle = degrees, Expand = expand }); } diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index fda11d833..2c321358e 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The to perform the rotation. /// The to perform the flip. /// The - public static IImageOperations RotateFlip(this IImageOperations source, RotateType rotateType, FlipType flipType) + public static IImageProcessorApplicator RotateFlip(this IImageProcessorApplicator source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index f38606eda..8fde7270d 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY) + public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY) where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); @@ -39,7 +39,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static IImageOperations Skew(this IImageOperations source, float degreesX, float degreesY, bool expand) + public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }); } diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 2b5130f8c..54c57b508 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static IImageOperations Quantize(this IImageOperations source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, Quantization mode = Quantization.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; @@ -54,7 +54,7 @@ namespace ImageSharp /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . - public static IImageOperations Quantize(this IImageOperations source, IQuantizer quantizer, int maxColors) + public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { return source.Run(img => diff --git a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs index 2e3ea7a54..d8a2de148 100644 --- a/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs +++ b/src/ImageSharp/Quantizers/Quantizer{TPixel}.cs @@ -70,7 +70,7 @@ namespace ImageSharp.Quantizers if (this.Dither) { // We clone the image as we don't want to alter the original. - using (var clone = new Image(image)) + using (ImageBase clone = image.Clone()) { this.SecondPass(clone, quantizedPixels, width, height); } diff --git a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs index 53cdb1b93..88851bd0c 100644 --- a/tests/ImageSharp.Benchmarks/Samplers/Glow.cs +++ b/tests/ImageSharp.Benchmarks/Samplers/Glow.cs @@ -35,7 +35,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(bulk, image.Bounds); + bulk.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } @@ -45,7 +45,7 @@ namespace ImageSharp.Benchmarks { using (Image image = new Image(800, 800)) { - image.ApplyProcessor(parallel, image.Bounds); + parallel.Apply(image, image.Bounds()); return new CoreSize(image.Width, image.Height); } } diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs index 398db976e..997215ce2 100644 --- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -17,7 +17,7 @@ namespace ImageSharp.Tests { this.options = new GraphicsOptions(false) { }; this.rect = new Rectangle(91, 123, 324, 56); // make this random? - this.operations = new FakeImageOperationsProvider.FakeImageOperations(null); + this.operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); } public T Verify(int index = 0) @@ -28,6 +28,7 @@ namespace ImageSharp.Tests return Assert.IsType(operation.Processor); } + public T Verify(Rectangle rect, int index = 0) { Assert.InRange(index, 0, this.operations.applied.Count - 1); diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index b9a1d80a2..70e55b426 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -8,7 +8,7 @@ using ImageSharp.Processing; using SixLabors.Primitives; - public class FakeImageOperationsProvider : IImageOperationsProvider + public class FakeImageOperationsProvider : IImageProcessorApplicatorFactory { private List ImageOperators = new List(); @@ -29,27 +29,41 @@ .SelectMany(x => x.applied); } - public IImageOperations CreateMutator(Image source) where TPixel : struct, IPixel + public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel { - var op = new FakeImageOperations(source); + var op = new FakeImageOperations(source, mutate); this.ImageOperators.Add(op); return op; } - public class FakeImageOperations : IImageOperations + public class FakeImageOperations : IInternalImageProcessorApplicator where TPixel : struct, IPixel { public Image source; public List applied = new List(); + public bool mutate; - public FakeImageOperations(Image source) + public FakeImageOperations(Image source, bool mutate) { - this.source = source; + this.mutate = mutate; + if (mutate) + { + this.source = source; + } + else + { + this.source = source.Clone(); + } + } + + public Image Apply() + { + return source; } - public IImageOperations ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { applied.Add(new AppliedOpperation { @@ -59,7 +73,7 @@ return this; } - public IImageOperations ApplyProcessor(IImageProcessor processor) + public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) { applied.Add(new AppliedOpperation { diff --git a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs index 1f669ba24..be6ce1343 100644 --- a/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs +++ b/tests/ImageSharp.Tests/Formats/GeneralFormatTests.cs @@ -64,7 +64,7 @@ namespace ImageSharp.Tests { using (Image srcImage = Image.Load(file.Bytes, out var mimeType)) { - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Octree-{file.FileName}")) { @@ -74,7 +74,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Wu-{file.FileName}")) { @@ -83,7 +83,7 @@ namespace ImageSharp.Tests } } - using (Image image = new Image(srcImage)) + using (Image image = srcImage.Clone()) { using (FileStream output = File.OpenWrite($"{path}/Palette-{file.FileName}")) { diff --git a/tests/ImageSharp.Tests/ImageOperationTests.cs b/tests/ImageSharp.Tests/ImageOperationTests.cs index a84b0fcb0..f7352a8ea 100644 --- a/tests/ImageSharp.Tests/ImageOperationTests.cs +++ b/tests/ImageSharp.Tests/ImageOperationTests.cs @@ -92,9 +92,9 @@ namespace ImageSharp.Tests } [Fact] - public void ApplyProcessors_ListOfProcessors_AppliesALlProcessorsToOperation() + public void ApplyProcessors_ListOfProcessors_AppliesAllProcessorsToOperation() { - var operations = new FakeImageOperationsProvider.FakeImageOperations(null); + var operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); operations.ApplyProcessors(this.processor); Assert.Contains(this.processor, operations.applied.Select(x => x.Processor)); } diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs index 3e8c99e35..209d50661 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/BinaryThresholdTest.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs index 0a4ccaeb1..edaede58d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Binarization/DitherTest.cs @@ -49,7 +49,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); @@ -78,7 +78,7 @@ namespace ImageSharp.Tests.Processing.Processors.Binarization where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs index 5b4953d60..dcc61a629 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/BlackWhiteTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs index 6d2df4c9b..59f389cfd 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/ColorBlindnessTest.cs @@ -43,7 +43,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs index 3fba626c2..7fdc07005 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/GrayscaleTest.cs @@ -48,7 +48,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); image.Mutate(x => x.Grayscale(value, bounds)); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs index 1019e2def..30beb61d0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/HueTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs index 9e7c2c02f..be2464d1d 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/KodachromeTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs index d44f7005f..170999594 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/LomographTest.cs @@ -31,7 +31,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs index 29ae45be4..367ce04c7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/PolaroidTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs index df0af2bb6..ba0cc344e 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SaturationTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs index 82bd4b26e..5879a8bb7 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/ColorMatrix/SepiaTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.ColorMatrix where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs index 71b5ee69b..3daa8c933 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/BoxBlurTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs index 7a5dbc1fc..72a3e9023 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/DetectEdgesTest.cs @@ -45,7 +45,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs index 5bb372e54..9ccc4e453 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianBlurTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs index 71eae5b09..dab576c2b 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Convolution/GaussianSharpenTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Convolution where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs index c29267b10..a7626f386 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/AlphaTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs index 2e2768115..70c2844de 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BackgroundColorTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs index abd9951ab..57b7cd8d9 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/BrightnessTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs index c9d322a97..a5423ba93 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/ContrastTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs index 839b1bb99..2816cb925 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/InvertTest.cs @@ -29,7 +29,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs index 17598c648..0a26cee69 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/OilPaintTest.cs @@ -36,7 +36,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs index e24b359e3..92703ca07 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Effects/PixelateTest.cs @@ -52,7 +52,7 @@ namespace ImageSharp.Tests.Processing.Processors.Effects where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(image.Width / 4, image.Height / 4, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs index cab607973..3f69ba148 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/GlowTest.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs index 6f856c686..c65b254c0 100644 --- a/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs +++ b/tests/ImageSharp.Tests/Processing/Processors/Overlays/VignetteTest.cs @@ -53,7 +53,7 @@ namespace ImageSharp.Tests.Processing.Processors.Overlays where TPixel : struct, IPixel { using (Image source = provider.GetImage()) - using (var image = new Image(source)) + using (var image = source.Clone()) { var bounds = new Rectangle(10, 10, image.Width / 2, image.Height / 2); diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index f634eb3f4..2b505a2e4 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -129,7 +129,7 @@ namespace ImageSharp.Tests /// public Image CreateImage() { - return new Image(this.image); + return this.image.Clone(); } /// diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs index 4a0950788..bfa70a2a5 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/GenericFactory.cs @@ -28,7 +28,7 @@ namespace ImageSharp.Tests public virtual Image CreateImage(Image other) { - return new Image(other); + return other.Clone(); } } } \ No newline at end of file diff --git a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs index 20af430a5..052a4c774 100644 --- a/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs +++ b/tests/ImageSharp.Tests/TestUtilities/Factories/ImageFactory.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Tests public override Image CreateImage(Image other) { - return new Image(other); + return other.Clone(); } } } diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index e939d78bb..ae10bf9af 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -85,7 +85,7 @@ namespace ImageSharp.Tests /// /// Returns an instance to the test case with the necessary traits. /// - public Image GetImage(Action> operationsToApply) + public Image GetImage(Action> operationsToApply) { var img = GetImage(); img.Mutate(operationsToApply); diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs index 96d38fc40..f25beb726 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestPatternProvider.cs @@ -49,7 +49,7 @@ namespace ImageSharp.Tests } } - return new Image(testImages[this.SourceFileOrDescription]); + return testImages[this.SourceFileOrDescription].Clone(); } /// From 9b865253a6fdb5de4786f635103e21460859bbc8 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 15 Jul 2017 09:39:48 +0100 Subject: [PATCH 13/20] fix some comments --- src/ImageSharp/ApplyProcessors.cs | 2 +- src/ImageSharp/IImageProcessorApplicatorFactory.cs | 2 +- src/ImageSharp/Image/ImageExtensions.cs | 2 +- src/ImageSharp/Image/Image{TPixel}.cs | 7 +------ 4 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 78a5fc079..c0a7f20df 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/IImageProcessorApplicatorFactory.cs b/src/ImageSharp/IImageProcessorApplicatorFactory.cs index b79353ef5..e07b1a752 100644 --- a/src/ImageSharp/IImageProcessorApplicatorFactory.cs +++ b/src/ImageSharp/IImageProcessorApplicatorFactory.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Image/ImageExtensions.cs b/src/ImageSharp/Image/ImageExtensions.cs index 9c2575a86..6095b49e3 100644 --- a/src/ImageSharp/Image/ImageExtensions.cs +++ b/src/ImageSharp/Image/ImageExtensions.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // diff --git a/src/ImageSharp/Image/Image{TPixel}.cs b/src/ImageSharp/Image/Image{TPixel}.cs index ae89b777c..70e0a8349 100644 --- a/src/ImageSharp/Image/Image{TPixel}.cs +++ b/src/ImageSharp/Image/Image{TPixel}.cs @@ -114,17 +114,12 @@ namespace ImageSharp /// The stream to save the image to. /// The encoder to save the image with. /// Thrown if the stream or encoder is null. - /// - /// The . - /// - public Image Save(Stream stream, IImageEncoder encoder) + public void Save(Stream stream, IImageEncoder encoder) { Guard.NotNull(stream, nameof(stream)); Guard.NotNull(encoder, nameof(encoder)); encoder.Encode(this, stream); - - return this; } /// From 41cadf98ac05a5b6ef73e10e3721dc8db9eb87c7 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 15 Jul 2017 15:12:30 +0100 Subject: [PATCH 14/20] fix broken tests --- tests/ImageSharp.Tests/FakeImageOperationsProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index 70e55b426..e06b918af 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -54,7 +54,7 @@ } else { - this.source = source.Clone(); + this.source = source?.Clone(); } } From c421e6de0a69716f570701dee44e50483f5e16b1 Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sat, 15 Jul 2017 22:27:19 +0100 Subject: [PATCH 15/20] Cloneing Image Processor --- ...DefaultInternalImageProcessorApplicator.cs | 16 +- .../Image/ICloningImageProcessor.cs | 37 ++++ src/ImageSharp/Image/ImageBase{TPixel}.cs | 21 ++ src/ImageSharp/Image/ImageFrame{TPixel}.cs | 23 ++- src/ImageSharp/MetaData/ImageFrameMetaData.cs | 9 + src/ImageSharp/MetaData/ImageMetaData.cs | 9 + .../Processors/CLoneingImageProcessor.cs | 166 ++++++++++++++++ .../Transforms/ResamplingWeightedProcessor.cs | 8 +- .../Processors/Transforms/ResizeProcessor.cs | 180 ++++++++++-------- 9 files changed, 376 insertions(+), 93 deletions(-) create mode 100644 src/ImageSharp/Image/ICloningImageProcessor.cs create mode 100644 src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs diff --git a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs index 4dda4f070..ba476ba33 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs @@ -54,9 +54,19 @@ namespace ImageSharp { if (!this.mutate && this.destination == null) { - // TODO check if the processor implements a special interface and if it does then allow it to take - // over and crereate the clone on behalf ImageOperations class. - this.destination = this.source.Clone(); + // this will only work if the first processor applied is the cloning one thus + // realistically for this optermissation to work the resize must the first processor + // applied any only up processors will take the douple data path. + if (processor is ICloningImageProcessor) + { + var cloningProcessor = (ICloningImageProcessor)processor; + this.destination = cloningProcessor.CloneAndApply(this.source, rectangle); + return this; + } + else + { + this.destination = this.source.Clone(); + } } processor.Apply(this.destination, rectangle); diff --git a/src/ImageSharp/Image/ICloningImageProcessor.cs b/src/ImageSharp/Image/ICloningImageProcessor.cs new file mode 100644 index 000000000..8906063f9 --- /dev/null +++ b/src/ImageSharp/Image/ICloningImageProcessor.cs @@ -0,0 +1,37 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Processing +{ + using System; + using System.Threading.Tasks; + + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Encapsulates methods to alter the pixels of an image. + /// + /// The pixel format. + public interface ICloningImageProcessor : IImageProcessor + where TPixel : struct, IPixel + { + /// + /// Applies the process to the specified portion of the specified . + /// + /// The source image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + /// + /// is null. + /// + /// + /// doesnt fit the dimension of the image. + /// + /// Returns the cloned image after thre processor has been applied to it. + Image CloneAndApply(Image source, Rectangle sourceRectangle); + } +} diff --git a/src/ImageSharp/Image/ImageBase{TPixel}.cs b/src/ImageSharp/Image/ImageBase{TPixel}.cs index 95d537518..7d965cb05 100644 --- a/src/ImageSharp/Image/ImageBase{TPixel}.cs +++ b/src/ImageSharp/Image/ImageBase{TPixel}.cs @@ -244,6 +244,27 @@ namespace ImageSharp this.PixelBuffer = newPixels; } + /// + /// Switches the buffers used by the image and the pixelSource meaning that the Image will "own" the buffer from the pixelSource and the pixelSource will now own the Images buffer. + /// + /// The pixel source. + internal void SwapPixelsData(ImageBase pixelSource) + { + Guard.NotNull(pixelSource, nameof(pixelSource)); + + int newWidth = pixelSource.Width; + int newHeight = pixelSource.Height; + TPixel[] newPixels = pixelSource.PixelBuffer; + + pixelSource.PixelBuffer = this.PixelBuffer; + pixelSource.Width = this.Width; + pixelSource.Height = this.Height; + + this.Width = newWidth; + this.Height = newHeight; + this.PixelBuffer = newPixels; + } + /// /// Clones the image /// diff --git a/src/ImageSharp/Image/ImageFrame{TPixel}.cs b/src/ImageSharp/Image/ImageFrame{TPixel}.cs index c8cad1648..1e55d7b3b 100644 --- a/src/ImageSharp/Image/ImageFrame{TPixel}.cs +++ b/src/ImageSharp/Image/ImageFrame{TPixel}.cs @@ -28,6 +28,23 @@ namespace ImageSharp public ImageFrame(Configuration configuration, int width, int height) : base(configuration, width, height) { + this.MetaData = new ImageFrameMetaData(); + } + + /// + /// Initializes a new instance of the class. + /// + /// + /// The configuration providing initialization code which allows extending the library. + /// + /// The width of the image in pixels. + /// The height of the image in pixels. + /// The metadata of the frame. + public ImageFrame(Configuration configuration, int width, int height, ImageFrameMetaData metadata) + : base(configuration, width, height) + { + Guard.NotNull(metadata, nameof(metadata)); + this.MetaData = metadata; } /// @@ -38,6 +55,7 @@ namespace ImageSharp public ImageFrame(int width, int height) : this(null, width, height) { + this.MetaData = new ImageFrameMetaData(); } /// @@ -47,6 +65,7 @@ namespace ImageSharp internal ImageFrame(ImageBase image) : base(image) { + this.MetaData = new ImageFrameMetaData(); } /// @@ -62,12 +81,12 @@ namespace ImageSharp /// /// Gets the meta data of the frame. /// - public ImageFrameMetaData MetaData { get; private set; } = new ImageFrameMetaData(); + public ImageFrameMetaData MetaData { get; private set; } /// public override string ToString() { - return $"ImageFrame: {this.Width}x{this.Height}"; + return $"ImageFrame<{typeof(TPixel).Name}>: {this.Width}x{this.Height}"; } /// diff --git a/src/ImageSharp/MetaData/ImageFrameMetaData.cs b/src/ImageSharp/MetaData/ImageFrameMetaData.cs index b55bfd1ad..9004fbd1d 100644 --- a/src/ImageSharp/MetaData/ImageFrameMetaData.cs +++ b/src/ImageSharp/MetaData/ImageFrameMetaData.cs @@ -39,5 +39,14 @@ namespace ImageSharp /// public DisposalMethod DisposalMethod { get; set; } + + /// + /// Clones this ImageFrameMetaData. + /// + /// The cloned instance. + public ImageFrameMetaData Clone() + { + return new ImageFrameMetaData(this); + } } } diff --git a/src/ImageSharp/MetaData/ImageMetaData.cs b/src/ImageSharp/MetaData/ImageMetaData.cs index 5361b486d..a5b36f884 100644 --- a/src/ImageSharp/MetaData/ImageMetaData.cs +++ b/src/ImageSharp/MetaData/ImageMetaData.cs @@ -132,6 +132,15 @@ namespace ImageSharp /// public ushort RepeatCount { get; set; } + /// + /// Clones this into a new instance + /// + /// The cloned metadata instance + public ImageMetaData Clone() + { + return new ImageMetaData(this); + } + /// /// Synchronizes the profiles with the current meta data. /// diff --git a/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs b/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs new file mode 100644 index 000000000..0b6dbd3ed --- /dev/null +++ b/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs @@ -0,0 +1,166 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Processing +{ + using System; + using System.Threading.Tasks; + + using ImageSharp.PixelFormats; + using SixLabors.Primitives; + + /// + /// Allows the application of processors to images. + /// + /// The pixel format. + internal abstract class CloneingImageProcessor : IImageProcessor, ICloningImageProcessor + where TPixel : struct, IPixel + { + /// + public virtual ParallelOptions ParallelOptions { get; set; } + + /// + public virtual bool Compand { get; set; } = false; + + /// + public Image CloneAndApply(Image source, Rectangle sourceRectangle) + { + if (this.ParallelOptions == null) + { + this.ParallelOptions = source.Configuration.ParallelOptions; + } + + try + { + Image clone = this.CreateDestination(source, sourceRectangle); + + if (clone.Frames.Count != source.Frames.Count) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. The processor changed the number of frames."); + } + + this.BeforeImageApply(source, clone, sourceRectangle); + + this.BeforeApply(source, clone, sourceRectangle); + this.OnApply(source, clone, sourceRectangle); + this.AfterApply(source, clone, sourceRectangle); + + for (int i = 0; i < source.Frames.Count; i++) + { + ImageFrame sourceFrame = source.Frames[i]; + ImageFrame clonedFrame = clone.Frames[i]; + + this.BeforeApply(sourceFrame, clonedFrame, sourceRectangle); + + this.OnApply(sourceFrame, clonedFrame, sourceRectangle); + this.AfterApply(sourceFrame, clonedFrame, sourceRectangle); + } + + this.AfterImageApply(source, clone, sourceRectangle); + + return clone; + } +#if DEBUG + catch (Exception) + { + throw; +#else + catch (Exception ex) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. See the inner exception for more detail.", ex); +#endif + } + } + + /// + public void Apply(Image source, Rectangle sourceRectangle) + { + using (Image cloned = this.CloneAndApply(source, sourceRectangle)) + { + // we now need to move the pixel data/size data from one image base to another + if (cloned.Frames.Count != source.Frames.Count) + { + throw new ImageProcessingException($"An error occured when processing the image using {this.GetType().Name}. The processor changed the number of frames."); + } + + source.SwapPixelsData(cloned); + for (int i = 0; i < source.Frames.Count; i++) + { + source.Frames[i].SwapPixelsData(cloned.Frames[i]); + } + } + } + + /// + /// Generates the clone of the source image that operatinos should be applied to. + /// + /// The source image. Cannot be null. + /// The source rectangle. + /// The cloned image. + protected virtual Image CreateDestination(Image source, Rectangle sourceRectangle) + { + return source.Clone(); + } + + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeImageApply(Image source, Image destination, Rectangle sourceRectangle) + { + } + + /// + /// This method is called before the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void BeforeApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) + { + } + + /// + /// Applies the process to the specified portion of the specified at the specified location + /// and with the specified size. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected abstract void OnApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle); + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) + { + } + + /// + /// This method is called after the process is applied to prepare the processor. + /// + /// The source image. Cannot be null. + /// The cloned/destination image. Cannot be null. + /// + /// The structure that specifies the portion of the image object to draw. + /// + protected virtual void AfterImageApply(Image source, Image destination, Rectangle sourceRectangle) + { + } + } +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 0f1e166fd..957f917be 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Processing.Processors /// Adapted from /// /// The pixel format. - internal abstract partial class ResamplingWeightedProcessor : ImageProcessor + internal abstract partial class ResamplingWeightedProcessor : CloneingImageProcessor where TPixel : struct, IPixel { /// @@ -140,7 +140,7 @@ namespace ImageSharp.Processing.Processors } /// - protected override void BeforeApply(ImageBase source, Rectangle sourceRectangle) + protected override void BeforeApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) { if (!(this.Sampler is NearestNeighborResampler)) { @@ -155,9 +155,9 @@ namespace ImageSharp.Processing.Processors } /// - protected override void AfterApply(ImageBase source, Rectangle sourceRectangle) + protected override void AfterApply(ImageBase source, ImageBase destination, Rectangle sourceRectangle) { - base.AfterApply(source, sourceRectangle); + base.AfterApply(source, destination, sourceRectangle); this.HorizontalWeights?.Dispose(); this.HorizontalWeights = null; this.VerticalWeights?.Dispose(); diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index be1680cf1..65fbb65fb 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -46,11 +46,33 @@ namespace ImageSharp.Processing.Processors } /// - protected override unsafe void OnApply(ImageBase source, Rectangle sourceRectangle) + protected override Image CreateDestination(Image source, Rectangle sourceRectangle) + { + // we will always be creating the clone even for mutate because thatsa the way this base processor works + // ------------ + // for resize we know we are going to populate every pixel with fresh data and we want a different target size so + // lets manually clone an empty set of images at the correct target and then have the base class processs them in. + // turn. + var image = new Image(source.Configuration, this.Width, this.Height, source.MetaData.Clone()); + + // now 'clone' the ImageFrames + foreach (ImageFrame sourceFrame in source.Frames) + { + var targetFrame = new ImageFrame(sourceFrame.Configuration, this.Width, this.Height, sourceFrame.MetaData.Clone()); + image.Frames.Add(targetFrame); + } + + return image; + } + + /// + protected override unsafe void OnApply(ImageBase source, ImageBase cloned, Rectangle sourceRectangle) { // Jump out, we'll deal with that later. - if (source.Width == this.Width && source.Height == this.Height && sourceRectangle == this.ResizeRectangle) + if (source.Width == cloned.Width && source.Height == cloned.Height && sourceRectangle == this.ResizeRectangle) { + // the cloned will be blank here copy all the pixel data over + source.Pixels.CopyTo(cloned.Pixels); return; } @@ -74,29 +96,24 @@ namespace ImageSharp.Processing.Processors float widthFactor = sourceRectangle.Width / (float)this.ResizeRectangle.Width; float heightFactor = sourceRectangle.Height / (float)this.ResizeRectangle.Height; - using (var targetPixels = new PixelAccessor(width, height)) - { - Parallel.For( - minY, - maxY, - this.ParallelOptions, - y => + Parallel.For( + minY, + maxY, + this.ParallelOptions, + y => + { + // Y coordinates of source points + Span sourceRow = source.GetRowSpan((int)(((y - startY) * heightFactor) + sourceY)); + Span targetRow = cloned.GetRowSpan(y); + + for (int x = minX; x < maxX; x++) { - // Y coordinates of source points - Span sourceRow = source.GetRowSpan((int)(((y - startY) * heightFactor) + sourceY)); - Span targetRow = targetPixels.GetRowSpan(y); + // X coordinates of source points + targetRow[x] = sourceRow[(int)(((x - startX) * widthFactor) + sourceX)]; + } + }); - for (int x = minX; x < maxX; x++) - { - // X coordinates of source points - targetRow[x] = sourceRow[(int)(((x - startX) * widthFactor) + sourceX)]; - } - }); - - // Break out now. - source.SwapPixelsBuffers(targetPixels); - return; - } + return; } // Interpolate the image using the calculated weights. @@ -105,82 +122,77 @@ namespace ImageSharp.Processing.Processors // are the upper and lower bounds of the source rectangle. // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! - using (var targetPixels = new PixelAccessor(width, height)) + using (var firstPassPixels = new Buffer2D(width, source.Height)) { - using (var firstPassPixels = new Buffer2D(width, source.Height)) - { - firstPassPixels.Clear(); - - Parallel.For( - 0, - sourceRectangle.Bottom, - this.ParallelOptions, - y => + firstPassPixels.Clear(); + + Parallel.For( + 0, + sourceRectangle.Bottom, + this.ParallelOptions, + y => + { + // TODO: Without Parallel.For() this buffer object could be reused: + using (var tempRowBuffer = new Buffer(source.Width)) { - // TODO: Without Parallel.For() this buffer object could be reused: - using (var tempRowBuffer = new Buffer(source.Width)) - { - Span firstPassRow = firstPassPixels.GetRowSpan(y); - Span sourceRow = source.GetRowSpan(y); - PixelOperations.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); + Span firstPassRow = firstPassPixels.GetRowSpan(y); + Span sourceRow = source.GetRowSpan(y); + PixelOperations.Instance.ToVector4(sourceRow, tempRowBuffer, sourceRow.Length); - if (this.Compand) + if (this.Compand) + { + for (int x = minX; x < maxX; x++) { - for (int x = minX; x < maxX; x++) - { - WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; - firstPassRow[x] = window.ComputeExpandedWeightedRowSum(tempRowBuffer, sourceX); - } + WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; + firstPassRow[x] = window.ComputeExpandedWeightedRowSum(tempRowBuffer, sourceX); } - else + } + else + { + for (int x = minX; x < maxX; x++) { - for (int x = minX; x < maxX; x++) - { - WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; - firstPassRow[x] = window.ComputeWeightedRowSum(tempRowBuffer, sourceX); - } + WeightsWindow window = this.HorizontalWeights.Weights[x - startX]; + firstPassRow[x] = window.ComputeWeightedRowSum(tempRowBuffer, sourceX); } } - }); - - // Now process the rows. - Parallel.For( - minY, - maxY, - this.ParallelOptions, - y => - { - // Ensure offsets are normalised for cropping and padding. - WeightsWindow window = this.VerticalWeights.Weights[y - startY]; - Span targetRow = targetPixels.GetRowSpan(y); + } + }); - if (this.Compand) + // Now process the rows. + Parallel.For( + minY, + maxY, + this.ParallelOptions, + y => + { + // Ensure offsets are normalised for cropping and padding. + WeightsWindow window = this.VerticalWeights.Weights[y - startY]; + Span targetRow = cloned.GetRowSpan(y); + + if (this.Compand) + { + for (int x = 0; x < width; x++) { - for (int x = 0; x < width; x++) - { - // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); - destination = destination.Compress(); + // Destination color components + Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + destination = destination.Compress(); - ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); - } + ref TPixel pixel = ref targetRow[x]; + pixel.PackFromVector4(destination); } - else + } + else + { + for (int x = 0; x < width; x++) { - for (int x = 0; x < width; x++) - { - // Destination color components - Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); + // Destination color components + Vector4 destination = window.ComputeWeightedColumnSum(firstPassPixels, x, sourceY); - ref TPixel pixel = ref targetRow[x]; - pixel.PackFromVector4(destination); - } + ref TPixel pixel = ref targetRow[x]; + pixel.PackFromVector4(destination); } - }); - } - - source.SwapPixelsBuffers(targetPixels); + } + }); } } } From 7635558f9b2c43373b2eea09c6750445ff312f1e Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Sun, 16 Jul 2017 09:18:01 +0100 Subject: [PATCH 16/20] internalise cloning processor + rename context --- samples/AvatarWithRoundedCorner/Program.cs | 2 +- src/ImageSharp.Drawing/DrawImage.cs | 12 +++++----- src/ImageSharp.Drawing/FillRegion.cs | 14 +++++------ src/ImageSharp.Drawing/Paths/DrawBeziers.cs | 12 +++++----- src/ImageSharp.Drawing/Paths/DrawLines.cs | 12 +++++----- src/ImageSharp.Drawing/Paths/DrawPath.cs | 12 +++++----- .../Paths/DrawPathCollection.cs | 12 +++++----- src/ImageSharp.Drawing/Paths/DrawPolygon.cs | 12 +++++----- src/ImageSharp.Drawing/Paths/DrawRectangle.cs | 12 +++++----- .../Paths/FillPathBuilder.cs | 8 +++---- .../Paths/FillPathCollection.cs | 8 +++---- src/ImageSharp.Drawing/Paths/FillPaths.cs | 8 +++---- src/ImageSharp.Drawing/Paths/FillPolygon.cs | 8 +++---- src/ImageSharp.Drawing/Paths/FillRectangle.cs | 8 +++---- src/ImageSharp.Drawing/Text/DrawText.Path.cs | 16 ++++++------- src/ImageSharp.Drawing/Text/DrawText.cs | 16 ++++++------- src/ImageSharp/ApplyProcessors.cs | 14 +++++------ src/ImageSharp/Configuration.cs | 2 +- ...> DefaultInternalImageProcessorContext.cs} | 14 +++++------ ...y.cs => IImageProcessingContextFactory.cs} | 10 ++++---- ....cs => IImageProcessingContext{TPixel}.cs} | 8 +++---- ...rocessor.cs => ICloneingImageProcessor.cs} | 4 ++-- .../Binarization/BinaryThreshold.cs | 4 ++-- .../Processing/Binarization/Dither.cs | 12 +++++----- .../Processing/ColorMatrix/BlackWhite.cs | 4 ++-- .../Processing/ColorMatrix/ColorBlindness.cs | 4 ++-- .../Processing/ColorMatrix/Grayscale.cs | 8 +++---- src/ImageSharp/Processing/ColorMatrix/Hue.cs | 4 ++-- .../Processing/ColorMatrix/Kodachrome.cs | 4 ++-- .../Processing/ColorMatrix/Lomograph.cs | 8 +++---- .../Processing/ColorMatrix/Polaroid.cs | 8 +++---- .../Processing/ColorMatrix/Saturation.cs | 4 ++-- .../Processing/ColorMatrix/Sepia.cs | 4 ++-- .../Processing/Convolution/BoxBlur.cs | 6 ++--- .../Processing/Convolution/DetectEdges.cs | 14 +++++------ .../Processing/Convolution/GaussianBlur.cs | 6 ++--- .../Processing/Convolution/GaussianSharpen.cs | 6 ++--- src/ImageSharp/Processing/Delegate.cs | 2 +- src/ImageSharp/Processing/Effects/Alpha.cs | 4 ++-- .../Processing/Effects/BackgroundColor.cs | 8 +++---- .../Processing/Effects/Brightness.cs | 4 ++-- src/ImageSharp/Processing/Effects/Contrast.cs | 4 ++-- src/ImageSharp/Processing/Effects/Invert.cs | 4 ++-- .../Processing/Effects/OilPainting.cs | 8 +++---- src/ImageSharp/Processing/Effects/Pixelate.cs | 6 ++--- src/ImageSharp/Processing/Overlays/Glow.cs | 24 +++++++++---------- .../Processing/Overlays/Vignette.cs | 24 +++++++++---------- .../Processors/CLoneingImageProcessor.cs | 2 +- .../Processing/Transforms/AutoOrient.cs | 2 +- src/ImageSharp/Processing/Transforms/Crop.cs | 4 ++-- .../Processing/Transforms/EntropyCrop.cs | 2 +- src/ImageSharp/Processing/Transforms/Flip.cs | 2 +- src/ImageSharp/Processing/Transforms/Pad.cs | 2 +- .../Processing/Transforms/Resize.cs | 18 +++++++------- .../Processing/Transforms/Rotate.cs | 6 ++--- .../Processing/Transforms/RotateFlip.cs | 2 +- src/ImageSharp/Processing/Transforms/Skew.cs | 4 ++-- src/ImageSharp/Quantizers/Quantize.cs | 4 ++-- .../BaseImageOperationsExtensionTest.cs | 14 ++++++----- .../FakeImageOperationsProvider.cs | 10 ++++---- .../ImageProviders/TestImageProvider.cs | 2 +- 61 files changed, 242 insertions(+), 240 deletions(-) rename src/ImageSharp/{DefaultInternalImageProcessorApplicator.cs => DefaultInternalImageProcessorContext.cs} (79%) rename src/ImageSharp/{IImageProcessorApplicatorFactory.cs => IImageProcessingContextFactory.cs} (74%) rename src/ImageSharp/{IImageProcessorApplicator{TPixel}.cs => IImageProcessingContext{TPixel}.cs} (83%) rename src/ImageSharp/Image/{ICloningImageProcessor.cs => ICloneingImageProcessor.cs} (89%) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index f635ed203..caed6687f 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -36,7 +36,7 @@ namespace AvatarWithRoundedCorner } // lets create our custom image mutating pipeline - private static IImageProcessorApplicator ConvertToAvatar(this IImageProcessorApplicator operations, Size size, float cornerRadius) + private static IImageProcessingContext ConvertToAvatar(this IImageProcessingContext operations, Size size, float cornerRadius) { return operations.Resize(new ImageSharp.Processing.ResizeOptions { diff --git a/src/ImageSharp.Drawing/DrawImage.cs b/src/ImageSharp.Drawing/DrawImage.cs index a7b1faa15..a89fc7e6f 100644 --- a/src/ImageSharp.Drawing/DrawImage.cs +++ b/src/ImageSharp.Drawing/DrawImage.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The location to draw the blended image. /// The options. /// The . - public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, Size size, Point location, GraphicsOptions options) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Size size, Point location, GraphicsOptions options) where TPixel : struct, IPixel { if (size == default(Size)) @@ -49,7 +49,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, float percent) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -66,7 +66,7 @@ namespace ImageSharp /// The blending mode. /// The opacity of the image image to blend. Must be between 0 and 1. /// The . - public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -83,7 +83,7 @@ namespace ImageSharp /// The image to blend with the currently processing image. /// The options, including the blending type and belnding amount. /// The . - public static IImageProcessorApplicator Blend(this IImageProcessorApplicator source, Image image, GraphicsOptions options) + public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options) where TPixel : struct, IPixel { return DrawImage(source, image, default(Size), default(Point), options); @@ -99,7 +99,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, float percent, Size size, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; @@ -118,7 +118,7 @@ namespace ImageSharp /// The size to draw the blended image. /// The location to draw the blended image. /// The . - public static IImageProcessorApplicator DrawImage(this IImageProcessorApplicator source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float percent, Size size, Point location) where TPixel : struct, IPixel { GraphicsOptions options = GraphicsOptions.Default; diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs index ff86c7240..829d7b826 100644 --- a/src/ImageSharp.Drawing/FillRegion.cs +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The details how to fill the region of interest. /// The graphics options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, GraphicsOptions options) where TPixel : struct, IPixel { return source.ApplyProcessor(new FillProcessor(brush, options)); @@ -36,7 +36,7 @@ namespace ImageSharp /// The image this method extends. /// The details how to fill the region of interest. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) where TPixel : struct, IPixel { return source.Fill(brush, GraphicsOptions.Default); @@ -49,7 +49,7 @@ namespace ImageSharp /// The image this method extends. /// The color. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color)); @@ -64,7 +64,7 @@ namespace ImageSharp /// The region. /// The graphics options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); @@ -78,7 +78,7 @@ namespace ImageSharp /// The brush. /// The region. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Region region) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) where TPixel : struct, IPixel { return source.Fill(brush, region, GraphicsOptions.Default); @@ -93,7 +93,7 @@ namespace ImageSharp /// The region. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region, options); @@ -107,7 +107,7 @@ namespace ImageSharp /// The color. /// The region. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Region region) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), region); diff --git a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs index b83edb7a2..07cc832d7 100644 --- a/src/ImageSharp.Drawing/Paths/DrawBeziers.cs +++ b/src/ImageSharp.Drawing/Paths/DrawBeziers.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawBeziers(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageProcessorApplicator DrawBeziers(this IImageProcessorApplicator source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new CubicBezierLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawLines.cs b/src/ImageSharp.Drawing/Paths/DrawLines.cs index 553ec2ca5..79a5037db 100644 --- a/src/ImageSharp.Drawing/Paths/DrawLines.cs +++ b/src/ImageSharp.Drawing/Paths/DrawLines.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The .> - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawLines(new SolidBrush(color), thickness, points, options); @@ -89,7 +89,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points)), options); @@ -103,7 +103,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageProcessorApplicator DrawLines(this IImageProcessorApplicator source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Path(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/DrawPath.cs b/src/ImageSharp.Drawing/Paths/DrawPath.cs index 68ba89ff1..91ad05894 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPath.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPath.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The path. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) where TPixel : struct, IPixel { return source.Draw(pen, path, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), path); @@ -86,7 +86,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The path. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPath path) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, path); diff --git a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs index 086ce9723..8ac048e3e 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPathCollection.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath path in paths) @@ -44,7 +44,7 @@ namespace ImageSharp /// The pen. /// The paths. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(pen, paths, GraphicsOptions.Default); @@ -60,7 +60,7 @@ namespace ImageSharp /// The shapes. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths, options); @@ -75,7 +75,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), paths); @@ -91,7 +91,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths, options); @@ -106,7 +106,7 @@ namespace ImageSharp /// The thickness. /// The paths. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, IPathCollection paths) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, paths); diff --git a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs index 12b687415..8033e6fb6 100644 --- a/src/ImageSharp.Drawing/Paths/DrawPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/DrawPolygon.cs @@ -28,7 +28,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); @@ -43,7 +43,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -58,7 +58,7 @@ namespace ImageSharp /// The thickness. /// The points. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -74,7 +74,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.DrawPolygon(new SolidBrush(color), thickness, points, options); @@ -88,7 +88,7 @@ namespace ImageSharp /// The pen. /// The points. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); @@ -103,7 +103,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator DrawPolygon(this IImageProcessorApplicator source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); diff --git a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs index a9832a628..720327270 100644 --- a/src/ImageSharp.Drawing/Paths/DrawRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/DrawRectangle.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -39,7 +39,7 @@ namespace ImageSharp /// The pen. /// The shape. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IPen pen, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(pen, shape, GraphicsOptions.Default); @@ -55,7 +55,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape, options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, IBrush brush, float thickness, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new Pen(brush, thickness), shape); @@ -86,7 +86,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape, options); @@ -101,7 +101,7 @@ namespace ImageSharp /// The thickness. /// The shape. /// The . - public static IImageProcessorApplicator Draw(this IImageProcessorApplicator source, TPixel color, float thickness, RectangleF shape) + public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel { return source.Draw(new SolidBrush(color), thickness, shape); diff --git a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs index 38d3ad10f..086288201 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathBuilder.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path, GraphicsOptions options) where TPixel : struct, IPixel { var pb = new PathBuilder(); @@ -42,7 +42,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, Action path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path) where TPixel : struct, IPixel { return source.Fill(brush, path, GraphicsOptions.Default); @@ -57,7 +57,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, Action path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs index eec3fa795..dd7d2cf3e 100644 --- a/src/ImageSharp.Drawing/Paths/FillPathCollection.cs +++ b/src/ImageSharp.Drawing/Paths/FillPathCollection.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shapes. /// The graphics options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { foreach (IPath s in paths) @@ -43,7 +43,7 @@ namespace ImageSharp /// The brush. /// The paths. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPathCollection paths) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(brush, paths, GraphicsOptions.Default); @@ -58,7 +58,7 @@ namespace ImageSharp /// The paths. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths, options); @@ -72,7 +72,7 @@ namespace ImageSharp /// The color. /// The paths. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPathCollection paths) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), paths); diff --git a/src/ImageSharp.Drawing/Paths/FillPaths.cs b/src/ImageSharp.Drawing/Paths/FillPaths.cs index 7cd6dbe54..2cd6ab0fc 100644 --- a/src/ImageSharp.Drawing/Paths/FillPaths.cs +++ b/src/ImageSharp.Drawing/Paths/FillPaths.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The graphics options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The path. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, IPath path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// The path. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The path. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, IPath path) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), path); diff --git a/src/ImageSharp.Drawing/Paths/FillPolygon.cs b/src/ImageSharp.Drawing/Paths/FillPolygon.cs index 6b6cef8ac..2fc481b5c 100644 --- a/src/ImageSharp.Drawing/Paths/FillPolygon.cs +++ b/src/ImageSharp.Drawing/Paths/FillPolygon.cs @@ -27,7 +27,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); @@ -41,7 +41,7 @@ namespace ImageSharp /// The brush. /// The points. /// The . - public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, IBrush brush, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points) where TPixel : struct, IPixel { return source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -56,7 +56,7 @@ namespace ImageSharp /// The points. /// The options. /// The . - public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); @@ -70,7 +70,7 @@ namespace ImageSharp /// The color. /// The points. /// The . - public static IImageProcessorApplicator FillPolygon(this IImageProcessorApplicator source, TPixel color, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); diff --git a/src/ImageSharp.Drawing/Paths/FillRectangle.cs b/src/ImageSharp.Drawing/Paths/FillRectangle.cs index 9e475137a..22cd1ac16 100644 --- a/src/ImageSharp.Drawing/Paths/FillRectangle.cs +++ b/src/ImageSharp.Drawing/Paths/FillRectangle.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -38,7 +38,7 @@ namespace ImageSharp /// The brush. /// The shape. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, IBrush brush, RectangleF shape) + public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); @@ -53,7 +53,7 @@ namespace ImageSharp /// The shape. /// The options. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape, GraphicsOptions options) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape, options); @@ -67,7 +67,7 @@ namespace ImageSharp /// The color. /// The shape. /// The . - public static IImageProcessorApplicator Fill(this IImageProcessorApplicator source, TPixel color, RectangleF shape) + public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape) where TPixel : struct, IPixel { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing/Text/DrawText.Path.cs b/src/ImageSharp.Drawing/Text/DrawText.Path.cs index c109047b2..8adab652f 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.Path.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.Path.cs @@ -31,7 +31,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, color, path, TextGraphicsOptions.Default); @@ -50,7 +50,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, path, options); @@ -68,7 +68,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); @@ -87,7 +87,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, path, options); @@ -105,7 +105,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); @@ -124,7 +124,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, path, options); @@ -143,7 +143,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); @@ -163,7 +163,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp.Drawing/Text/DrawText.cs b/src/ImageSharp.Drawing/Text/DrawText.cs index 338d06058..340c88d5e 100644 --- a/src/ImageSharp.Drawing/Text/DrawText.cs +++ b/src/ImageSharp.Drawing/Text/DrawText.cs @@ -34,7 +34,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, color, location, TextGraphicsOptions.Default); @@ -53,7 +53,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, Brushes.Solid(color), null, location, options); @@ -71,7 +71,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); @@ -90,7 +90,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, null, location, options); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); @@ -127,7 +127,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { return source.DrawText(text, font, null, pen, location, options); @@ -146,7 +146,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); @@ -166,7 +166,7 @@ namespace ImageSharp /// /// The . /// - public static IImageProcessorApplicator DrawText(this IImageProcessorApplicator source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index c0a7f20df..40cd7500a 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -22,13 +22,13 @@ namespace ImageSharp /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. - public static void Mutate(this Image source, Action> operations) + public static void Mutate(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); - IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, true); operations(operationsRunner); operationsRunner.Apply(); } @@ -45,7 +45,7 @@ namespace ImageSharp Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); - IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, true); + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, true); operationsRunner.ApplyProcessors(operations); operationsRunner.Apply(); } @@ -57,13 +57,13 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// Anew Image which has teh data from the but with the applied. - public static Image Clone(this Image source, Action> operations) + public static Image Clone(this Image source, Action> operations) where TPixel : struct, IPixel { Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); - IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, false); operations(operationsRunner); return operationsRunner.Apply(); } @@ -81,7 +81,7 @@ namespace ImageSharp Guard.NotNull(operations, nameof(operations)); Guard.NotNull(source, nameof(source)); - IInternalImageProcessorApplicator operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageOperations(source, false); + IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, false); operationsRunner.ApplyProcessors(operations); return operationsRunner.Apply(); } @@ -93,7 +93,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// returns the current optinoatins class to allow chaining of oprations. - public static IImageProcessorApplicator ApplyProcessors(this IImageProcessorApplicator source, params IImageProcessor[] operations) + public static IImageProcessingContext ApplyProcessors(this IImageProcessingContext source, params IImageProcessor[] operations) where TPixel : struct, IPixel { foreach (IImageProcessor p in operations) diff --git a/src/ImageSharp/Configuration.cs b/src/ImageSharp/Configuration.cs index b86819430..71f6bf412 100644 --- a/src/ImageSharp/Configuration.cs +++ b/src/ImageSharp/Configuration.cs @@ -111,7 +111,7 @@ namespace ImageSharp /// /// Gets or sets the image operations providers. /// - internal IImageProcessorApplicatorFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); + internal IImageProcessingContextFactory ImageOperationsProvider { get; set; } = new DefaultImageOperationsProvider(); /// /// Registers a new format provider. diff --git a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs similarity index 79% rename from src/ImageSharp/DefaultInternalImageProcessorApplicator.cs rename to src/ImageSharp/DefaultInternalImageProcessorContext.cs index ba476ba33..64f444325 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorApplicator.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -15,7 +15,7 @@ namespace ImageSharp /// The static collection of all the default image formats /// /// The pixel format - internal class DefaultInternalImageProcessorApplicator : IInternalImageProcessorApplicator + internal class DefaultInternalImageProcessorContext : IInternalImageProcessingContext where TPixel : struct, IPixel { private readonly bool mutate; @@ -23,11 +23,11 @@ namespace ImageSharp private Image destination; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The image. /// The mutate. - public DefaultInternalImageProcessorApplicator(Image source, bool mutate) + public DefaultInternalImageProcessorContext(Image source, bool mutate) { this.mutate = mutate; this.source = source; @@ -50,16 +50,16 @@ namespace ImageSharp } /// - public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { if (!this.mutate && this.destination == null) { // this will only work if the first processor applied is the cloning one thus // realistically for this optermissation to work the resize must the first processor // applied any only up processors will take the douple data path. - if (processor is ICloningImageProcessor) + if (processor is ICloneingImageProcessor) { - var cloningProcessor = (ICloningImageProcessor)processor; + var cloningProcessor = (ICloneingImageProcessor)processor; this.destination = cloningProcessor.CloneAndApply(this.source, rectangle); return this; } @@ -74,7 +74,7 @@ namespace ImageSharp } /// - public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) + public IImageProcessingContext ApplyProcessor(IImageProcessor processor) { return this.ApplyProcessor(processor, this.source.Bounds()); } diff --git a/src/ImageSharp/IImageProcessorApplicatorFactory.cs b/src/ImageSharp/IImageProcessingContextFactory.cs similarity index 74% rename from src/ImageSharp/IImageProcessorApplicatorFactory.cs rename to src/ImageSharp/IImageProcessingContextFactory.cs index e07b1a752..a9cd23905 100644 --- a/src/ImageSharp/IImageProcessorApplicatorFactory.cs +++ b/src/ImageSharp/IImageProcessingContextFactory.cs @@ -11,7 +11,7 @@ namespace ImageSharp /// /// Represents an interface that will create IImageOperations /// - internal interface IImageProcessorApplicatorFactory + internal interface IImageProcessingContextFactory { /// /// Called during Mutate operations to generate the imageoperations provider. @@ -20,20 +20,20 @@ namespace ImageSharp /// The source image. /// A flag to determin with the image operations is allowed to mutate the source image or not. /// A new IImageOPeration - IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) + IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) where TPixel : struct, IPixel; } /// /// The default implmentation of IImageOperationsProvider /// - internal class DefaultImageOperationsProvider : IImageProcessorApplicatorFactory + internal class DefaultImageOperationsProvider : IImageProcessingContextFactory { /// - public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) + public IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) where TPixel : struct, IPixel { - return new DefaultInternalImageProcessorApplicator(source, mutate); + return new DefaultInternalImageProcessorContext(source, mutate); } } } diff --git a/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs b/src/ImageSharp/IImageProcessingContext{TPixel}.cs similarity index 83% rename from src/ImageSharp/IImageProcessorApplicator{TPixel}.cs rename to src/ImageSharp/IImageProcessingContext{TPixel}.cs index 861c5b010..e79b20ba6 100644 --- a/src/ImageSharp/IImageProcessorApplicator{TPixel}.cs +++ b/src/ImageSharp/IImageProcessingContext{TPixel}.cs @@ -15,7 +15,7 @@ namespace ImageSharp /// An interface to queue up image operations. /// /// The pixel format - public interface IImageProcessorApplicator + public interface IImageProcessingContext where TPixel : struct, IPixel { /// @@ -24,21 +24,21 @@ namespace ImageSharp /// The processor to apply /// The area to apply it to /// returns the current optinoatins class to allow chaining of oprations. - IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle); + IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle); /// /// Adds the processor to the current setr of image operations to be applied. /// /// The processor to apply /// returns the current optinoatins class to allow chaining of oprations. - IImageProcessorApplicator ApplyProcessor(IImageProcessor processor); + IImageProcessingContext ApplyProcessor(IImageProcessor processor); } /// /// An internal interface to queue up image operations and have a method to apply them to and return a result /// /// The pixel format - public interface IInternalImageProcessorApplicator : IImageProcessorApplicator + internal interface IInternalImageProcessingContext : IImageProcessingContext where TPixel : struct, IPixel { /// diff --git a/src/ImageSharp/Image/ICloningImageProcessor.cs b/src/ImageSharp/Image/ICloneingImageProcessor.cs similarity index 89% rename from src/ImageSharp/Image/ICloningImageProcessor.cs rename to src/ImageSharp/Image/ICloneingImageProcessor.cs index 8906063f9..92f87d02e 100644 --- a/src/ImageSharp/Image/ICloningImageProcessor.cs +++ b/src/ImageSharp/Image/ICloneingImageProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -15,7 +15,7 @@ namespace ImageSharp.Processing /// Encapsulates methods to alter the pixels of an image. /// /// The pixel format. - public interface ICloningImageProcessor : IImageProcessor + internal interface ICloneingImageProcessor : IImageProcessor where TPixel : struct, IPixel { /// diff --git a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs index 796b4f597..89d62cc4c 100644 --- a/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs +++ b/src/ImageSharp/Processing/Binarization/BinaryThreshold.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold) + public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold)); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator BinaryThreshold(this IImageProcessorApplicator source, float threshold, Rectangle rectangle) + public static IImageProcessingContext BinaryThreshold(this IImageProcessingContext source, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BinaryThresholdProcessor(threshold), rectangle); diff --git a/src/ImageSharp/Processing/Binarization/Dither.cs b/src/ImageSharp/Processing/Binarization/Dither.cs index 177279cea..2d9ef4263 100644 --- a/src/ImageSharp/Processing/Binarization/Dither.cs +++ b/src/ImageSharp/Processing/Binarization/Dither.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The ordered ditherer. /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0)); @@ -39,7 +39,7 @@ namespace ImageSharp /// The ordered ditherer. /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, int index) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index)); @@ -56,7 +56,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, 0), rectangle); @@ -74,7 +74,7 @@ namespace ImageSharp /// /// The component index to test the threshold against. Must range from 0 to 3. /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IOrderedDither dither, Rectangle rectangle, int index) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IOrderedDither dither, Rectangle rectangle, int index) where TPixel : struct, IPixel { source.ApplyProcessor(new OrderedDitherProcessor(dither, index), rectangle); @@ -89,7 +89,7 @@ namespace ImageSharp /// The diffusion algorithm to apply. /// The threshold to apply binarization of the image. Must be between 0 and 1. /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold)); @@ -107,7 +107,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Dither(this IImageProcessorApplicator source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) + public static IImageProcessingContext Dither(this IImageProcessingContext source, IErrorDiffuser diffuser, float threshold, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new ErrorDiffusionDitherProcessor(diffuser, threshold), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs index 3d15d1cbc..71d1d5070 100644 --- a/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs +++ b/src/ImageSharp/Processing/ColorMatrix/BlackWhite.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source) + public static IImageProcessingContext BlackWhite(this IImageProcessingContext source) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator BlackWhite(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext BlackWhite(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new BlackWhiteProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs index 8a055c33c..9ba961a71 100644 --- a/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs +++ b/src/ImageSharp/Processing/ColorMatrix/ColorBlindness.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The type of color blindness simulator to apply. /// The . - public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator ColorBlindness(this IImageProcessorApplicator source, ColorBlindness colorBlindness, Rectangle rectangle) + public static IImageProcessingContext ColorBlindness(this IImageProcessingContext source, ColorBlindness colorBlindness, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(GetProcessor(colorBlindness), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs index 7b00ae0d8..6109c5404 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Grayscale.cs @@ -22,7 +22,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The formula to apply to perform the operation. /// The . - public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 @@ -55,7 +55,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Grayscale(source, GrayscaleMode.Bt709, rectangle); @@ -71,7 +71,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Grayscale(this IImageProcessorApplicator source, GrayscaleMode mode, Rectangle rectangle) + public static IImageProcessingContext Grayscale(this IImageProcessingContext source, GrayscaleMode mode, Rectangle rectangle) where TPixel : struct, IPixel { IImageProcessor processor = mode == GrayscaleMode.Bt709 diff --git a/src/ImageSharp/Processing/ColorMatrix/Hue.cs b/src/ImageSharp/Processing/ColorMatrix/Hue.cs index cd2adaadb..d299b650a 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Hue.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Hue.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The angle in degrees to adjust the image. /// The . - public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees) + public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Hue(this IImageProcessorApplicator source, float degrees, Rectangle rectangle) + public static IImageProcessingContext Hue(this IImageProcessingContext source, float degrees, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new HueProcessor(degrees), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs index b16f241c0..c0cd7caf7 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Kodachrome.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source) + public static IImageProcessingContext Kodachrome(this IImageProcessingContext source) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor()); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Kodachrome(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Kodachrome(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new KodachromeProcessor(), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs index 0a2f80cc4..a90551bf3 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Lomograph.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source) where TPixel : struct, IPixel { return Lomograph(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Lomograph(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, GraphicsOptions options) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Lomograph(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Lomograph(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new LomographProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs index e579a3251..b968aedfc 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Polaroid.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source) where TPixel : struct, IPixel { return Polaroid(source, GraphicsOptions.Default); @@ -39,7 +39,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Polaroid(source, rectangle, GraphicsOptions.Default); @@ -52,7 +52,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, GraphicsOptions options) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options)); @@ -69,7 +69,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Polaroid(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Polaroid(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel { source.ApplyProcessor(new PolaroidProcessor(options), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs index 768eb97c5..895362c68 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Saturation.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Saturation.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The image this method extends. /// The new saturation of the image. Must be between -100 and 100. /// The . - public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount) + public static IImageProcessingContext Saturation(this IImageProcessingContext source, int amount) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount)); @@ -42,7 +42,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Saturation(this IImageProcessorApplicator source, int amount, Rectangle rectangle) + public static IImageProcessingContext Saturation(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel { source.ApplyProcessor(new SaturationProcessor(amount), rectangle); diff --git a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs index 5cf64a020..4ef4db14e 100644 --- a/src/ImageSharp/Processing/ColorMatrix/Sepia.cs +++ b/src/ImageSharp/Processing/ColorMatrix/Sepia.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source) + public static IImageProcessingContext Sepia(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor()); @@ -37,7 +37,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Sepia(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Sepia(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new SepiaProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/BoxBlur.cs b/src/ImageSharp/Processing/Convolution/BoxBlur.cs index c25de3571..eaddfe2dc 100644 --- a/src/ImageSharp/Processing/Convolution/BoxBlur.cs +++ b/src/ImageSharp/Processing/Convolution/BoxBlur.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source) + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(7)); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The 'radius' value representing the size of the area to sample. /// The . - public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius) + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator BoxBlur(this IImageProcessorApplicator source, int radius, Rectangle rectangle) + public static IImageProcessingContext BoxBlur(this IImageProcessingContext source, int radius, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BoxBlurProcessor(radius), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/DetectEdges.cs b/src/ImageSharp/Processing/Convolution/DetectEdges.cs index 7ececcfe2..8721bf4f8 100644 --- a/src/ImageSharp/Processing/Convolution/DetectEdges.cs +++ b/src/ImageSharp/Processing/Convolution/DetectEdges.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source) where TPixel : struct, IPixel { return DetectEdges(source, new SobelProcessor { Grayscale = true }); @@ -41,7 +41,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true }); @@ -54,7 +54,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, true)); @@ -66,7 +66,7 @@ namespace ImageSharp /// The filter for detecting edges. /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, bool grayscale) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, bool grayscale) where TPixel : struct, IPixel => DetectEdges(source, GetProcessor(filter, grayscale)); @@ -81,7 +81,7 @@ namespace ImageSharp /// /// Whether to convert the image to Grayscale first. Defaults to true. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true) where TPixel : struct, IPixel => DetectEdges(source, rectangle, GetProcessor(filter, grayscale)); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The filter for detecting edges. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, IEdgeDetectorProcessor filter) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { return source.ApplyProcessor(filter); @@ -108,7 +108,7 @@ namespace ImageSharp /// /// The filter for detecting edges. /// The . - public static IImageProcessorApplicator DetectEdges(this IImageProcessorApplicator source, Rectangle rectangle, IEdgeDetectorProcessor filter) + public static IImageProcessingContext DetectEdges(this IImageProcessingContext source, Rectangle rectangle, IEdgeDetectorProcessor filter) where TPixel : struct, IPixel { source.ApplyProcessor(filter, rectangle); diff --git a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs index 4b1682818..1db4fd500 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianBlur.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianBlur.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source) + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(3f)); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma) + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator GaussianBlur(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) + public static IImageProcessingContext GaussianBlur(this IImageProcessingContext source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianBlurProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs index 8c8ac6ed2..5f66f1771 100644 --- a/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs +++ b/src/ImageSharp/Processing/Convolution/GaussianSharpen.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source) + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(3f)); @@ -35,7 +35,7 @@ namespace ImageSharp /// The image this method extends. /// The 'sigma' value representing the weight of the blur. /// The . - public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma) + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source, float sigma) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma)); @@ -49,7 +49,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator GaussianSharpen(this IImageProcessorApplicator source, float sigma, Rectangle rectangle) + public static IImageProcessingContext GaussianSharpen(this IImageProcessingContext source, float sigma, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GaussianSharpenProcessor(sigma), rectangle); } diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs index a5647d69e..733c4d090 100644 --- a/src/ImageSharp/Processing/Delegate.cs +++ b/src/ImageSharp/Processing/Delegate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The operations to perform on the source. /// returns the current optinoatins class to allow chaining of oprations. - public static IImageProcessorApplicator Run(this IImageProcessorApplicator source, Action> operation) + public static IImageProcessingContext Run(this IImageProcessingContext source, Action> operation) where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateProcessor(operation)); } diff --git a/src/ImageSharp/Processing/Effects/Alpha.cs b/src/ImageSharp/Processing/Effects/Alpha.cs index b49a697da..2081c91bd 100644 --- a/src/ImageSharp/Processing/Effects/Alpha.cs +++ b/src/ImageSharp/Processing/Effects/Alpha.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new opacity of the image. Must be between 0 and 1. /// The . - public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent) + public static IImageProcessingContext Alpha(this IImageProcessingContext source, float percent) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Alpha(this IImageProcessorApplicator source, float percent, Rectangle rectangle) + public static IImageProcessingContext Alpha(this IImageProcessingContext source, float percent, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new AlphaProcessor(percent), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/BackgroundColor.cs b/src/ImageSharp/Processing/Effects/BackgroundColor.cs index c4754c8e6..ec9fe32d6 100644 --- a/src/ImageSharp/Processing/Effects/BackgroundColor.cs +++ b/src/ImageSharp/Processing/Effects/BackgroundColor.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The color to set as the background. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); @@ -40,7 +40,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); @@ -51,7 +51,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the background. /// The . - public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return BackgroundColor(source, color, GraphicsOptions.Default); @@ -67,7 +67,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator BackgroundColor(this IImageProcessorApplicator source, TPixel color, Rectangle rectangle) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel { return BackgroundColor(source, color, rectangle, GraphicsOptions.Default); diff --git a/src/ImageSharp/Processing/Effects/Brightness.cs b/src/ImageSharp/Processing/Effects/Brightness.cs index 59a02d456..d9ed57612 100644 --- a/src/ImageSharp/Processing/Effects/Brightness.cs +++ b/src/ImageSharp/Processing/Effects/Brightness.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new brightness of the image. Must be between -100 and 100. /// The . - public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount) + public static IImageProcessingContext Brightness(this IImageProcessingContext source, int amount) where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Brightness(this IImageProcessorApplicator source, int amount, Rectangle rectangle) + public static IImageProcessingContext Brightness(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BrightnessProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Contrast.cs b/src/ImageSharp/Processing/Effects/Contrast.cs index e94605a75..0af86e1df 100644 --- a/src/ImageSharp/Processing/Effects/Contrast.cs +++ b/src/ImageSharp/Processing/Effects/Contrast.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image this method extends. /// The new contrast of the image. Must be between -100 and 100. /// The . - public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount) + public static IImageProcessingContext Contrast(this IImageProcessingContext source, int amount) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Contrast(this IImageProcessorApplicator source, int amount, Rectangle rectangle) + public static IImageProcessingContext Contrast(this IImageProcessingContext source, int amount, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new ContrastProcessor(amount), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Invert.cs b/src/ImageSharp/Processing/Effects/Invert.cs index 5e0ceab75..cc480cf0c 100644 --- a/src/ImageSharp/Processing/Effects/Invert.cs +++ b/src/ImageSharp/Processing/Effects/Invert.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source) + public static IImageProcessingContext Invert(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor()); @@ -36,7 +36,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Invert(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Invert(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new InvertProcessor(), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/OilPainting.cs b/src/ImageSharp/Processing/Effects/OilPainting.cs index e6a8c8373..844b5ceb6 100644 --- a/src/ImageSharp/Processing/Effects/OilPainting.cs +++ b/src/ImageSharp/Processing/Effects/OilPainting.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source) where TPixel : struct, IPixel { return OilPaint(source, 10, 15); @@ -40,7 +40,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return OilPaint(source, 10, 15, rectangle); @@ -54,7 +54,7 @@ namespace ImageSharp /// The number of intensity levels. Higher values result in a broader range of color intensities forming part of the result image. /// The number of neighboring pixels used in calculating each individual pixel value. /// The . - public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize)); @@ -69,7 +69,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator OilPaint(this IImageProcessorApplicator source, int levels, int brushSize, Rectangle rectangle) + public static IImageProcessingContext OilPaint(this IImageProcessingContext source, int levels, int brushSize, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new OilPaintingProcessor(levels, brushSize), rectangle); } diff --git a/src/ImageSharp/Processing/Effects/Pixelate.cs b/src/ImageSharp/Processing/Effects/Pixelate.cs index c1e631838..3ae152c2b 100644 --- a/src/ImageSharp/Processing/Effects/Pixelate.cs +++ b/src/ImageSharp/Processing/Effects/Pixelate.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source) + public static IImageProcessingContext Pixelate(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(4)); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The size of the pixels. /// The . - public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size) + public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size)); @@ -48,7 +48,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Pixelate(this IImageProcessorApplicator source, int size, Rectangle rectangle) + public static IImageProcessingContext Pixelate(this IImageProcessingContext source, int size, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new PixelateProcessor(size), rectangle); } diff --git a/src/ImageSharp/Processing/Overlays/Glow.cs b/src/ImageSharp/Processing/Overlays/Glow.cs index 30ff66692..e34cbf591 100644 --- a/src/ImageSharp/Processing/Overlays/Glow.cs +++ b/src/ImageSharp/Processing/Overlays/Glow.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source) + public static IImageProcessingContext Glow(this IImageProcessingContext source) where TPixel : struct, IPixel { return Glow(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the glow. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return Glow(source, color, GraphicsOptions.Default); @@ -47,7 +47,7 @@ namespace ImageSharp /// The image this method extends. /// The the radius. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius) + public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) where TPixel : struct, IPixel { return Glow(source, radius, GraphicsOptions.Default); @@ -62,7 +62,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(rectangle, GraphicsOptions.Default); @@ -77,7 +77,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); @@ -88,7 +88,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting things like blending. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); @@ -100,7 +100,7 @@ namespace ImageSharp /// The color to set as the glow. /// The options effecting things like blending. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); @@ -112,7 +112,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, float radius, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); @@ -126,7 +126,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); @@ -142,7 +142,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - public static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); @@ -158,7 +158,7 @@ namespace ImageSharp /// /// The options effecting things like blending. /// The . - private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); @@ -171,7 +171,7 @@ namespace ImageSharp /// The the radius. /// The options effecting things like blending. /// The . - private static IImageProcessorApplicator Glow(this IImageProcessorApplicator source, TPixel color, ValueSize radius, GraphicsOptions options) + private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } diff --git a/src/ImageSharp/Processing/Overlays/Vignette.cs b/src/ImageSharp/Processing/Overlays/Vignette.cs index 81cd773b2..f0c962627 100644 --- a/src/ImageSharp/Processing/Overlays/Vignette.cs +++ b/src/ImageSharp/Processing/Overlays/Vignette.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image this method extends. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source) + public static IImageProcessingContext Vignette(this IImageProcessingContext source) where TPixel : struct, IPixel { return Vignette(source, GraphicsOptions.Default); @@ -34,7 +34,7 @@ namespace ImageSharp /// The image this method extends. /// The color to set as the vignette. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { return Vignette(source, color, GraphicsOptions.Default); @@ -48,7 +48,7 @@ namespace ImageSharp /// The the x-radius. /// The the y-radius. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY) where TPixel : struct, IPixel { return Vignette(source, radiusX, radiusY, GraphicsOptions.Default); @@ -63,7 +63,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel { return Vignette(source, rectangle, GraphicsOptions.Default); @@ -81,7 +81,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to alter. /// /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); @@ -92,7 +92,7 @@ namespace ImageSharp /// The image this method extends. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -104,7 +104,7 @@ namespace ImageSharp /// The color to set as the vignette. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); @@ -117,7 +117,7 @@ namespace ImageSharp /// The the y-radius. /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); @@ -131,7 +131,7 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); @@ -148,15 +148,15 @@ namespace ImageSharp /// /// The options effecting pixel blending. /// The . - public static IImageProcessorApplicator Vignette(this IImageProcessorApplicator source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); - private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); - private static IImageProcessorApplicator VignetteInternal(this IImageProcessorApplicator source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } diff --git a/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs b/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs index 0b6dbd3ed..a95e466ab 100644 --- a/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Processing /// Allows the application of processors to images. /// /// The pixel format. - internal abstract class CloneingImageProcessor : IImageProcessor, ICloningImageProcessor + internal abstract class CloneingImageProcessor : IImageProcessor, ICloneingImageProcessor where TPixel : struct, IPixel { /// diff --git a/src/ImageSharp/Processing/Transforms/AutoOrient.cs b/src/ImageSharp/Processing/Transforms/AutoOrient.cs index f741e41b1..f01fbef3d 100644 --- a/src/ImageSharp/Processing/Transforms/AutoOrient.cs +++ b/src/ImageSharp/Processing/Transforms/AutoOrient.cs @@ -21,7 +21,7 @@ namespace ImageSharp /// The pixel format. /// The image to auto rotate. /// The - public static IImageProcessorApplicator AutoOrient(this IImageProcessorApplicator source) + public static IImageProcessingContext AutoOrient(this IImageProcessingContext source) where TPixel : struct, IPixel => source.ApplyProcessor(new Processing.Processors.AutoRotateProcessor()); } diff --git a/src/ImageSharp/Processing/Transforms/Crop.cs b/src/ImageSharp/Processing/Transforms/Crop.cs index aad80fa0f..6a8b02d02 100644 --- a/src/ImageSharp/Processing/Transforms/Crop.cs +++ b/src/ImageSharp/Processing/Transforms/Crop.cs @@ -25,7 +25,7 @@ namespace ImageSharp /// The target image width. /// The target image height. /// The - public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, int width, int height) + public static IImageProcessingContext Crop(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel => Crop(source, new Rectangle(0, 0, width, height)); @@ -38,7 +38,7 @@ namespace ImageSharp /// The structure that specifies the portion of the image object to retain. /// /// The - public static IImageProcessorApplicator Crop(this IImageProcessorApplicator source, Rectangle cropRectangle) + public static IImageProcessingContext Crop(this IImageProcessingContext source, Rectangle cropRectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new CropProcessor(cropRectangle)); } diff --git a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs index a0704619c..8c5f32dd0 100644 --- a/src/ImageSharp/Processing/Transforms/EntropyCrop.cs +++ b/src/ImageSharp/Processing/Transforms/EntropyCrop.cs @@ -23,7 +23,7 @@ namespace ImageSharp /// The image to crop. /// The threshold for entropic density. /// The - public static IImageProcessorApplicator EntropyCrop(this IImageProcessorApplicator source, float threshold = .5f) + public static IImageProcessingContext EntropyCrop(this IImageProcessingContext source, float threshold = .5f) where TPixel : struct, IPixel => source.ApplyProcessor(new EntropyCropProcessor(threshold)); } diff --git a/src/ImageSharp/Processing/Transforms/Flip.cs b/src/ImageSharp/Processing/Transforms/Flip.cs index 2f20c3bd8..071662ae6 100644 --- a/src/ImageSharp/Processing/Transforms/Flip.cs +++ b/src/ImageSharp/Processing/Transforms/Flip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate, flip, or both. /// The to perform the flip. /// The - public static IImageProcessorApplicator Flip(this IImageProcessorApplicator source, FlipType flipType) + public static IImageProcessingContext Flip(this IImageProcessingContext source, FlipType flipType) where TPixel : struct, IPixel => source.ApplyProcessor(new FlipProcessor(flipType)); } diff --git a/src/ImageSharp/Processing/Transforms/Pad.cs b/src/ImageSharp/Processing/Transforms/Pad.cs index 90a9e281b..40fd6da6e 100644 --- a/src/ImageSharp/Processing/Transforms/Pad.cs +++ b/src/ImageSharp/Processing/Transforms/Pad.cs @@ -26,7 +26,7 @@ namespace ImageSharp /// The new width. /// The new height. /// The . - public static IImageProcessorApplicator Pad(this IImageProcessorApplicator source, int width, int height) + public static IImageProcessingContext Pad(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel { ResizeOptions options = new ResizeOptions diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index 4c04991c0..c73581a93 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The resize options. /// The /// Passing zero for one of height or width within the resize options will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, ResizeOptions options) + public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options) where TPixel : struct, IPixel { return source.Run(img => @@ -56,7 +56,7 @@ namespace ImageSharp /// The target image size. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size) + public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), false); @@ -71,7 +71,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, Size size, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, Size size, bool compand) where TPixel : struct, IPixel { return Resize(source, size.Width, size.Height, new BicubicResampler(), compand); @@ -86,7 +86,7 @@ namespace ImageSharp /// The target image height. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), false); @@ -102,7 +102,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, new BicubicResampler(), compand); @@ -118,7 +118,7 @@ namespace ImageSharp /// The to perform the resampling. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, false); @@ -135,7 +135,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, bool compand) where TPixel : struct, IPixel { return Resize(source, width, height, sampler, new Rectangle(0, 0, width, height), compand); @@ -159,7 +159,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => @@ -199,7 +199,7 @@ namespace ImageSharp /// Whether to compress and expand the image color-space to gamma correct the image during processing. /// The /// Passing zero for one of height or width will automatically preserve the aspect ratio of the original image - public static IImageProcessorApplicator Resize(this IImageProcessorApplicator source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) + public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { return source.Run(img => diff --git a/src/ImageSharp/Processing/Transforms/Rotate.cs b/src/ImageSharp/Processing/Transforms/Rotate.cs index 08ac44dad..435efa30f 100644 --- a/src/ImageSharp/Processing/Transforms/Rotate.cs +++ b/src/ImageSharp/Processing/Transforms/Rotate.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The image to rotate. /// The angle in degrees to perform the rotation. /// The - public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees) where TPixel : struct, IPixel { return Rotate(source, degrees, true); @@ -37,7 +37,7 @@ namespace ImageSharp /// The image to rotate. /// The to perform the rotation. /// The - public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, RotateType rotateType) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, RotateType rotateType) where TPixel : struct, IPixel => Rotate(source, (float)rotateType, false); @@ -49,7 +49,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation. /// Whether to expand the image to fit the rotated result. /// The - public static IImageProcessorApplicator Rotate(this IImageProcessorApplicator source, float degrees, bool expand) + public static IImageProcessingContext Rotate(this IImageProcessingContext source, float degrees, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new RotateProcessor { Angle = degrees, Expand = expand }); } diff --git a/src/ImageSharp/Processing/Transforms/RotateFlip.cs b/src/ImageSharp/Processing/Transforms/RotateFlip.cs index 2c321358e..83edba0f9 100644 --- a/src/ImageSharp/Processing/Transforms/RotateFlip.cs +++ b/src/ImageSharp/Processing/Transforms/RotateFlip.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The to perform the rotation. /// The to perform the flip. /// The - public static IImageProcessorApplicator RotateFlip(this IImageProcessorApplicator source, RotateType rotateType, FlipType flipType) + public static IImageProcessingContext RotateFlip(this IImageProcessingContext source, RotateType rotateType, FlipType flipType) where TPixel : struct, IPixel { return source.Rotate(rotateType).Flip(flipType); diff --git a/src/ImageSharp/Processing/Transforms/Skew.cs b/src/ImageSharp/Processing/Transforms/Skew.cs index 8fde7270d..5f7853f05 100644 --- a/src/ImageSharp/Processing/Transforms/Skew.cs +++ b/src/ImageSharp/Processing/Transforms/Skew.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the x-axis. /// The angle in degrees to perform the rotation along the y-axis. /// The - public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY) + public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY) where TPixel : struct, IPixel { return Skew(source, degreesX, degreesY, true); @@ -39,7 +39,7 @@ namespace ImageSharp /// The angle in degrees to perform the rotation along the y-axis. /// Whether to expand the image to fit the skewed result. /// The - public static IImageProcessorApplicator Skew(this IImageProcessorApplicator source, float degreesX, float degreesY, bool expand) + public static IImageProcessingContext Skew(this IImageProcessingContext source, float degreesX, float degreesY, bool expand) where TPixel : struct, IPixel => source.ApplyProcessor(new SkewProcessor { AngleX = degreesX, AngleY = degreesY, Expand = expand }); } diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 54c57b508..0edc1557a 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -24,7 +24,7 @@ namespace ImageSharp /// The quantization mode to apply to perform the operation. /// The maximum number of colors to return. Defaults to 256. /// The . - public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, Quantization mode = Quantization.Octree, int maxColors = 256) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, Quantization mode = Quantization.Octree, int maxColors = 256) where TPixel : struct, IPixel { IQuantizer quantizer; @@ -54,7 +54,7 @@ namespace ImageSharp /// The quantizer to apply to perform the operation. /// The maximum number of colors to return. /// The . - public static IImageProcessorApplicator Quantize(this IImageProcessorApplicator source, IQuantizer quantizer, int maxColors) + public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { return source.Run(img => diff --git a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs index 997215ce2..f2afe2f4f 100644 --- a/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs +++ b/tests/ImageSharp.Tests/BaseImageOperationsExtensionTest.cs @@ -9,7 +9,8 @@ namespace ImageSharp.Tests { public abstract class BaseImageOperationsExtensionTest { - protected readonly FakeImageOperationsProvider.FakeImageOperations operations; + protected readonly IImageProcessingContext operations; + private readonly FakeImageOperationsProvider.FakeImageOperations internalOperations; protected readonly Rectangle rect; protected readonly GraphicsOptions options; @@ -17,23 +18,24 @@ namespace ImageSharp.Tests { this.options = new GraphicsOptions(false) { }; this.rect = new Rectangle(91, 123, 324, 56); // make this random? - this.operations = new FakeImageOperationsProvider.FakeImageOperations(null, false); + this.internalOperations = new FakeImageOperationsProvider.FakeImageOperations(null, false); + this.operations = this.internalOperations; } public T Verify(int index = 0) { - Assert.InRange(index, 0, this.operations.applied.Count - 1); + Assert.InRange(index, 0, this.internalOperations.applied.Count - 1); - var operation = this.operations.applied[index]; + var operation = this.internalOperations.applied[index]; return Assert.IsType(operation.Processor); } public T Verify(Rectangle rect, int index = 0) { - Assert.InRange(index, 0, this.operations.applied.Count - 1); + Assert.InRange(index, 0, this.internalOperations.applied.Count - 1); - var operation = this.operations.applied[index]; + var operation = this.internalOperations.applied[index]; Assert.Equal(rect, operation.Rectangle); return Assert.IsType(operation.Processor); diff --git a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs index e06b918af..1c6fec0a4 100644 --- a/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs +++ b/tests/ImageSharp.Tests/FakeImageOperationsProvider.cs @@ -8,7 +8,7 @@ using ImageSharp.Processing; using SixLabors.Primitives; - public class FakeImageOperationsProvider : IImageProcessorApplicatorFactory + internal class FakeImageOperationsProvider : IImageProcessingContextFactory { private List ImageOperators = new List(); @@ -29,7 +29,7 @@ .SelectMany(x => x.applied); } - public IInternalImageProcessorApplicator CreateImageOperations(Image source, bool mutate) where TPixel : struct, IPixel + public IInternalImageProcessingContext CreateImageProcessingContext(Image source, bool mutate) where TPixel : struct, IPixel { var op = new FakeImageOperations(source, mutate); this.ImageOperators.Add(op); @@ -37,7 +37,7 @@ } - public class FakeImageOperations : IInternalImageProcessorApplicator + public class FakeImageOperations : IInternalImageProcessingContext where TPixel : struct, IPixel { public Image source; @@ -63,7 +63,7 @@ return source; } - public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor, Rectangle rectangle) + public IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle) { applied.Add(new AppliedOpperation { @@ -73,7 +73,7 @@ return this; } - public IImageProcessorApplicator ApplyProcessor(IImageProcessor processor) + public IImageProcessingContext ApplyProcessor(IImageProcessor processor) { applied.Add(new AppliedOpperation { diff --git a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs index ae10bf9af..8681bb334 100644 --- a/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs +++ b/tests/ImageSharp.Tests/TestUtilities/ImageProviders/TestImageProvider.cs @@ -85,7 +85,7 @@ namespace ImageSharp.Tests /// /// Returns an instance to the test case with the necessary traits. /// - public Image GetImage(Action> operationsToApply) + public Image GetImage(Action> operationsToApply) { var img = GetImage(); img.Mutate(operationsToApply); From 3e233139aa9a5d394ef4722b47bd3e3013a3a2e3 Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 17 Jul 2017 02:23:45 +0200 Subject: [PATCH 17/20] made FormatsDirectory a lazy value -> folders are no longer walked in TestFile type initializer. Might be healthy for test discoverers. Conflicts: tests/ImageSharp.Tests/TestFile.cs --- tests/ImageSharp.Tests/TestFile.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 2b505a2e4..13944cc3c 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -25,10 +25,10 @@ namespace ImageSharp.Tests private static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); /// - /// The formats directory. + /// The formats directory, as lazy value /// - private static readonly string FormatsDirectory = GetFormatsDirectory(); - + private static readonly Lazy formatsDirectory = new Lazy(GetFormatsDirectory); + private Image _image; private byte[] _bytes; @@ -71,6 +71,11 @@ namespace ImageSharp.Tests /// public string FileNameWithoutExtension => Path.GetFileNameWithoutExtension(this.file); + /// + /// Gets the "Formats" test file directory. + /// + private static string FormatsDirectory => formatsDirectory.Value; + /// /// Gets the full qualified path to the file. /// From d9fb5bda4db1a1f9f3a67f5cccb956a91ac5d02d Mon Sep 17 00:00:00 2001 From: Anton Firszov Date: Mon, 17 Jul 2017 02:29:37 +0200 Subject: [PATCH 18/20] clean up TestFile.cs --- tests/ImageSharp.Tests/TestFile.cs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/tests/ImageSharp.Tests/TestFile.cs b/tests/ImageSharp.Tests/TestFile.cs index 13944cc3c..4f286f4da 100644 --- a/tests/ImageSharp.Tests/TestFile.cs +++ b/tests/ImageSharp.Tests/TestFile.cs @@ -25,17 +25,19 @@ namespace ImageSharp.Tests private static readonly ConcurrentDictionary Cache = new ConcurrentDictionary(); /// - /// The formats directory, as lazy value + /// The "Formats" directory, as lazy value /// private static readonly Lazy formatsDirectory = new Lazy(GetFormatsDirectory); - private Image _image; - private byte[] _bytes; + /// + /// The image (lazy initialized value) + /// + private Image image; /// - /// The image. + /// The image bytes /// - private Image image => this._image ?? (this._image = Image.Load(this.Bytes)); + private byte[] bytes; /// /// The file. @@ -52,9 +54,9 @@ namespace ImageSharp.Tests } /// - /// Gets the bytes. + /// Gets the image bytes. /// - public byte[] Bytes => this._bytes ?? (this._bytes = File.ReadAllBytes(this.file)); + public byte[] Bytes => this.bytes ?? (this.bytes = File.ReadAllBytes(this.file)); /// /// The file name. @@ -71,6 +73,11 @@ namespace ImageSharp.Tests /// public string FileNameWithoutExtension => Path.GetFileNameWithoutExtension(this.file); + /// + /// Gets the image with lazy initialization. + /// + private Image Image => this.image ?? (this.image = ImageSharp.Image.Load(this.Bytes)); + /// /// Gets the "Formats" test file directory. /// @@ -130,22 +137,22 @@ namespace ImageSharp.Tests /// Creates a new image. /// /// - /// The . + /// The . /// public Image CreateImage() { - return this.image.Clone(); + return this.Image.Clone(); } /// /// Creates a new image. /// /// - /// The . + /// The . /// public Image CreateImage(IImageDecoder decoder) { - return Image.Load(this.image.Configuration, this.Bytes, decoder); + return ImageSharp.Image.Load(this.Image.Configuration, this.Bytes, decoder); } /// From 06271fa69362ae165a030c422ee5aa00e72df1e2 Mon Sep 17 00:00:00 2001 From: JimBobSquarePants Date: Tue, 18 Jul 2017 17:07:54 +1000 Subject: [PATCH 19/20] Fix spelling errors --- src/ImageSharp/ApplyProcessors.cs | 22 +++++++++---------- .../DefaultInternalImageProcessorContext.cs | 4 ++-- ...Processor.cs => ICloningImageProcessor.cs} | 9 +++----- ...eProcessor.cs => CloningImageProcessor.cs} | 2 +- .../Transforms/ResamplingWeightedProcessor.cs | 2 +- 5 files changed, 18 insertions(+), 21 deletions(-) rename src/ImageSharp/Image/{ICloneingImageProcessor.cs => ICloningImageProcessor.cs} (82%) rename src/ImageSharp/Processing/Processors/{CLoneingImageProcessor.cs => CloningImageProcessor.cs} (98%) diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index 40cd7500a..aa44dfc21 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -17,19 +17,19 @@ namespace ImageSharp public static partial class ImageExtensions { /// - /// Mutates the image by applying the operations to it. + /// Mutates the image by applying the image operation to it. /// /// The pixel format. /// The image to rotate, flip, or both. - /// The operations to perform on the source. - public static void Mutate(this Image source, Action> operations) + /// The operations to perform on the source. + public static void Mutate(this Image source, Action> operation) where TPixel : struct, IPixel { - Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(operation, nameof(operation)); Guard.NotNull(source, nameof(source)); IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, true); - operations(operationsRunner); + operation(operationsRunner); operationsRunner.Apply(); } @@ -51,20 +51,20 @@ namespace ImageSharp } /// - /// Clones the current image mutating the clone by applying the operations to it. + /// Clones the current image mutating the clone by applying the operation to it. /// /// The pixel format. /// The image to rotate, flip, or both. - /// The operations to perform on the source. - /// Anew Image which has teh data from the but with the applied. - public static Image Clone(this Image source, Action> operations) + /// The operations to perform on the source. + /// Anew Image which has teh data from the but with the applied. + public static Image Clone(this Image source, Action> operation) where TPixel : struct, IPixel { - Guard.NotNull(operations, nameof(operations)); + Guard.NotNull(operation, nameof(operation)); Guard.NotNull(source, nameof(source)); IInternalImageProcessingContext operationsRunner = source.Configuration.ImageOperationsProvider.CreateImageProcessingContext(source, false); - operations(operationsRunner); + operation(operationsRunner); return operationsRunner.Apply(); } diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs index 64f444325..0562f90ce 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -57,9 +57,9 @@ namespace ImageSharp // this will only work if the first processor applied is the cloning one thus // realistically for this optermissation to work the resize must the first processor // applied any only up processors will take the douple data path. - if (processor is ICloneingImageProcessor) + if (processor is ICloningImageProcessor) { - var cloningProcessor = (ICloneingImageProcessor)processor; + var cloningProcessor = (ICloningImageProcessor)processor; this.destination = cloningProcessor.CloneAndApply(this.source, rectangle); return this; } diff --git a/src/ImageSharp/Image/ICloneingImageProcessor.cs b/src/ImageSharp/Image/ICloningImageProcessor.cs similarity index 82% rename from src/ImageSharp/Image/ICloneingImageProcessor.cs rename to src/ImageSharp/Image/ICloningImageProcessor.cs index 92f87d02e..a6a3a9a73 100644 --- a/src/ImageSharp/Image/ICloneingImageProcessor.cs +++ b/src/ImageSharp/Image/ICloningImageProcessor.cs @@ -1,21 +1,18 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Processing { - using System; - using System.Threading.Tasks; - using ImageSharp.PixelFormats; using SixLabors.Primitives; /// - /// Encapsulates methods to alter the pixels of an image. + /// Encapsulates methods to alter the pixels of a new image, cloned from the original image. /// /// The pixel format. - internal interface ICloneingImageProcessor : IImageProcessor + internal interface ICloningImageProcessor : IImageProcessor where TPixel : struct, IPixel { /// diff --git a/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs similarity index 98% rename from src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs rename to src/ImageSharp/Processing/Processors/CloningImageProcessor.cs index a95e466ab..cf84462c5 100644 --- a/src/ImageSharp/Processing/Processors/CLoneingImageProcessor.cs +++ b/src/ImageSharp/Processing/Processors/CloningImageProcessor.cs @@ -15,7 +15,7 @@ namespace ImageSharp.Processing /// Allows the application of processors to images. /// /// The pixel format. - internal abstract class CloneingImageProcessor : IImageProcessor, ICloneingImageProcessor + internal abstract class CloningImageProcessor : IImageProcessor, ICloningImageProcessor where TPixel : struct, IPixel { /// diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs index 957f917be..59c0c37a2 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResamplingWeightedProcessor.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Processing.Processors /// Adapted from /// /// The pixel format. - internal abstract partial class ResamplingWeightedProcessor : CloneingImageProcessor + internal abstract partial class ResamplingWeightedProcessor : CloningImageProcessor where TPixel : struct, IPixel { /// From 70892a146826e337ae95e6a535dd7e6e6faa301a Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 26 Jul 2017 16:54:47 +1000 Subject: [PATCH 20/20] Cleanup + Rename Run to Apply --- samples/AvatarWithRoundedCorner/Program.cs | 20 ++++---- src/ImageSharp/ApplyProcessors.cs | 4 +- .../DefaultInternalImageProcessorContext.cs | 20 +++----- .../IImageProcessingContextFactory.cs | 5 +- .../IImageProcessingContext{TPixel}.cs | 12 ++--- src/ImageSharp/Processing/Delegate.cs | 6 +-- .../Processors/DelegateProcessor.cs | 5 +- .../Processors/Transforms/ResizeProcessor.cs | 10 ++-- .../Processing/Transforms/Resize.cs | 51 +++++++++---------- src/ImageSharp/Quantizers/Quantize.cs | 4 +- .../Processing/DelegateTest.cs | 2 +- 11 files changed, 64 insertions(+), 75 deletions(-) diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index caed6687f..4fa2912c1 100644 --- a/samples/AvatarWithRoundedCorner/Program.cs +++ b/samples/AvatarWithRoundedCorner/Program.cs @@ -42,13 +42,13 @@ namespace AvatarWithRoundedCorner { Size = size, Mode = ImageSharp.Processing.ResizeMode.Crop - }).Run(i => ApplyRoundedCourners(i, cornerRadius)); + }).Apply(i => ApplyRoundedCorners(i, cornerRadius)); } // the combination of `IImageOperations.Run()` + this could be replaced with an `IImageProcessor` - public static void ApplyRoundedCourners(Image img, float cornerRadius) + public static void ApplyRoundedCorners(Image img, float cornerRadius) { - var corners = BuildCorners(img.Width, img.Height, cornerRadius); + IPathCollection corners = BuildCorners(img.Width, img.Height, cornerRadius); // mutating in here as we already have a cloned original img.Mutate(x => x.Fill(Rgba32.Transparent, corners, new GraphicsOptions(true) @@ -60,22 +60,22 @@ namespace AvatarWithRoundedCorner public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius) { // first create a square - var rect = new SixLabors.Shapes.RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); + var rect = new RectangularePolygon(-0.5f, -0.5f, cornerRadius, cornerRadius); // then cut out of the square a circle so we are left with a corner - var cornerToptLeft = rect.Clip(new SixLabors.Shapes.EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); + IPath cornerToptLeft = rect.Clip(new EllipsePolygon(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius)); // corner is now a corner shape positions top left - //lets make 3 more positioned correctly, we cando that by translating the orgional artound the center of the image - var center = new Vector2(imageWidth / 2, imageHeight / 2); + //lets make 3 more positioned correctly, we can do that by translating the orgional artound the center of the image + var center = new Vector2(imageWidth / 2F, imageHeight / 2F); float rightPos = imageWidth - cornerToptLeft.Bounds.Width + 1; float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1; // move it across the widthof the image - the width of the shape - var cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); - var cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); - var cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); + IPath cornerTopRight = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0); + IPath cornerBottomLeft = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos); + IPath cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos); return new PathCollection(cornerToptLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight); } diff --git a/src/ImageSharp/ApplyProcessors.cs b/src/ImageSharp/ApplyProcessors.cs index aa44dfc21..e60cff2e0 100644 --- a/src/ImageSharp/ApplyProcessors.cs +++ b/src/ImageSharp/ApplyProcessors.cs @@ -92,7 +92,7 @@ namespace ImageSharp /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. - /// returns the current optinoatins class to allow chaining of oprations. + /// returns the current operations class to allow chaining of operations. public static IImageProcessingContext ApplyProcessors(this IImageProcessingContext source, params IImageProcessor[] operations) where TPixel : struct, IPixel { @@ -104,4 +104,4 @@ namespace ImageSharp return source; } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/DefaultInternalImageProcessorContext.cs b/src/ImageSharp/DefaultInternalImageProcessorContext.cs index 0562f90ce..6165fbf00 100644 --- a/src/ImageSharp/DefaultInternalImageProcessorContext.cs +++ b/src/ImageSharp/DefaultInternalImageProcessorContext.cs @@ -5,14 +5,12 @@ namespace ImageSharp { - using System; - using System.Collections.Generic; using ImageSharp.PixelFormats; using ImageSharp.Processing; using SixLabors.Primitives; /// - /// The static collection of all the default image formats + /// Performs processor application operations on the source image /// /// The pixel format internal class DefaultInternalImageProcessorContext : IInternalImageProcessingContext @@ -42,7 +40,7 @@ namespace ImageSharp { if (!this.mutate && this.destination == null) { - // ensure we have cloned it if we are not mutating as we might have failed to register any Processors + // Ensure we have cloned it if we are not mutating as we might have failed to register any Processors this.destination = this.source.Clone(); } @@ -54,19 +52,17 @@ namespace ImageSharp { if (!this.mutate && this.destination == null) { - // this will only work if the first processor applied is the cloning one thus + // This will only work if the first processor applied is the cloning one thus // realistically for this optermissation to work the resize must the first processor // applied any only up processors will take the douple data path. - if (processor is ICloningImageProcessor) + var cloningImageProcessor = processor as ICloningImageProcessor; + if (cloningImageProcessor != null) { - var cloningProcessor = (ICloningImageProcessor)processor; - this.destination = cloningProcessor.CloneAndApply(this.source, rectangle); + this.destination = cloningImageProcessor.CloneAndApply(this.source, rectangle); return this; } - else - { - this.destination = this.source.Clone(); - } + + this.destination = this.source.Clone(); } processor.Apply(this.destination, rectangle); diff --git a/src/ImageSharp/IImageProcessingContextFactory.cs b/src/ImageSharp/IImageProcessingContextFactory.cs index a9cd23905..394f198bf 100644 --- a/src/ImageSharp/IImageProcessingContextFactory.cs +++ b/src/ImageSharp/IImageProcessingContextFactory.cs @@ -5,16 +5,15 @@ namespace ImageSharp { - using System; using ImageSharp.PixelFormats; /// - /// Represents an interface that will create IImageOperations + /// Represents an interface that will create IInternalImageProcessingContext instances /// internal interface IImageProcessingContextFactory { /// - /// Called during Mutate operations to generate the imageoperations provider. + /// Called during Mutate operations to generate the image operations provider. /// /// The pixel format /// The source image. diff --git a/src/ImageSharp/IImageProcessingContext{TPixel}.cs b/src/ImageSharp/IImageProcessingContext{TPixel}.cs index e79b20ba6..a3f24186b 100644 --- a/src/ImageSharp/IImageProcessingContext{TPixel}.cs +++ b/src/ImageSharp/IImageProcessingContext{TPixel}.cs @@ -5,8 +5,6 @@ namespace ImageSharp { - using System; - using ImageSharp.Formats; using ImageSharp.PixelFormats; using ImageSharp.Processing; using SixLabors.Primitives; @@ -19,18 +17,18 @@ namespace ImageSharp where TPixel : struct, IPixel { /// - /// Adds the processor to the current setr of image operations to be applied. + /// Adds the processor to the current set of image operations to be applied. /// /// The processor to apply /// The area to apply it to - /// returns the current optinoatins class to allow chaining of oprations. + /// The current operations class to allow chaining of operations. IImageProcessingContext ApplyProcessor(IImageProcessor processor, Rectangle rectangle); /// - /// Adds the processor to the current setr of image operations to be applied. + /// Adds the processor to the current set of image operations to be applied. /// /// The processor to apply - /// returns the current optinoatins class to allow chaining of oprations. + /// The current operations class to allow chaining of operations. IImageProcessingContext ApplyProcessor(IImageProcessor processor); } @@ -44,7 +42,7 @@ namespace ImageSharp /// /// Adds the processors to the current image /// - /// returns the current image or a new image depending on withere this is alloed to mutate the source image. + /// The current image or a new image depending on withere this is alloed to mutate the source image. Image Apply(); } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Delegate.cs b/src/ImageSharp/Processing/Delegate.cs index 733c4d090..76f968dec 100644 --- a/src/ImageSharp/Processing/Delegate.cs +++ b/src/ImageSharp/Processing/Delegate.cs @@ -17,13 +17,13 @@ namespace ImageSharp public static partial class ImageExtensions { /// - /// Queues up a simple operation that provides access to the mutatable image. + /// Queues up an operation that provides access to the mutatable image. /// /// The pixel format. /// The image to rotate, flip, or both. /// The operations to perform on the source. - /// returns the current optinoatins class to allow chaining of oprations. - public static IImageProcessingContext Run(this IImageProcessingContext source, Action> operation) + /// returns the current operations class to allow chaining of operations. + public static IImageProcessingContext Apply(this IImageProcessingContext source, Action> operation) where TPixel : struct, IPixel => source.ApplyProcessor(new DelegateProcessor(operation)); } diff --git a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs index 756c3d8e4..d594bf23e 100644 --- a/src/ImageSharp/Processing/Processors/DelegateProcessor.cs +++ b/src/ImageSharp/Processing/Processors/DelegateProcessor.cs @@ -6,7 +6,6 @@ namespace ImageSharp.Processing { using System; - using System.Threading.Tasks; using ImageSharp.PixelFormats; using SixLabors.Primitives; @@ -37,13 +36,13 @@ namespace ImageSharp.Processing /// protected override void BeforeImageApply(Image source, Rectangle sourceRectangle) { - this.action?.Invoke((Image)source); + this.action?.Invoke(source); } /// protected override void OnApply(ImageBase source, Rectangle sourceRectangle) { - // no op, we did all we wanted to do inside BeforeImageApply + // NOP, we did all we wanted to do inside BeforeImageApply } } } \ No newline at end of file diff --git a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs index 65fbb65fb..285386746 100644 --- a/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs +++ b/src/ImageSharp/Processing/Processors/Transforms/ResizeProcessor.cs @@ -48,14 +48,13 @@ namespace ImageSharp.Processing.Processors /// protected override Image CreateDestination(Image source, Rectangle sourceRectangle) { - // we will always be creating the clone even for mutate because thatsa the way this base processor works + // We will always be creating the clone even for mutate because thats the way this base processor works // ------------ - // for resize we know we are going to populate every pixel with fresh data and we want a different target size so - // lets manually clone an empty set of images at the correct target and then have the base class processs them in. - // turn. + // For resize we know we are going to populate every pixel with fresh data and we want a different target size so + // let's manually clone an empty set of images at the correct target and then have the base class processs them in turn. var image = new Image(source.Configuration, this.Width, this.Height, source.MetaData.Clone()); - // now 'clone' the ImageFrames + // Now 'clone' the ImageFrames foreach (ImageFrame sourceFrame in source.Frames) { var targetFrame = new ImageFrame(sourceFrame.Configuration, this.Width, this.Height, sourceFrame.MetaData.Clone()); @@ -120,7 +119,6 @@ namespace ImageSharp.Processing.Processors // A 2-pass 1D algorithm appears to be faster than splitting a 1-pass 2D algorithm // First process the columns. Since we are not using multiple threads startY and endY // are the upper and lower bounds of the source rectangle. - // TODO: Using a transposed variant of 'firstPassPixels' could eliminate the need for the WeightsWindow.ComputeWeightedColumnSum() method, and improve speed! using (var firstPassPixels = new Buffer2D(width, source.Height)) { diff --git a/src/ImageSharp/Processing/Transforms/Resize.cs b/src/ImageSharp/Processing/Transforms/Resize.cs index c73581a93..38662317b 100644 --- a/src/ImageSharp/Processing/Transforms/Resize.cs +++ b/src/ImageSharp/Processing/Transforms/Resize.cs @@ -27,10 +27,9 @@ namespace ImageSharp public static IImageProcessingContext Resize(this IImageProcessingContext source, ResizeOptions options) where TPixel : struct, IPixel { - return source.Run(img => + return source.Apply(img => { - // cheat and bound through a run, inside here we should just be mutating, this reallt needs moving over to a processor - + // Cheat and bound through a run, inside here we should just be mutating, this really needs moving over to a processor // Ensure size is populated across both dimensions. if (options.Size.Width == 0 && options.Size.Height > 0) { @@ -162,26 +161,26 @@ namespace ImageSharp public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle sourceRectangle, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { - return source.Run(img => - { - // todo : stop cheeting here and move this stuff into the processors itself - if (width == 0 && height > 0) - { - width = (int)MathF.Round(img.Width * height / (float)img.Height); - targetRectangle.Width = width; - } - - if (height == 0 && width > 0) - { - height = (int)MathF.Round(img.Height * width / (float)img.Width); - targetRectangle.Height = height; - } - - Guard.MustBeGreaterThan(width, 0, nameof(width)); - Guard.MustBeGreaterThan(height, 0, nameof(height)); - - img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); - }); + return source.Apply(img => + { + // TODO : Stop cheating here and move this stuff into the processors itself + if (width == 0 && height > 0) + { + width = (int)MathF.Round(img.Width * height / (float)img.Height); + targetRectangle.Width = width; + } + + if (height == 0 && width > 0) + { + height = (int)MathF.Round(img.Height * width / (float)img.Width); + targetRectangle.Height = height; + } + + Guard.MustBeGreaterThan(width, 0, nameof(width)); + Guard.MustBeGreaterThan(height, 0, nameof(height)); + + img.Mutate(x => x.ApplyProcessor(new ResizeProcessor(sampler, width, height, targetRectangle) { Compand = compand }, sourceRectangle)); + }); } /// @@ -202,9 +201,9 @@ namespace ImageSharp public static IImageProcessingContext Resize(this IImageProcessingContext source, int width, int height, IResampler sampler, Rectangle targetRectangle, bool compand) where TPixel : struct, IPixel { - return source.Run(img => + return source.Apply(img => { - // todo : stop cheeting here and move this stuff into the processors itself + // TODO : stop cheating here and move this stuff into the processors itself if (width == 0 && height > 0) { width = (int)MathF.Round(img.Width * height / (float)img.Height); @@ -224,4 +223,4 @@ namespace ImageSharp }); } } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Quantizers/Quantize.cs b/src/ImageSharp/Quantizers/Quantize.cs index 0edc1557a..612816eef 100644 --- a/src/ImageSharp/Quantizers/Quantize.cs +++ b/src/ImageSharp/Quantizers/Quantize.cs @@ -57,13 +57,13 @@ namespace ImageSharp public static IImageProcessingContext Quantize(this IImageProcessingContext source, IQuantizer quantizer, int maxColors) where TPixel : struct, IPixel { - return source.Run(img => + return source.Apply(img => { // TODO : move helper logic into the processor QuantizedImage quantized = quantizer.Quantize(img, maxColors); int palleteCount = quantized.Palette.Length - 1; - using (PixelAccessor pixels = new PixelAccessor(quantized.Width, quantized.Height)) + using (var pixels = new PixelAccessor(quantized.Width, quantized.Height)) { Parallel.For( 0, diff --git a/tests/ImageSharp.Tests/Processing/DelegateTest.cs b/tests/ImageSharp.Tests/Processing/DelegateTest.cs index 73011bee1..d5846b158 100644 --- a/tests/ImageSharp.Tests/Processing/DelegateTest.cs +++ b/tests/ImageSharp.Tests/Processing/DelegateTest.cs @@ -16,7 +16,7 @@ namespace ImageSharp.Tests.Processing public void Run_CreatedDelegateProcessor() { Action> action = (i) => { }; - this.operations.Run(action); + this.operations.Apply(action); DelegateProcessor processor = this.Verify>(); Assert.Equal(action, processor.Action);