diff --git a/ImageSharp.v2.ncrunchsolution b/ImageSharp.v2.ncrunchsolution
new file mode 100644
index 0000000000..b98737f1c0
--- /dev/null
+++ b/ImageSharp.v2.ncrunchsolution
@@ -0,0 +1,14 @@
+
+ 1
+ false
+ false
+ true
+ UseDynamicAnalysis
+ UseStaticAnalysis
+ UseStaticAnalysis
+ UseStaticAnalysis
+ UseDynamicAnalysis
+
+
+
+
\ No newline at end of file
diff --git a/global.json b/global.json
index 0ddf69c7e5..7346bdc280 100644
--- a/global.json
+++ b/global.json
@@ -1,3 +1,6 @@
{
- "projects": [ "src" ]
+ "projects": [ "src" ],
+ "sdk": {
+ "version": "1.0.0-preview2-003121"
+ }
}
\ No newline at end of file
diff --git a/src/ImageSharp/Drawing/Brushes/Brushes.cs b/src/ImageSharp/Drawing/Brushes/Brushes.cs
new file mode 100644
index 0000000000..5de4287b73
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/Brushes.cs
@@ -0,0 +1,297 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing.Brushes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Numerics;
+ using System.Threading.Tasks;
+
+ ///
+ /// A collection of methods for creating brushes
+ ///
+ public class Brushes
+ {
+ ///
+ /// Create as brush that will paint a solid color
+ ///
+ /// The color.
+ /// A Brush
+ public static SolidBrush Solid(Color color)
+ => new SolidBrush(color);
+
+ ///
+ /// Create as brush that will paint a Percent10 Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush Percent10(Color foreColor)
+ => new PatternBrush(Brushes.Percent10(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Percent10 Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Percent10(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.Percent10(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Percent20 Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush Percent20(Color foreColor)
+ => new PatternBrush(Brushes.Percent20(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Percent20 Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Percent20(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.Percent20(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Horizontal Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush Horizontal(Color foreColor)
+ => new PatternBrush(Brushes.Horizontal(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Horizontal Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Horizontal(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.Horizontal(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Min Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush Min(Color foreColor)
+ => new PatternBrush(Brushes.Min(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Min Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Min(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.Min(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Vertical Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush Vertical(Color foreColor)
+ => new PatternBrush(Brushes.Vertical(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Vertical Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Vertical(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.Vertical(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush ForwardDiagonal(Color foreColor)
+ => new PatternBrush(Brushes.ForwardDiagonal(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Forward Diagonal Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush ForwardDiagonal(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.ForwardDiagonal(foreColor, backColor));
+
+ ///
+ /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
+ /// in the specified foreground color and a transparent background
+ ///
+ /// Color of the foreground.
+ /// A Brush
+ public static PatternBrush BackwardDiagonal(Color foreColor)
+ => new PatternBrush(Brushes.BackwardDiagonal(foreColor, Color.Transparent));
+
+ ///
+ /// Create as brush that will paint a Backward Diagonal Hatch Pattern with
+ /// in the specified foreground and background colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush BackwardDiagonal(Color foreColor, Color backColor)
+ => new PatternBrush(Brushes.BackwardDiagonal(foreColor, backColor));
+ }
+
+ ///
+ /// A collection of methods for creating brushes.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// A Brush
+ public partial class Brushes
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ // note 2d arrays when configured using initalizer look inverted
+ // ---> Y axis
+ // ^
+ // | X - axis
+ // |
+ // see PatternBrush for details about how to make new patterns work
+ private static readonly bool[,] Percent10Pattern = new bool[,]
+ {
+ { true, false, false, false },
+ { false, false, false, false },
+ { false, false, true, false },
+ { false, false, false, false }
+ };
+
+ private static readonly bool[,] Percent20Pattern = new bool[,]
+ {
+ { true, false, true, false },
+ { false, false, false, false },
+ { false, true, false, true },
+ { false, false, false, false }
+ };
+
+ private static readonly bool[,] HorizontalPattern = new bool[,]
+ {
+ { false, true, false, false },
+ };
+
+ private static readonly bool[,] MinPattern = new bool[,]
+ {
+ { false, false, false, true },
+ };
+
+ private static readonly bool[,] VerticalPattern = new bool[,]
+ {
+ { false },
+ { true },
+ { false },
+ { false }
+ };
+
+ private static readonly bool[,] ForwardDiagonalPattern = new bool[,]
+ {
+ { true, false, false, false },
+ { false, true, false, false },
+ { false, false, true, false },
+ { false, false, false, true }
+ };
+
+ private static readonly bool[,] BackwardDiagonalPattern = new bool[,]
+ {
+ { false, false, false, true },
+ { false, false, true, false },
+ { false, true, false, false },
+ { true, false, false, false }
+ };
+
+ ///
+ /// Create as brush that will paint a solid color
+ ///
+ /// The color.
+ /// A Brush
+ public static SolidBrush Solid(TColor color)
+ => new SolidBrush(color);
+
+ ///
+ /// Create as brush that will paint a Percent10 Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Percent10(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, Percent10Pattern);
+
+ ///
+ /// Create as brush that will paint a Percent20 Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Percent20(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, Percent20Pattern);
+
+ ///
+ /// Create as brush that will paint a Horizontal Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Horizontal(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, HorizontalPattern);
+
+ ///
+ /// Create as brush that will paint a Min Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Min(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, MinPattern);
+
+ ///
+ /// Create as brush that will paint a Vertical Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush Vertical(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, VerticalPattern);
+
+ ///
+ /// Create as brush that will paint a Forward Diagonal Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush ForwardDiagonal(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, ForwardDiagonalPattern);
+
+ ///
+ /// Create as brush that will paint a Backward Diagonal Hatch Pattern within the specified colors
+ ///
+ /// Color of the foreground.
+ /// Color of the background.
+ /// A Brush
+ public static PatternBrush BackwardDiagonal(TColor foreColor, TColor backColor)
+ => new PatternBrush(foreColor, backColor, BackwardDiagonalPattern);
+ }
+}
diff --git a/src/ImageSharp/Drawing/Brushes/IBrush.cs b/src/ImageSharp/Drawing/Brushes/IBrush.cs
new file mode 100644
index 0000000000..fc48bb2f1d
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/IBrush.cs
@@ -0,0 +1,35 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing
+{
+ using System;
+ using Processors;
+
+ ///
+ /// Brush represents a logical configuration of a brush whcih can be used to source pixel colors
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ ///
+ /// A brush is a simple class that will return an that will perform the
+ /// logic for converting a pixel location to a .
+ ///
+ public interface IBrush
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ ///
+ /// Creates the applicator for this brush.
+ ///
+ /// The region the brush will be applied to.
+ /// The brush applicator for this brush
+ ///
+ /// The when being applied to things like shapes would usually be the
+ /// bounding box of the shape not necessarily the bounds of the whole image
+ ///
+ IBrushApplicator CreateApplicator(RectangleF region);
+ }
+}
diff --git a/src/ImageSharp/Drawing/Brushes/ImageBrush.cs b/src/ImageSharp/Drawing/Brushes/ImageBrush.cs
new file mode 100644
index 0000000000..8ac4f43d29
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/ImageBrush.cs
@@ -0,0 +1,108 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing.Brushes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Numerics;
+ using System.Threading.Tasks;
+ using Processors;
+
+ ///
+ /// Provides an implementaion of a solid brush for painting with repeating images.
+ ///
+ public class ImageBrush : ImageBrush
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The color.
+ public ImageBrush(IImageBase image)
+ : base(image)
+ {
+ }
+ }
+
+ ///
+ /// Provides an implementaion of a solid brush for painting solid color areas.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ public class ImageBrush : IBrush
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ private readonly IImageBase image;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The color.
+ public ImageBrush(IImageBase image)
+ {
+ this.image = image;
+ }
+
+ ///
+ /// Creates the applicator for this brush.
+ ///
+ /// The region the brush will be applied to.
+ ///
+ /// The brush applicator for this brush
+ ///
+ ///
+ /// The when being applied to things like shapes would ussually be the
+ /// bounding box of the shape not necessarily the bounds of the whole image
+ ///
+ public IBrushApplicator CreateApplicator(RectangleF region)
+ {
+ return new ImageBrushApplicator(this.image, region);
+ }
+
+ private class ImageBrushApplicator : IBrushApplicator
+ {
+ private readonly PixelAccessor source;
+ private readonly int yLength;
+ private readonly int xLength;
+ private readonly Vector2 offset;
+ private readonly float YOffset;
+
+ public ImageBrushApplicator(IImageBase image, RectangleF region)
+ {
+ this.source = image.Lock();
+ this.xLength = image.Width;
+ this.yLength = image.Height;
+ this.offset = new Vector2((float)Math.Max(Math.Floor(region.Top), 0),
+ (float)Math.Max(Math.Floor(region.Left), 0));
+ }
+
+ ///
+ /// Gets the color for a single pixel.
+ ///
+ /// The point.
+ ///
+ /// The color
+ ///
+ public TColor GetColor(Vector2 point)
+ {
+ //offset the requested pixel by the value in the rectangle (the shapes position)
+ point = point - offset;
+ var x = (int)point.X % this.xLength;
+ var y = (int)point.Y % this.yLength;
+
+ return source[x, y];
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ source.Dispose();
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Drawing/Brushes/PatternBrush.cs b/src/ImageSharp/Drawing/Brushes/PatternBrush.cs
new file mode 100644
index 0000000000..c9e4d5bc7f
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/PatternBrush.cs
@@ -0,0 +1,177 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing.Brushes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Numerics;
+ using System.Threading.Tasks;
+ using Processors;
+
+ ///
+ /// Provides an implementaion of a pattern brush for painting patterns.
+ ///
+ ///
+ /// The patterns that are used to create a custom pattern brush are made up of a repeating matrix of flags,
+ /// where each flag denotes weather to draw the foregound color or the background color.
+ /// so to create a new bool[,] with your flags
+ ///
+ /// For example if you wated to create a diagonal line that repeat every 4 pixels you would use a pattern like so
+ /// 1000
+ /// 0100
+ /// 0010
+ /// 0001
+ ///
+ /// or you want a horrizontal stripe which is 3 pixels apart you would use a pattern like
+ /// 1
+ /// 0
+ /// 0
+ ///
+ /// warning when use array initallzer across multiple lines the bools look inverted i.e.
+ /// new bool[,]{
+ /// {true, false, false},
+ /// {false,true, false}
+ /// }
+ /// would be
+ /// 10
+ /// 01
+ /// 00
+ ///
+ public class PatternBrush : PatternBrush
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Color of the fore.
+ /// Color of the back.
+ /// The pattern.
+ public PatternBrush(Color foreColor, Color backColor, bool[,] pattern)
+ : base(foreColor, backColor, pattern)
+ {
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The brush.
+ internal PatternBrush(PatternBrush brush)
+ : base(brush)
+ {
+ }
+ }
+
+ ///
+ /// Provides an implementaion of a pattern brush for painting patterns.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ public partial class PatternBrush : IBrush
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ private readonly TColor[][] pattern;
+ private readonly int stride;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Color of the fore.
+ /// Color of the back.
+ /// The pattern.
+ public PatternBrush(TColor foreColor, TColor backColor, bool[,] pattern)
+ {
+ this.stride = pattern.GetLength(1);
+
+ // convert the multidimension array into a jagged one.
+ var height = pattern.GetLength(0);
+ this.pattern = new TColor[height][];
+ for (var x = 0; x < height; x++)
+ {
+ this.pattern[x] = new TColor[stride];
+ for (var y = 0; y < stride; y++)
+ {
+ if (pattern[x, y])
+ {
+ this.pattern[x][y] = foreColor;
+ }else
+ {
+ this.pattern[x][y] = backColor;
+ }
+ }
+ }
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The brush.
+ internal PatternBrush(PatternBrush brush)
+ {
+ this.pattern = brush.pattern;
+ this.stride = brush.stride;
+ }
+
+ ///
+ /// Creates the applicator for this bursh.
+ ///
+ /// The region the brush will be applied to.
+ ///
+ /// The brush applicator for this brush
+ ///
+ ///
+ /// The when being applied to things like shapes would ussually be the
+ /// bounding box of the shape not necessarily the bounds of the whole image
+ ///
+ public IBrushApplicator CreateApplicator(RectangleF region)
+ {
+ return new PatternBrushApplicator(this.pattern, this.stride);
+ }
+
+ private class PatternBrushApplicator : IBrushApplicator
+ {
+ private readonly int xLength;
+ private readonly int stride;
+ private readonly TColor[][] pattern;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// Color of the fore.
+ /// Color of the back.
+ /// The pattern.
+ /// The stride.
+ public PatternBrushApplicator(TColor[][] pattern, int stride)
+ {
+ this.pattern = pattern;
+ this.xLength = pattern.Length;
+ this.stride = stride;
+ }
+
+ ///
+ /// Gets the color for a single pixel.
+ ///
+ /// The point.
+ ///
+ /// The color
+ ///
+ public TColor GetColor(Vector2 point)
+ {
+ var x = (int)point.X % this.xLength;
+ var y = (int)point.Y % this.stride;
+
+ return this.pattern[x][y];
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ // noop
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs b/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs
new file mode 100644
index 0000000000..834bbde870
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/Processors/IBrushApplicator.cs
@@ -0,0 +1,28 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing.Processors
+{
+ using System;
+ using System.Numerics;
+
+ ///
+ /// primitive that converts a point in to a color for discoving the fill color based on an implmentation
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ ///
+ public interface IBrushApplicator : IDisposable // disposable will be required if/when there is an ImageBrush
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ ///
+ /// Gets the color for a single pixel.
+ ///
+ /// The point.
+ /// The color
+ TColor GetColor(Vector2 point);
+ }
+}
diff --git a/src/ImageSharp/Drawing/Brushes/SolidBrush.cs b/src/ImageSharp/Drawing/Brushes/SolidBrush.cs
new file mode 100644
index 0000000000..8e64ad6e23
--- /dev/null
+++ b/src/ImageSharp/Drawing/Brushes/SolidBrush.cs
@@ -0,0 +1,107 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp.Drawing.Brushes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Numerics;
+ using System.Threading.Tasks;
+ using Processors;
+
+ ///
+ /// Provides an implementaion of a solid brush for painting solid color areas.
+ ///
+ public class SolidBrush : SolidBrush
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The color.
+ public SolidBrush(Color color)
+ : base(color)
+ {
+ }
+ }
+
+ ///
+ /// Provides an implementaion of a solid brush for painting solid color areas.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ public class SolidBrush : IBrush
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ private readonly TColor color;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The color.
+ public SolidBrush(TColor color)
+ {
+ this.color = color;
+ }
+
+ ///
+ /// Gets the color.
+ ///
+ ///
+ /// The color.
+ ///
+ public TColor Color => this.color;
+
+ ///
+ /// Creates the applicator for this brush.
+ ///
+ /// The region the brush will be applied to.
+ ///
+ /// The brush applicator for this brush
+ ///
+ ///
+ /// The when being applied to things like shapes would ussually be the
+ /// bounding box of the shape not necessarily the bounds of the whole image
+ ///
+ public IBrushApplicator CreateApplicator(RectangleF region)
+ {
+ return new SolidBrushApplicator(this.color);
+ }
+
+ private class SolidBrushApplicator : IBrushApplicator
+ {
+ private TColor color;
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ /// The color.
+ public SolidBrushApplicator(TColor color)
+ {
+ this.color = color;
+ }
+
+ ///
+ /// Gets the color for a single pixel.
+ ///
+ /// The point.
+ ///
+ /// The color
+ ///
+ public TColor GetColor(Vector2 point)
+ {
+ return this.color;
+ }
+
+ ///
+ /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
+ ///
+ public void Dispose()
+ {
+ // noop
+ }
+ }
+ }
+}
diff --git a/src/ImageSharp/Drawing/Draw.cs b/src/ImageSharp/Drawing/Draw.cs
new file mode 100644
index 0000000000..5c2f208a38
--- /dev/null
+++ b/src/ImageSharp/Drawing/Draw.cs
@@ -0,0 +1,566 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp
+{
+ using System.Numerics;
+ using Drawing;
+ using Drawing.Brushes;
+ using Drawing.Paths;
+ using Drawing.Pens;
+ using Drawing.Processors;
+ using Drawing.Shapes;
+ using Processors;
+
+ ///
+ /// 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ return source.Process(new DrawPathProcessor(pen, shape, options));
+ }
+
+ ///
+ /// Draws the outline of the polygon with the provided pen.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// The source.
+ /// The pen.
+ /// The shape.
+ /// The Image
+ public static Image DrawPolygon(this Image source, IPen pen, IShape shape)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// The source.
+ /// The pen.
+ /// The points.
+ /// The Image
+ public static Image DrawPolygon(this Image source, IPen pen, Vector2[] points)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)));
+ }
+
+ ///
+ /// Draws the path with the provided pen.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ return source.Process(new DrawPathProcessor(pen, path, options));
+ }
+
+ ///
+ /// Draws the path with the provided pen.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// The source.
+ /// The pen.
+ /// The path.
+ /// The Image
+ public static Image DrawPath(this Image source, IPen pen, IPath path)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.Process(new DrawPathProcessor(pen, path, GraphicsOptions.Default));
+ }
+
+ ///
+ /// Draws the path with the bursh at the privdied thickness.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ return source.DrawPath(new Pen(brush, thickness), path);
+ }
+
+ ///
+ /// Draws the path with the bursh at the privdied thickness.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// The source.
+ /// The pen.
+ /// The points.
+ /// The Image
+ public static Image DrawLines(this Image source, IPen pen, Vector2[] points)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// The source.
+ /// The pen.
+ /// The points.
+ /// The Image
+ public static Image DrawBeziers(this Image source, IPen pen, Vector2[] points)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.DrawPath(pen, new Path(new BezierLineSegment(points)));
+ }
+ }
+}
diff --git a/src/ImageSharp/Drawing/Fill.cs b/src/ImageSharp/Drawing/Fill.cs
new file mode 100644
index 0000000000..ebd15a614b
--- /dev/null
+++ b/src/ImageSharp/Drawing/Fill.cs
@@ -0,0 +1,192 @@
+//
+// Copyright (c) James Jackson-South and contributors.
+// Licensed under the Apache License, Version 2.0.
+//
+
+namespace ImageSharp
+{
+ using System.Numerics;
+ using Drawing;
+ using Drawing.Brushes;
+ using Drawing.Paths;
+ using Drawing.Processors;
+ using Drawing.Shapes;
+ using 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 type of the packed.
+ /// The source.
+ /// The brush.
+ /// The Image
+ public static Image Fill(this Image source, IBrush brush)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.Process(new FillProcessor(brush));
+ }
+
+ ///
+ /// Flood fills the image with the specified color.
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// The source.
+ /// The color.
+ /// The Image
+ public static Image Fill(this Image source, TColor color)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// The source.
+ /// The brush.
+ /// The shape.
+ /// The Image
+ public static Image Fill(this Image source, IBrush brush, IShape shape, GraphicsOptions options)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.Process(new FillShapeProcessor(brush, shape, options));
+ }
+
+ ///
+ /// Flood fills the image in the shape o fhte provided polygon with the specified brush..
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// The source.
+ /// The brush.
+ /// The shape.
+ /// The Image
+ public static Image Fill(this Image source, IBrush brush, IShape shape)
+ where TColor : struct, IPackedPixel
+ where TPacked : struct
+ {
+ return source.Process(new FillShapeProcessor(brush, shape, GraphicsOptions.Default));
+ }
+
+ ///
+ /// Flood fills the image in the shape o fhte provided polygon with the specified brush..
+ ///
+ /// The type of the color.
+ /// The type of the packed.
+ /// 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
+ where TPacked : struct
+ {
+ 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 type of the packed.
+ /// The source.
+ /// The color.
+ /// The shape.
+ /// The Image
+ public static Image Fill