Browse Source

ImageSharp.Drawing compiles

af/merge-core
Anton Firszov 7 years ago
parent
commit
6672741c45
  1. 10
      src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs
  2. 61
      src/ImageSharp.Drawing/Processing/DrawBezierExtensions.cs
  3. 61
      src/ImageSharp.Drawing/Processing/DrawLineExtensions.cs
  4. 57
      src/ImageSharp.Drawing/Processing/DrawPathCollectionExtensions.cs
  5. 44
      src/ImageSharp.Drawing/Processing/DrawPathExtensions.cs
  6. 61
      src/ImageSharp.Drawing/Processing/DrawPolygonExtensions.cs
  7. 58
      src/ImageSharp.Drawing/Processing/DrawRectangleExtensions.cs
  8. 94
      src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs
  9. 21
      src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs
  10. 36
      src/ImageSharp.Drawing/Processing/FillPathBuilderExtensions.cs
  11. 36
      src/ImageSharp.Drawing/Processing/FillPathCollectionExtensions.cs
  12. 28
      src/ImageSharp.Drawing/Processing/FillPathExtensions.cs
  13. 38
      src/ImageSharp.Drawing/Processing/FillPolygonExtensions.cs
  14. 34
      src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs
  15. 52
      src/ImageSharp.Drawing/Processing/FillRegionExtensions.cs
  16. 38
      src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs
  17. 19
      src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs
  18. 7
      src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs
  19. 22
      src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs
  20. 1
      src/ImageSharp/GraphicsOptions.cs

10
src/ImageSharp.Drawing/Processing/ColorStop{TPixel}.cs

@ -10,17 +10,15 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// A struct that defines a single color stop. /// A struct that defines a single color stop.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
[DebuggerDisplay("ColorStop({Ratio} -> {Color}")] [DebuggerDisplay("ColorStop({Ratio} -> {Color}")]
public struct ColorStop<TPixel> public readonly struct ColorStop
where TPixel : struct, IPixel<TPixel>
{ {
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="ColorStop{TPixel}" /> struct. /// Initializes a new instance of the <see cref="ColorStop" /> struct.
/// </summary> /// </summary>
/// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the Gradient.</param> /// <param name="ratio">Where should it be? 0 is at the start, 1 at the end of the Gradient.</param>
/// <param name="color">What color should be used at that point?</param> /// <param name="color">What color should be used at that point?</param>
public ColorStop(float ratio, TPixel color) public ColorStop(float ratio, in Color color)
{ {
this.Ratio = ratio; this.Ratio = ratio;
this.Color = color; this.Color = color;
@ -34,6 +32,6 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Gets the color to be used. /// Gets the color to be used.
/// </summary> /// </summary>
public TPixel Color { get; } public Color Color { get; }
} }
} }

61
src/ImageSharp.Drawing/Processing/DrawBezierExtensions.cs

@ -15,80 +15,93 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); GraphicsOptions options,
IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(options, new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IBrush brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points))); IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(new Pen(brush, thickness), new Path(new CubicBezierLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.DrawBeziers(new SolidBrush(color), thickness, points); Color color,
float thickness,
params PointF[] points) =>
source.DrawBeziers(new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush /// Draws the provided points as an open Bezier path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.DrawBeziers(options, new SolidBrush(color), thickness, points); GraphicsOptions options,
Color color,
float thickness,
params PointF[] points) =>
source.DrawBeziers(options, new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path with the supplied pen /// Draws the provided points as an open Bezier path with the supplied pen
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, GraphicsOptions options, IPen pen, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.Draw(options, pen, new Path(new CubicBezierLineSegment(points))); GraphicsOptions options,
IPen pen,
params PointF[] points) =>
source.Draw(options, pen, new Path(new CubicBezierLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided points as an open Bezier path with the supplied pen /// Draws the provided points as an open Bezier path with the supplied pen
/// </summary> /// </summary>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext DrawBeziers(this IImageProcessingContext source, IPen pen, params PointF[] points) public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
=> source.Draw(pen, new Path(new CubicBezierLineSegment(points))); IPen pen,
params PointF[] points) =>
source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
} }
} }

61
src/ImageSharp.Drawing/Processing/DrawLineExtensions.cs

@ -15,80 +15,93 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points))); GraphicsOptions options,
IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(options, new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points))); IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(new Pen(brush, thickness), new Path(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawLines(new SolidBrush<TPixel>(color), thickness, points); Color color,
float thickness,
params PointF[] points) =>
source.DrawLines(new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush /// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>> /// <returns>The <see cref="Image{TPixel}"/>.</returns>>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawLines(options, new SolidBrush<TPixel>(color), thickness, points); GraphicsOptions options,
Color color,
float thickness,
params PointF[] points) =>
source.DrawLines(options, new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen /// Draws the provided Points as an open Linear path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IPen<TPixel> pen, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, pen, new Path(new LinearLineSegment(points))); GraphicsOptions options,
IPen pen,
params PointF[] points) =>
source.Draw(options, pen, new Path(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen /// Draws the provided Points as an open Linear path with the supplied pen
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, params PointF[] points) public static IImageProcessingContext DrawLines(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(pen, new Path(new LinearLineSegment(points))); IPen pen,
params PointF[] points) =>
source.Draw(pen, new Path(new LinearLineSegment(points)));
} }
} }

57
src/ImageSharp.Drawing/Processing/DrawPathCollectionExtensions.cs

@ -14,14 +14,16 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IPen<TPixel> pen, IPathCollection paths) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
GraphicsOptions options,
IPen pen,
IPathCollection paths)
{ {
foreach (IPath path in paths) foreach (IPath path in paths)
{ {
@ -34,67 +36,76 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPathCollection paths) public static IImageProcessingContext
where TPixel : struct, IPixel<TPixel> Draw(this IImageProcessingContext source, IPen pen, IPathCollection paths) =>
=> source.Draw(GraphicsOptions.Default, pen, paths); source.Draw(GraphicsOptions.Default, pen, paths);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="paths">The shapes.</param> /// <param name="paths">The shapes.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, float thickness, IPathCollection paths) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new Pen<TPixel>(brush, thickness), paths); GraphicsOptions options,
IBrush brush,
float thickness,
IPathCollection paths) =>
source.Draw(options, new Pen(brush, thickness), paths);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPathCollection paths) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new Pen<TPixel>(brush, thickness), paths); IBrush brush,
float thickness,
IPathCollection paths) =>
source.Draw(new Pen(brush, thickness), paths);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, float thickness, IPathCollection paths) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new SolidBrush<TPixel>(color), thickness, paths); GraphicsOptions options,
Color color,
float thickness,
IPathCollection paths) =>
source.Draw(options, new SolidBrush(color), thickness, paths);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPathCollection paths) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new SolidBrush<TPixel>(color), thickness, paths); Color color,
float thickness,
IPathCollection paths) =>
source.Draw(new SolidBrush(color), thickness, paths);
} }
} }

44
src/ImageSharp.Drawing/Processing/DrawPathExtensions.cs

@ -15,80 +15,80 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IPen<TPixel> pen, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IPen pen, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(options, pen.StrokeFill, new ShapePath(path, pen)); => source.Fill(options, pen.StrokeFill, new ShapePath(path, pen));
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided pen. /// Draws the outline of the polygon with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Draw(GraphicsOptions.Default, pen, path); => source.Draw(GraphicsOptions.Default, pen, path);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The shape.</param> /// <param name="path">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, float thickness, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Draw(options, new Pen<TPixel>(brush, thickness), path); => source.Draw(options, new Pen(brush, thickness), path);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, IBrush brush, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), path); => source.Draw(new Pen(brush, thickness), path);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, float thickness, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, GraphicsOptions options, Color color, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Draw(options, new SolidBrush<TPixel>(color), thickness, path); => source.Draw(options, new SolidBrush(color), thickness, path);
/// <summary> /// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness. /// Draws the outline of the polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPath path) public static IImageProcessingContext Draw(this IImageProcessingContext source, Color color, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, path); => source.Draw(new SolidBrush(color), thickness, path);
} }
} }

61
src/ImageSharp.Drawing/Processing/DrawPolygonExtensions.cs

@ -15,80 +15,93 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points))); GraphicsOptions options,
IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(options, new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points))); IBrush brush,
float thickness,
params PointF[] points) =>
source.Draw(new Pen(brush, thickness), new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points); Color color,
float thickness,
params PointF[] points) =>
source.DrawPolygon(new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness. /// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param> /// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, float thickness, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawPolygon(options, new SolidBrush<TPixel>(color), thickness, points); GraphicsOptions options,
Color color,
float thickness,
params PointF[] points) =>
source.DrawPolygon(options, new SolidBrush(color), thickness, points);
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points))); IPen pen,
params PointF[] points) =>
source.Draw(GraphicsOptions.Default, pen, new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen. /// Draws the provided Points as a closed Linear Polygon with the provided Pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="pen">The pen.</param> /// <param name="pen">The pen.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IPen<TPixel> pen, params PointF[] points) public static IImageProcessingContext DrawPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, pen, new Polygon(new LinearLineSegment(points))); GraphicsOptions options,
IPen pen,
params PointF[] points) =>
source.Draw(options, pen, new Polygon(new LinearLineSegment(points)));
} }
} }

58
src/ImageSharp.Drawing/Processing/DrawRectangleExtensions.cs

@ -15,80 +15,90 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided pen. /// Draws the outline of the rectangle with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IPen<TPixel> pen, RectangleF shape) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, pen, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height)); GraphicsOptions options,
IPen pen,
RectangleF shape) =>
source.Draw(options, pen, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided pen. /// Draws the outline of the rectangle with the provided pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, RectangleF shape) public static IImageProcessingContext Draw(this IImageProcessingContext source, IPen pen, RectangleF shape) =>
where TPixel : struct, IPixel<TPixel> source.Draw(GraphicsOptions.Default, pen, shape);
=> source.Draw(GraphicsOptions.Default, pen, shape);
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness. /// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, float thickness, RectangleF shape) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new Pen<TPixel>(brush, thickness), shape); GraphicsOptions options,
IBrush brush,
float thickness,
RectangleF shape) =>
source.Draw(options, new Pen(brush, thickness), shape);
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness. /// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, RectangleF shape) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new Pen<TPixel>(brush, thickness), shape); IBrush brush,
float thickness,
RectangleF shape) =>
source.Draw(new Pen(brush, thickness), shape);
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness. /// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, float thickness, RectangleF shape) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(options, new SolidBrush<TPixel>(color), thickness, shape); GraphicsOptions options,
Color color,
float thickness,
RectangleF shape) =>
source.Draw(options, new SolidBrush(color), thickness, shape);
/// <summary> /// <summary>
/// Draws the outline of the rectangle with the provided brush at the provided thickness. /// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, RectangleF shape) public static IImageProcessingContext Draw(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Draw(new SolidBrush<TPixel>(color), thickness, shape); Color color,
float thickness,
RectangleF shape) =>
source.Draw(new SolidBrush(color), thickness, shape);
} }
} }

94
src/ImageSharp.Drawing/Processing/DrawTextExtensions.cs

@ -16,7 +16,6 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -25,14 +24,17 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(TextGraphicsOptions.Default, text, font, color, location); string text,
Font font,
Color color,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, color, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
@ -42,14 +44,18 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, TextGraphicsOptions options, string text, Font font, TPixel color, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(options, text, font, Brushes.Solid(color), null, location); TextGraphicsOptions options,
string text,
Font font,
Color color,
PointF location) =>
source.DrawText(options, text, font, Brushes.Solid(color), null, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -58,14 +64,17 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(TextGraphicsOptions.Default, text, font, brush, location); string text,
Font font,
IBrush brush,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush. /// Draws the text onto the the image filled via the brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
@ -75,14 +84,18 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, TextGraphicsOptions options, string text, Font font, IBrush<TPixel> brush, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(options, text, font, brush, null, location); TextGraphicsOptions options,
string text,
Font font,
IBrush brush,
PointF location) =>
source.DrawText(options, text, font, brush, null, location);
/// <summary> /// <summary>
/// Draws the text onto the the image outlined via the pen. /// Draws the text onto the the image outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -91,14 +104,17 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(TextGraphicsOptions.Default, text, font, pen, location); string text,
Font font,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, pen, location);
/// <summary> /// <summary>
/// Draws the text onto the the image outlined via the pen. /// Draws the text onto the the image outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
@ -108,14 +124,18 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, TextGraphicsOptions options, string text, Font font, IPen<TPixel> pen, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(options, text, font, null, pen, location); TextGraphicsOptions options,
string text,
Font font,
IPen pen,
PointF location) =>
source.DrawText(options, text, font, null, pen, location);
/// <summary> /// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen. /// Draws the text onto the the image filled via the brush then outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
/// <param name="font">The font.</param> /// <param name="font">The font.</param>
@ -125,14 +145,18 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location); string text,
Font font,
IBrush brush,
IPen pen,
PointF location) =>
source.DrawText(TextGraphicsOptions.Default, text, font, brush, pen, location);
/// <summary> /// <summary>
/// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen. /// Draws the text using the default resolution of <value>72dpi</value> onto the the image filled via the brush then outlined via the pen.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="text">The text.</param> /// <param name="text">The text.</param>
@ -143,8 +167,14 @@ namespace SixLabors.ImageSharp.Processing
/// <returns> /// <returns>
/// The <see cref="Image{TPixel}" />. /// The <see cref="Image{TPixel}" />.
/// </returns> /// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, TextGraphicsOptions options, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location) public static IImageProcessingContext DrawText(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.ApplyProcessor(new DrawTextProcessor<TPixel>(options, text, font, brush, pen, location)); TextGraphicsOptions options,
string text,
Font font,
IBrush brush,
IPen pen,
PointF location) =>
source.ApplyProcessor(new DrawTextProcessor(options, text, font, brush, pen, location));
} }
} }

21
src/ImageSharp.Drawing/Processing/EllipticGradientBrush{TPixel}.cs

@ -14,9 +14,7 @@ namespace SixLabors.ImageSharp.Processing
/// a point on the longest extension of the ellipse and /// a point on the longest extension of the ellipse and
/// the ratio between longest and shortest extension. /// the ratio between longest and shortest extension.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The Pixel format that is used.</typeparam> public sealed class EllipticGradientBrush : GradientBrushBase
public sealed class EllipticGradientBrush<TPixel> : GradientBrushBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF center; private readonly PointF center;
@ -24,7 +22,7 @@ namespace SixLabors.ImageSharp.Processing
private readonly float axisRatio; private readonly float axisRatio;
/// <inheritdoc cref="GradientBrushBase{TPixel}" /> /// <inheritdoc cref="GradientBrushBase" />
/// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param> /// <param name="center">The center of the elliptical gradient and 0 for the color stops.</param>
/// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param> /// <param name="referenceAxisEnd">The end point of the reference axis of the ellipse.</param>
/// <param name="axisRatio"> /// <param name="axisRatio">
@ -39,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing
PointF referenceAxisEnd, PointF referenceAxisEnd,
float axisRatio, float axisRatio,
GradientRepetitionMode repetitionMode, GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops) params ColorStop[] colorStops)
: base(repetitionMode, colorStops) : base(repetitionMode, colorStops)
{ {
this.center = center; this.center = center;
@ -47,12 +45,12 @@ namespace SixLabors.ImageSharp.Processing
this.axisRatio = axisRatio; this.axisRatio = axisRatio;
} }
/// <inheritdoc cref="CreateApplicator" /> /// <inheritdoc />
public override BrushApplicator<TPixel> CreateApplicator( public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
RectangleF region, RectangleF region,
GraphicsOptions options) => GraphicsOptions options) =>
new RadialGradientBrushApplicator( new RadialGradientBrushApplicator<TPixel>(
source, source,
options, options,
this.center, this.center,
@ -62,7 +60,8 @@ namespace SixLabors.ImageSharp.Processing
this.RepetitionMode); this.RepetitionMode);
/// <inheritdoc /> /// <inheritdoc />
private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF center; private readonly PointF center;
@ -85,7 +84,7 @@ namespace SixLabors.ImageSharp.Processing
private readonly float referenceRadiusSquared; private readonly float referenceRadiusSquared;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RadialGradientBrushApplicator" /> class. /// Initializes a new instance of the <see cref="RadialGradientBrushApplicator{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="target">The target image</param> /// <param name="target">The target image</param>
/// <param name="options">The options</param> /// <param name="options">The options</param>
@ -102,7 +101,7 @@ namespace SixLabors.ImageSharp.Processing
PointF center, PointF center,
PointF referenceAxisEnd, PointF referenceAxisEnd,
float axisRatio, float axisRatio,
ColorStop<TPixel>[] colorStops, ColorStop[] colorStops,
GradientRepetitionMode repetitionMode) GradientRepetitionMode repetitionMode)
: base(target, options, colorStops, repetitionMode) : base(target, options, colorStops, repetitionMode)
{ {

36
src/ImageSharp.Drawing/Processing/FillPathBuilderExtensions.cs

@ -15,14 +15,16 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The shape.</param> /// <param name="path">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, Action<PathBuilder> path) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
GraphicsOptions options,
IBrush brush,
Action<PathBuilder> path)
{ {
var pb = new PathBuilder(); var pb = new PathBuilder();
path(pb); path(pb);
@ -33,38 +35,42 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Action<PathBuilder> path) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(GraphicsOptions.Default, brush, path); IBrush brush,
Action<PathBuilder> path) =>
source.Fill(GraphicsOptions.Default, brush, path);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, Action<PathBuilder> path) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, new SolidBrush<TPixel>(color), path); GraphicsOptions options,
Color color,
Action<PathBuilder> path) =>
source.Fill(options, new SolidBrush(color), path);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Action<PathBuilder> path) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(new SolidBrush<TPixel>(color), path); Color color,
Action<PathBuilder> path) =>
source.Fill(new SolidBrush(color), path);
} }
} }

36
src/ImageSharp.Drawing/Processing/FillPathCollectionExtensions.cs

@ -14,14 +14,16 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="paths">The shapes.</param> /// <param name="paths">The shapes.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, IPathCollection paths) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
GraphicsOptions options,
IBrush brush,
IPathCollection paths)
{ {
foreach (IPath s in paths) foreach (IPath s in paths)
{ {
@ -34,38 +36,42 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPathCollection paths) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(GraphicsOptions.Default, brush, paths); IBrush brush,
IPathCollection paths) =>
source.Fill(GraphicsOptions.Default, brush, paths);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, IPathCollection paths) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, new SolidBrush<TPixel>(color), paths); GraphicsOptions options,
Color color,
IPathCollection paths) =>
source.Fill(options, new SolidBrush(color), paths);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="paths">The paths.</param> /// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPathCollection paths) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(new SolidBrush<TPixel>(color), paths); Color color,
IPathCollection paths) =>
source.Fill(new SolidBrush(color), paths);
} }
} }

28
src/ImageSharp.Drawing/Processing/FillPathExtensions.cs

@ -15,51 +15,51 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The shape.</param> /// <param name="path">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, IPath path) public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(options, brush, new ShapeRegion(path)); => source.Fill(options, brush, new ShapeRegion(path));
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush. /// Flood fills the image in the shape of the provided polygon with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path) public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path)); => source.Fill(GraphicsOptions.Default, brush, new ShapeRegion(path));
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, IPath path) public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, Color color, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(options, new SolidBrush<TPixel>(color), path); => source.Fill(options, new SolidBrush(color), path);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.. /// Flood fills the image in the shape of the provided polygon with the specified brush..
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="path">The path.</param> /// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPath path) public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color, IPath path)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path); => source.Fill(new SolidBrush(color), path);
} }
} }

38
src/ImageSharp.Drawing/Processing/FillPolygonExtensions.cs

@ -15,51 +15,57 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, params PointF[] points) public static IImageProcessingContext FillPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, brush, new Polygon(new LinearLineSegment(points))); GraphicsOptions options,
IBrush brush,
params PointF[] points) =>
source.Fill(options, brush, new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, params PointF[] points) public static IImageProcessingContext FillPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(brush, new Polygon(new LinearLineSegment(points))); IBrush brush,
params PointF[] points) =>
source.Fill(brush, new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, params PointF[] points) public static IImageProcessingContext FillPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points))); GraphicsOptions options,
Color color,
params PointF[] points) =>
source.Fill(options, new SolidBrush(color), new Polygon(new LinearLineSegment(points)));
/// <summary> /// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points /// Flood fills the image in the shape of a Linear polygon described by the points
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="points">The points.</param> /// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, params PointF[] points) public static IImageProcessingContext FillPolygon(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points))); Color color,
params PointF[] points) =>
source.Fill(new SolidBrush(color), new Polygon(new LinearLineSegment(points)));
} }
} }

34
src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs

@ -15,51 +15,53 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush. /// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, RectangleF shape) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height)); GraphicsOptions options,
IBrush brush,
RectangleF shape) =>
source.Fill(options, brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush. /// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, RectangleF shape) public static IImageProcessingContext
where TPixel : struct, IPixel<TPixel> Fill(this IImageProcessingContext source, IBrush brush, RectangleF shape) =>
=> source.Fill(brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height)); source.Fill(brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush. /// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, RectangleF shape) public static IImageProcessingContext Fill(
where TPixel : struct, IPixel<TPixel> this IImageProcessingContext source,
=> source.Fill(options, new SolidBrush<TPixel>(color), shape); GraphicsOptions options,
Color color,
RectangleF shape) =>
source.Fill(options, new SolidBrush(color), shape);
/// <summary> /// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush. /// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <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 <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape) public static IImageProcessingContext
where TPixel : struct, IPixel<TPixel> Fill(this IImageProcessingContext source, Color color, RectangleF shape) =>
=> source.Fill(new SolidBrush<TPixel>(color), shape); source.Fill(new SolidBrush(color), shape);
} }
} }

52
src/ImageSharp.Drawing/Processing/FillRegionExtensions.cs

@ -15,85 +15,85 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Flood fills the image with the specified brush. /// Flood fills the image with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param> /// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush) public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(GraphicsOptions.Default, brush); => source.Fill(GraphicsOptions.Default, brush);
/// <summary> /// <summary>
/// Flood fills the image with the specified color. /// Flood fills the image with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color) public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color)); => source.Fill(new SolidBrush(color));
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified brush. /// Flood fills the image with in the region with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region) public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(GraphicsOptions.Default, brush, region); => source.Fill(GraphicsOptions.Default, brush, region);
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified color. /// Flood fills the image with in the region with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, Region region) public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, Color color, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(options, new SolidBrush<TPixel>(color), region); => source.Fill(options, new SolidBrush(color), region);
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified color. /// Flood fills the image with in the region with the specified color.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param> /// <param name="color">The color.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region) public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), region); => source.Fill(new SolidBrush(color), region);
/// <summary> /// <summary>
/// Flood fills the image with in the region with the specified brush. /// Flood fills the image with in the region with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
/// <param name="region">The region.</param> /// <param name="region">The region.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, Region region) public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options)); => source.ApplyProcessor(new FillRegionProcessor(brush, region, options));
/// <summary> /// <summary>
/// Flood fills the image with the specified brush. /// Flood fills the image with the specified brush.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param> /// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param> /// <param name="options">The graphics options.</param>
/// <param name="brush">The details how to fill the region of interest.</param> /// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns> /// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush) public static IImageProcessingContext Fill(this IImageProcessingContext source, GraphicsOptions options, IBrush brush)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillProcessor<TPixel>(brush, options)); => source.ApplyProcessor(new FillProcessor(brush, options));
} }
} }

38
src/ImageSharp.Drawing/Processing/GradientBrushBase{TPixel}.cs

@ -13,16 +13,14 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Base class for Gradient brushes /// Base class for Gradient brushes
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam> public abstract class GradientBrushBase : IBrush
public abstract class GradientBrushBase<TPixel> : IBrush<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
/// <inheritdoc cref="IBrush{TPixel}"/> /// <inheritdoc cref="IBrush"/>
/// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param> /// <param name="repetitionMode">Defines how the colors are repeated beyond the interval [0..1]</param>
/// <param name="colorStops">The gradient colors.</param> /// <param name="colorStops">The gradient colors.</param>
protected GradientBrushBase( protected GradientBrushBase(
GradientRepetitionMode repetitionMode, GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops) params ColorStop[] colorStops)
{ {
this.RepetitionMode = repetitionMode; this.RepetitionMode = repetitionMode;
this.ColorStops = colorStops; this.ColorStops = colorStops;
@ -36,25 +34,27 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// Gets the list of color stops for this gradient. /// Gets the list of color stops for this gradient.
/// </summary> /// </summary>
protected ColorStop<TPixel>[] ColorStops { get; } protected ColorStop[] ColorStops { get; }
/// <inheritdoc cref="IBrush{TPixel}" /> /// <inheritdoc />
public abstract BrushApplicator<TPixel> CreateApplicator( public abstract BrushApplicator<TPixel> CreateApplicator<TPixel>(
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
RectangleF region, RectangleF region,
GraphicsOptions options); GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>;
/// <summary> /// <summary>
/// Base class for gradient brush applicators /// Base class for gradient brush applicators
/// </summary> /// </summary>
protected abstract class GradientBrushApplicatorBase : BrushApplicator<TPixel> protected abstract class GradientBrushApplicatorBase<TPixel> : BrushApplicator<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly ColorStop<TPixel>[] colorStops; private readonly ColorStop[] colorStops;
private readonly GradientRepetitionMode repetitionMode; private readonly GradientRepetitionMode repetitionMode;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="GradientBrushApplicatorBase"/> class. /// Initializes a new instance of the <see cref="GradientBrushApplicatorBase{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="target">The target.</param> /// <param name="target">The target.</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
@ -63,7 +63,7 @@ namespace SixLabors.ImageSharp.Processing
protected GradientBrushApplicatorBase( protected GradientBrushApplicatorBase(
ImageFrame<TPixel> target, ImageFrame<TPixel> target,
GraphicsOptions options, GraphicsOptions options,
ColorStop<TPixel>[] colorStops, ColorStop[] colorStops,
GradientRepetitionMode repetitionMode) GradientRepetitionMode repetitionMode)
: base(target, options) : base(target, options)
{ {
@ -111,11 +111,11 @@ namespace SixLabors.ImageSharp.Processing
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
(ColorStop<TPixel> from, ColorStop<TPixel> to) = this.GetGradientSegment(positionOnCompleteGradient); (ColorStop from, ColorStop to) = this.GetGradientSegment(positionOnCompleteGradient);
if (from.Color.Equals(to.Color)) if (from.Color.Equals(to.Color))
{ {
return from.Color; return from.Color.ToPixel<TPixel>();
} }
else else
{ {
@ -150,14 +150,14 @@ namespace SixLabors.ImageSharp.Processing
/// </returns> /// </returns>
protected abstract float PositionOnGradient(float x, float y); protected abstract float PositionOnGradient(float x, float y);
private (ColorStop<TPixel> from, ColorStop<TPixel> to) GetGradientSegment( private (ColorStop from, ColorStop to) GetGradientSegment(
float positionOnCompleteGradient) float positionOnCompleteGradient)
{ {
ColorStop<TPixel> localGradientFrom = this.colorStops[0]; ColorStop localGradientFrom = this.colorStops[0];
ColorStop<TPixel> localGradientTo = default; ColorStop localGradientTo = default;
// TODO: ensure colorStops has at least 2 items (technically 1 would be okay, but that's no gradient) // TODO: ensure colorStops has at least 2 items (technically 1 would be okay, but that's no gradient)
foreach (ColorStop<TPixel> colorStop in this.colorStops) foreach (ColorStop colorStop in this.colorStops)
{ {
localGradientTo = colorStop; localGradientTo = colorStop;

19
src/ImageSharp.Drawing/Processing/LinearGradientBrush{TPixel}.cs

@ -14,15 +14,15 @@ namespace SixLabors.ImageSharp.Processing
/// - a set of colors in relative distances to each other. /// - a set of colors in relative distances to each other.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam> /// <typeparam name="TPixel">The pixel format</typeparam>
public sealed class LinearGradientBrush<TPixel> : GradientBrushBase<TPixel> public sealed class LinearGradientBrush : GradientBrushBase
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF p1; private readonly PointF p1;
private readonly PointF p2; private readonly PointF p2;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LinearGradientBrush{TPixel}"/> class. /// Initializes a new instance of the <see cref="LinearGradientBrush"/> class.
/// </summary> /// </summary>
/// <param name="p1">Start point</param> /// <param name="p1">Start point</param>
/// <param name="p2">End point</param> /// <param name="p2">End point</param>
@ -32,7 +32,7 @@ namespace SixLabors.ImageSharp.Processing
PointF p1, PointF p1,
PointF p2, PointF p2,
GradientRepetitionMode repetitionMode, GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops) params ColorStop[] colorStops)
: base(repetitionMode, colorStops) : base(repetitionMode, colorStops)
{ {
this.p1 = p1; this.p1 = p1;
@ -40,13 +40,14 @@ namespace SixLabors.ImageSharp.Processing
} }
/// <inheritdoc /> /// <inheritdoc />
public override BrushApplicator<TPixel> CreateApplicator(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options) public override BrushApplicator<TPixel> CreateApplicator<TPixel>(ImageFrame<TPixel> source, RectangleF region, GraphicsOptions options)
=> new LinearGradientBrushApplicator(source, this.p1, this.p2, this.ColorStops, this.RepetitionMode, options); => new LinearGradientBrushApplicator<TPixel>(source, this.p1, this.p2, this.ColorStops, this.RepetitionMode, options);
/// <summary> /// <summary>
/// The linear gradient brush applicator. /// The linear gradient brush applicator.
/// </summary> /// </summary>
private sealed class LinearGradientBrushApplicator : GradientBrushApplicatorBase private sealed class LinearGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF start; private readonly PointF start;
@ -83,7 +84,7 @@ namespace SixLabors.ImageSharp.Processing
private readonly float length; private readonly float length;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="LinearGradientBrushApplicator" /> class. /// Initializes a new instance of the <see cref="LinearGradientBrushApplicator{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="source">The source</param> /// <param name="source">The source</param>
/// <param name="start">start point of the gradient</param> /// <param name="start">start point of the gradient</param>
@ -95,7 +96,7 @@ namespace SixLabors.ImageSharp.Processing
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
PointF start, PointF start,
PointF end, PointF end,
ColorStop<TPixel>[] colorStops, ColorStop[] colorStops,
GradientRepetitionMode repetitionMode, GradientRepetitionMode repetitionMode,
GraphicsOptions options) GraphicsOptions options)
: base(source, options, colorStops, repetitionMode) : base(source, options, colorStops, repetitionMode)

7
src/ImageSharp.Drawing/Processing/PatternBrush{TPixel}.cs

@ -34,7 +34,6 @@ namespace SixLabors.ImageSharp.Processing
/// 0 /// 0
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <typeparam name="TPixel">The pixel format.</typeparam>
public class PatternBrush : IBrush public class PatternBrush : IBrush
{ {
/// <summary> /// <summary>
@ -44,7 +43,7 @@ namespace SixLabors.ImageSharp.Processing
private readonly DenseMatrix<Vector4> patternVector; private readonly DenseMatrix<Vector4> patternVector;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class. /// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary> /// </summary>
/// <param name="foreColor">Color of the fore.</param> /// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param> /// <param name="backColor">Color of the back.</param>
@ -55,7 +54,7 @@ namespace SixLabors.ImageSharp.Processing
} }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class. /// Initializes a new instance of the <see cref="PatternBrush"/> class.
/// </summary> /// </summary>
/// <param name="foreColor">Color of the fore.</param> /// <param name="foreColor">Color of the fore.</param>
/// <param name="backColor">Color of the back.</param> /// <param name="backColor">Color of the back.</param>
@ -85,7 +84,7 @@ namespace SixLabors.ImageSharp.Processing
/// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class. /// Initializes a new instance of the <see cref="PatternBrush{TPixel}"/> class.
/// </summary> /// </summary>
/// <param name="brush">The brush.</param> /// <param name="brush">The brush.</param>
internal PatternBrush(PatternBrush<Color> brush) internal PatternBrush(PatternBrush brush)
{ {
this.pattern = brush.pattern; this.pattern = brush.pattern;
this.patternVector = brush.patternVector; this.patternVector = brush.patternVector;

22
src/ImageSharp.Drawing/Processing/RadialGradientBrush{TPixel}.cs

@ -11,15 +11,14 @@ namespace SixLabors.ImageSharp.Processing
/// <summary> /// <summary>
/// A Circular Gradient Brush, defined by center point and radius. /// A Circular Gradient Brush, defined by center point and radius.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam> public sealed class RadialGradientBrush : GradientBrushBase
public sealed class RadialGradientBrush<TPixel> : GradientBrushBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF center; private readonly PointF center;
private readonly float radius; private readonly float radius;
/// <inheritdoc cref="GradientBrushBase{TPixel}" /> /// <inheritdoc cref="GradientBrushBase" />
/// <param name="center">The center of the circular gradient and 0 for the color stops.</param> /// <param name="center">The center of the circular gradient and 0 for the color stops.</param>
/// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param> /// <param name="radius">The radius of the circular gradient and 1 for the color stops.</param>
/// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param> /// <param name="repetitionMode">Defines how the colors in the gradient are repeated.</param>
@ -28,19 +27,19 @@ namespace SixLabors.ImageSharp.Processing
PointF center, PointF center,
float radius, float radius,
GradientRepetitionMode repetitionMode, GradientRepetitionMode repetitionMode,
params ColorStop<TPixel>[] colorStops) params ColorStop[] colorStops)
: base(repetitionMode, colorStops) : base(repetitionMode, colorStops)
{ {
this.center = center; this.center = center;
this.radius = radius; this.radius = radius;
} }
/// <inheritdoc cref="CreateApplicator" /> /// <inheritdoc />
public override BrushApplicator<TPixel> CreateApplicator( public override BrushApplicator<TPixel> CreateApplicator<TPixel>(
ImageFrame<TPixel> source, ImageFrame<TPixel> source,
RectangleF region, RectangleF region,
GraphicsOptions options) => GraphicsOptions options) =>
new RadialGradientBrushApplicator( new RadialGradientBrushApplicator<TPixel>(
source, source,
options, options,
this.center, this.center,
@ -49,14 +48,15 @@ namespace SixLabors.ImageSharp.Processing
this.RepetitionMode); this.RepetitionMode);
/// <inheritdoc /> /// <inheritdoc />
private sealed class RadialGradientBrushApplicator : GradientBrushApplicatorBase private sealed class RadialGradientBrushApplicator<TPixel> : GradientBrushApplicatorBase<TPixel>
where TPixel : struct, IPixel<TPixel>
{ {
private readonly PointF center; private readonly PointF center;
private readonly float radius; private readonly float radius;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="RadialGradientBrushApplicator" /> class. /// Initializes a new instance of the <see cref="RadialGradientBrushApplicator{TPixel}" /> class.
/// </summary> /// </summary>
/// <param name="target">The target image</param> /// <param name="target">The target image</param>
/// <param name="options">The options.</param> /// <param name="options">The options.</param>
@ -69,7 +69,7 @@ namespace SixLabors.ImageSharp.Processing
GraphicsOptions options, GraphicsOptions options,
PointF center, PointF center,
float radius, float radius,
ColorStop<TPixel>[] colorStops, ColorStop[] colorStops,
GradientRepetitionMode repetitionMode) GradientRepetitionMode repetitionMode)
: base(target, options, colorStops, repetitionMode) : base(target, options, colorStops, repetitionMode)
{ {

1
src/ImageSharp/GraphicsOptions.cs

@ -141,7 +141,6 @@ namespace SixLabors.ImageSharp
/// <summary> /// <summary>
/// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings. /// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings.
/// </summary> /// </summary>
/// <typeparam name="TPixel">The pixel format</typeparam>
/// <param name="color">the color</param> /// <param name="color">the color</param>
/// <returns>true if the color can be considered opaque</returns> /// <returns>true if the color can be considered opaque</returns>
/// <remarks> /// <remarks>

Loading…
Cancel
Save