From 884dfab3e1905f01106dc2535ca88a3d7a33f94c Mon Sep 17 00:00:00 2001 From: Scott Williams Date: Tue, 31 Jan 2017 22:12:26 +0000 Subject: [PATCH] split out paths from basic drawing --- ImageSharp.sln | 8 + src/ImageSharp.Drawing.Paths/DrawBeziers.cs | 120 +++++ src/ImageSharp.Drawing.Paths/DrawLines.cs | 120 +++++ src/ImageSharp.Drawing.Paths/DrawPath.cs | 124 +++++ src/ImageSharp.Drawing.Paths/DrawPolygon.cs | 104 ++++ .../DrawRectangle.cs | 24 +- src/ImageSharp.Drawing.Paths/DrawShape.cs | 118 ++++ src/ImageSharp.Drawing.Paths/FillPaths.cs | 87 +++ src/ImageSharp.Drawing.Paths/FillPolygon.cs | 83 +++ .../FillRectangle.cs | 8 +- src/ImageSharp.Drawing.Paths/FillShapes.cs | 83 +++ .../ImageSharp.Drawing.Paths.xproj | 25 + .../PointInfoExtensions.cs | 21 +- .../Properties/AssemblyInfo.cs | 6 + .../RectangleExtensions.cs | 12 +- .../ShapePath.cs} | 31 +- src/ImageSharp.Drawing.Paths/ShapeRegion.cs | 137 +++++ src/ImageSharp.Drawing.Paths/project.json | 96 ++++ .../Brushes/Processors/BrushApplicator.cs | 1 - src/ImageSharp.Drawing/Draw.cs | 506 ------------------ src/ImageSharp.Drawing/DrawPath.cs | 123 +++++ src/ImageSharp.Drawing/Fill.cs | 173 ------ src/ImageSharp.Drawing/FillRegion.cs | 111 ++++ src/ImageSharp.Drawing/IDrawableRegion.cs | 24 - src/ImageSharp.Drawing/Path.cs | 57 ++ .../Processors/DrawPathProcessor.cs | 5 +- ...apeProcessor.cs => FillRegionProcessor.cs} | 29 +- .../{IRegion.cs => Region.cs} | 14 +- src/ImageSharp.Drawing/project.json | 1 - .../Drawing/FillRectangle.cs | 2 +- tests/ImageSharp.Benchmarks/project.json | 24 +- .../ImageSharp.Sandbox46.csproj | 5 +- .../ImageSharp.Tests/Drawing/DrawPathTests.cs | 10 +- .../Drawing/LineComplexPolygonTests.cs | 12 +- .../ImageSharp.Tests/Drawing/PolygonTests.cs | 2 +- .../Drawing/SolidPolygonTests.cs | 2 +- tests/ImageSharp.Tests/project.json | 24 +- 37 files changed, 1509 insertions(+), 823 deletions(-) create mode 100644 src/ImageSharp.Drawing.Paths/DrawBeziers.cs create mode 100644 src/ImageSharp.Drawing.Paths/DrawLines.cs create mode 100644 src/ImageSharp.Drawing.Paths/DrawPath.cs create mode 100644 src/ImageSharp.Drawing.Paths/DrawPolygon.cs rename src/{ImageSharp.Drawing => ImageSharp.Drawing.Paths}/DrawRectangle.cs (73%) create mode 100644 src/ImageSharp.Drawing.Paths/DrawShape.cs create mode 100644 src/ImageSharp.Drawing.Paths/FillPaths.cs create mode 100644 src/ImageSharp.Drawing.Paths/FillPolygon.cs rename src/{ImageSharp.Drawing => ImageSharp.Drawing.Paths}/FillRectangle.cs (93%) create mode 100644 src/ImageSharp.Drawing.Paths/FillShapes.cs create mode 100644 src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj rename src/{ImageSharp.Drawing/Processors => ImageSharp.Drawing.Paths}/PointInfoExtensions.cs (62%) create mode 100644 src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs rename src/{ImageSharp.Drawing/Processors => ImageSharp.Drawing.Paths}/RectangleExtensions.cs (58%) rename src/{ImageSharp.Drawing/ShapeRegion.cs => ImageSharp.Drawing.Paths/ShapePath.cs} (83%) create mode 100644 src/ImageSharp.Drawing.Paths/ShapeRegion.cs create mode 100644 src/ImageSharp.Drawing.Paths/project.json delete mode 100644 src/ImageSharp.Drawing/Draw.cs create mode 100644 src/ImageSharp.Drawing/DrawPath.cs delete mode 100644 src/ImageSharp.Drawing/Fill.cs create mode 100644 src/ImageSharp.Drawing/FillRegion.cs delete mode 100644 src/ImageSharp.Drawing/IDrawableRegion.cs create mode 100644 src/ImageSharp.Drawing/Path.cs rename src/ImageSharp.Drawing/Processors/{FillShapeProcessor.cs => FillRegionProcessor.cs} (95%) rename src/ImageSharp.Drawing/{IRegion.cs => Region.cs} (78%) diff --git a/ImageSharp.sln b/ImageSharp.sln index f1e9fb1045..503a5b8601 100644 --- a/ImageSharp.sln +++ b/ImageSharp.sln @@ -60,11 +60,14 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ImageSharp.Sandbox46", "tes {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} = {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} {27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} = {27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} {7213767C-0003-41CA-AB18-0223CFA7CE4B} = {7213767C-0003-41CA-AB18-0223CFA7CE4B} + {E5BD4F96-28A8-410C-8B63-1C5731948549} = {E5BD4F96-28A8-410C-8B63-1C5731948549} {C77661B9-F793-422E-8E27-AC60ECC5F215} = {C77661B9-F793-422E-8E27-AC60ECC5F215} {556ABDCF-ED93-4327-BE98-F6815F78B9B8} = {556ABDCF-ED93-4327-BE98-F6815F78B9B8} {A623CFE9-9D2B-4528-AD1F-2E834B061134} = {A623CFE9-9D2B-4528-AD1F-2E834B061134} EndProjectSection EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ImageSharp.Drawing.Paths", "src\ImageSharp.Drawing.Paths\ImageSharp.Drawing.Paths.xproj", "{E5BD4F96-28A8-410C-8B63-1C5731948549}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -115,6 +118,10 @@ Global {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|Any CPU.Build.0 = Release|Any CPU + {E5BD4F96-28A8-410C-8B63-1C5731948549}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E5BD4F96-28A8-410C-8B63-1C5731948549}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E5BD4F96-28A8-410C-8B63-1C5731948549}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E5BD4F96-28A8-410C-8B63-1C5731948549}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -132,5 +139,6 @@ Global {A623CFE9-9D2B-4528-AD1F-2E834B061134} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {9E574A07-F879-4811-9C41-5CBDC6BAFDB7} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {96188137-5FA6-4924-AB6E-4EFF79C6E0BB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC} + {E5BD4F96-28A8-410C-8B63-1C5731948549} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} EndGlobalSection EndGlobal diff --git a/src/ImageSharp.Drawing.Paths/DrawBeziers.cs b/src/ImageSharp.Drawing.Paths/DrawBeziers.cs new file mode 100644 index 0000000000..6515db5771 --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/DrawBeziers.cs @@ -0,0 +1,120 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + using SixLabors.Shapes; + + using Path = SixLabors.Shapes.Path; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); + } + + /// + /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The Image + public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); + } + + /// + /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The Image + public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawBeziers(new SolidBrush(color), thickness, points); + } + + /// + /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawBeziers(new SolidBrush(color), thickness, points, options); + } + + /// + /// Draws the provided Points as an open Bezier path with the supplied pen + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Path(new BezierLineSegment(points)), options); + } + + /// + /// Draws the provided Points as an open Bezier path with the supplied pen + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// The Image + public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Path(new BezierLineSegment(points))); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/DrawLines.cs b/src/ImageSharp.Drawing.Paths/DrawLines.cs new file mode 100644 index 0000000000..2e4f849870 --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/DrawLines.cs @@ -0,0 +1,120 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + using SixLabors.Shapes; + + using Path = SixLabors.Shapes.Path; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); + } + + /// + /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The Image + public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(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 + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The Image + public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawLines(new SolidBrush(color), thickness, points); + } + + /// + /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawLines(new SolidBrush(color), thickness, points, options); + } + + /// + /// Draws the provided Points as an open Linear path with the supplied pen + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Path(new LinearLineSegment(points)), options); + } + + /// + /// Draws the provided Points as an open Linear path with the supplied pen + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// The Image + public static Image DrawLines(this Image source, IPen pen, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Path(new LinearLineSegment(points))); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/DrawPath.cs b/src/ImageSharp.Drawing.Paths/DrawPath.cs new file mode 100644 index 0000000000..201984e0ac --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/DrawPath.cs @@ -0,0 +1,124 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the outline of the polygon with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IPen pen, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new ShapePath(path), options); + } + + /// + /// Draws the outline of the polygon with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, IPen pen, IPath path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, path, GraphicsOptions.Default); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), path, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, IBrush brush, float thickness, IPath path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), path); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, TColor color, float thickness, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, path, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, TColor color, float thickness, IPath path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, path); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/DrawPolygon.cs b/src/ImageSharp.Drawing.Paths/DrawPolygon.cs new file mode 100644 index 0000000000..73d8ec0e7f --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/DrawPolygon.cs @@ -0,0 +1,104 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); + } + + /// + /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The points. + /// The Image + public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(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. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The Image + public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawPolygon(new SolidBrush(color), thickness, points); + } + + /// + /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.DrawPolygon(new SolidBrush(color), thickness, points, options); + } + + /// + /// Draws the provided Points as a closed Linear Polygon with the provided Pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options); + } + } +} diff --git a/src/ImageSharp.Drawing/DrawRectangle.cs b/src/ImageSharp.Drawing.Paths/DrawRectangle.cs similarity index 73% rename from src/ImageSharp.Drawing/DrawRectangle.cs rename to src/ImageSharp.Drawing.Paths/DrawRectangle.cs index 243aa082d4..28ea3d6e03 100644 --- a/src/ImageSharp.Drawing/DrawRectangle.cs +++ b/src/ImageSharp.Drawing.Paths/DrawRectangle.cs @@ -30,10 +30,10 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape, GraphicsOptions options) + public static Image Draw(this Image source, IPen pen, Rectangle shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable { - return source.Apply(new DrawPathProcessor(pen, new ShapeRegion(new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height)), options)); + return source.Draw(pen, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); } /// @@ -44,10 +44,10 @@ namespace ImageSharp /// The pen. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IPen pen, RectangleF shape) + public static Image Draw(this Image source, IPen pen, Rectangle shape) where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(pen, shape, GraphicsOptions.Default); + return source.Draw(pen, shape, GraphicsOptions.Default); } /// @@ -62,10 +62,10 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape, GraphicsOptions options) + public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape, options); + return source.Draw(new Pen(brush, thickness), shape, options); } /// @@ -77,10 +77,10 @@ namespace ImageSharp /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, RectangleF shape) + public static Image Draw(this Image source, IBrush brush, float thickness, Rectangle shape) where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new Pen(brush, thickness), shape); + return source.Draw(new Pen(brush, thickness), shape); } /// @@ -95,10 +95,10 @@ namespace ImageSharp /// /// The Image /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape, GraphicsOptions options) + public static Image Draw(this Image source, TColor color, float thickness, Rectangle shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); + return source.Draw(new SolidBrush(color), thickness, shape, options); } /// @@ -110,10 +110,10 @@ namespace ImageSharp /// The thickness. /// The shape. /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, RectangleF shape) + public static Image Draw(this Image source, TColor color, float thickness, Rectangle shape) where TColor : struct, IPackedPixel, IEquatable { - return source.DrawPolygon(new SolidBrush(color), thickness, shape); + return source.Draw(new SolidBrush(color), thickness, shape); } } } diff --git a/src/ImageSharp.Drawing.Paths/DrawShape.cs b/src/ImageSharp.Drawing.Paths/DrawShape.cs new file mode 100644 index 0000000000..15ae2b1797 --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/DrawShape.cs @@ -0,0 +1,118 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the outline of the polygon with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IPen pen, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, new ShapePath(shape), options); + } + + /// + /// Draws the outline of the polygon with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The shape. + /// The Image + public static Image Draw(this Image source, IPen pen, IShape shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, shape, GraphicsOptions.Default); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IBrush brush, float thickness, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), shape, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The shape. + /// The Image + public static Image Draw(this Image source, IBrush brush, float thickness, IShape shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), shape); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, TColor color, float thickness, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, shape, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The shape. + /// The Image + public static Image Draw(this Image source, TColor color, float thickness, IShape shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, shape); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/FillPaths.cs b/src/ImageSharp.Drawing.Paths/FillPaths.cs new file mode 100644 index 0000000000..3095ee7cdf --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/FillPaths.cs @@ -0,0 +1,87 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Processors; + + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The shape. + /// The graphics options. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new ShapeRegion(path), options); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The path. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, IPath path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, IPath path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), path, options); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The path. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, IPath path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), path); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/FillPolygon.cs b/src/ImageSharp.Drawing.Paths/FillPolygon.cs new file mode 100644 index 0000000000..4092e5fc64 --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/FillPolygon.cs @@ -0,0 +1,83 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Processors; + + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Flood fills the image in the shape of a Linear polygon described by the points + /// + /// The type of the color. + /// The source. + /// The brush. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); + } + + /// + /// Flood fills the image in the shape of a Linear polygon described by the points + /// + /// The type of the color. + /// The source. + /// The brush. + /// The points. + /// The Image + public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new Polygon(new LinearLineSegment(points))); + } + + /// + /// Flood fills the image in the shape of a Linear polygon described by the points + /// + /// The type of the color. + /// The source. + /// The color. + /// The points. + /// The options. + /// + /// The Image + /// + public static Image FillPolygon(this Image source, TColor color, Vector2[] points, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); + } + + /// + /// Flood fills the image in the shape of a Linear polygon described by the points + /// + /// The type of the color. + /// The source. + /// The color. + /// The points. + /// The Image + public static Image FillPolygon(this Image source, TColor color, Vector2[] points) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); + } + } +} diff --git a/src/ImageSharp.Drawing/FillRectangle.cs b/src/ImageSharp.Drawing.Paths/FillRectangle.cs similarity index 93% rename from src/ImageSharp.Drawing/FillRectangle.cs rename to src/ImageSharp.Drawing.Paths/FillRectangle.cs index d60a5a19d8..aef777edd2 100644 --- a/src/ImageSharp.Drawing/FillRectangle.cs +++ b/src/ImageSharp.Drawing.Paths/FillRectangle.cs @@ -27,7 +27,7 @@ namespace ImageSharp /// /// The Image /// - public static Image Fill(this Image source, IBrush brush, RectangleF shape, GraphicsOptions options) + public static Image Fill(this Image source, IBrush brush, Rectangle shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable { return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); @@ -41,7 +41,7 @@ namespace ImageSharp /// The brush. /// The shape. /// The Image - public static Image Fill(this Image source, IBrush brush, RectangleF shape) + public static Image Fill(this Image source, IBrush brush, Rectangle shape) where TColor : struct, IPackedPixel, IEquatable { return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height)); @@ -58,7 +58,7 @@ namespace ImageSharp /// /// The Image /// - public static Image Fill(this Image source, TColor color, RectangleF shape, GraphicsOptions options) + public static Image Fill(this Image source, TColor color, Rectangle shape, GraphicsOptions options) where TColor : struct, IPackedPixel, IEquatable { return source.Fill(new SolidBrush(color), shape, options); @@ -72,7 +72,7 @@ namespace ImageSharp /// The color. /// The shape. /// The Image - public static Image Fill(this Image source, TColor color, RectangleF shape) + public static Image Fill(this Image source, TColor color, Rectangle shape) where TColor : struct, IPackedPixel, IEquatable { return source.Fill(new SolidBrush(color), shape); diff --git a/src/ImageSharp.Drawing.Paths/FillShapes.cs b/src/ImageSharp.Drawing.Paths/FillShapes.cs new file mode 100644 index 0000000000..9fe473ee1c --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/FillShapes.cs @@ -0,0 +1,83 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Processors; + + using SixLabors.Shapes; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The shape. + /// The graphics options. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new ShapeRegion(shape), options); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The shape. + /// The Image + public static Image Fill(this Image source, IBrush brush, IShape shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The shape. + /// The options. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, IShape shape, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), shape, options); + } + + /// + /// Flood fills the image in the shape of the provided polygon with the specified brush.. + /// + /// The type of the color. + /// The source. + /// The color. + /// The shape. + /// The Image + public static Image Fill(this Image source, TColor color, IShape shape) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), shape); + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj b/src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj new file mode 100644 index 0000000000..196f7bc1bc --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj @@ -0,0 +1,25 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + e5bd4f96-28a8-410c-8b63-1c5731948549 + ImageSharp.Drawing + .\obj + .\bin\ + v4.5.1 + + + 2.0 + + + True + + + + + + \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processors/PointInfoExtensions.cs b/src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs similarity index 62% rename from src/ImageSharp.Drawing/Processors/PointInfoExtensions.cs rename to src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs index 6613d15acb..ea38dfb9d3 100644 --- a/src/ImageSharp.Drawing/Processors/PointInfoExtensions.cs +++ b/src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs @@ -3,19 +3,8 @@ // Licensed under the Apache License, Version 2.0. // -namespace ImageSharp.Drawing.Processors +namespace ImageSharp.Drawing { - using System; - using System.Buffers; - using System.Numerics; - using System.Threading.Tasks; - using Drawing; - using ImageSharp.Processing; - using SixLabors.Shapes; - - using PointInfo = ImageSharp.Drawing.PointInfo; - using Rectangle = ImageSharp.Rectangle; - /// /// Extension methods for helping to bridge Shaper2D and ImageSharp primitives. /// @@ -29,10 +18,10 @@ namespace ImageSharp.Drawing.Processors public static PointInfo Convert(this SixLabors.Shapes.PointInfo source) { return new PointInfo - { - DistanceAlongPath = source.DistanceAlongPath, - DistanceFromPath = source.DistanceFromPath - }; + { + DistanceAlongPath = source.DistanceAlongPath, + DistanceFromPath = source.DistanceFromPath + }; } } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs b/src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..fba25a9dba --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +// Common values read from `AssemblyInfo.Common.cs` diff --git a/src/ImageSharp.Drawing/Processors/RectangleExtensions.cs b/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs similarity index 58% rename from src/ImageSharp.Drawing/Processors/RectangleExtensions.cs rename to src/ImageSharp.Drawing.Paths/RectangleExtensions.cs index 327b618fa4..05d6bb6ced 100644 --- a/src/ImageSharp.Drawing/Processors/RectangleExtensions.cs +++ b/src/ImageSharp.Drawing.Paths/RectangleExtensions.cs @@ -20,13 +20,17 @@ namespace ImageSharp.Drawing.Processors internal static class RectangleExtensions { /// - /// Converts a Shaper2D to an ImageSharp . + /// Converts a Shaper2D to an ImageSharp by creating a the entirely surrounds the source. /// /// The source. - /// A representation of this - public static RectangleF Convert(this SixLabors.Shapes.Rectangle source) + /// A representation of this + public static Rectangle Convert(this SixLabors.Shapes.Rectangle source) { - return new RectangleF(source.Location.X, source.Location.Y, source.Size.Width, source.Size.Height); + int y = (int)Math.Floor(source.Y); + int width = (int)Math.Ceiling(source.Size.Width); + int x = (int)Math.Floor(source.X); + int height = (int)Math.Ceiling(source.Size.Height); + return new Rectangle(x, y, width, height); } } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/ShapeRegion.cs b/src/ImageSharp.Drawing.Paths/ShapePath.cs similarity index 83% rename from src/ImageSharp.Drawing/ShapeRegion.cs rename to src/ImageSharp.Drawing.Paths/ShapePath.cs index 6bd0703672..63d5fc9e1b 100644 --- a/src/ImageSharp.Drawing/ShapeRegion.cs +++ b/src/ImageSharp.Drawing.Paths/ShapePath.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -18,8 +18,7 @@ namespace ImageSharp.Drawing /// /// A drawable mapping between a / and a drawable/fillable region. /// - /// - internal class ShapeRegion : IDrawableRegion + internal class ShapePath : ImageSharp.Drawing.Path { /// /// The fillable shape @@ -32,10 +31,10 @@ namespace ImageSharp.Drawing private readonly ImmutableArray paths; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The path. - public ShapeRegion(IPath path) + public ShapePath(IPath path) : this(ImmutableArray.Create(path)) { this.shape = path.AsShape(); @@ -43,10 +42,10 @@ namespace ImageSharp.Drawing } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The shape. - public ShapeRegion(IShape shape) + public ShapePath(IShape shape) : this(shape.Paths) { this.shape = shape; @@ -54,10 +53,10 @@ namespace ImageSharp.Drawing } /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The paths. - private ShapeRegion(ImmutableArray paths) + private ShapePath(ImmutableArray paths) { this.paths = paths; } @@ -68,7 +67,7 @@ namespace ImageSharp.Drawing /// /// The maximum intersections. /// - public int MaxIntersections => this.shape.MaxIntersections; + public override int MaxIntersections => this.shape.MaxIntersections; /// /// Gets the bounds. @@ -76,7 +75,7 @@ namespace ImageSharp.Drawing /// /// The bounds. /// - public Rectangle Bounds { get; } + public override Rectangle Bounds { get; } /// /// Scans the X axis for intersections. @@ -88,7 +87,7 @@ namespace ImageSharp.Drawing /// /// The number of intersections found. /// - public int ScanX(int x, float[] buffer, int length, int offset) + public override int ScanX(int x, float[] buffer, int length, int offset) { var start = new Vector2(x, this.Bounds.Top - 1); var end = new Vector2(x, this.Bounds.Bottom + 1); @@ -125,10 +124,10 @@ namespace ImageSharp.Drawing /// /// The number of intersections found. /// - public int ScanY(int y, float[] buffer, int length, int offset) + public override int ScanY(int y, float[] buffer, int length, int offset) { - var start = new Vector2(this.Bounds.Left - 1, y); - var end = new Vector2(this.Bounds.Right + 1, y); + var start = new Vector2(float.MinValue, y); + var end = new Vector2(float.MaxValue, y); Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); try { @@ -158,7 +157,7 @@ namespace ImageSharp.Drawing /// The x. /// The y. /// Information about the the point - public PointInfo GetPointInfo(int x, int y) + public override PointInfo GetPointInfo(int x, int y) { var point = new Vector2(x, y); SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo); diff --git a/src/ImageSharp.Drawing.Paths/ShapeRegion.cs b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs new file mode 100644 index 0000000000..d1a59a99d9 --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/ShapeRegion.cs @@ -0,0 +1,137 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Drawing +{ + using System.Buffers; + using System.Collections.Immutable; + using System.Numerics; + + using ImageSharp.Drawing.Processors; + + using SixLabors.Shapes; + + using Rectangle = ImageSharp.Rectangle; + + /// + /// A drawable mapping between a / and a drawable/fillable region. + /// + internal class ShapeRegion : Region + { + /// + /// The fillable shape + /// + private readonly IShape shape; + + /// + /// Initializes a new instance of the class. + /// + /// The path. + public ShapeRegion(IPath path) + : this(path.AsShape()) + { + } + + /// + /// Initializes a new instance of the class. + /// + /// The shape. + public ShapeRegion(IShape shape) + { + this.shape = shape; + this.Bounds = shape.Bounds.Convert(); + } + + /// + /// Gets the maximum number of intersections to could be returned. + /// + /// + /// The maximum intersections. + /// + public override int MaxIntersections => this.shape.MaxIntersections; + + /// + /// Gets the bounds. + /// + /// + /// The bounds. + /// + public override Rectangle Bounds { get; } + + /// + /// Scans the X axis for intersections. + /// + /// The x. + /// The buffer. + /// The length. + /// The offset. + /// + /// The number of intersections found. + /// + public override int ScanX(int x, float[] buffer, int length, int offset) + { + var start = new Vector2(x, this.Bounds.Top - 1); + var end = new Vector2(x, this.Bounds.Bottom + 1); + Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); + try + { + int count = this.shape.FindIntersections( + start, + end, + innerbuffer, + length, + 0); + + for (var i = 0; i < count; i++) + { + buffer[i + offset] = innerbuffer[i].Y; + } + + return count; + } + finally + { + ArrayPool.Shared.Return(innerbuffer); + } + } + + /// + /// Scans the Y axis for intersections. + /// + /// The position along the y axis to find intersections. + /// The buffer. + /// The length. + /// The offset. + /// + /// The number of intersections found. + /// + public override int ScanY(int y, float[] buffer, int length, int offset) + { + var start = new Vector2(float.MinValue, y); + var end = new Vector2(float.MaxValue, y); + Vector2[] innerbuffer = ArrayPool.Shared.Rent(length); + try + { + int count = this.shape.FindIntersections( + start, + end, + innerbuffer, + length, + 0); + + for (var i = 0; i < count; i++) + { + buffer[i + offset] = innerbuffer[i].X; + } + + return count; + } + finally + { + ArrayPool.Shared.Return(innerbuffer); + } + } + } +} diff --git a/src/ImageSharp.Drawing.Paths/project.json b/src/ImageSharp.Drawing.Paths/project.json new file mode 100644 index 0000000000..cdc5d2244f --- /dev/null +++ b/src/ImageSharp.Drawing.Paths/project.json @@ -0,0 +1,96 @@ +{ + "version": "1.0.0-alpha1-*", + "title": "ImageSharp.Drawing.Paths", + "description": "A cross-platform library for the processing of image files; written in C#", + "authors": [ + "James Jackson-South and contributors" + ], + "packOptions": { + "owners": [ + "James Jackson-South and contributors" + ], + "projectUrl": "https://github.com/JimBobSquarePants/ImageSharp", + "licenseUrl": "http://www.apache.org/licenses/LICENSE-2.0", + "iconUrl": "https://raw.githubusercontent.com/JimBobSquarePants/ImageSharp/master/build/icons/imagesharp-logo-128.png", + "requireLicenseAcceptance": false, + "repository": { + "type": "git", + "url": "https://github.com/JimBobSquarePants/ImageSharp" + }, + "tags": [ + "Image Resize Crop Gif Jpg Jpeg Bitmap Png Core" + ] + }, + "buildOptions": { + "allowUnsafe": true, + "xmlDoc": true, + "additionalArguments": [ "/additionalfile:../Shared/stylecop.json", "/ruleset:../../ImageSharp.ruleset" ], + "compile": [ + "../Shared/*.cs" + ] + }, + "configurations": { + "Release": { + "buildOptions": { + "warningsAsErrors": true, + "optimize": true + } + } + }, + "dependencies": { + "ImageSharp": { + "target": "project" + }, + "ImageSharp.Drawing": { + "target": "project" + }, + "SixLabors.Shapes": "0.1.0-ci0050", + "StyleCop.Analyzers": { + "version": "1.0.0", + "type": "build" + }, + "System.Buffers": "4.0.0", + "System.Runtime.CompilerServices.Unsafe": "4.0.0" + }, + "frameworks": { + "netstandard1.1": { + "dependencies": { + "System.Collections": "4.0.11", + "System.Diagnostics.Debug": "4.0.11", + "System.Diagnostics.Tools": "4.0.1", + "System.IO": "4.1.0", + "System.IO.Compression": "4.1.0", + "System.Linq": "4.1.0", + "System.Numerics.Vectors": "4.1.1", + "System.ObjectModel": "4.0.12", + "System.Resources.ResourceManager": "4.0.1", + "System.Runtime.Extensions": "4.1.0", + "System.Runtime.InteropServices": "4.1.0", + "System.Runtime.Numerics": "4.0.1", + "System.Text.Encoding.Extensions": "4.0.11", + "System.Threading": "4.0.11", + "System.Threading.Tasks": "4.0.11", + "System.Threading.Tasks.Parallel": "4.0.1" + } + }, + "net45": { + "dependencies": { + "System.Numerics.Vectors": "4.1.1", + "System.Threading.Tasks.Parallel": "4.0.0" + }, + "frameworkAssemblies": { + "System.Runtime": { "type": "build" } + } + }, + "net461": { + "dependencies": { + "System.Threading.Tasks.Parallel": "4.0.0" + }, + "frameworkAssemblies": { + "System.Runtime": { "type": "build" }, + "System.Numerics": "4.0.0.0", + "System.Numerics.Vectors": "4.0.0.0" + } + } + } +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs index 9103dfdf66..97d3f840cb 100644 --- a/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs +++ b/src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs @@ -16,7 +16,6 @@ namespace ImageSharp.Drawing.Processors public abstract class BrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush where TColor : struct, IPackedPixel, IEquatable { - /// /// Gets the color for a single pixel. /// diff --git a/src/ImageSharp.Drawing/Draw.cs b/src/ImageSharp.Drawing/Draw.cs deleted file mode 100644 index 55dba9257d..0000000000 --- a/src/ImageSharp.Drawing/Draw.cs +++ /dev/null @@ -1,506 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Pens; - using Drawing.Processors; - using SixLabors.Shapes; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Draws the outline of the polygon with the provided pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, IPen pen, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new DrawPathProcessor(pen, new ShapeRegion(shape), options)); - } - - /// - /// Draws the outline of the polygon with the provided pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The shape. - /// The Image - public static Image DrawPolygon(this Image source, IPen pen, IShape shape) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(pen, shape, GraphicsOptions.Default); - } - - /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new Pen(brush, thickness), shape, options); - } - - /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The shape. - /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, IShape shape) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new Pen(brush, thickness), shape); - } - - /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new SolidBrush(color), thickness, shape, options); - } - - /// - /// Draws the outline of the polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The shape. - /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, IShape shape) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new SolidBrush(color), thickness, shape); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)), options); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(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. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(new SolidBrush(color), thickness, points, options); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided Pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)), options); - } - - /// - /// Draws the provided Points as a closed Linear Polygon with the provided Pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points))); - } - - /// - /// Draws the path with the provided pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The path. - /// The options. - /// - /// The Image - /// - public static Image DrawPath(this Image source, IPen pen, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new DrawPathProcessor(pen, new ShapeRegion(path), options)); - } - - /// - /// Draws the path with the provided pen. - /// - /// The type of the color. - /// The source. - /// The pen. - /// The path. - /// The Image - public static Image DrawPath(this Image source, IPen pen, IPath path) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new DrawPathProcessor(pen, new ShapeRegion(path), GraphicsOptions.Default)); - } - - /// - /// Draws the path with the bursh at the privdied thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The path. - /// The options. - /// - /// The Image - /// - public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new Pen(brush, thickness), path, options); - } - - /// - /// Draws the path with the bursh at the privdied thickness. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The path. - /// The Image - public static Image DrawPath(this Image source, IBrush brush, float thickness, IPath path) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new Pen(brush, thickness), path); - } - - /// - /// Draws the path with the bursh at the privdied thickness. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The path. - /// The options. - /// - /// The Image - /// - public static Image DrawPath(this Image source, TColor color, float thickness, IPath path, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new SolidBrush(color), thickness, path, options); - } - - /// - /// Draws the path with the bursh at the privdied thickness. - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The path. - /// The Image - public static Image DrawPath(this Image source, TColor color, float thickness, IPath path) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new SolidBrush(color), thickness, path); - } - - /// - /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new Pen(brush, thickness), new Path(new LinearLineSegment(points)), options); - } - - /// - /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawLines(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(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 - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawLines(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawLines(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawLines(new SolidBrush(color), thickness, points, options); - } - - /// - /// Draws the provided Points as an open Linear path with the supplied pen - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawLines(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(pen, new Path(new LinearLineSegment(points)), options); - } - - /// - /// Draws the provided Points as an open Linear path with the supplied pen - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawLines(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(pen, new Path(new LinearLineSegment(points))); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points)), options); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The brush. - /// The thickness. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, IBrush brush, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(new Pen(brush, thickness), new Path(new BezierLineSegment(points))); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawBeziers(new SolidBrush(color), thickness, points); - } - - /// - /// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush - /// - /// The type of the color. - /// The source. - /// The color. - /// The thickness. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawBeziers(this Image source, TColor color, float thickness, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawBeziers(new SolidBrush(color), thickness, points, options); - } - - /// - /// Draws the provided Points as an open Bezier path with the supplied pen - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(pen, new Path(new BezierLineSegment(points)), options); - } - - /// - /// Draws the provided Points as an open Bezier path with the supplied pen - /// - /// The type of the color. - /// The source. - /// The pen. - /// The points. - /// The Image - public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - return source.DrawPath(pen, new Path(new BezierLineSegment(points))); - } - } -} diff --git a/src/ImageSharp.Drawing/DrawPath.cs b/src/ImageSharp.Drawing/DrawPath.cs new file mode 100644 index 0000000000..828d50fb33 --- /dev/null +++ b/src/ImageSharp.Drawing/DrawPath.cs @@ -0,0 +1,123 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Pens; + using Drawing.Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Draws the outline of the region with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IPen pen, Path path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Apply(new DrawPathProcessor(pen, path, options)); + } + + /// + /// Draws the outline of the polygon with the provided pen. + /// + /// The type of the color. + /// The source. + /// The pen. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, IPen pen, Path path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(pen, path, GraphicsOptions.Default); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, IBrush brush, float thickness, Path path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), path, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The thickness. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, IBrush brush, float thickness, Path path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new Pen(brush, thickness), path); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The path. + /// The options. + /// + /// The Image + /// + public static Image Draw(this Image source, TColor color, float thickness, Path path, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, path, options); + } + + /// + /// Draws the outline of the polygon with the provided brush at the provided thickness. + /// + /// The type of the color. + /// The source. + /// The color. + /// The thickness. + /// The path. + /// + /// The Image + /// + public static Image Draw(this Image source, TColor color, float thickness, Path path) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Draw(new SolidBrush(color), thickness, path); + } + } +} diff --git a/src/ImageSharp.Drawing/Fill.cs b/src/ImageSharp.Drawing/Fill.cs deleted file mode 100644 index f94d9ca6f9..0000000000 --- a/src/ImageSharp.Drawing/Fill.cs +++ /dev/null @@ -1,173 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp -{ - using System; - using System.Numerics; - using Drawing; - using Drawing.Brushes; - using Drawing.Processors; - - using SixLabors.Shapes; - - /// - /// Extension methods for the type. - /// - public static partial class ImageExtensions - { - /// - /// Flood fills the image with the specified brush. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The Image - public static Image Fill(this Image source, IBrush brush) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new FillProcessor(brush)); - } - - /// - /// Flood fills the image with the specified color. - /// - /// The type of the color. - /// The source. - /// The color. - /// The Image - public static Image Fill(this Image source, TColor color) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Fill(new SolidBrush(color)); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The shape. - /// The graphics options. - /// The Image - public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new FillShapeProcessor(brush, new ShapeRegion(shape), options)); - } - - /// - /// Flood fills the image in the shape of the provided polygon with the specified brush. - /// - /// The type of the color. - /// The source. - /// The brush. - /// The shape. - /// The Image - public static Image Fill(this Image source, IBrush brush, IShape shape) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Apply(new FillShapeProcessor(brush, new ShapeRegion(shape), GraphicsOptions.Default)); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The source. - /// The color. - /// The shape. - /// The options. - /// - /// The Image - /// - public static Image Fill(this Image source, TColor color, IShape shape, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Fill(new SolidBrush(color), shape, options); - } - - /// - /// Flood fills the image in the shape o fhte provided polygon with the specified brush.. - /// - /// The type of the color. - /// The source. - /// The color. - /// The shape. - /// The Image - public static Image Fill(this Image source, TColor color, IShape shape) - where TColor : struct, IPackedPixel, IEquatable - { - return source.Fill(new SolidBrush(color), shape); - } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The source. - /// The brush. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options); - } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The source. - /// The brush. - /// The points. - /// The Image - public static Image FillPolygon(this Image source, IBrush brush, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(brush, new Polygon(new LinearLineSegment(points))); - } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The source. - /// The color. - /// The points. - /// The options. - /// - /// The Image - /// - public static Image FillPolygon(this Image source, TColor color, Vector2[] points, GraphicsOptions options) - where TColor : struct, IPackedPixel, IEquatable - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)), options); - } - - /// - /// Flood fills the image in the shape of a Linear polygon described by the points - /// - /// The type of the color. - /// The source. - /// The color. - /// The points. - /// The Image - public static Image FillPolygon(this Image source, TColor color, Vector2[] points) - where TColor : struct, IPackedPixel, IEquatable - { - // using Polygon directly instead of LinearPolygon as its will have less indirection - return source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points))); - } - } -} diff --git a/src/ImageSharp.Drawing/FillRegion.cs b/src/ImageSharp.Drawing/FillRegion.cs new file mode 100644 index 0000000000..8d4f20b673 --- /dev/null +++ b/src/ImageSharp.Drawing/FillRegion.cs @@ -0,0 +1,111 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp +{ + using System; + using System.Numerics; + using Drawing; + using Drawing.Brushes; + using Drawing.Processors; + + /// + /// Extension methods for the type. + /// + public static partial class ImageExtensions + { + /// + /// Flood fills the image with the specified brush. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The Image + public static Image Fill(this Image source, IBrush brush) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Apply(new FillProcessor(brush)); + } + + /// + /// Flood fills the image with the specified color. + /// + /// The type of the color. + /// The source. + /// The color. + /// The Image + public static Image Fill(this Image source, TColor color) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color)); + } + + /// + /// Flood fills the image with in the region with the specified brush. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The region. + /// The graphics options. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, Region region, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Apply(new FillRegionProcessor(brush, region, options)); + } + + /// + /// Flood fills the image with in the region with the specified brush. + /// + /// The type of the color. + /// The source. + /// The brush. + /// The region. + /// + /// The Image + /// + public static Image Fill(this Image source, IBrush brush, Region region) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(brush, region, GraphicsOptions.Default); + } + + /// + /// Flood fills the image with in the region with the specified color. + /// + /// The type of the color. + /// The source. + /// The color. + /// The region. + /// The options. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, Region region, GraphicsOptions options) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), region, options); + } + + /// + /// Flood fills the image with in the region with the specified color. + /// + /// The type of the color. + /// The source. + /// The color. + /// The region. + /// + /// The Image + /// + public static Image Fill(this Image source, TColor color, Region region) + where TColor : struct, IPackedPixel, IEquatable + { + return source.Fill(new SolidBrush(color), region); + } + } +} diff --git a/src/ImageSharp.Drawing/IDrawableRegion.cs b/src/ImageSharp.Drawing/IDrawableRegion.cs deleted file mode 100644 index 82e9c39acf..0000000000 --- a/src/ImageSharp.Drawing/IDrawableRegion.cs +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (c) James Jackson-South and contributors. -// Licensed under the Apache License, Version 2.0. -// - -namespace ImageSharp.Drawing -{ - using System.Numerics; - - /// - /// Represents a region with knowledge about its outline. - /// - /// - public interface IDrawableRegion : IRegion - { - /// - /// Gets the point information for the specified x and y location. - /// - /// The x. - /// The y. - /// Information about the point in relation to a drawable edge - PointInfo GetPointInfo(int x, int y); - } -} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Path.cs b/src/ImageSharp.Drawing/Path.cs new file mode 100644 index 0000000000..a997fa18f7 --- /dev/null +++ b/src/ImageSharp.Drawing/Path.cs @@ -0,0 +1,57 @@ +// +// Copyright (c) James Jackson-South and contributors. +// Licensed under the Apache License, Version 2.0. +// + +namespace ImageSharp.Drawing +{ + /// + /// Represents a something that has knowledge about its outline. + /// + public abstract class Path + { + /// + /// Gets the maximum number of intersections to could be returned. + /// + /// + /// The maximum intersections. + /// + public abstract int MaxIntersections { get; } + + /// + /// Gets the bounds. + /// + /// + /// The bounds. + /// + public abstract Rectangle Bounds { get; } + + /// + /// Gets the point information for the specified x and y location. + /// + /// The x. + /// The y. + /// Information about the point in relation to a drawable edge + public abstract PointInfo GetPointInfo(int x, int y); + + /// + /// Scans the X axis for intersections. + /// + /// The x. + /// The buffer. + /// The length. + /// The offset. + /// The number of intersections found. + public abstract int ScanX(int x, float[] buffer, int length, int offset); + + /// + /// Scans the Y axis for intersections. + /// + /// The position along the y axis to find intersections. + /// The buffer. + /// The length. + /// The offset. + /// The number of intersections found. + public abstract int ScanY(int y, float[] buffer, int length, int offset); + } +} \ No newline at end of file diff --git a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs index bbb5e1ab6c..1513443c4e 100644 --- a/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs @@ -12,7 +12,6 @@ namespace ImageSharp.Drawing.Processors using System.Threading.Tasks; using ImageSharp.Processing; using Pens; - using SixLabors.Shapes; using Rectangle = ImageSharp.Rectangle; /// @@ -27,7 +26,7 @@ namespace ImageSharp.Drawing.Processors private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor private readonly IPen pen; - private readonly IDrawableRegion region; + private readonly Path region; private readonly GraphicsOptions options; /// @@ -36,7 +35,7 @@ namespace ImageSharp.Drawing.Processors /// The pen. /// The region. /// The options. - public DrawPathProcessor(IPen pen, IDrawableRegion region, GraphicsOptions options) + public DrawPathProcessor(IPen pen, Path region, GraphicsOptions options) { this.region = region; this.pen = pen; diff --git a/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs similarity index 95% rename from src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs rename to src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs index bdec022d49..2f6f8af7ba 100644 --- a/src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs +++ b/src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs @@ -1,4 +1,4 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // @@ -11,30 +11,28 @@ namespace ImageSharp.Drawing.Processors using System.Threading.Tasks; using Drawing; using ImageSharp.Processing; - using SixLabors.Shapes; - using Rectangle = ImageSharp.Rectangle; /// /// Usinf a brsuh and a shape fills shape with contents of brush the /// /// The type of the color. /// - public class FillShapeProcessor : ImageProcessor + public class FillRegionProcessor : ImageProcessor where TColor : struct, IPackedPixel, IEquatable { private const float AntialiasFactor = 1f; private const int DrawPadding = 1; private readonly IBrush fillColor; - private readonly IRegion region; + private readonly Region region; private readonly GraphicsOptions options; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The brush. /// The region. /// The options. - public FillShapeProcessor(IBrush brush, IRegion region, GraphicsOptions options) + public FillRegionProcessor(IBrush brush, Region region, GraphicsOptions options) { this.region = region; this.fillColor = brush; @@ -89,6 +87,12 @@ namespace ImageSharp.Drawing.Processors return; } + if (pointsFound % 2 == 1) + { + // we seem to have just clipped a corner lets just skip it + return; + } + QuickSort(buffer, pointsFound); int currentIntersection = 0; @@ -96,13 +100,8 @@ namespace ImageSharp.Drawing.Processors float lastPoint = float.MinValue; bool isInside = false; - // every odd point is the start of a line - Vector2 currentPoint = default(Vector2); - for (int x = minX; x < maxX; x++) { - currentPoint.X = x; - currentPoint.Y = y; if (!isInside) { if (x < (nextPoint - DrawPadding) && x > (lastPoint + DrawPadding)) @@ -232,6 +231,12 @@ namespace ImageSharp.Drawing.Processors return; } + if (pointsFound % 2 == 1) + { + // we seem to have just clipped a corner lets just skip it + return; + } + QuickSort(buffer, pointsFound); int currentIntersection = 0; diff --git a/src/ImageSharp.Drawing/IRegion.cs b/src/ImageSharp.Drawing/Region.cs similarity index 78% rename from src/ImageSharp.Drawing/IRegion.cs rename to src/ImageSharp.Drawing/Region.cs index 2264a91bee..95f0e17480 100644 --- a/src/ImageSharp.Drawing/IRegion.cs +++ b/src/ImageSharp.Drawing/Region.cs @@ -1,16 +1,14 @@ -// +// // Copyright (c) James Jackson-South and contributors. // Licensed under the Apache License, Version 2.0. // namespace ImageSharp.Drawing { - using System.Numerics; - /// /// Represents a region of an image. /// - public interface IRegion + public abstract class Region { /// /// Gets the maximum number of intersections to could be returned. @@ -18,7 +16,7 @@ namespace ImageSharp.Drawing /// /// The maximum intersections. /// - int MaxIntersections { get; } + public abstract int MaxIntersections { get; } /// /// Gets the bounds. @@ -26,7 +24,7 @@ namespace ImageSharp.Drawing /// /// The bounds. /// - Rectangle Bounds { get; } + public abstract Rectangle Bounds { get; } /// /// Scans the X axis for intersections. @@ -36,7 +34,7 @@ namespace ImageSharp.Drawing /// The length. /// The offset. /// The number of intersections found. - int ScanX(int x, float[] buffer, int length, int offset); + public abstract int ScanX(int x, float[] buffer, int length, int offset); /// /// Scans the Y axis for intersections. @@ -46,6 +44,6 @@ namespace ImageSharp.Drawing /// The length. /// The offset. /// The number of intersections found. - int ScanY(int y, float[] buffer, int length, int offset); + public abstract int ScanY(int y, float[] buffer, int length, int offset); } } \ No newline at end of file diff --git a/src/ImageSharp.Drawing/project.json b/src/ImageSharp.Drawing/project.json index 5fcee9b41e..ff2900d9fa 100644 --- a/src/ImageSharp.Drawing/project.json +++ b/src/ImageSharp.Drawing/project.json @@ -44,7 +44,6 @@ "ImageSharp.Processing": { "target": "project" }, - "SixLabors.Shapes": "0.1.0-ci0047", "StyleCop.Analyzers": { "version": "1.0.0", "type": "build" diff --git a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs index defb0e65e7..691955e8ed 100644 --- a/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs +++ b/tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs @@ -39,7 +39,7 @@ namespace ImageSharp.Benchmarks { using (CoreImage image = new CoreImage(800, 800)) { - image.Fill(CoreColor.HotPink, new SixLabors.Shapes.Rectangle(10, 10, 190, 140)); + image.Fill(CoreColor.HotPink, new CoreRectangle(10, 10, 190, 140)); return new CoreSize(image.Width, image.Height); } diff --git a/tests/ImageSharp.Benchmarks/project.json b/tests/ImageSharp.Benchmarks/project.json index 8650a8af41..866a36faae 100644 --- a/tests/ImageSharp.Benchmarks/project.json +++ b/tests/ImageSharp.Benchmarks/project.json @@ -16,32 +16,28 @@ "dependencies": { "BenchmarkDotNet.Diagnostics.Windows": "0.10.1", "ImageSharp": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Drawing": { - "target": "project", - "version": "1.0.0-*" + "target": "project" + }, + "ImageSharp.Drawing.Paths": { + "target": "project" }, "ImageSharp.Formats.Jpeg": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Png": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Bmp": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Gif": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Processing": { - "target": "project", - "version": "1.0.0-*" + "target": "project" } }, "commands": { diff --git a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj index 75212d3617..1bce8003ea 100644 --- a/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj +++ b/tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj @@ -179,8 +179,11 @@ ..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\ImageSharp.Drawing.dll + + ..\..\src\ImageSharp.Drawing.Paths\bin\$(Configuration)\net461\ImageSharp.Drawing.Paths.dll + - ..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\SixLabors.Shapes.dll + ..\..\src\ImageSharp.Drawing.Paths\bin\$(Configuration)\net461\SixLabors.Shapes.dll ..\..\src\ImageSharp.Formats.Bmp\bin\$(Configuration)\net461\ImageSharp.Formats.Bmp.dll diff --git a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs index 31aa87d4b7..f4465027df 100644 --- a/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs +++ b/tests/ImageSharp.Tests/Drawing/DrawPathTests.cs @@ -7,7 +7,7 @@ namespace ImageSharp.Tests.Drawing { using Drawing; using ImageSharp.Drawing; - using CorePath = SixLabors.Shapes.Path; + using ShapePath = SixLabors.Shapes.Path; using SixLabors.Shapes; using System; using System.Diagnostics.CodeAnalysis; @@ -33,13 +33,13 @@ namespace ImageSharp.Tests.Drawing new Vector2(60, 10), new Vector2(10, 400)); - CorePath p = new CorePath(linerSegemnt, bazierSegment); + ShapePath p = new ShapePath(linerSegemnt, bazierSegment); using (FileStream output = File.OpenWrite($"{path}/Simple.png")) { image .BackgroundColor(Color.Blue) - .DrawPath(Color.HotPink, 5, p) + .Draw(Color.HotPink, 5, p) .Save(output); } @@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(60, 10), new Vector2(10, 400)); - CorePath p = new CorePath(linerSegemnt, bazierSegment); + ShapePath p = new ShapePath(linerSegemnt, bazierSegment); using (Image image = new Image(500, 500)) { @@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPath(color, 10, p) + .Draw(color, 10, p) .Save(output); } diff --git a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs index dd2ea5249c..03ec5d0c89 100644 --- a/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs @@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } @@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } @@ -131,7 +131,7 @@ namespace ImageSharp.Tests.Drawing new Vector2(37, 85), new Vector2(130, 40), new Vector2(65, 137)); - var clipped = simplePath.Clip(hole1); + using (Image image = new Image(500, 500)) { @@ -139,7 +139,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 5, clipped) + .Draw(Color.HotPink, 5, simplePath.Clip(hole1)) .Save(output); } @@ -185,7 +185,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(Pens.Dash(Color.HotPink, 5), new ComplexPolygon(simplePath, hole1)) + .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1)) .Save(output); } } @@ -213,7 +213,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(color, 5, new ComplexPolygon(simplePath, hole1)) + .Draw(color, 5, simplePath.Clip(hole1)) .Save(output); } diff --git a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs index f987440754..a166464c9e 100644 --- a/tests/ImageSharp.Tests/Drawing/PolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/PolygonTests.cs @@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing { image .BackgroundColor(Color.Blue) - .DrawPolygon(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) + .Draw(Color.HotPink, 10, new Rectangle(10, 10, 190, 140)) .Save(output); } diff --git a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs index 3e20b3a09a..d5b2067239 100644 --- a/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs +++ b/tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs @@ -71,7 +71,7 @@ namespace ImageSharp.Tests.Drawing { Assert.Equal(Color.HotPink, sourcePixels[11, 11]); - Assert.Equal(Color.HotPink, sourcePixels[200, 150]); + Assert.Equal(Color.HotPink, sourcePixels[199, 150]); Assert.Equal(Color.HotPink, sourcePixels[50, 50]); diff --git a/tests/ImageSharp.Tests/project.json b/tests/ImageSharp.Tests/project.json index 9f9c0c7150..2a01aff847 100644 --- a/tests/ImageSharp.Tests/project.json +++ b/tests/ImageSharp.Tests/project.json @@ -21,34 +21,30 @@ }, "dependencies": { "ImageSharp": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "xunit": "2.2.0-*", "dotnet-test-xunit": "2.2.0-*", "ImageSharp.Drawing": { - "target": "project", - "version": "1.0.0-*" + "target": "project" + }, + "ImageSharp.Drawing.Paths": { + "target": "project" }, "ImageSharp.Formats.Png": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Jpeg": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Bmp": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Formats.Gif": { - "target": "project", - "version": "1.0.0-*" + "target": "project" }, "ImageSharp.Processing": { - "target": "project", - "version": "1.0.0-*" + "target": "project" } }, "frameworks": {