diff --git a/samples/AvatarWithRoundedCorner/Program.cs b/samples/AvatarWithRoundedCorner/Program.cs index b164c8d3bc..45fe1e3c86 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 03eb7be289..bd51e4ac0a 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 b3ee2ed996..d8bb78e906 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 59bcf40363..d332f1d05a 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 3ce0dc4da6..db1e46af8a 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 1fba06370d..57ce2032a9 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 877737653d..f909e98da6 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 4fa469a496..b787afcd58 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 b3f0e6fc3b..544ca2fe96 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 abb5ef73a7..eae34f0342 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 3ea9fb94b8..662245dc30 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 f579c4ad02..07342d47b9 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 6266d3bd64..7feac5b0a4 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 bd6460cf90..52512ca1cb 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 62344b1012..07a3ae8c29 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 523813188a..459d5de0d8 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 6352836a9c..989322a739 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 593ac36d4f..e360e8aeed 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 0000000000..2a9c3ccbef --- /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 aba24f9997..96d0ceb9f2 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 ea9c9b5047..717df44238 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 8fbf9e5a74..c69007e664 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 c817385760..697380c19f 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 0000000000..a176c0e28a --- /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 8687766d5e..1e144e835c 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 20b891f2dd..d4a7af9ca4 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 8eed103d10..44fcba7cfe 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 5e8bcab31b..13b8655211 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 0000000000..dde3153d16 --- /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 0000000000..5d81e2f952 --- /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 e37f80c25a..a4ee73af48 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 efaf63b06c..614eabca79 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 6a4e3807ba..5710991dc3 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 14641afba1..4d83ba9a20 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 635b6747a6..6cdc3343de 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 d218b3a104..86a5336219 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 09eb131907..2f331d6478 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 bca4577e48..e2c8f3674c 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 b2d8515d6c..bfbf6477b9 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 88f3b15296..5a26505272 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 000c0ffba8..f4dbb26c1a 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 ad5e477dc9..f000a6aa4e 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 1cc8b693ff..14bcf20598 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 f9658fcb5d..7d551ceb8d 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 bb616cc67e..58c5ad12ac 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 0000000000..e1d1060c67 --- /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 a0d218651a..4978caf86c 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 a1e04c8a3d..276bfa2a72 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 165f897b80..9bc27e75d7 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 0a55fd067b..52eb0d5eca 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 d9a0695566..4f8c6a8864 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 3b300e9197..23d5528856 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 07fdd50a35..cd0551ad39 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 dd2a93bc52..bf88d5ff7b 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 84f6bf10ae..4c58a27d45 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 75c4611a1e..78060570c7 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 9e54574df9..5c1bd20b16 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 f484c8eec8..383917c45f 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 ff83117c5f..a44e85ef31 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 8a13eabca8..5a816da14d 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 8cb58739b0..6a46692d23 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 0000000000..f18eb80926 --- /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 0186a8fa8e..0f1e166fdc 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 07e5d5bc9a..fb7bfb4ac7 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 94e9ba1f49..c518ac5ac1 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 2f4a8e3833..00f4043215 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 1c8baebf13..6cde1257c9 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 8138fd7654..fb064f5ce5 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 e00faf10ea..6ccea5f42d 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 af7c06a27e..92349dba37 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 805deb8d16..fda11d8338 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 d42d79225b..f38606eda1 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 a235092787..2b5130f8c1 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 66104944ea..0a5750fe93 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 a6af5a9769..3a3b5f30db 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 3abd3b889d..b9a9605898 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 b7d1b96b74..b0981b94d5 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 0738812a1c..6219a97f68 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 aa97efe00b..fec6332d25 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 cb13378a13..ee8fdcf250 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 1f69030a00..380a0abb03 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 2aa8df96ca..53cdb1b93e 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 3873400698..db22167704 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 7ddc2de5a4..1b3aeacb15 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 40a1cb3d3c..e1ff00ca23 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 728ed749a2..29e3d94fb3 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 da5028f04f..c609aa9918 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 bbabdf0ea6..5dd7c55211 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 b04a413857..d0e93e7343 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 ce127cfe03..f2f6ad06a4 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 e058572fb3..fea7ee8183 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 f47d566967..693bbc28fb 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 3a2b66c3c2..b80173bcf8 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 24efa976e8..8fe18713d8 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 b46d3d0d9c..2fd9a89b3c 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 7e6a3deee5..56c7d51093 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 501b10e4af..827cde5a85 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 9c62e860a8..53b7d950f4 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 ba904cb3f2..aa9ffb1877 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 c3af3d5c28..70369a6a8c 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 793bcfc9f0..469669acf2 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 05a1f1e363..067ea122d8 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 1c8c9f1d16..d03af54562 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 ce2a5becf9..af401264dc 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 4ef8fe0612..1f669ba240 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 86faeee232..49802a8d23 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 bac340a71c..43ca2a1b6d 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 b59023340b..4ffc33580a 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 6cd80e9e83..46d4351ded 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 642df598a3..a8140aac71 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 a06397c864..25b34bfe4e 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 4dc70fb0f5..90c02be197 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 bc1c8ad226..9006e3e33d 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 9bf55a6d25..6dd0e82488 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 ba1cf2b8f7..1fe56a8be9 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 971cdb6d81..779ca0f6b2 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 5b41cdb3b7..ebfacb7203 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 48f7a6c0a8..54836cedfa 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 a4a4f3bb51..73c3f98b53 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 af554e30d8..ae7865c11a 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 ef049a539a..58a2665d0d 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 d5817ab14f..9f3a2d79a6 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 fa4e4b0b6b..763e806af9 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 d15042ee69..6313bc72aa 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 34a24e70be..e01e67e181 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 63efbf3e73..55f11b8b54 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 c3b37705a9..081fdf319c 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 892eb93622..2c2ef1403a 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 3d8b3d1a1f..7d79517bc9 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 3d0e8f1177..002d57d847 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 253f1f4598..3a6e273d00 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 d0633dca59..20e521c8d9 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 56fcf0ee0d..74c5296fa3 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 7bc0c8bb52..6c1d32b337 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 ca20abf790..b95c9d82ae 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 24febd5b2f..1c97c70ad0 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 45ab1e5f8b..8e048ae04e 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 7caa1e7c0e..7471330bea 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 a300672e85..7b83f0a8e2 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 fb195254e3..0092ae9da6 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 f85ef6f13a..432b2549bb 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 1f18564290..2db86390de 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 f2c2d7cbd2..63924c535f 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 0caded4201..08e3e1054d 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 03a685d34f..e939d78bba 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 437c295b9c..88ab987ed8 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)); }