Browse Source

split out paths from basic drawing

pull/98/head
Scott Williams 9 years ago
parent
commit
884dfab3e1
  1. 8
      ImageSharp.sln
  2. 120
      src/ImageSharp.Drawing.Paths/DrawBeziers.cs
  3. 120
      src/ImageSharp.Drawing.Paths/DrawLines.cs
  4. 124
      src/ImageSharp.Drawing.Paths/DrawPath.cs
  5. 104
      src/ImageSharp.Drawing.Paths/DrawPolygon.cs
  6. 24
      src/ImageSharp.Drawing.Paths/DrawRectangle.cs
  7. 118
      src/ImageSharp.Drawing.Paths/DrawShape.cs
  8. 87
      src/ImageSharp.Drawing.Paths/FillPaths.cs
  9. 83
      src/ImageSharp.Drawing.Paths/FillPolygon.cs
  10. 8
      src/ImageSharp.Drawing.Paths/FillRectangle.cs
  11. 83
      src/ImageSharp.Drawing.Paths/FillShapes.cs
  12. 25
      src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj
  13. 21
      src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs
  14. 6
      src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs
  15. 12
      src/ImageSharp.Drawing.Paths/RectangleExtensions.cs
  16. 31
      src/ImageSharp.Drawing.Paths/ShapePath.cs
  17. 137
      src/ImageSharp.Drawing.Paths/ShapeRegion.cs
  18. 96
      src/ImageSharp.Drawing.Paths/project.json
  19. 1
      src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs
  20. 506
      src/ImageSharp.Drawing/Draw.cs
  21. 123
      src/ImageSharp.Drawing/DrawPath.cs
  22. 173
      src/ImageSharp.Drawing/Fill.cs
  23. 111
      src/ImageSharp.Drawing/FillRegion.cs
  24. 24
      src/ImageSharp.Drawing/IDrawableRegion.cs
  25. 57
      src/ImageSharp.Drawing/Path.cs
  26. 5
      src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs
  27. 29
      src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs
  28. 14
      src/ImageSharp.Drawing/Region.cs
  29. 1
      src/ImageSharp.Drawing/project.json
  30. 2
      tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs
  31. 24
      tests/ImageSharp.Benchmarks/project.json
  32. 5
      tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj
  33. 10
      tests/ImageSharp.Tests/Drawing/DrawPathTests.cs
  34. 12
      tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs
  35. 2
      tests/ImageSharp.Tests/Drawing/PolygonTests.cs
  36. 2
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs
  37. 24
      tests/ImageSharp.Tests/project.json

8
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} {2AA31A1F-142C-43F4-8687-09ABCA4B3A26} = {2AA31A1F-142C-43F4-8687-09ABCA4B3A26}
{27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} = {27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} {27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F} = {27AD4B5F-ECC4-4C63-9ECB-04EC772FDB6F}
{7213767C-0003-41CA-AB18-0223CFA7CE4B} = {7213767C-0003-41CA-AB18-0223CFA7CE4B} {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} {C77661B9-F793-422E-8E27-AC60ECC5F215} = {C77661B9-F793-422E-8E27-AC60ECC5F215}
{556ABDCF-ED93-4327-BE98-F6815F78B9B8} = {556ABDCF-ED93-4327-BE98-F6815F78B9B8} {556ABDCF-ED93-4327-BE98-F6815F78B9B8} = {556ABDCF-ED93-4327-BE98-F6815F78B9B8}
{A623CFE9-9D2B-4528-AD1F-2E834B061134} = {A623CFE9-9D2B-4528-AD1F-2E834B061134} {A623CFE9-9D2B-4528-AD1F-2E834B061134} = {A623CFE9-9D2B-4528-AD1F-2E834B061134}
EndProjectSection EndProjectSection
EndProject 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 Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{96188137-5FA6-4924-AB6E-4EFF79C6E0BB}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE
@ -132,5 +139,6 @@ Global
{A623CFE9-9D2B-4528-AD1F-2E834B061134} = {815C0625-CD3D-440F-9F80-2D83856AB7AE} {A623CFE9-9D2B-4528-AD1F-2E834B061134} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
{9E574A07-F879-4811-9C41-5CBDC6BAFDB7} = {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} {96188137-5FA6-4924-AB6E-4EFF79C6E0BB} = {56801022-D71A-4FBE-BC5B-CBA08E2284EC}
{E5BD4F96-28A8-410C-8B63-1C5731948549} = {815C0625-CD3D-440F-9F80-2D83856AB7AE}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

120
src/ImageSharp.Drawing.Paths/DrawBeziers.cs

@ -0,0 +1,120 @@
// <copyright file="DrawBeziers.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
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;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new Path(new BezierLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new Path(new BezierLineSegment(points)));
}
}
}

120
src/ImageSharp.Drawing.Paths/DrawLines.cs

@ -0,0 +1,120 @@
// <copyright file="DrawLines.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
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;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)));
}
}
}

124
src/ImageSharp.Drawing.Paths/DrawPath.cs

@ -0,0 +1,124 @@
// <copyright file="DrawPath.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new ShapePath(path), options);
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), path, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), path);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, path);
}
}
}

104
src/ImageSharp.Drawing.Paths/DrawPolygon.cs

@ -0,0 +1,104 @@
// <copyright file="DrawPolygon.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}
}
}

24
src/ImageSharp.Drawing/DrawRectangle.cs → src/ImageSharp.Drawing.Paths/DrawRectangle.cs

@ -30,10 +30,10 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, RectangleF shape, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Apply(new DrawPathProcessor<TColor>(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);
} }
/// <summary> /// <summary>
@ -44,10 +44,10 @@ namespace ImageSharp
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The Image</returns> /// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, RectangleF shape) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Rectangle shape)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.DrawPolygon(pen, shape, GraphicsOptions.Default); return source.Draw(pen, shape, GraphicsOptions.Default);
} }
/// <summary> /// <summary>
@ -62,10 +62,10 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, RectangleF shape, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape, options); return source.Draw(new Pen<TColor>(brush, thickness), shape, options);
} }
/// <summary> /// <summary>
@ -77,10 +77,10 @@ namespace ImageSharp
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The Image</returns> /// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, RectangleF shape) public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Rectangle shape)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape); return source.Draw(new Pen<TColor>(brush, thickness), shape);
} }
/// <summary> /// <summary>
@ -95,10 +95,10 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, RectangleF shape, GraphicsOptions options) public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape, options); return source.Draw(new SolidBrush<TColor>(color), thickness, shape, options);
} }
/// <summary> /// <summary>
@ -110,10 +110,10 @@ namespace ImageSharp
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The Image</returns> /// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, RectangleF shape) public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Rectangle shape)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape); return source.Draw(new SolidBrush<TColor>(color), thickness, shape);
} }
} }
} }

118
src/ImageSharp.Drawing.Paths/DrawShape.cs

@ -0,0 +1,118 @@
// <copyright file="DrawShape.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, new ShapePath(shape), options);
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, shape, GraphicsOptions.Default);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, shape);
}
}
}

87
src/ImageSharp.Drawing.Paths/FillPaths.cs

@ -0,0 +1,87 @@
// <copyright file="FillPaths.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="path">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(path), options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), path, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), path);
}
}
}

83
src/ImageSharp.Drawing.Paths/FillPolygon.cs

@ -0,0 +1,83 @@
// <copyright file="FillPolygon.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)));
}
}
}

8
src/ImageSharp.Drawing/FillRectangle.cs → src/ImageSharp.Drawing.Paths/FillRectangle.cs

@ -27,7 +27,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, RectangleF shape, GraphicsOptions options) public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options); return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height), options);
@ -41,7 +41,7 @@ namespace ImageSharp
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The Image</returns> /// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, RectangleF shape) public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Rectangle shape)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height)); return source.Fill(brush, new SixLabors.Shapes.Rectangle(shape.X, shape.Y, shape.Width, shape.Height));
@ -58,7 +58,7 @@ namespace ImageSharp
/// <returns> /// <returns>
/// The Image /// The Image
/// </returns> /// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, RectangleF shape, GraphicsOptions options) public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Fill(new SolidBrush<TColor>(color), shape, options); return source.Fill(new SolidBrush<TColor>(color), shape, options);
@ -72,7 +72,7 @@ namespace ImageSharp
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
/// <returns>The Image</returns> /// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, RectangleF shape) public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Rectangle shape)
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
return source.Fill(new SolidBrush<TColor>(color), shape); return source.Fill(new SolidBrush<TColor>(color), shape);

83
src/ImageSharp.Drawing.Paths/FillShapes.cs

@ -0,0 +1,83 @@
// <copyright file="FillShapes.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(shape), options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, new ShapeRegion(shape), GraphicsOptions.Default);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape);
}
}
}

25
src/ImageSharp.Drawing.Paths/ImageSharp.Drawing.Paths.xproj

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>e5bd4f96-28a8-410c-8b63-1c5731948549</ProjectGuid>
<RootNamespace>ImageSharp.Drawing</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<ItemGroup>
<Service Include="{508349b6-6b84-4df5-91f0-309beebad82d}" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

21
src/ImageSharp.Drawing/Processors/PointInfoExtensions.cs → src/ImageSharp.Drawing.Paths/PointInfoExtensions.cs

@ -3,19 +3,8 @@
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
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;
/// <summary> /// <summary>
/// Extension methods for helping to bridge Shaper2D and ImageSharp primitives. /// Extension methods for helping to bridge Shaper2D and ImageSharp primitives.
/// </summary> /// </summary>
@ -29,10 +18,10 @@ namespace ImageSharp.Drawing.Processors
public static PointInfo Convert(this SixLabors.Shapes.PointInfo source) public static PointInfo Convert(this SixLabors.Shapes.PointInfo source)
{ {
return new PointInfo return new PointInfo
{ {
DistanceAlongPath = source.DistanceAlongPath, DistanceAlongPath = source.DistanceAlongPath,
DistanceFromPath = source.DistanceFromPath DistanceFromPath = source.DistanceFromPath
}; };
} }
} }
} }

6
src/ImageSharp.Drawing.Paths/Properties/AssemblyInfo.cs

@ -0,0 +1,6 @@
// <copyright file="AssemblyInfo.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
// Common values read from `AssemblyInfo.Common.cs`

12
src/ImageSharp.Drawing/Processors/RectangleExtensions.cs → src/ImageSharp.Drawing.Paths/RectangleExtensions.cs

@ -20,13 +20,17 @@ namespace ImageSharp.Drawing.Processors
internal static class RectangleExtensions internal static class RectangleExtensions
{ {
/// <summary> /// <summary>
/// Converts a Shaper2D <see cref="SixLabors.Shapes.Rectangle"/> to an ImageSharp <see cref="RectangleF"/>. /// Converts a Shaper2D <see cref="SixLabors.Shapes.Rectangle"/> to an ImageSharp <see cref="Rectangle"/> by creating a <see cref="Rectangle"/> the entirely surrounds the source.
/// </summary> /// </summary>
/// <param name="source">The source.</param> /// <param name="source">The source.</param>
/// <returns>A <see cref="RectangleF"/> representation of this <see cref="SixLabors.Shapes.Rectangle"/></returns> /// <returns>A <see cref="Rectangle"/> representation of this <see cref="SixLabors.Shapes.Rectangle"/></returns>
public static RectangleF Convert(this SixLabors.Shapes.Rectangle source) 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);
} }
} }
} }

31
src/ImageSharp.Drawing/ShapeRegion.cs → src/ImageSharp.Drawing.Paths/ShapePath.cs

@ -1,4 +1,4 @@
// <copyright file="ShapeRegion.cs" company="James Jackson-South"> // <copyright file="ShapePath.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -18,8 +18,7 @@ namespace ImageSharp.Drawing
/// <summary> /// <summary>
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region. /// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
/// </summary> /// </summary>
/// <seealso cref="ImageSharp.Drawing.IDrawableRegion" /> internal class ShapePath : ImageSharp.Drawing.Path
internal class ShapeRegion : IDrawableRegion
{ {
/// <summary> /// <summary>
/// The fillable shape /// The fillable shape
@ -32,10 +31,10 @@ namespace ImageSharp.Drawing
private readonly ImmutableArray<IPath> paths; private readonly ImmutableArray<IPath> paths;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class. /// Initializes a new instance of the <see cref="ShapePath"/> class.
/// </summary> /// </summary>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
public ShapeRegion(IPath path) public ShapePath(IPath path)
: this(ImmutableArray.Create(path)) : this(ImmutableArray.Create(path))
{ {
this.shape = path.AsShape(); this.shape = path.AsShape();
@ -43,10 +42,10 @@ namespace ImageSharp.Drawing
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class. /// Initializes a new instance of the <see cref="ShapePath"/> class.
/// </summary> /// </summary>
/// <param name="shape">The shape.</param> /// <param name="shape">The shape.</param>
public ShapeRegion(IShape shape) public ShapePath(IShape shape)
: this(shape.Paths) : this(shape.Paths)
{ {
this.shape = shape; this.shape = shape;
@ -54,10 +53,10 @@ namespace ImageSharp.Drawing
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class. /// Initializes a new instance of the <see cref="ShapePath" /> class.
/// </summary> /// </summary>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
private ShapeRegion(ImmutableArray<IPath> paths) private ShapePath(ImmutableArray<IPath> paths)
{ {
this.paths = paths; this.paths = paths;
} }
@ -68,7 +67,7 @@ namespace ImageSharp.Drawing
/// <value> /// <value>
/// The maximum intersections. /// The maximum intersections.
/// </value> /// </value>
public int MaxIntersections => this.shape.MaxIntersections; public override int MaxIntersections => this.shape.MaxIntersections;
/// <summary> /// <summary>
/// Gets the bounds. /// Gets the bounds.
@ -76,7 +75,7 @@ namespace ImageSharp.Drawing
/// <value> /// <value>
/// The bounds. /// The bounds.
/// </value> /// </value>
public Rectangle Bounds { get; } public override Rectangle Bounds { get; }
/// <summary> /// <summary>
/// Scans the X axis for intersections. /// Scans the X axis for intersections.
@ -88,7 +87,7 @@ namespace ImageSharp.Drawing
/// <returns> /// <returns>
/// The number of intersections found. /// The number of intersections found.
/// </returns> /// </returns>
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 start = new Vector2(x, this.Bounds.Top - 1);
var end = new Vector2(x, this.Bounds.Bottom + 1); var end = new Vector2(x, this.Bounds.Bottom + 1);
@ -125,10 +124,10 @@ namespace ImageSharp.Drawing
/// <returns> /// <returns>
/// The number of intersections found. /// The number of intersections found.
/// </returns> /// </returns>
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 start = new Vector2(float.MinValue, y);
var end = new Vector2(this.Bounds.Right + 1, y); var end = new Vector2(float.MaxValue, y);
Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length); Vector2[] innerbuffer = ArrayPool<Vector2>.Shared.Rent(length);
try try
{ {
@ -158,7 +157,7 @@ namespace ImageSharp.Drawing
/// <param name="x">The x.</param> /// <param name="x">The x.</param>
/// <param name="y">The y.</param> /// <param name="y">The y.</param>
/// <returns>Information about the the point</returns> /// <returns>Information about the the point</returns>
public PointInfo GetPointInfo(int x, int y) public override PointInfo GetPointInfo(int x, int y)
{ {
var point = new Vector2(x, y); var point = new Vector2(x, y);
SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo); SixLabors.Shapes.PointInfo result = default(SixLabors.Shapes.PointInfo);

137
src/ImageSharp.Drawing.Paths/ShapeRegion.cs

@ -0,0 +1,137 @@
// <copyright file="ShapeRegion.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing
{
using System.Buffers;
using System.Collections.Immutable;
using System.Numerics;
using ImageSharp.Drawing.Processors;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
/// <summary>
/// A drawable mapping between a <see cref="SixLabors.Shapes.IShape"/>/<see cref="SixLabors.Shapes.IPath"/> and a drawable/fillable region.
/// </summary>
internal class ShapeRegion : Region
{
/// <summary>
/// The fillable shape
/// </summary>
private readonly IShape shape;
/// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
/// </summary>
/// <param name="path">The path.</param>
public ShapeRegion(IPath path)
: this(path.AsShape())
{
}
/// <summary>
/// Initializes a new instance of the <see cref="ShapeRegion"/> class.
/// </summary>
/// <param name="shape">The shape.</param>
public ShapeRegion(IShape shape)
{
this.shape = shape;
this.Bounds = shape.Bounds.Convert();
}
/// <summary>
/// Gets the maximum number of intersections to could be returned.
/// </summary>
/// <value>
/// The maximum intersections.
/// </value>
public override int MaxIntersections => this.shape.MaxIntersections;
/// <summary>
/// Gets the bounds.
/// </summary>
/// <value>
/// The bounds.
/// </value>
public override Rectangle Bounds { get; }
/// <summary>
/// Scans the X axis for intersections.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>
/// The number of intersections found.
/// </returns>
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<Vector2>.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<Vector2>.Shared.Return(innerbuffer);
}
}
/// <summary>
/// Scans the Y axis for intersections.
/// </summary>
/// <param name="y">The position along the y axis to find intersections.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>
/// The number of intersections found.
/// </returns>
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<Vector2>.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<Vector2>.Shared.Return(innerbuffer);
}
}
}
}

96
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"
}
}
}
}

1
src/ImageSharp.Drawing/Brushes/Processors/BrushApplicator.cs

@ -16,7 +16,6 @@ namespace ImageSharp.Drawing.Processors
public abstract class BrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush public abstract class BrushApplicator<TColor> : IDisposable // disposable will be required if/when there is an ImageBrush
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
/// <summary> /// <summary>
/// Gets the color for a single pixel. /// Gets the color for a single pixel.
/// </summary> /// </summary>

506
src/ImageSharp.Drawing/Draw.cs

@ -1,506 +0,0 @@
// <copyright file="Draw.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(shape), options));
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, shape, GraphicsOptions.Default);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor>(brush, thickness), shape);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, shape);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new Pen<TColor>(brush, thickness), new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPolygon<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPolygon(pen, new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the path with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(path), options));
}
/// <summary>
/// Draws the path with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IPen<TColor> pen, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new DrawPathProcessor<TColor>(pen, new ShapeRegion(path), GraphicsOptions.Default));
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), path, options);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), path);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path, options);
}
/// <summary>
/// Draws the path with the bursh at the privdied thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawPath<TColor>(this Image<TColor> source, TColor color, float thickness, IPath path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new SolidBrush<TColor>(color), thickness, path);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawLines(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new LinearLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawLines<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new LinearLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(new Pen<TColor>(brush, thickness), new Path(new BezierLineSegment(points)));
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points);
}
/// <summary>
/// Draws the provided Points as an open Bezier path at the provided thickness with the supplied brush
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, TColor color, float thickness, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawBeziers(new SolidBrush<TColor>(color), thickness, points, options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new BezierLineSegment(points)), options);
}
/// <summary>
/// Draws the provided Points as an open Bezier path with the supplied pen
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> DrawBeziers<TColor>(this Image<TColor> source, IPen<TColor> pen, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.DrawPath(pen, new Path(new BezierLineSegment(points)));
}
}
}

123
src/ImageSharp.Drawing/DrawPath.cs

@ -0,0 +1,123 @@
// <copyright file="DrawPath.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Pens;
using Drawing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Draws the outline of the region with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new DrawPathProcessor<TColor>(pen, path, options));
}
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="pen">The pen.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IPen<TColor> pen, Path path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), path, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, IBrush<TColor> brush, float thickness, Path path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new Pen<TColor>(brush, thickness), path);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, path, options);
}
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Draw<TColor>(this Image<TColor> source, TColor color, float thickness, Path path)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Draw(new SolidBrush<TColor>(color), thickness, path);
}
}
}

173
src/ImageSharp.Drawing/Fill.cs

@ -1,173 +0,0 @@
// <copyright file="Fill.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
using SixLabors.Shapes;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new FillProcessor<TColor>(brush));
}
/// <summary>
/// Flood fills the image with the specified color.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new FillShapeProcessor<TColor>(brush, new ShapeRegion(shape), options));
}
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new FillShapeProcessor<TColor>(brush, new ShapeRegion(shape), GraphicsOptions.Default));
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape, options);
}
/// <summary>
/// Flood fills the image in the shape o fhte provided polygon with the specified brush..
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, IShape shape)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), shape);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, IBrush<TColor> brush, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)), options);
}
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="points">The points.</param>
/// <returns>The Image</returns>
public static Image<TColor> FillPolygon<TColor>(this Image<TColor> source, TColor color, Vector2[] points)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
// using Polygon directly instead of LinearPolygon as its will have less indirection
return source.Fill(new SolidBrush<TColor>(color), new Polygon(new LinearLineSegment(points)));
}
}
}

111
src/ImageSharp.Drawing/FillRegion.cs

@ -0,0 +1,111 @@
// <copyright file="FillRegion.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp
{
using System;
using System.Numerics;
using Drawing;
using Drawing.Brushes;
using Drawing.Processors;
/// <summary>
/// Extension methods for the <see cref="Image{TColor}"/> type.
/// </summary>
public static partial class ImageExtensions
{
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new FillProcessor<TColor>(brush));
}
/// <summary>
/// Flood fills the image with the specified color.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <returns>The Image</returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color));
}
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Apply(new FillRegionProcessor<TColor>(brush, region, options));
}
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, IBrush<TColor> brush, Region region)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(brush, region, GraphicsOptions.Default);
}
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region, GraphicsOptions options)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), region, options);
}
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam>
/// <param name="source">The source.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <returns>
/// The Image
/// </returns>
public static Image<TColor> Fill<TColor>(this Image<TColor> source, TColor color, Region region)
where TColor : struct, IPackedPixel, IEquatable<TColor>
{
return source.Fill(new SolidBrush<TColor>(color), region);
}
}
}

24
src/ImageSharp.Drawing/IDrawableRegion.cs

@ -1,24 +0,0 @@
// <copyright file="IDrawableRegion.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing
{
using System.Numerics;
/// <summary>
/// Represents a region with knowledge about its outline.
/// </summary>
/// <seealso cref="ImageSharp.Drawing.IRegion" />
public interface IDrawableRegion : IRegion
{
/// <summary>
/// Gets the point information for the specified x and y location.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <returns>Information about the point in relation to a drawable edge</returns>
PointInfo GetPointInfo(int x, int y);
}
}

57
src/ImageSharp.Drawing/Path.cs

@ -0,0 +1,57 @@
// <copyright file="Path.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageSharp.Drawing
{
/// <summary>
/// Represents a something that has knowledge about its outline.
/// </summary>
public abstract class Path
{
/// <summary>
/// Gets the maximum number of intersections to could be returned.
/// </summary>
/// <value>
/// The maximum intersections.
/// </value>
public abstract int MaxIntersections { get; }
/// <summary>
/// Gets the bounds.
/// </summary>
/// <value>
/// The bounds.
/// </value>
public abstract Rectangle Bounds { get; }
/// <summary>
/// Gets the point information for the specified x and y location.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <returns>Information about the point in relation to a drawable edge</returns>
public abstract PointInfo GetPointInfo(int x, int y);
/// <summary>
/// Scans the X axis for intersections.
/// </summary>
/// <param name="x">The x.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns>
public abstract int ScanX(int x, float[] buffer, int length, int offset);
/// <summary>
/// Scans the Y axis for intersections.
/// </summary>
/// <param name="y">The position along the y axis to find intersections.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="length">The length.</param>
/// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns>
public abstract int ScanY(int y, float[] buffer, int length, int offset);
}
}

5
src/ImageSharp.Drawing/Processors/DrawPathProcessor.cs

@ -12,7 +12,6 @@ namespace ImageSharp.Drawing.Processors
using System.Threading.Tasks; using System.Threading.Tasks;
using ImageSharp.Processing; using ImageSharp.Processing;
using Pens; using Pens;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle; using Rectangle = ImageSharp.Rectangle;
/// <summary> /// <summary>
@ -27,7 +26,7 @@ namespace ImageSharp.Drawing.Processors
private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor private const int PaddingFactor = 1; // needs to been the same or greater than AntialiasFactor
private readonly IPen<TColor> pen; private readonly IPen<TColor> pen;
private readonly IDrawableRegion region; private readonly Path region;
private readonly GraphicsOptions options; private readonly GraphicsOptions options;
/// <summary> /// <summary>
@ -36,7 +35,7 @@ namespace ImageSharp.Drawing.Processors
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
public DrawPathProcessor(IPen<TColor> pen, IDrawableRegion region, GraphicsOptions options) public DrawPathProcessor(IPen<TColor> pen, Path region, GraphicsOptions options)
{ {
this.region = region; this.region = region;
this.pen = pen; this.pen = pen;

29
src/ImageSharp.Drawing/Processors/FillShapeProcessor.cs → src/ImageSharp.Drawing/Processors/FillRegionProcessor.cs

@ -1,4 +1,4 @@
// <copyright file="FillShapeProcessor.cs" company="James Jackson-South"> // <copyright file="FillRegionProcessor.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
@ -11,30 +11,28 @@ namespace ImageSharp.Drawing.Processors
using System.Threading.Tasks; using System.Threading.Tasks;
using Drawing; using Drawing;
using ImageSharp.Processing; using ImageSharp.Processing;
using SixLabors.Shapes;
using Rectangle = ImageSharp.Rectangle;
/// <summary> /// <summary>
/// Usinf a brsuh and a shape fills shape with contents of brush the /// Usinf a brsuh and a shape fills shape with contents of brush the
/// </summary> /// </summary>
/// <typeparam name="TColor">The type of the color.</typeparam> /// <typeparam name="TColor">The type of the color.</typeparam>
/// <seealso cref="ImageSharp.Processing.ImageProcessor{TColor}" /> /// <seealso cref="ImageSharp.Processing.ImageProcessor{TColor}" />
public class FillShapeProcessor<TColor> : ImageProcessor<TColor> public class FillRegionProcessor<TColor> : ImageProcessor<TColor>
where TColor : struct, IPackedPixel, IEquatable<TColor> where TColor : struct, IPackedPixel, IEquatable<TColor>
{ {
private const float AntialiasFactor = 1f; private const float AntialiasFactor = 1f;
private const int DrawPadding = 1; private const int DrawPadding = 1;
private readonly IBrush<TColor> fillColor; private readonly IBrush<TColor> fillColor;
private readonly IRegion region; private readonly Region region;
private readonly GraphicsOptions options; private readonly GraphicsOptions options;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FillShapeProcessor{TColor}" /> class. /// Initializes a new instance of the <see cref="FillRegionProcessor{TColor}" /> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
public FillShapeProcessor(IBrush<TColor> brush, IRegion region, GraphicsOptions options) public FillRegionProcessor(IBrush<TColor> brush, Region region, GraphicsOptions options)
{ {
this.region = region; this.region = region;
this.fillColor = brush; this.fillColor = brush;
@ -89,6 +87,12 @@ namespace ImageSharp.Drawing.Processors
return; return;
} }
if (pointsFound % 2 == 1)
{
// we seem to have just clipped a corner lets just skip it
return;
}
QuickSort(buffer, pointsFound); QuickSort(buffer, pointsFound);
int currentIntersection = 0; int currentIntersection = 0;
@ -96,13 +100,8 @@ namespace ImageSharp.Drawing.Processors
float lastPoint = float.MinValue; float lastPoint = float.MinValue;
bool isInside = false; bool isInside = false;
// every odd point is the start of a line
Vector2 currentPoint = default(Vector2);
for (int x = minX; x < maxX; x++) for (int x = minX; x < maxX; x++)
{ {
currentPoint.X = x;
currentPoint.Y = y;
if (!isInside) if (!isInside)
{ {
if (x < (nextPoint - DrawPadding) && x > (lastPoint + DrawPadding)) if (x < (nextPoint - DrawPadding) && x > (lastPoint + DrawPadding))
@ -232,6 +231,12 @@ namespace ImageSharp.Drawing.Processors
return; return;
} }
if (pointsFound % 2 == 1)
{
// we seem to have just clipped a corner lets just skip it
return;
}
QuickSort(buffer, pointsFound); QuickSort(buffer, pointsFound);
int currentIntersection = 0; int currentIntersection = 0;

14
src/ImageSharp.Drawing/IRegion.cs → src/ImageSharp.Drawing/Region.cs

@ -1,16 +1,14 @@
// <copyright file="IRegion.cs" company="James Jackson-South"> // <copyright file="Region.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors. // Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
// </copyright> // </copyright>
namespace ImageSharp.Drawing namespace ImageSharp.Drawing
{ {
using System.Numerics;
/// <summary> /// <summary>
/// Represents a region of an image. /// Represents a region of an image.
/// </summary> /// </summary>
public interface IRegion public abstract class Region
{ {
/// <summary> /// <summary>
/// Gets the maximum number of intersections to could be returned. /// Gets the maximum number of intersections to could be returned.
@ -18,7 +16,7 @@ namespace ImageSharp.Drawing
/// <value> /// <value>
/// The maximum intersections. /// The maximum intersections.
/// </value> /// </value>
int MaxIntersections { get; } public abstract int MaxIntersections { get; }
/// <summary> /// <summary>
/// Gets the bounds. /// Gets the bounds.
@ -26,7 +24,7 @@ namespace ImageSharp.Drawing
/// <value> /// <value>
/// The bounds. /// The bounds.
/// </value> /// </value>
Rectangle Bounds { get; } public abstract Rectangle Bounds { get; }
/// <summary> /// <summary>
/// Scans the X axis for intersections. /// Scans the X axis for intersections.
@ -36,7 +34,7 @@ namespace ImageSharp.Drawing
/// <param name="length">The length.</param> /// <param name="length">The length.</param>
/// <param name="offset">The offset.</param> /// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns> /// <returns>The number of intersections found.</returns>
int ScanX(int x, float[] buffer, int length, int offset); public abstract int ScanX(int x, float[] buffer, int length, int offset);
/// <summary> /// <summary>
/// Scans the Y axis for intersections. /// Scans the Y axis for intersections.
@ -46,6 +44,6 @@ namespace ImageSharp.Drawing
/// <param name="length">The length.</param> /// <param name="length">The length.</param>
/// <param name="offset">The offset.</param> /// <param name="offset">The offset.</param>
/// <returns>The number of intersections found.</returns> /// <returns>The number of intersections found.</returns>
int ScanY(int y, float[] buffer, int length, int offset); public abstract int ScanY(int y, float[] buffer, int length, int offset);
} }
} }

1
src/ImageSharp.Drawing/project.json

@ -44,7 +44,6 @@
"ImageSharp.Processing": { "ImageSharp.Processing": {
"target": "project" "target": "project"
}, },
"SixLabors.Shapes": "0.1.0-ci0047",
"StyleCop.Analyzers": { "StyleCop.Analyzers": {
"version": "1.0.0", "version": "1.0.0",
"type": "build" "type": "build"

2
tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs

@ -39,7 +39,7 @@ namespace ImageSharp.Benchmarks
{ {
using (CoreImage image = new CoreImage(800, 800)) 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); return new CoreSize(image.Width, image.Height);
} }

24
tests/ImageSharp.Benchmarks/project.json

@ -16,32 +16,28 @@
"dependencies": { "dependencies": {
"BenchmarkDotNet.Diagnostics.Windows": "0.10.1", "BenchmarkDotNet.Diagnostics.Windows": "0.10.1",
"ImageSharp": { "ImageSharp": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Drawing": { "ImageSharp.Drawing": {
"target": "project", "target": "project"
"version": "1.0.0-*" },
"ImageSharp.Drawing.Paths": {
"target": "project"
}, },
"ImageSharp.Formats.Jpeg": { "ImageSharp.Formats.Jpeg": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Png": { "ImageSharp.Formats.Png": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Bmp": { "ImageSharp.Formats.Bmp": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Gif": { "ImageSharp.Formats.Gif": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Processing": { "ImageSharp.Processing": {
"target": "project", "target": "project"
"version": "1.0.0-*"
} }
}, },
"commands": { "commands": {

5
tests/ImageSharp.Sandbox46/ImageSharp.Sandbox46.csproj

@ -179,8 +179,11 @@
<Reference Include="ImageSharp.Drawing"> <Reference Include="ImageSharp.Drawing">
<HintPath>..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\ImageSharp.Drawing.dll</HintPath> <HintPath>..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\ImageSharp.Drawing.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Drawing.Paths">
<HintPath>..\..\src\ImageSharp.Drawing.Paths\bin\$(Configuration)\net461\ImageSharp.Drawing.Paths.dll</HintPath>
</Reference>
<Reference Include="SixLabors.Shapes"> <Reference Include="SixLabors.Shapes">
<HintPath>..\..\src\ImageSharp.Drawing\bin\$(Configuration)\net461\SixLabors.Shapes.dll</HintPath> <HintPath>..\..\src\ImageSharp.Drawing.Paths\bin\$(Configuration)\net461\SixLabors.Shapes.dll</HintPath>
</Reference> </Reference>
<Reference Include="ImageSharp.Formats.Bmp"> <Reference Include="ImageSharp.Formats.Bmp">
<HintPath>..\..\src\ImageSharp.Formats.Bmp\bin\$(Configuration)\net461\ImageSharp.Formats.Bmp.dll</HintPath> <HintPath>..\..\src\ImageSharp.Formats.Bmp\bin\$(Configuration)\net461\ImageSharp.Formats.Bmp.dll</HintPath>

10
tests/ImageSharp.Tests/Drawing/DrawPathTests.cs

@ -7,7 +7,7 @@ namespace ImageSharp.Tests.Drawing
{ {
using Drawing; using Drawing;
using ImageSharp.Drawing; using ImageSharp.Drawing;
using CorePath = SixLabors.Shapes.Path; using ShapePath = SixLabors.Shapes.Path;
using SixLabors.Shapes; using SixLabors.Shapes;
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
@ -33,13 +33,13 @@ namespace ImageSharp.Tests.Drawing
new Vector2(60, 10), new Vector2(60, 10),
new Vector2(10, 400)); new Vector2(10, 400));
CorePath p = new CorePath(linerSegemnt, bazierSegment); ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
using (FileStream output = File.OpenWrite($"{path}/Simple.png")) using (FileStream output = File.OpenWrite($"{path}/Simple.png"))
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPath(Color.HotPink, 5, p) .Draw(Color.HotPink, 5, p)
.Save(output); .Save(output);
} }
@ -74,7 +74,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(60, 10), new Vector2(60, 10),
new Vector2(10, 400)); new Vector2(10, 400));
CorePath p = new CorePath(linerSegemnt, bazierSegment); ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
using (Image image = new Image(500, 500)) using (Image image = new Image(500, 500))
{ {
@ -82,7 +82,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPath(color, 10, p) .Draw(color, 10, p)
.Save(output); .Save(output);
} }

12
tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs

@ -37,7 +37,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -87,7 +87,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPolygon(Color.HotPink, 5, new ComplexPolygon(simplePath, hole1)) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -131,7 +131,7 @@ namespace ImageSharp.Tests.Drawing
new Vector2(37, 85), new Vector2(37, 85),
new Vector2(130, 40), new Vector2(130, 40),
new Vector2(65, 137)); new Vector2(65, 137));
var clipped = simplePath.Clip(hole1);
using (Image image = new Image(500, 500)) using (Image image = new Image(500, 500))
{ {
@ -139,7 +139,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPolygon(Color.HotPink, 5, clipped) .Draw(Color.HotPink, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
@ -185,7 +185,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPolygon(Pens.Dash(Color.HotPink, 5), new ComplexPolygon(simplePath, hole1)) .Draw(Pens.Dash(Color.HotPink, 5), simplePath.Clip(hole1))
.Save(output); .Save(output);
} }
} }
@ -213,7 +213,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .BackgroundColor(Color.Blue)
.DrawPolygon(color, 5, new ComplexPolygon(simplePath, hole1)) .Draw(color, 5, simplePath.Clip(hole1))
.Save(output); .Save(output);
} }

2
tests/ImageSharp.Tests/Drawing/PolygonTests.cs

@ -97,7 +97,7 @@ namespace ImageSharp.Tests.Drawing
{ {
image image
.BackgroundColor(Color.Blue) .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); .Save(output);
} }

2
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[11, 11]);
Assert.Equal(Color.HotPink, sourcePixels[200, 150]); Assert.Equal(Color.HotPink, sourcePixels[199, 150]);
Assert.Equal(Color.HotPink, sourcePixels[50, 50]); Assert.Equal(Color.HotPink, sourcePixels[50, 50]);

24
tests/ImageSharp.Tests/project.json

@ -21,34 +21,30 @@
}, },
"dependencies": { "dependencies": {
"ImageSharp": { "ImageSharp": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"xunit": "2.2.0-*", "xunit": "2.2.0-*",
"dotnet-test-xunit": "2.2.0-*", "dotnet-test-xunit": "2.2.0-*",
"ImageSharp.Drawing": { "ImageSharp.Drawing": {
"target": "project", "target": "project"
"version": "1.0.0-*" },
"ImageSharp.Drawing.Paths": {
"target": "project"
}, },
"ImageSharp.Formats.Png": { "ImageSharp.Formats.Png": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Jpeg": { "ImageSharp.Formats.Jpeg": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Bmp": { "ImageSharp.Formats.Bmp": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Formats.Gif": { "ImageSharp.Formats.Gif": {
"target": "project", "target": "project"
"version": "1.0.0-*"
}, },
"ImageSharp.Processing": { "ImageSharp.Processing": {
"target": "project", "target": "project"
"version": "1.0.0-*"
} }
}, },
"frameworks": { "frameworks": {

Loading…
Cancel
Save