From bf9b3cfd3ff92080882e56dd5432d58f5dd86ab6 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Sun, 18 Mar 2018 22:15:53 +1100 Subject: [PATCH 1/9] Move GraphicsOptions parameter --- .../Drawing/DrawBezierExtensions.cs | 18 ++++---- .../Processing/Drawing/DrawImageExtensions.cs | 8 ++-- .../Processing/Drawing/DrawLineExtensions.cs | 20 ++++----- .../Drawing/DrawPathCollectionExtensions.cs | 20 ++++----- .../Processing/Drawing/DrawPathExtensions.cs | 22 +++++----- .../Drawing/DrawPolygonExtensions.cs | 20 ++++----- .../Drawing/DrawRectangleExtensions.cs | 20 ++++----- .../Drawing/FillPathBuilderExtensions.cs | 14 +++--- .../Drawing/FillPathCollectionExtensions.cs | 14 +++--- .../Processing/Drawing/FillPathExtensions.cs | 14 +++--- .../Drawing/FillPolygonExtensions.cs | 12 ++--- .../Drawing/FillRectangleExtensions.cs | 12 ++--- .../Drawing/FillRegionExtensions.cs | 18 ++++---- .../Text/DrawTextExtensions.Path.cs | 34 +++++++------- .../Processing/Text/DrawTextExtensions.cs | 34 +++++++------- .../Overlays/BackgroundColorExtensions.cs | 12 ++--- .../Processing/Overlays/GlowExtensions.cs | 44 +++++++++---------- .../Processing/Overlays/VignetteExtensions.cs | 38 ++++++++-------- .../ImageSharp.Tests/Drawing/BlendedShapes.cs | 31 +++---------- tests/ImageSharp.Tests/Drawing/LineTests.cs | 16 ++++--- .../Drawing/Paths/FillPath.cs | 4 +- .../Drawing/Paths/FillPathCollection.cs | 6 +-- .../Drawing/Paths/FillPolygon.cs | 4 +- .../Drawing/Paths/FillRectangle.cs | 4 +- .../Drawing/SolidPolygonTests.cs | 6 +-- .../Drawing/Text/DrawText.Path.cs | 22 +++++----- .../ImageSharp.Tests/Drawing/Text/DrawText.cs | 22 +++++----- tests/ImageSharp.Tests/Issues/Issue412.cs | 8 ++-- .../Processing/Effects/BackgroundColorTest.cs | 4 +- 29 files changed, 243 insertions(+), 258 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs index 8f075d5c2..37fade35e 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs @@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)), options); + => source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); /// /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush @@ -59,27 +59,27 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.DrawBeziers(new SolidBrush(color), thickness, points, options); + => source.DrawBeziers(options, new SolidBrush(color), thickness, points); /// /// Draws the provided points as an open Bezier path with the supplied pen /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) where TPixel : struct, IPixel - => source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options); + => source.Draw(options, pen, new Path(new CubicBezierLineSegment(points))); /// /// Draws the provided points as an open Bezier path with the supplied pen diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs index 618768206..e2951ee2c 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs @@ -42,10 +42,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The pixel format. /// The image this method extends. - /// The image to blend with the currently processing image. /// The options, including the blending type and blending amount. + /// The image to blend with the currently processing image. /// The . - public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, GraphicsOptions options) + public static IImageProcessingContext Blend(this IImageProcessingContext source, GraphicsOptions options, Image image) where TPixel : struct, IPixel { return source.ApplyProcessor(new DrawImageProcessor(image, options)); @@ -82,12 +82,12 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// Draws the given image together with the current one by blending their pixels. /// /// The image this method extends. + /// The options containing the blend mode and opacity. /// The image to blend with the currently processing image. /// The pixel format. /// The location to draw the blended image. - /// The options containing the blend mode and opacity. /// The . - public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, Point location, GraphicsOptions options) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, GraphicsOptions options, Image image, Point location) where TPixel : struct, IPixel => source.ApplyProcessor(new DrawImageProcessor(image, location, options)); } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs index 9d2ea0c1d..7acbd0e85 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs @@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); + => source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points))); /// /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush @@ -59,27 +59,27 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The points. - /// The options. /// The .> - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.DrawLines(new SolidBrush(color), thickness, points, options); + => source.DrawLines(options, new SolidBrush(color), thickness, points); /// /// Draws the provided Points as an open Linear path with the supplied pen /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) where TPixel : struct, IPixel - => source.Draw(pen, new Path(new LinearLineSegment(points)), options); + => source.Draw(options, pen, new Path(new LinearLineSegment(points))); /// /// Draws the provided Points as an open Linear path with the supplied pen @@ -93,4 +93,4 @@ namespace SixLabors.ImageSharp.Processing.Drawing where TPixel : struct, IPixel => source.Draw(pen, new Path(new LinearLineSegment(points))); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs index d148638ae..eca3805bd 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathCollectionExtensions.cs @@ -18,16 +18,16 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The paths. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IPen pen, IPathCollection paths) where TPixel : struct, IPixel { foreach (IPath path in paths) { - source.Draw(pen, path, options); + source.Draw(options, pen, path); } return source; @@ -43,21 +43,21 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) where TPixel : struct, IPixel - => source.Draw(pen, paths, GraphicsOptions.Default); + => source.Draw(GraphicsOptions.Default, pen, paths); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The shapes. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, IPathCollection paths) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), paths, options); + => source.Draw(options, new Pen(brush, thickness), paths); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -77,14 +77,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The paths. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, IPathCollection paths) where TPixel : struct, IPixel - => source.Draw(new SolidBrush(color), thickness, paths, options); + => source.Draw(options, new SolidBrush(color), thickness, paths); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs index a795ee295..a15412a45 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPathExtensions.cs @@ -19,13 +19,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The path. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IPen pen, IPath path) where TPixel : struct, IPixel - => source.Fill(pen.StrokeFill, new ShapePath(path, pen), options); + => source.Fill(options, pen.StrokeFill, new ShapePath(path, pen)); /// /// Draws the outline of the polygon with the provided pen. @@ -37,21 +37,21 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path) where TPixel : struct, IPixel - => source.Draw(pen, path, GraphicsOptions.Default); + => source.Draw(GraphicsOptions.Default, pen, path); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, IPath path) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), path, options); + => source.Draw(options, new Pen(brush, thickness), path); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -71,14 +71,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The path. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, IPath path, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, IPath path) where TPixel : struct, IPixel - => source.Draw(new SolidBrush(color), thickness, path, options); + => source.Draw(options, new SolidBrush(color), thickness, path); /// /// Draws the outline of the polygon with the provided brush at the provided thickness. @@ -93,4 +93,4 @@ namespace SixLabors.ImageSharp.Processing.Drawing where TPixel : struct, IPixel => source.Draw(new SolidBrush(color), thickness, path); } -} +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs index 833b616f8..504b9cd7e 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs @@ -19,14 +19,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); + => source.Draw(options, new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); /// /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. @@ -59,14 +59,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) where TPixel : struct, IPixel - => source.DrawPolygon(new SolidBrush(color), thickness, points, options); + => source.DrawPolygon(options, new SolidBrush(color), thickness, points); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. @@ -78,19 +78,19 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) where TPixel : struct, IPixel - => source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default); + => source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points))); /// /// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The points. - /// The options. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) where TPixel : struct, IPixel - => source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); + => source.Draw(options, pen, new Polygon(new LinearLineSegment(points))); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs index 3d6702be9..03be4de47 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawRectangleExtensions.cs @@ -19,13 +19,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The pen. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IPen pen, RectangleF shape) where TPixel : struct, IPixel - => source.Draw(pen, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); + => source.Draw(options, pen, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); /// /// Draws the outline of the rectangle with the provided pen. @@ -37,21 +37,21 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) where TPixel : struct, IPixel - => source.Draw(pen, shape, GraphicsOptions.Default); + => source.Draw(GraphicsOptions.Default, pen, shape); /// /// Draws the outline of the rectangle with the provided brush at the provided thickness. /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The thickness. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, RectangleF shape) where TPixel : struct, IPixel - => source.Draw(new Pen(brush, thickness), shape, options); + => source.Draw(options, new Pen(brush, thickness), shape); /// /// Draws the outline of the rectangle with the provided brush at the provided thickness. @@ -71,14 +71,14 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The thickness. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Draw(this IImageProcessingContext source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, RectangleF shape) where TPixel : struct, IPixel - => source.Draw(new SolidBrush(color), thickness, shape, options); + => source.Draw(options, new SolidBrush(color), thickness, shape); /// /// Draws the outline of the rectangle with the provided brush at the provided thickness. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs index 975b5db4c..921209d2e 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathBuilderExtensions.cs @@ -18,17 +18,17 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The graphics options. /// The brush. /// The shape. - /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, Action path) where TPixel : struct, IPixel { var pb = new PathBuilder(); path(pb); - return source.Fill(brush, pb.Build(), options); + return source.Fill(options, brush, pb.Build()); } /// @@ -41,20 +41,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Action path) where TPixel : struct, IPixel - => source.Fill(brush, path, GraphicsOptions.Default); + => source.Fill(GraphicsOptions.Default, brush, path); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The path. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Action path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, TPixel color, Action path) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), path, options); + => source.Fill(options, new SolidBrush(color), path); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs index be472d373..71474dceb 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathCollectionExtensions.cs @@ -17,16 +17,16 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The graphics options. /// The brush. /// The shapes. - /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel { foreach (IPath s in paths) { - source.Fill(brush, s, options); + source.Fill(options, brush, s); } return source; @@ -42,20 +42,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPathCollection paths) where TPixel : struct, IPixel - => source.Fill(brush, paths, GraphicsOptions.Default); + => source.Fill(GraphicsOptions.Default, brush, paths); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The paths. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPathCollection paths, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, TPixel color, IPathCollection paths) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), paths, options); + => source.Fill(options, new SolidBrush(color), paths); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs index 9b288c8be..36eef8d63 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPathExtensions.cs @@ -18,13 +18,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The graphics options. /// The brush. /// The shape. - /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, IPath path) where TPixel : struct, IPixel - => source.Fill(brush, new ShapeRegion(path), options); + => source.Fill(options, brush, new ShapeRegion(path)); /// /// Flood fills the image in the shape of the provided polygon with the specified brush. @@ -36,20 +36,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path) where TPixel : struct, IPixel - => source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); + => source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path)); /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The path. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, IPath path, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, TPixel color, IPath path) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), path, options); + => source.Fill(options, new SolidBrush(color), path); /// /// Flood fills the image in the shape of the provided polygon with the specified brush.. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs index 692f88337..0b3d493b7 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs @@ -18,13 +18,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The points. - /// The options. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, PointF[] points) where TPixel : struct, IPixel - => source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); + => source.Fill(options, brush, new Polygon(new LinearLineSegment(points))); /// /// Flood fills the image in the shape of a Linear polygon described by the points @@ -43,13 +43,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The points. - /// The options. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points, GraphicsOptions options) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, PointF[] points) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); + => source.Fill(options, new SolidBrush(color), new Polygon(new LinearLineSegment(points))); /// /// Flood fills the image in the shape of a Linear polygon described by the points diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs index eff333a4f..234b94df5 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillRectangleExtensions.cs @@ -18,13 +18,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The brush. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, RectangleF shape) where TPixel : struct, IPixel - => source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options); + => source.Fill(options, brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height)); /// /// Flood fills the image in the shape of the provided rectangle with the specified brush. @@ -43,13 +43,13 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The shape. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, RectangleF shape, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, TPixel color, RectangleF shape) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), shape, options); + => source.Fill(options, new SolidBrush(color), shape); /// /// Flood fills the image in the shape of the provided rectangle with the specified brush. diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs index d3e223222..997dba22e 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillRegionExtensions.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) where TPixel : struct, IPixel - => source.Fill(brush, GraphicsOptions.Default); + => source.Fill(GraphicsOptions.Default, brush); /// /// Flood fills the image with the specified color. @@ -45,20 +45,20 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The . public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region) where TPixel : struct, IPixel - => source.Fill(brush, region, GraphicsOptions.Default); + => source.Fill(GraphicsOptions.Default, brush, region); /// /// Flood fills the image with in the region with the specified color. /// /// The type of the color. /// The image this method extends. + /// The options. /// The color. /// The region. - /// The options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, TPixel color, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, TPixel color, Region region) where TPixel : struct, IPixel - => source.Fill(new SolidBrush(color), region, options); + => source.Fill(options, new SolidBrush(color), region); /// /// Flood fills the image with in the region with the specified color. @@ -77,11 +77,11 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. + /// The graphics options. /// The brush. /// The region. - /// The graphics options. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, Region region) where TPixel : struct, IPixel => source.ApplyProcessor(new FillRegionProcessor(brush, region, options)); @@ -90,10 +90,10 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// /// The type of the color. /// The image this method extends. - /// The details how to fill the region of interest. /// The graphics options. + /// The details how to fill the region of interest. /// The . - public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, GraphicsOptions options) + public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush) where TPixel : struct, IPixel => source.ApplyProcessor(new FillProcessor(brush, options)); } diff --git a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs index 84bf26c51..9de73afcc 100644 --- a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs +++ b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs @@ -29,24 +29,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, color, path, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, color, path); /// /// Draws the text onto the the image filled via the brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The color. /// The path. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, TPixel color, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, Brushes.Solid(color), null, path, options); + => source.DrawText(options, text, font, Brushes.Solid(color), null, path); /// /// Draws the text onto the the image filled via the brush. @@ -62,24 +62,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, path, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, brush, path); /// /// Draws the text onto the the image filled via the brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The brush. /// The path. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IBrush brush, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, null, path, options); + => source.DrawText(options, text, font, brush, null, path); /// /// Draws the text onto the the image outlined via the pen. @@ -95,24 +95,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, pen, path, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, pen, path); /// /// Draws the text onto the the image outlined via the pen. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The pen. /// The path. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IPen pen, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, null, pen, path, options); + => source.DrawText(options, text, font, null, pen, path); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. @@ -129,23 +129,23 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, path); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The brush. /// The pen. /// The path. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, IPath path, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IBrush brush, IPen pen, IPath path) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; @@ -165,12 +165,12 @@ namespace SixLabors.ImageSharp.Processing.Text var pathOptions = (GraphicsOptions)options; if (brush != null) { - source.Fill(brush, glyphs, pathOptions); + source.Fill(pathOptions, brush, glyphs); } if (pen != null) { - source.Draw(pen, glyphs, pathOptions); + source.Draw(pathOptions, pen, glyphs); } return source; diff --git a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs index 5731804ac..8fede9693 100644 --- a/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs @@ -32,24 +32,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, color, location, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, color, location); /// /// Draws the text onto the the image filled via the brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The color. /// The location. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, TPixel color, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, Brushes.Solid(color), null, location, options); + => source.DrawText(options, text, font, Brushes.Solid(color), null, location); /// /// Draws the text onto the the image filled via the brush. @@ -65,24 +65,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, location, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, brush, location); /// /// Draws the text onto the the image filled via the brush. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The brush. /// The location. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IBrush brush, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, null, location, options); + => source.DrawText(options, text, font, brush, null, location); /// /// Draws the text onto the the image outlined via the pen. @@ -98,24 +98,24 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, pen, location, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, pen, location); /// /// Draws the text onto the the image outlined via the pen. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The pen. /// The location. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IPen pen, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, null, pen, location, options); + => source.DrawText(options, text, font, null, pen, location); /// /// Draws the text onto the the image filled via the brush then outlined via the pen. @@ -132,23 +132,23 @@ namespace SixLabors.ImageSharp.Processing.Text /// public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel - => source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default); + => source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location); /// /// Draws the text using the default resolution of 72dpi onto the the image filled via the brush then outlined via the pen. /// /// The type of the color. /// The image this method extends. + /// The options. /// The text. /// The font. /// The brush. /// The pen. /// The location. - /// The options. /// /// The . /// - public static IImageProcessingContext DrawText(this IImageProcessingContext source, string text, Font font, IBrush brush, IPen pen, PointF location, TextGraphicsOptions options) + public static IImageProcessingContext DrawText(this IImageProcessingContext source, TextGraphicsOptions options, string text, Font font, IBrush brush, IPen pen, PointF location) where TPixel : struct, IPixel { float dpiX = DefaultTextDpi; @@ -168,12 +168,12 @@ namespace SixLabors.ImageSharp.Processing.Text var pathOptions = (GraphicsOptions)options; if (brush != null) { - source.Fill(brush, glyphs, pathOptions); + source.Fill(pathOptions, brush, glyphs); } if (pen != null) { - source.Draw(pen, glyphs, pathOptions); + source.Draw(pathOptions, pen, glyphs); } return source; diff --git a/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs b/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs index 72cba78e5..1a8224769 100644 --- a/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs +++ b/src/ImageSharp/Processing/Overlays/BackgroundColorExtensions.cs @@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel - => BackgroundColor(source, color, GraphicsOptions.Default); + => BackgroundColor(source, GraphicsOptions.Default, color); /// /// Replaces the background color of image with the given one. @@ -35,17 +35,17 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel - => BackgroundColor(source, color, rectangle, GraphicsOptions.Default); + => BackgroundColor(source, GraphicsOptions.Default, color, rectangle); /// /// Replaces the background color of image with the given one. /// /// The pixel format. /// The image this method extends. - /// The color to set as the background. /// The options effecting pixel blending. + /// The color to set as the background. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, GraphicsOptions options, TPixel color) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options)); @@ -54,13 +54,13 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// /// The pixel format. /// The image this method extends. + /// The options effecting pixel blending. /// The color to set as the background. /// /// The structure that specifies the portion of the image object to alter. /// - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, TPixel color, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext BackgroundColor(this IImageProcessingContext source, GraphicsOptions options, TPixel color, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new BackgroundColorProcessor(color, options), rectangle); } diff --git a/src/ImageSharp/Processing/Overlays/GlowExtensions.cs b/src/ImageSharp/Processing/Overlays/GlowExtensions.cs index a86128f88..54af9f274 100644 --- a/src/ImageSharp/Processing/Overlays/GlowExtensions.cs +++ b/src/ImageSharp/Processing/Overlays/GlowExtensions.cs @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel { - return Glow(source, color, GraphicsOptions.Default); + return Glow(source, GraphicsOptions.Default, color); } /// @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius) where TPixel : struct, IPixel - => Glow(source, radius, GraphicsOptions.Default); + => Glow(source, GraphicsOptions.Default, radius); /// /// Applies a radial glow effect to an image. @@ -58,7 +58,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(rectangle, GraphicsOptions.Default); + => source.Glow(GraphicsOptions.Default, rectangle); /// /// Applies a radial glow effect to an image. @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.Absolute(radius), rectangle, GraphicsOptions.Default); + => source.Glow(GraphicsOptions.Default, color, ValueSize.Absolute(radius), rectangle); /// /// Applies a radial glow effect to an image. @@ -84,75 +84,75 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), options); + => source.Glow(options, NamedColors.Black, ValueSize.PercentageOfWidth(0.5f)); /// /// Applies a radial glow effect to an image. /// /// The pixel format. /// The image this method extends. - /// The color to set as the glow. /// The options effecting things like blending. + /// The color to set as the glow. /// The . - public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, TPixel color) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.PercentageOfWidth(0.5f), options); + => source.Glow(options, color, ValueSize.PercentageOfWidth(0.5f)); /// /// Applies a radial glow effect to an image. /// /// The pixel format. /// The image this method extends. - /// The the radius. /// The options effecting things like blending. + /// The the radius. /// The . - public static IImageProcessingContext Glow(this IImageProcessingContext source, float radius, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, float radius) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.Absolute(radius), options); + => source.Glow(options, NamedColors.Black, ValueSize.Absolute(radius)); /// /// Applies a radial glow effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting things like blending. /// /// The structure that specifies the portion of the image object to alter. /// - /// The options effecting things like blending. /// The . - public static IImageProcessingContext Glow(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle, options); + => source.Glow(options, NamedColors.Black, ValueSize.PercentageOfWidth(0.5f), rectangle); /// /// Applies a radial glow effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting things like blending. /// 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 . - public static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, float radius, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float radius, Rectangle rectangle) where TPixel : struct, IPixel - => source.Glow(color, ValueSize.Absolute(radius), rectangle, options); + => source.Glow(options, color, ValueSize.Absolute(radius), rectangle); /// /// Applies a radial glow effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting things like blending. /// 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 IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, TPixel color, ValueSize radius, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options), rectangle); @@ -161,12 +161,12 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// /// The pixel format. /// The image this method extends. + /// The options effecting things like blending. /// The color to set as the glow. /// The the radius. - /// The options effecting things like blending. /// The . - private static IImageProcessingContext Glow(this IImageProcessingContext source, TPixel color, ValueSize radius, GraphicsOptions options) + private static IImageProcessingContext Glow(this IImageProcessingContext source, GraphicsOptions options, TPixel color, ValueSize radius) where TPixel : struct, IPixel => source.ApplyProcessor(new GlowProcessor(color, radius, options)); } -} +} \ No newline at end of file diff --git a/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs b/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs index e533c914f..25b067d7f 100644 --- a/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs +++ b/src/ImageSharp/Processing/Overlays/VignetteExtensions.cs @@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color) where TPixel : struct, IPixel - => Vignette(source, color, GraphicsOptions.Default); + => Vignette(source, GraphicsOptions.Default, color); /// /// Applies a radial vignette effect to an image. @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY) where TPixel : struct, IPixel - => Vignette(source, radiusX, radiusY, GraphicsOptions.Default); + => Vignette(source, GraphicsOptions.Default, radiusX, radiusY); /// /// Applies a radial vignette effect to an image. @@ -57,7 +57,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle) where TPixel : struct, IPixel - => Vignette(source, rectangle, GraphicsOptions.Default); + => Vignette(source, GraphicsOptions.Default, rectangle); /// /// Applies a radial vignette effect to an image. @@ -73,7 +73,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel - => source.Vignette(color, radiusX, radiusY, rectangle, GraphicsOptions.Default); + => source.Vignette(GraphicsOptions.Default, color, radiusX, radiusY, rectangle); /// /// Applies a radial vignette effect to an image. @@ -84,69 +84,69 @@ namespace SixLabors.ImageSharp.Processing.Overlays /// The . public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); + => source.VignetteInternal(options, NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f)); /// /// Applies a radial vignette effect to an image. /// /// The pixel format. /// The image this method extends. - /// The color to set as the vignette. /// The options effecting pixel blending. + /// The color to set as the vignette. /// The . - public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options, TPixel color) where TPixel : struct, IPixel - => source.VignetteInternal(color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), options); + => source.VignetteInternal(options, color, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f)); /// /// Applies a radial vignette effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting pixel blending. /// The the x-radius. /// The the y-radius. - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext Vignette(this IImageProcessingContext source, float radiusX, float radiusY, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options, float radiusX, float radiusY) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, radiusX, radiusY, options); + => source.VignetteInternal(options, NamedColors.Black, radiusX, radiusY); /// /// Applies a radial vignette effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting pixel blending. /// /// The structure that specifies the portion of the image object to alter. /// - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext Vignette(this IImageProcessingContext source, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options, Rectangle rectangle) where TPixel : struct, IPixel - => source.VignetteInternal(NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle, options); + => source.VignetteInternal(options, NamedColors.Black, ValueSize.PercentageOfWidth(.5f), ValueSize.PercentageOfHeight(.5f), rectangle); /// /// Applies a radial vignette effect to an image. /// /// The pixel format. /// The image this method extends. + /// The options effecting pixel blending. /// The color to set as the vignette. /// The the x-radius. /// The the y-radius. /// /// The structure that specifies the portion of the image object to alter. /// - /// The options effecting pixel blending. /// The . - public static IImageProcessingContext Vignette(this IImageProcessingContext source, TPixel color, float radiusX, float radiusY, Rectangle rectangle, GraphicsOptions options) + public static IImageProcessingContext Vignette(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float radiusX, float radiusY, Rectangle rectangle) where TPixel : struct, IPixel - => source.VignetteInternal(color, radiusX, radiusY, rectangle, options); + => source.VignetteInternal(options, color, radiusX, radiusY, rectangle); - private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle, GraphicsOptions options) + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, GraphicsOptions options, TPixel color, ValueSize radiusX, ValueSize radiusY, Rectangle rectangle) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options), rectangle); - private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, TPixel color, ValueSize radiusX, ValueSize radiusY, GraphicsOptions options) + private static IImageProcessingContext VignetteInternal(this IImageProcessingContext source, GraphicsOptions options, TPixel color, ValueSize radiusX, ValueSize radiusY) where TPixel : struct, IPixel => source.ApplyProcessor(new VignetteProcessor(color, radiusX, radiusY, options)); } diff --git a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs index 993adb169..c39b5bc34 100644 --- a/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs +++ b/tests/ImageSharp.Tests/Drawing/BlendedShapes.cs @@ -29,10 +29,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing var scaleY = (img.Height / 100); 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 - })); + .Fill(new GraphicsOptions(true) { BlenderMode = mode }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY) + )); img.DebugSave(provider, new { mode }); } } @@ -47,14 +45,8 @@ namespace SixLabors.ImageSharp.Tests.Drawing var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); 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.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.Mutate(x => x.Fill(new GraphicsOptions(true) { BlenderMode = mode }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY))); + img.Mutate(x => x.Fill(new GraphicsOptions(true) { BlenderMode = mode }, NamedColors.Transparent, new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))); img.DebugSave(provider, new { mode }); } } @@ -69,19 +61,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); 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 - })); + img.Mutate(x => x.Fill(new GraphicsOptions(true) { BlenderMode = mode }, NamedColors.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY))); var c = NamedColors.Red.ToVector4(); c.W *= 0.5f; TPixel pixel = default(TPixel); pixel.PackFromVector4(c); - 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.Mutate(x => x.Fill(new GraphicsOptions(true) { BlenderMode = mode }, pixel, new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))); img.DebugSave(provider, new { mode }); } } @@ -98,10 +84,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing var scaleX = (img.Width / 100); var scaleY = (img.Height / 100); 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.Mutate(x => x.Fill(new GraphicsOptions(true) { BlenderMode = mode }, NamedColors.Black, new Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY))); img.DebugSave(provider, new { mode }); } } diff --git a/tests/ImageSharp.Tests/Drawing/LineTests.cs b/tests/ImageSharp.Tests/Drawing/LineTests.cs index d7eb0b657..e23616b1e 100644 --- a/tests/ImageSharp.Tests/Drawing/LineTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineTests.cs @@ -50,13 +50,15 @@ namespace SixLabors.ImageSharp.Tests.Drawing { 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) - }, - new GraphicsOptions(false))); + .DrawLines( + new GraphicsOptions(false), + Rgba32.HotPink, + 5, + new SixLabors.Primitives.PointF[] { + new Vector2(10, 10), + new Vector2(200, 150), + new Vector2(50, 300) + })); image.Save($"{path}/Simple_noantialias.png"); using (PixelAccessor sourcePixels = image.Lock()) diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs index 4713e63c2..1a402c5b7 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(this.brush, this.path, this.noneDefault); + this.operations.Fill(this.noneDefault, this.brush, this.path); var processor = this.Verify>(); Assert.Equal(this.noneDefault, processor.Options); @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(this.color, this.path, this.noneDefault); + this.operations.Fill(this.noneDefault, this.color, this.path); var processor = this.Verify>(); Assert.Equal(this.noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs index 526cf1b92..b728ea7bf 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs @@ -31,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths })); IPathCollection pathCollection; - + public FillPathCollection() { this.pathCollection = new PathCollection(this.path1, this.path2); @@ -61,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathOptions() { - this.operations.Fill(this.brush, this.pathCollection, this.noneDefault); + this.operations.Fill(this.noneDefault, this.brush, this.pathCollection); for (int i = 0; i < 2; i++) { @@ -100,7 +100,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.Fill(this.color, this.pathCollection, this.noneDefault); + this.operations.Fill(this.noneDefault, this.color, this.pathCollection); for (int i = 0; i < 2; i++) { diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs index a1f083cf4..717feafa8 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs @@ -44,7 +44,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushPathAndOptions() { - this.operations.FillPolygon(this.brush, this.path, this.noneDefault); + this.operations.FillPolygon(this.noneDefault, this.brush, this.path); FillRegionProcessor processor = this.Verify>(); Assert.Equal(this.noneDefault, processor.Options); @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorPathAndOptions() { - this.operations.FillPolygon(this.color, this.path, this.noneDefault); + this.operations.FillPolygon(this.noneDefault, this.color, this.path); FillRegionProcessor processor = this.Verify>(); diff --git a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs index 263eb9a9c..03a59cc8d 100644 --- a/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs +++ b/tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs @@ -38,7 +38,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsBrushRectangleAndOptions() { - this.operations.Fill(this.brush, this.rectangle, this.noneDefault); + this.operations.Fill(this.noneDefault, this.brush, this.rectangle); FillRegionProcessor processor = this.Verify>(); Assert.Equal(this.noneDefault, processor.Options); @@ -75,7 +75,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths [Fact] public void CorrectlySetsColorRectangleAndOptions() { - this.operations.Fill(this.color, this.rectangle, this.noneDefault); + this.operations.Fill(this.noneDefault, this.color, this.rectangle); FillRegionProcessor processor = this.Verify>(); Assert.Equal(this.noneDefault, processor.Options); diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 6eeed144c..bf1f6d45a 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -29,7 +29,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (var image = new Image(500, 500)) { image.Mutate(x => x - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(true))); + .FillPolygon(new GraphicsOptions(true), Rgba32.HotPink, simplePath)); image.Save($"{path}/Simple.png"); using (PixelAccessor sourcePixels = image.Lock()) @@ -52,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing using (var image = new Image(500, 500)) { image.Mutate(x => x - .FillPolygon(Brushes.Horizontal(Rgba32.HotPink), simplePath, new GraphicsOptions(true))); + .FillPolygon(new GraphicsOptions(true), Brushes.Horizontal(Rgba32.HotPink), simplePath)); image.Save($"{path}/Pattern.png"); using (PixelAccessor sourcePixels = image.Lock()) @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing { image.Mutate(x => x .BackgroundColor(Rgba32.Blue) - .FillPolygon(Rgba32.HotPink, simplePath, new GraphicsOptions(false))); + .FillPolygon(new GraphicsOptions(false), Rgba32.HotPink, simplePath)); image.Save($"{path}/Simple_NoAntialias.png"); using (PixelAccessor sourcePixels = image.Lock()) diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs index 85503a552..30d47ab5d 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs @@ -37,12 +37,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void FillsForEachACharachterWhenBrushSetAndNotPen() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), null, - this.path, - new TextGraphicsOptions(true)); + this.path); this.Verify>(0); this.Verify>(1); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), this.path, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), this.path); this.Verify>(0); this.Verify>(1); @@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSet() { - this.operations.DrawText("123", this.Font, Rgba32.Red, this.path, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Rgba32.Red, this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -109,12 +109,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void DrawForEachACharachterWhenPenSetAndNotBrush() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, null, Pens.Dash(Rgba32.Red, 1), - this.path, - new TextGraphicsOptions(true)); + this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSet() { - this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), this.path, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Pens.Dash(Rgba32.Red, 1), this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -155,12 +155,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - this.path, - new TextGraphicsOptions(true)); + this.path); var processor = this.Verify>(0); this.Verify>(1); @@ -187,12 +187,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void BrushAppliesBeforPen() { this.operations.DrawText( + new TextGraphicsOptions(true), "1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - this.path, - new TextGraphicsOptions(true)); + this.path); var processor = this.Verify>(0); this.Verify>(1); diff --git a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs index 058ce6f95..9c929d1c7 100644 --- a/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs +++ b/tests/ImageSharp.Tests/Drawing/Text/DrawText.cs @@ -37,12 +37,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void FillsForEachACharachterWhenBrushSetAndNotPen() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), null, - Vector2.Zero, - new TextGraphicsOptions(true)); + Vector2.Zero); this.Verify>(0); this.Verify>(1); @@ -62,7 +62,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenBrushSet() { - this.operations.DrawText("123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), Vector2.Zero); this.Verify>(0); this.Verify>(1); @@ -82,7 +82,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void FillsForEachACharachterWhenColorSet() { - this.operations.DrawText("123", this.Font, Rgba32.Red, Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Rgba32.Red, Vector2.Zero); var processor = this.Verify>(0); this.Verify>(1); @@ -109,12 +109,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void DrawForEachACharachterWhenPenSetAndNotBrush() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, null, Pens.Dash(Rgba32.Red, 1), - Vector2.Zero, - new TextGraphicsOptions(true)); + Vector2.Zero); var processor = this.Verify>(0); this.Verify>(1); @@ -134,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text [Fact] public void DrawForEachACharachterWhenPenSet() { - this.operations.DrawText("123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero, new TextGraphicsOptions(true)); + this.operations.DrawText(new TextGraphicsOptions(true), "123", this.Font, Pens.Dash(Rgba32.Red, 1), Vector2.Zero); var processor = this.Verify>(0); this.Verify>(1); @@ -155,12 +155,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void DrawForEachACharachterWhenPenSetAndFillFroEachWhenBrushSet() { this.operations.DrawText( + new TextGraphicsOptions(true), "123", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - Vector2.Zero, - new TextGraphicsOptions(true)); + Vector2.Zero); var processor = this.Verify>(0); this.Verify>(1); @@ -188,12 +188,12 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text public void BrushAppliesBeforePen() { this.operations.DrawText( + new TextGraphicsOptions(true), "1", this.Font, Brushes.Solid(Rgba32.Red), Pens.Dash(Rgba32.Red, 1), - Vector2.Zero, - new TextGraphicsOptions(true)); + Vector2.Zero); var processor = this.Verify>(0); this.Verify>(1); diff --git a/tests/ImageSharp.Tests/Issues/Issue412.cs b/tests/ImageSharp.Tests/Issues/Issue412.cs index f48696cd9..a1bf7f36a 100644 --- a/tests/ImageSharp.Tests/Issues/Issue412.cs +++ b/tests/ImageSharp.Tests/Issues/Issue412.cs @@ -22,24 +22,24 @@ namespace SixLabors.ImageSharp.Tests.Issues for (var i = 0; i < 40; ++i) { context.DrawLines( + new GraphicsOptions(false), NamedColors.Black, 1, new[] { new PointF(i, 0.1066f), new PointF(i, 10.1066f) - }, - new GraphicsOptions(true)); + }); context.DrawLines( + new GraphicsOptions(false), NamedColors.Red, 1, new[] { new PointF(i, 15.1066f), new PointF(i, 25.1066f) - }, - new GraphicsOptions(false)); + }); } }); diff --git a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs index d7204d0cf..7aa1720e2 100644 --- a/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs +++ b/tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs @@ -35,7 +35,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects [Fact] public void BackgroundColor_amount_options_BackgroundColorProcessorDefaultsSet() { - this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.options); + this.operations.BackgroundColor(this.options, Rgba32.BlanchedAlmond); var processor = this.Verify>(); Assert.Equal(this.options, processor.GraphicsOptions); @@ -45,7 +45,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects [Fact] public void BackgroundColor_amount_rect_options_BackgroundColorProcessorDefaultsSet() { - this.operations.BackgroundColor(Rgba32.BlanchedAlmond, this.rect, this.options); + this.operations.BackgroundColor(this.options, Rgba32.BlanchedAlmond, this.rect); var processor = this.Verify>(this.rect); Assert.Equal(this.options, processor.GraphicsOptions); From 642576d5b424e23bc1480df1c9157976db8eaf26 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Mon, 19 Mar 2018 10:10:28 +1100 Subject: [PATCH 2/9] Add params --- .../Processing/Drawing/DrawBezierExtensions.cs | 12 ++++++------ .../Processing/Drawing/DrawLineExtensions.cs | 12 ++++++------ .../Processing/Drawing/DrawPolygonExtensions.cs | 12 ++++++------ .../Processing/Drawing/FillPolygonExtensions.cs | 8 ++++---- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs index 37fade35e..72bd76fa6 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawBezierExtensions.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawBeziers(new SolidBrush(color), thickness, points); @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawBeziers(options, new SolidBrush(color), thickness, points); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, pen, new Path(new CubicBezierLineSegment(points))); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(pen, new Path(new CubicBezierLineSegment(points))); } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs index 7acbd0e85..981a07e13 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawLineExtensions.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points))); @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawLines(new SolidBrush(color), thickness, points); @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The .> - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawLines(options, new SolidBrush(color), thickness, points); @@ -77,7 +77,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, GraphicsOptions options, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, pen, new Path(new LinearLineSegment(points))); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawLines(this IImageProcessingContext source, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(pen, new Path(new LinearLineSegment(points))); } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs index 504b9cd7e..9f8d74f00 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawPolygonExtensions.cs @@ -24,7 +24,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IBrush brush, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points))); @@ -50,7 +50,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawPolygon(new SolidBrush(color), thickness, points); @@ -64,7 +64,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The thickness. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) where TPixel : struct, IPixel => source.DrawPolygon(options, new SolidBrush(color), thickness, points); @@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points))); @@ -89,7 +89,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The pen. /// The points. /// The . - public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IPen pen, PointF[] points) + public static IImageProcessingContext DrawPolygon(this IImageProcessingContext source, GraphicsOptions options, IPen pen, params PointF[] points) where TPixel : struct, IPixel => source.Draw(options, pen, new Polygon(new LinearLineSegment(points))); } diff --git a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs index 0b3d493b7..3b80dd0f4 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/FillPolygonExtensions.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The brush. /// The points. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, params PointF[] points) where TPixel : struct, IPixel => source.Fill(options, brush, new Polygon(new LinearLineSegment(points))); @@ -34,7 +34,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The brush. /// The points. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, IBrush brush, params PointF[] points) where TPixel : struct, IPixel => source.Fill(brush, new Polygon(new LinearLineSegment(points))); @@ -47,7 +47,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The color. /// The points. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, GraphicsOptions options, TPixel color, params PointF[] points) where TPixel : struct, IPixel => source.Fill(options, new SolidBrush(color), new Polygon(new LinearLineSegment(points))); @@ -59,7 +59,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The color. /// The points. /// The . - public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, PointF[] points) + public static IImageProcessingContext FillPolygon(this IImageProcessingContext source, TPixel color, params PointF[] points) where TPixel : struct, IPixel => source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); } From fc06762f4e26032e9c87e3b085d826a37f2e22a3 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 20 Mar 2018 13:43:05 +1100 Subject: [PATCH 3/9] Fix spelling --- .../DefaultPixelBlenders.Generated.cs | 8 +++---- .../DefaultPixelBlenders.Generated.tt | 2 +- .../PorterDuffFunctions.Generated.cs | 4 ++-- .../PorterDuffFunctions.Generated.tt | 2 +- .../PixelBlenders/PorterDuffFunctions.cs | 24 +++++++++---------- .../PixelBlenders/PorterDuffFunctionsTests.cs | 2 +- .../PorterDuffFunctionsTests_TPixel.cs | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs index d3c6cf16c..6635a5a2a 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.cs @@ -141,17 +141,17 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } } - internal class Substract : PixelBlender + internal class Subtract : PixelBlender { /// /// Gets the static instance of this blender. /// - public static Substract Instance { get; } = new Substract(); + public static Subtract Instance { get; } = new Subtract(); /// public override TPixel Blend(TPixel background, TPixel source, float amount) { - return PorterDuffFunctions.Substract(background, source, amount); + return PorterDuffFunctions.Subtract(background, source, amount); } /// @@ -172,7 +172,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders for (int i = 0; i < destination.Length; i++) { - destinationSpan[i] = PorterDuffFunctions.Substract(backgroundSpan[i], sourceSpan[i], amount[i]); + destinationSpan[i] = PorterDuffFunctions.Subtract(backgroundSpan[i], sourceSpan[i], amount[i]); } PixelOperations.Instance.PackFromVector4(destinationSpan, destination, destination.Length); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt index eebee676f..485bc31ad 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/DefaultPixelBlenders.Generated.tt @@ -42,7 +42,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders "Normal", "Multiply", "Add", - "Substract", + "Subtract", "Screen", "Darken", "Lighten", diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs index 21ae335be..43fcc68ad 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs @@ -285,11 +285,11 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static TPixel Substract(TPixel backdrop, TPixel source, float amount) + public static TPixel Subtract(TPixel backdrop, TPixel source, float amount) where TPixel : struct, IPixel { TPixel dest = default(TPixel); - dest.PackFromVector4(Substract(backdrop.ToVector4(), source.ToVector4(), amount)); + dest.PackFromVector4(Subtract(backdrop.ToVector4(), source.ToVector4(), amount)); return dest; } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt index c92ab6dd6..f3e0b1f17 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt @@ -83,7 +83,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders GeneratePixelBlender("Normal"); GeneratePixelBlender("Multiply"); GeneratePixelBlender("Add"); - GeneratePixelBlender("Substract"); + GeneratePixelBlender("Subtract"); GeneratePixelBlender("Screen"); GeneratePixelBlender("Darken"); GeneratePixelBlender("Lighten"); diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs index f09d6d51c..c47ef35a3 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.cs @@ -23,7 +23,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Source over backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Source multiplied by backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -51,7 +51,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Source added to backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -63,14 +63,14 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders } /// - /// Source substracted from backdrop + /// Source subtracted from backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static Vector4 Substract(Vector4 backdrop, Vector4 source, float opacity) + public static Vector4 Subtract(Vector4 backdrop, Vector4 source, float opacity) { source.W *= opacity; return Compose(backdrop, source, Vector4.Max(Vector4.Zero, backdrop - source)); @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Complement of source multiplied by the complement of backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -93,7 +93,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Per element, chooses the smallest value of source and backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -107,7 +107,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Per element, chooses the largest value of source and backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Overlays source over backdrop /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -139,7 +139,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// Hard light effect /// - /// Backgrop color + /// Backdrop color /// Source color /// Opacity applied to Source Alpha /// Output color @@ -169,7 +169,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders /// /// General composition function for all modes, with a general solution for alpha channel /// - /// Original backgrop color + /// Original Backdrop color /// Original source color /// Desired transformed color, without taking Alpha channel in account /// The final color diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs index 9aa2e01a6..c5910e13a 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests.cs @@ -79,7 +79,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders [MemberData(nameof(SubstractFunctionData))] public void SubstractFunction(TestVector4 back, TestVector4 source, float amount, TestVector4 expected) { - Vector4 actual = PorterDuffFunctions.Substract((Vector4)back, source, amount); + Vector4 actual = PorterDuffFunctions.Subtract((Vector4)back, source, amount); VectorAssert.Equal(expected, actual, 5); } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index 50babde69..d77c42086 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -151,7 +151,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders public void SubstractFunction(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - TPixel actual = PorterDuffFunctions.Substract((TPixel)back, source, amount); + TPixel actual = PorterDuffFunctions.Subtract((TPixel)back, source, amount); VectorAssert.Equal(expected, actual, 2); } From 4059448dc634b4cb58b0df86a7382988f3202394 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 20 Mar 2018 16:21:01 +1100 Subject: [PATCH 4/9] Add basic comparision tests --- .../PixelFormats/PixelBlenderMode.cs | 2 +- .../PixelOperations{TPixel}.PixelBenders.cs | 2 +- .../ImageSharp.Tests/Drawing/DrawImageTest.cs | 2 +- .../PorterDuffCompositorTests.cs | 52 +++++++++++ .../PorterDuffFunctionsTests_TPixel.cs | 4 +- .../PixelOperationsTests.Blender.cs | 88 +++++++++--------- tests/ImageSharp.Tests/TestImages.cs | 2 + tests/Images/Input/Png/pd-dest.png | Bin 0 -> 2563 bytes tests/Images/Input/Png/pd-source.png | Bin 0 -> 2393 bytes 9 files changed, 103 insertions(+), 49 deletions(-) create mode 100644 tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs create mode 100644 tests/Images/Input/Png/pd-dest.png create mode 100644 tests/Images/Input/Png/pd-source.png diff --git a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs index 7541be789..4b8f56d76 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenderMode.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenderMode.cs @@ -26,7 +26,7 @@ namespace SixLabors.ImageSharp.PixelFormats /// /// Blends the 2 values by subtraction. /// - Substract, + Subtract, /// /// Multiplies the complements of the backdrop and source values, then complements the result. diff --git a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs index 154ec7373..2c225ba4c 100644 --- a/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs +++ b/src/ImageSharp/PixelFormats/PixelOperations{TPixel}.PixelBenders.cs @@ -22,7 +22,7 @@ namespace SixLabors.ImageSharp.PixelFormats { case PixelBlenderMode.Multiply: return DefaultPixelBlenders.Multiply.Instance; case PixelBlenderMode.Add: return DefaultPixelBlenders.Add.Instance; - case PixelBlenderMode.Substract: return DefaultPixelBlenders.Substract.Instance; + case PixelBlenderMode.Subtract: return DefaultPixelBlenders.Subtract.Instance; case PixelBlenderMode.Screen: return DefaultPixelBlenders.Screen.Instance; case PixelBlenderMode.Darken: return DefaultPixelBlenders.Darken.Instance; case PixelBlenderMode.Lighten: return DefaultPixelBlenders.Lighten.Instance; diff --git a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs index 3e7f3648f..0ff0b8557 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawImageTest.cs @@ -28,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Normal)] [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Multiply)] [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Add)] - [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Substract)] + [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Subtract)] [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Screen)] [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Darken)] [WithFileCollection(nameof(TestFiles), PixelTypes, PixelBlenderMode.Lighten)] diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs new file mode 100644 index 000000000..90b963f5c --- /dev/null +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -0,0 +1,52 @@ +// Copyright (c) Six Labors and contributors. +// Licensed under the Apache License, Version 2.0. + +using SixLabors.ImageSharp.PixelFormats; +using SixLabors.ImageSharp.Processing; +using SixLabors.ImageSharp.Processing.Drawing; + +using Xunit; + +namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders +{ + public class PorterDuffCompositorTests + { + // TODO: Add other modes to compare. + private static PixelBlenderMode[] CompositingOperators = + { + PixelBlenderMode.Src, + PixelBlenderMode.Atop, + PixelBlenderMode.Over, + PixelBlenderMode.In, + PixelBlenderMode.Out, + PixelBlenderMode.Dest, + PixelBlenderMode.DestAtop, + PixelBlenderMode.DestOver, + PixelBlenderMode.DestIn, + PixelBlenderMode.DestOut, + PixelBlenderMode.Clear, + PixelBlenderMode.Xor + }; + + [Fact] + public void PorterDuffOutputIsCorrect() + { + string path = TestEnvironment.CreateOutputDirectory("PorterDuff"); + var srcFile = TestFile.Create(TestImages.Png.PDSrc); + var destFile = TestFile.Create(TestImages.Png.PDDest); + + using (Image src = srcFile.CreateImage()) + using (Image dest = destFile.CreateImage()) + { + foreach (PixelBlenderMode m in CompositingOperators) + { + using (Image res = dest.Clone(x => x.Blend(src, new GraphicsOptions { BlenderMode = m }))) + { + // TODO: Generate reference files once this works. + res.Save($"{path}/{m}.png"); + } + } + } + } + } +} diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs index d77c42086..10a34ec31 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffFunctionsTests_TPixel.cs @@ -160,7 +160,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders public void SubstractFunction_Blender(TestPixel back, TestPixel source, float amount, TestPixel expected) where TPixel : struct, IPixel { - TPixel actual = new DefaultPixelBlenders.Substract().Blend(back, source, amount); + TPixel actual = new DefaultPixelBlenders.Subtract().Blend(back, source, amount); VectorAssert.Equal(expected, actual, 2); } @@ -170,7 +170,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders where TPixel : struct, IPixel { Span dest = new Span(new TPixel[1]); - new DefaultPixelBlenders.Substract().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); + new DefaultPixelBlenders.Subtract().Blend(this.MemoryManager, dest, back.AsSpan(), source.AsSpan(), AsSpan(amount)); VectorAssert.Equal(expected, dest[0], 2); } diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs index 524747afe..d3956ecd5 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelOperationsTests.Blender.cs @@ -16,53 +16,53 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats public static TheoryData BlenderMappings = new TheoryData() - { - { new TestPixel(), typeof(DefaultPixelBlenders.Normal), PixelBlenderMode.Normal }, - { new TestPixel(), typeof(DefaultPixelBlenders.Screen), PixelBlenderMode.Screen }, - { new TestPixel(), typeof(DefaultPixelBlenders.HardLight), PixelBlenderMode.HardLight }, - { new TestPixel(), typeof(DefaultPixelBlenders.Overlay), PixelBlenderMode.Overlay }, - { new TestPixel(), typeof(DefaultPixelBlenders.Darken), PixelBlenderMode.Darken }, - { new TestPixel(), typeof(DefaultPixelBlenders.Lighten), PixelBlenderMode.Lighten }, - { new TestPixel(), typeof(DefaultPixelBlenders.Add), PixelBlenderMode.Add }, - { new TestPixel(), typeof(DefaultPixelBlenders.Substract), PixelBlenderMode.Substract }, - { new TestPixel(), typeof(DefaultPixelBlenders.Multiply), PixelBlenderMode.Multiply }, + { + { new TestPixel(), typeof(DefaultPixelBlenders.Normal), PixelBlenderMode.Normal }, + { new TestPixel(), typeof(DefaultPixelBlenders.Screen), PixelBlenderMode.Screen }, + { new TestPixel(), typeof(DefaultPixelBlenders.HardLight), PixelBlenderMode.HardLight }, + { new TestPixel(), typeof(DefaultPixelBlenders.Overlay), PixelBlenderMode.Overlay }, + { new TestPixel(), typeof(DefaultPixelBlenders.Darken), PixelBlenderMode.Darken }, + { new TestPixel(), typeof(DefaultPixelBlenders.Lighten), PixelBlenderMode.Lighten }, + { new TestPixel(), typeof(DefaultPixelBlenders.Add), PixelBlenderMode.Add }, + { new TestPixel(), typeof(DefaultPixelBlenders.Subtract), PixelBlenderMode.Subtract }, + { new TestPixel(), typeof(DefaultPixelBlenders.Multiply), PixelBlenderMode.Multiply }, - { new TestPixel(), typeof(DefaultPixelBlenders.Src), PixelBlenderMode.Src }, - { new TestPixel(), typeof(DefaultPixelBlenders.Atop), PixelBlenderMode.Atop }, - { new TestPixel(), typeof(DefaultPixelBlenders.Over), PixelBlenderMode.Over }, - { new TestPixel(), typeof(DefaultPixelBlenders.In), PixelBlenderMode.In }, - { new TestPixel(), typeof(DefaultPixelBlenders.Out), PixelBlenderMode.Out }, - { new TestPixel(), typeof(DefaultPixelBlenders.Dest), PixelBlenderMode.Dest }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestAtop), PixelBlenderMode.DestAtop }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestOver), PixelBlenderMode.DestOver }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestIn), PixelBlenderMode.DestIn }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestOut), PixelBlenderMode.DestOut }, - { new TestPixel(), typeof(DefaultPixelBlenders.Clear), PixelBlenderMode.Clear }, - { new TestPixel(), typeof(DefaultPixelBlenders.Xor), PixelBlenderMode.Xor }, + { new TestPixel(), typeof(DefaultPixelBlenders.Src), PixelBlenderMode.Src }, + { new TestPixel(), typeof(DefaultPixelBlenders.Atop), PixelBlenderMode.Atop }, + { new TestPixel(), typeof(DefaultPixelBlenders.Over), PixelBlenderMode.Over }, + { new TestPixel(), typeof(DefaultPixelBlenders.In), PixelBlenderMode.In }, + { new TestPixel(), typeof(DefaultPixelBlenders.Out), PixelBlenderMode.Out }, + { new TestPixel(), typeof(DefaultPixelBlenders.Dest), PixelBlenderMode.Dest }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestAtop), PixelBlenderMode.DestAtop }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestOver), PixelBlenderMode.DestOver }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestIn), PixelBlenderMode.DestIn }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestOut), PixelBlenderMode.DestOut }, + { new TestPixel(), typeof(DefaultPixelBlenders.Clear), PixelBlenderMode.Clear }, + { new TestPixel(), typeof(DefaultPixelBlenders.Xor), PixelBlenderMode.Xor }, - { new TestPixel(), typeof(DefaultPixelBlenders.Normal), PixelBlenderMode.Normal }, - { new TestPixel(), typeof(DefaultPixelBlenders.Screen), PixelBlenderMode.Screen }, - { new TestPixel(), typeof(DefaultPixelBlenders.HardLight), PixelBlenderMode.HardLight }, - { new TestPixel(), typeof(DefaultPixelBlenders.Overlay), PixelBlenderMode.Overlay }, - { new TestPixel(), typeof(DefaultPixelBlenders.Darken), PixelBlenderMode.Darken }, - { new TestPixel(), typeof(DefaultPixelBlenders.Lighten), PixelBlenderMode.Lighten }, - { new TestPixel(), typeof(DefaultPixelBlenders.Add), PixelBlenderMode.Add }, - { new TestPixel(), typeof(DefaultPixelBlenders.Substract), PixelBlenderMode.Substract }, - { new TestPixel(), typeof(DefaultPixelBlenders.Multiply), PixelBlenderMode.Multiply }, - { new TestPixel(), typeof(DefaultPixelBlenders.Src), PixelBlenderMode.Src }, - { new TestPixel(), typeof(DefaultPixelBlenders.Atop), PixelBlenderMode.Atop }, - { new TestPixel(), typeof(DefaultPixelBlenders.Over), PixelBlenderMode.Over }, - { new TestPixel(), typeof(DefaultPixelBlenders.In), PixelBlenderMode.In }, - { new TestPixel(), typeof(DefaultPixelBlenders.Out), PixelBlenderMode.Out }, - { new TestPixel(), typeof(DefaultPixelBlenders.Dest), PixelBlenderMode.Dest }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestAtop), PixelBlenderMode.DestAtop }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestOver), PixelBlenderMode.DestOver }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestIn), PixelBlenderMode.DestIn }, - { new TestPixel(), typeof(DefaultPixelBlenders.DestOut), PixelBlenderMode.DestOut }, - { new TestPixel(), typeof(DefaultPixelBlenders.Clear), PixelBlenderMode.Clear }, - { new TestPixel(), typeof(DefaultPixelBlenders.Xor), PixelBlenderMode.Xor }, + { new TestPixel(), typeof(DefaultPixelBlenders.Normal), PixelBlenderMode.Normal }, + { new TestPixel(), typeof(DefaultPixelBlenders.Screen), PixelBlenderMode.Screen }, + { new TestPixel(), typeof(DefaultPixelBlenders.HardLight), PixelBlenderMode.HardLight }, + { new TestPixel(), typeof(DefaultPixelBlenders.Overlay), PixelBlenderMode.Overlay }, + { new TestPixel(), typeof(DefaultPixelBlenders.Darken), PixelBlenderMode.Darken }, + { new TestPixel(), typeof(DefaultPixelBlenders.Lighten), PixelBlenderMode.Lighten }, + { new TestPixel(), typeof(DefaultPixelBlenders.Add), PixelBlenderMode.Add }, + { new TestPixel(), typeof(DefaultPixelBlenders.Subtract), PixelBlenderMode.Subtract }, + { new TestPixel(), typeof(DefaultPixelBlenders.Multiply), PixelBlenderMode.Multiply }, + { new TestPixel(), typeof(DefaultPixelBlenders.Src), PixelBlenderMode.Src }, + { new TestPixel(), typeof(DefaultPixelBlenders.Atop), PixelBlenderMode.Atop }, + { new TestPixel(), typeof(DefaultPixelBlenders.Over), PixelBlenderMode.Over }, + { new TestPixel(), typeof(DefaultPixelBlenders.In), PixelBlenderMode.In }, + { new TestPixel(), typeof(DefaultPixelBlenders.Out), PixelBlenderMode.Out }, + { new TestPixel(), typeof(DefaultPixelBlenders.Dest), PixelBlenderMode.Dest }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestAtop), PixelBlenderMode.DestAtop }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestOver), PixelBlenderMode.DestOver }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestIn), PixelBlenderMode.DestIn }, + { new TestPixel(), typeof(DefaultPixelBlenders.DestOut), PixelBlenderMode.DestOut }, + { new TestPixel(), typeof(DefaultPixelBlenders.Clear), PixelBlenderMode.Clear }, + { new TestPixel(), typeof(DefaultPixelBlenders.Xor), PixelBlenderMode.Xor }, - }; + }; [Theory] [MemberData(nameof(BlenderMappings))] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index db469f87e..4e9c3192d 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/tests/ImageSharp.Tests/TestImages.cs @@ -36,6 +36,8 @@ namespace SixLabors.ImageSharp.Tests public const string SnakeGame = "Png/SnakeGame.png"; public const string Icon = "Png/icon.png"; public const string Kaboom = "Png/kaboom.png"; + public const string PDSrc = "Png/pd-source.png"; + public const string PDDest = "Png/pd-dest.png"; // Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html public const string Filter0 = "Png/filter0.png"; diff --git a/tests/Images/Input/Png/pd-dest.png b/tests/Images/Input/Png/pd-dest.png new file mode 100644 index 0000000000000000000000000000000000000000..8db8ce173d75e4e458a7c6c7005ac5a46d07f9f4 GIT binary patch literal 2563 zcmV+e3jFnnP)^DTt$%^h4-?5t6$bqOnq_ zXlWBPGf*Iqx6O08cZ;D1a!Duymb|pFFwuBYBy+N7@KeUcPqH zwQHG`0EYq0btw!3I8B6lB0idv(|^37;SW77#d1Vi2xA!GB>;8-xXt6xdn_yRh{rLL zLi0NT!>D=;z#H&h6adKfA!bqpe2h(oQCSD@!#?Jqgc(gJ6#fwaKScpRS^mZ!A72h- zq0ojRB0TFy?3>}VILD5KFTxPf762K3#J-vI6~^;J*A5&gWo`_k)eZ7=tY{?IVO8A8yVx{i4OuVltD zj3bn$rN`~USa>cB5iPQB&Go_Hu1}gY@V!K$j72QAzq7eHvMm_Q`3f^01#oHjvvfX`c`ghyebuJv;S(qJ zU9%gvv2lBMG#dGBFgS1Zi%rXOGU7KjK6lBo>b3wVV#Z%(_;dq5 zZZK`#)DbbuOv17v?*VvErcaspagK@GF=EC%*@>hxJ_y4f+cf;PVT7khO(l)-K^W~n zHVr2eVZGE;(ik63{`{6*TV`xEjPU1W=98}YaJh_Q4$P+lyhBW^9qoBZ8 z1>j5eJkZ^Rh35J8cI&j%#L^7ERxr0aF=pmHrKOd{vXV(hd=bX73Jw5V@4!X25OnCX ze7^B%kEs@#mhljPE(cC#G2>u)`PxacvPvg>5oY1S^|?aCcL12|#19d^+0_+%sl2?} z&)x-B@LU+f2+!&13A_cMLWVzPEWdiSeIL@K6-ySL{xYUnc^@;q2xkjr zcrc7`K7ivGyjsmmu;~k2^t+!Hf zU6@cP{1iZsyB%i;V&>;evvP$UVQ)@H6Kf(|6~-{aPZHr5ZpIjc05iR4nj6bg zH6%jHH?2fyN!2D9TocALE7t(n>X!crn8Yj&my}eQ$r@BtROkRoQw>CfXsR~J;EFJ& zxp6)-MI5-eAYs`zPt*7{!w4tU{BiEww7E$AzN$MXr|?YbsZES@Vdl@@{5fXvCjfTu z$gc@O%X@nRs{lUbFrDcDjv7XI=0qE68WyDLoCr+~4b`?*WGBo=wnHKM9|thQu00X0 zkHug1FMtk*sojy0AzmMEX?m#Mwm4O%MB4v{FuI=4_tSWPa>oVQ&#rFJOE`j z%`fHU_0=TWpt-rGfruUiAZ*4Mf|mibAE?%V!AiHi=>vYvSssazCd|MJg z%=B<`bM3*Q=5UAb1E$%&0|2_a_0>qde#e>?IO05y@sTEs5H#C??O&4JHX4om9^j|! z#u|nhn++rUq^40gb!$4*)U@Y)r#U1-nlMC|X4h8N#XG5NZ&`J}1hCg`yb)|=M$*-R zVKhxVEg^Q|7_uBW5k?3~wTqu~a|<>x;}yFx?L)6NHPtn_9Yx}yEaAdZLYPI$695ej z)$z>CoYerIup8F~y#oXIi5Gz+?lElp(ve8F)rvGY#6(L0wAziG8uXi%mfEvkM3Q(P zqg}RZ$;>HNb%(L6$Q4ZsECcXwyFQZSY=8faZ7#?71etrxf9>0%!bvB8Q`7DXLeM=J zF~%pEIDj>7-cXK4;vU0J>RGu?JNaX=+INYx6#!D2(M$#+Y_qJ$N!flAA@StTj(UlQ zI{7Co&nKd}x#k2j-w&I^QDZ|EGdw$l4I@pMyu2Cj0HvV?pD^QBhEe57t<05O|Ki1#8~OPqF(O(Gf1kVQ28#;|L+9JuqpsHH zTstOrbVSb=6d3OS_&(C$X|)m|fR^XyhhiNaQKzj{iGsLGC{(qai2n%J#xH!M8^99F ziX3;tx$EELXteeSfQ0}&DVHZfFMvIo#^rF_t@Z=CW&d>`eG8FRUtC-z{bAmo&n=qf#<_raf*Gqk zihmhEtq}2@vDm)$(I1wUR(@Rws)w_OW1kBI#3Gsh(80HXQo{(}jlr_X14umYXqSHi z^t+xOeScfq?u29OL$jfW;jCH^3j{LDPoCU))q#&s@O{$PFv8i)bT1LF0I&o=z702V z0OtTc!Hna90Ny-xsxGA~Cc_Aq0dTbJ0O0MR2h=&ncVR|TQu6RDT@REBfoVjT%FMY$ z$i?6@EaL!O2dIxobTZRPx#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02y>eSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;2FkAZe8V00_xRL_t(|UhSQ4a8%V9he-l41R@cNkXF%w zh*~kt-g}c6a4fZvn0xo8NolNAKB%1z6=rapYTI!-ZLPJX&Zr$m=m-DNfsUiL^n+5h zGipT*uzPQSR;@E=TPx}qK(Q*-Kxm&APTTGFmMq!b>}L1<%{)W??cICc-#zEN=j=I$ z2`ZIJrBbO>DwRs5QmIrbl}e>jsZ=VJN>zG#sIRX=FyE?*Maj7RdAKa;I}4!N{8&|J zB|SS1t1)M75Vx)hJ?ng!YJROMl#;G}F2?)_Q~n0KK)&t_Jo}8`Qv0N!!`5c55DIL& z3S%y##=H^4?L&qaFy@w^%bpi3v1|C9no|g2OdG+!AKt^1BXAI7_CP<}%+K3N5Gu`| ztHw$+XAPM16%5#eDZ}s&W6($N5~ z@_yi1G;h|OAO3^)f7$Z|WYcQtk#lG`uK(n`O#AyFC_$s_*0v%<*NXYACdPi!{ zX81maU(9%ErgZ1@OMUWX0zL0_jPwT8Ym9khu%Q4z!$ z@Kbm-BGB3JS8C4&@Zk(hnv!r^)Syg-A(NpKo{R`?Hjq$Q2jLC)ImRr(n3K)hszy@K zWmUoq0=JG}zLOT*Y@z?L=zpv?x&HGsZ)*~s)3f!`w)&?RFV@By-uQ8?*W`mlOE{v%lNQ(*9qmYZ#ITMC>&jYXb zyLy|Zf%ZSCqTN3eR>ELJ5c7pJo023*?Rf_7pug)4-Pq~7yBgIXQPOj2F~x=ff<>wu z8OVHch{5hYcm#89gwOG{%uZ+%#}hjf?uOSQ0ymZnV#sF9`5K%J(|B;o*B}g;0==*$ zB3NU|Fvfh0A=Du2F}M$cG>wF>J<^RWJuiJA0$BXTi5&Z$wav4C@^T;Xb%JaP9d)M~Nl~ zWIlBi`a<|U{QW;cC|ab+mFc8sNwt3n-PESD`uz(^Z=)84JQX&8Y~P3qMzJEzuk=4R zCE`wV!gFQ}xUtePh{8<;S?1IaQ2{7cB$JfSfZl`c^p~qJrqL8@{43GzRKXkyC$**! z^Jm#|EWJLqigXj@xPcnfxZQ89F-07|>hEi>qCnrGfG?&Lcsz1|anClm3Qjl08{Z0i ztAlJuYK@tuk1TjGBlr9+Y$YjJ0dq~!#ex`52_Xu3R1 z@#NvLelie`%`Jjtni}(6*c}m^!r<9&GHCo2_p}UVVoH^{-SSexcRT{{FhMcngot2` z3IATSz7b=-C|elKEtaPeeoF(!d=rMC5XKzgePyA>URaMY?Ye^iVa!AV^97LAD>54p z6})^R#>nX%w_?mW7&F=2nu-Bu6M?xMa=owScu4IW#)xNu8tX9V)e{TH>`$*7&67YttwLyxTWw&L~uuoEQ1ZX z=56$2joZ4~^sKbeh^KijP0jZRrW{`~>H#O$knxEOS_8N-=&+~i(Zg8?W8^far36=w zbR6~MCf7I!&m`i`vh8lmEKJeSe6}K>Hv9|@LOSY8n!IX8$ zxO1_&lq%Q4lvCh481q7e5$VY6uxum$2F%A8?N9Qhz_qHu4m?Xz=i_a7l8vwZuma|V zaclf9SuJJ_xUmYTBiOeQ{HPrQ$F@p%mTVPY9=g^X(0%-4C4zn>{5H)L`LuB#{D$9s zIrOYk&7Z5rN?}**T!Q~&%#iHt2>s4s7{rt(!g%b09r0%UPlXDhogGcp7;`zM$O#*A zR Date: Tue, 20 Mar 2018 22:54:38 +0100 Subject: [PATCH 5/9] turning PorterDuffOutputIsCorrect() into a [Theory] --- .../PorterDuffCompositorTests.cs | 59 +++++++++---------- 1 file changed, 29 insertions(+), 30 deletions(-) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index 90b963f5c..f70fa0a2a 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -1,35 +1,37 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. -using SixLabors.ImageSharp.PixelFormats; -using SixLabors.ImageSharp.Processing; -using SixLabors.ImageSharp.Processing.Drawing; - -using Xunit; - namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders { + using SixLabors.ImageSharp.PixelFormats; + using SixLabors.ImageSharp.Processing; + using SixLabors.ImageSharp.Processing.Drawing; + + using Xunit; + public class PorterDuffCompositorTests { // TODO: Add other modes to compare. - private static PixelBlenderMode[] CompositingOperators = - { - PixelBlenderMode.Src, - PixelBlenderMode.Atop, - PixelBlenderMode.Over, - PixelBlenderMode.In, - PixelBlenderMode.Out, - PixelBlenderMode.Dest, - PixelBlenderMode.DestAtop, - PixelBlenderMode.DestOver, - PixelBlenderMode.DestIn, - PixelBlenderMode.DestOut, - PixelBlenderMode.Clear, - PixelBlenderMode.Xor - }; + public static readonly TheoryData CompositingOperators = + new TheoryData + { + PixelBlenderMode.Src, + PixelBlenderMode.Atop, + PixelBlenderMode.Over, + PixelBlenderMode.In, + PixelBlenderMode.Out, + PixelBlenderMode.Dest, + PixelBlenderMode.DestAtop, + PixelBlenderMode.DestOver, + PixelBlenderMode.DestIn, + PixelBlenderMode.DestOut, + PixelBlenderMode.Clear, + PixelBlenderMode.Xor + }; - [Fact] - public void PorterDuffOutputIsCorrect() + [Theory] + [MemberData(nameof(CompositingOperators))] + public void PorterDuffOutputIsCorrect(PixelBlenderMode mode) { string path = TestEnvironment.CreateOutputDirectory("PorterDuff"); var srcFile = TestFile.Create(TestImages.Png.PDSrc); @@ -38,15 +40,12 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders using (Image src = srcFile.CreateImage()) using (Image dest = destFile.CreateImage()) { - foreach (PixelBlenderMode m in CompositingOperators) + using (Image res = dest.Clone(x => x.Blend(src, new GraphicsOptions { BlenderMode = mode }))) { - using (Image res = dest.Clone(x => x.Blend(src, new GraphicsOptions { BlenderMode = m }))) - { - // TODO: Generate reference files once this works. - res.Save($"{path}/{m}.png"); - } + // TODO: Generate reference files once this works. + res.Save($"{path}/{mode}.png"); } } } } -} +} \ No newline at end of file From 64345bb677c25a2f46a4cefe36f8359e2767f756 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Wed, 21 Mar 2018 00:10:03 +0100 Subject: [PATCH 6/9] Corrected implementation of PorterDuffFunctions. --- .../PorterDuffFunctions.Generated.cs | 126 +++++++++--------- .../PorterDuffFunctions.Generated.tt | 17 ++- 2 files changed, 73 insertions(+), 70 deletions(-) diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs index 43fcc68ad..e948c05ca 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.cs @@ -15,19 +15,19 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Src(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = source; + source.W *= opacity; // calculate weights - float xw = Vector4.Zero.W * source.W; - float bw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 0) + (xw * 1); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((source * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -36,18 +36,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Atop(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = source; // calculate weights - float xw = backdrop.W * Vector4.Zero.W; + float xw = backdrop.W * source.W; float bw = backdrop.W - xw; - float sw = Vector4.Zero.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 1) + (xw * 1); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((source * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -56,8 +56,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Over(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = source; + source.W *= opacity; // calculate weights float xw = backdrop.W * source.W; @@ -65,10 +64,11 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 1) + (xw * 1); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((source * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -77,18 +77,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 In(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = source; // calculate weights - float xw = Vector4.Zero.W * Vector4.Zero.W; - float bw = Vector4.Zero.W - xw; - float sw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 0) + (xw * 1); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((source * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -97,19 +97,19 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Out(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = Vector4.Zero; + source.W *= opacity; // calculate weights - float xw = Vector4.Zero.W * source.W; - float bw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 0) + (xw * 0); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((Vector4.Zero * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -118,18 +118,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Dest(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = backdrop; // calculate weights - float xw = backdrop.W * Vector4.Zero.W; + float xw = backdrop.W * source.W; float bw = backdrop.W - xw; - float sw = Vector4.Zero.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 1) + (xw * 1); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((backdrop * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -138,19 +138,19 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 DestAtop(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = backdrop; + source.W *= opacity; // calculate weights - float xw = Vector4.Zero.W * source.W; - float bw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 0) + (xw * 1); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((backdrop * xw) + (Vector4.Zero * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -159,8 +159,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 DestOver(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = backdrop; + source.W *= opacity; // calculate weights float xw = backdrop.W * source.W; @@ -168,10 +167,11 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 1) + (xw * 1); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((backdrop * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -180,18 +180,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 DestIn(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = backdrop; // calculate weights - float xw = Vector4.Zero.W * Vector4.Zero.W; - float bw = Vector4.Zero.W - xw; - float sw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 0) + (xw * 1); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((backdrop * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -200,18 +200,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 DestOut(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = Vector4.Zero; // calculate weights - float xw = backdrop.W * Vector4.Zero.W; + float xw = backdrop.W * source.W; float bw = backdrop.W - xw; - float sw = Vector4.Zero.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 1) + (xw * 0); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((Vector4.Zero * xw) + (backdrop * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -220,18 +220,18 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Clear(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - Vector4 xform = Vector4.Zero; // calculate weights - float xw = Vector4.Zero.W * Vector4.Zero.W; - float bw = Vector4.Zero.W - xw; - float sw = Vector4.Zero.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 0) + (bw * 0) + (xw * 0); // calculate final value - xform = ((xform * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((Vector4.Zero * xw) + (Vector4.Zero * bw) + (Vector4.Zero * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } @@ -240,8 +240,7 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders public static Vector4 Xor(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); - source.W *= opacity; - Vector4 xform = Vector4.Zero; + source.W *= opacity; // calculate weights float xw = backdrop.W * source.W; @@ -249,10 +248,11 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * 1) + (bw * 1) + (xw * 0); // calculate final value - xform = ((xform * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((Vector4.Zero * xw) + (backdrop * bw) + (source * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } diff --git a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt index f3e0b1f17..940b585aa 100644 --- a/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt +++ b/src/ImageSharp/PixelFormats/PixelBlenders/PorterDuffFunctions.Generated.tt @@ -40,26 +40,29 @@ namespace SixLabors.ImageSharp.PixelFormats.PixelBlenders void GenerateVectorCompositor(string name, string sourceVar, string destVar, string blendVar) { + int a_s = sourceVar == "Vector4.Zero" ? 0 : 1; + int a_b = destVar == "Vector4.Zero" ? 0 : 1; + int a_x = blendVar == "Vector4.Zero" ? 0 : 1; #> [MethodImpl(MethodImplOptions.AggressiveInlining)] public static Vector4 <#=name#>(Vector4 backdrop, Vector4 source, float opacity) { opacity = opacity.Clamp(0, 1); <# if(sourceVar != "Vector4.Zero" ) { #> - source.W *= opacity; + source.W *= opacity; <# } #> - Vector4 xform = <#=blendVar#>; // calculate weights - float xw = <#=destVar#>.W * <#=sourceVar#>.W; - float bw = <#=destVar#>.W - xw; - float sw = <#=sourceVar#>.W - xw; + float xw = backdrop.W * source.W; + float bw = backdrop.W - xw; + float sw = source.W - xw; // calculate final alpha - float a = xw + bw + sw; + float fw = (sw * <#=a_s#>) + (bw * <#=a_b#>) + (xw * <#=a_x#>); // calculate final value - xform = ((xform * xw) + (<#=destVar#> * bw) + (<#=sourceVar#> * sw)) / MathF.Max(a, Constants.Epsilon); + Vector4 xform = ((<#=blendVar#> * xw) + (<#=destVar#> * bw) + (<#=sourceVar#> * sw)) / MathF.Max(fw, Constants.Epsilon); + xform.W = fw; return Vector4.Lerp(backdrop, xform, opacity); } From 2b36c6ab00eb5eca3dd9e0800b3f7c6a004e35ba Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 21 Mar 2018 11:55:20 +1100 Subject: [PATCH 7/9] Update tests to add reference comparisons --- .../PixelBlenders/PorterDuffCompositorTests.cs | 13 +++++-------- tests/Images/External | 2 +- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index f70fa0a2a..ee2fa2cbe 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -30,20 +30,17 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders }; [Theory] - [MemberData(nameof(CompositingOperators))] - public void PorterDuffOutputIsCorrect(PixelBlenderMode mode) + [WithFile(TestImages.Png.PDDest, nameof(CompositingOperators), PixelTypes.Rgba32)] + public void PorterDuffOutputIsCorrect(TestImageProvider provider, PixelBlenderMode mode) { - string path = TestEnvironment.CreateOutputDirectory("PorterDuff"); var srcFile = TestFile.Create(TestImages.Png.PDSrc); - var destFile = TestFile.Create(TestImages.Png.PDDest); - using (Image src = srcFile.CreateImage()) - using (Image dest = destFile.CreateImage()) + using (Image dest = provider.GetImage()) { using (Image res = dest.Clone(x => x.Blend(src, new GraphicsOptions { BlenderMode = mode }))) { - // TODO: Generate reference files once this works. - res.Save($"{path}/{mode}.png"); + res.DebugSave(provider, mode.ToString()); + res.CompareToReferenceOutput(provider, mode.ToString()); } } } diff --git a/tests/Images/External b/tests/Images/External index e9f33352b..5a66c9c6d 160000 --- a/tests/Images/External +++ b/tests/Images/External @@ -1 +1 @@ -Subproject commit e9f33352b77a5176508d2d5dcafbd1bd33805530 +Subproject commit 5a66c9c6da02bf27345f90adc05d415c0d0450ea From 4b1d22643040c61eef13dd0c812f4ad27adaf555 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 21 Mar 2018 12:29:32 +1100 Subject: [PATCH 8/9] Fix test --- .../PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index ee2fa2cbe..11e6000fe 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders using (Image src = srcFile.CreateImage()) using (Image dest = provider.GetImage()) { - using (Image res = dest.Clone(x => x.Blend(src, new GraphicsOptions { BlenderMode = mode }))) + using (Image res = dest.Clone(x => x.Blend(new GraphicsOptions { BlenderMode = mode }, src))) { res.DebugSave(provider, mode.ToString()); res.CompareToReferenceOutput(provider, mode.ToString()); From c101fd7c2613e8094786a4e923a8b53979e296e3 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Wed, 21 Mar 2018 16:10:14 +1100 Subject: [PATCH 9/9] Blend => DrawImage --- .../Processing/Drawing/DrawImageExtensions.cs | 10 ++++------ .../PixelBlenders/PorterDuffCompositorTests.cs | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs index e2951ee2c..83e1b90f5 100644 --- a/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs +++ b/src/ImageSharp.Drawing/Processing/Drawing/DrawImageExtensions.cs @@ -20,7 +20,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The image to blend with the currently processing image. /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, float opacity) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, float opacity) where TPixel : struct, IPixel => source.ApplyProcessor(new DrawImageProcessor(image, opacity)); @@ -33,7 +33,7 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The blending mode. /// The opacity of the image to blend. Must be between 0 and 1. /// The . - public static IImageProcessingContext Blend(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, Image image, PixelBlenderMode blender, float opacity) where TPixel : struct, IPixel => source.ApplyProcessor(new DrawImageProcessor(image, opacity, blender)); @@ -45,11 +45,9 @@ namespace SixLabors.ImageSharp.Processing.Drawing /// The options, including the blending type and blending amount. /// The image to blend with the currently processing image. /// The . - public static IImageProcessingContext Blend(this IImageProcessingContext source, GraphicsOptions options, Image image) + public static IImageProcessingContext DrawImage(this IImageProcessingContext source, GraphicsOptions options, Image image) where TPixel : struct, IPixel - { - return source.ApplyProcessor(new DrawImageProcessor(image, options)); - } + => source.ApplyProcessor(new DrawImageProcessor(image, options)); /// /// Draws the given image together with the current one by blending their pixels. diff --git a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs index 11e6000fe..36473fa56 100644 --- a/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs +++ b/tests/ImageSharp.Tests/PixelFormats/PixelBlenders/PorterDuffCompositorTests.cs @@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.PixelFormats.PixelBlenders using (Image src = srcFile.CreateImage()) using (Image dest = provider.GetImage()) { - using (Image res = dest.Clone(x => x.Blend(new GraphicsOptions { BlenderMode = mode }, src))) + using (Image res = dest.Clone(x => x.DrawImage(new GraphicsOptions { BlenderMode = mode }, src))) { res.DebugSave(provider, mode.ToString()); res.CompareToReferenceOutput(provider, mode.ToString());