Browse Source

Combine drawing methods to new Overlays namespace.

pull/486/head
James Jackson-South 8 years ago
parent
commit
fb666df341
  1. 1
      src/ImageSharp.Drawing/Drawing/Brushes/IBrush.cs
  2. 2
      src/ImageSharp.Drawing/Drawing/Brushes/RecolorBrush{TPixel}.cs
  3. 1
      src/ImageSharp.Drawing/Drawing/Brushes/SolidBrush{TPixel}.cs
  4. 6
      src/ImageSharp.Drawing/Drawing/Pens/IPen.cs
  5. 11
      src/ImageSharp.Drawing/Drawing/Pens/Pens.cs
  6. 13
      src/ImageSharp.Drawing/Drawing/Pens/Pen{TPixel}.cs
  7. 13
      src/ImageSharp.Drawing/Primitives/ShapePath.cs
  8. 4
      src/ImageSharp.Drawing/Primitives/ShapeRegion.cs
  9. 55
      src/ImageSharp.Drawing/Processing/Overlays/DrawBezierExtensions.cs
  10. 66
      src/ImageSharp.Drawing/Processing/Overlays/DrawImageExtensions.cs
  11. 45
      src/ImageSharp.Drawing/Processing/Overlays/DrawLineExtensions.cs
  12. 40
      src/ImageSharp.Drawing/Processing/Overlays/DrawPathCollectionExtensions.cs
  13. 45
      src/ImageSharp.Drawing/Processing/Overlays/DrawPathExtensions.cs
  14. 47
      src/ImageSharp.Drawing/Processing/Overlays/DrawPolygonExtensions.cs
  15. 59
      src/ImageSharp.Drawing/Processing/Overlays/DrawRectangleExtensions.cs
  16. 35
      src/ImageSharp.Drawing/Processing/Overlays/FillPathBuilderExtensions.cs
  17. 34
      src/ImageSharp.Drawing/Processing/Overlays/FillPathCollectionExtensions.cs
  18. 35
      src/ImageSharp.Drawing/Processing/Overlays/FillPathExtensions.cs
  19. 36
      src/ImageSharp.Drawing/Processing/Overlays/FillPolygonExtensions.cs
  20. 37
      src/ImageSharp.Drawing/Processing/Overlays/FillRectangleExtensions.cs
  21. 88
      src/ImageSharp.Drawing/Processing/Overlays/FillRegionExtensions.cs
  22. 70
      src/ImageSharp.Drawing/Processing/Overlays/Processors/DrawImageProcessor.cs
  23. 54
      src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs
  24. 56
      src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs
  25. 7
      src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs
  26. 1
      src/ImageSharp/Formats/Jpeg/JpegEncoder.cs
  27. 4
      src/ImageSharp/Primitives/ValueSize.cs
  28. 6
      src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs
  29. 23
      src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs
  30. 4
      src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs
  31. 17
      tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs
  32. 2
      tests/ImageSharp.Benchmarks/Drawing/DrawLines.cs
  33. 17
      tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs
  34. 22
      tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs
  35. 19
      tests/ImageSharp.Benchmarks/Drawing/FillRectangle.cs
  36. 2
      tests/ImageSharp.Benchmarks/Drawing/FillWithPattern.cs
  37. 15
      tests/ImageSharp.Tests/Drawing/BeziersTests.cs
  38. 12
      tests/ImageSharp.Tests/Drawing/BlendedShapes.cs
  39. 1
      tests/ImageSharp.Tests/Drawing/DrawImageTest.cs
  40. 12
      tests/ImageSharp.Tests/Drawing/DrawPathTests.cs
  41. 2
      tests/ImageSharp.Tests/Drawing/FillPatternTests.cs
  42. 6
      tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
  43. 5
      tests/ImageSharp.Tests/Drawing/LineComplexPolygonTests.cs
  44. 5
      tests/ImageSharp.Tests/Drawing/LineTests.cs
  45. 26
      tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs
  46. 24
      tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs
  47. 29
      tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs
  48. 7
      tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs
  49. 2
      tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs
  50. 11
      tests/ImageSharp.Tests/Drawing/PolygonTests.cs
  51. 4
      tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs
  52. 5
      tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs
  53. 5
      tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs
  54. 7
      tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs
  55. 1
      tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs
  56. 3
      tests/ImageSharp.Tests/Drawing/Text/DrawText.cs
  57. 2
      tests/ImageSharp.Tests/Drawing/Text/OutputText.cs
  58. 2
      tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs
  59. 10
      tests/ImageSharp.Tests/Issues/Issue412.cs
  60. 11
      tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs
  61. 1
      tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs

1
src/ImageSharp.Drawing/Drawing/Brushes/IBrush.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Primitives;

2
src/ImageSharp.Drawing/Drawing/Brushes/RecolorBrush{TPixel}.cs

@ -92,7 +92,7 @@ namespace SixLabors.ImageSharp.Drawing.Brushes
this.targetColor = targetColor.ToVector4();
this.targetColorPixel = targetColor;
// Lets hack a min max extreams for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
// Lets hack a min max extremes for a color space by letting the IPackedPixel clamp our values to something in the correct spaces :)
var maxColor = default(TPixel);
maxColor.PackFromVector4(new Vector4(float.MaxValue));
var minColor = default(TPixel);

1
src/ImageSharp.Drawing/Drawing/Brushes/SolidBrush{TPixel}.cs

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Drawing.Brushes.Processors;
using SixLabors.ImageSharp.Memory;

6
src/ImageSharp.Drawing/Drawing/Pens/IPen.cs

@ -1,8 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Pens
@ -21,7 +21,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Iterface represting the pattern and size of the stroke to apply with a Pen.
/// Interface representing the pattern and size of the stroke to apply with a Pen.
/// </summary>
public interface IPen
{
@ -33,6 +33,6 @@ namespace SixLabors.ImageSharp.Drawing.Pens
/// <summary>
/// Gets the stoke pattern.
/// </summary>
System.ReadOnlySpan<float> StrokePattern { get; }
ReadOnlySpan<float> StrokePattern { get; }
}
}

11
src/ImageSharp.Drawing/Drawing/Pens/Pens.cs

@ -7,14 +7,15 @@ using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Pens
{
/// <summary>
/// Common Pen styles
/// Contains a collection of common Pen styles
/// </summary>
public static class Pens
{
private static readonly float[] DashDotPattern = new[] { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = new[] { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = new[] { 1f, 1f };
private static readonly float[] DashedPattern = new[] { 3f, 1f };
private static readonly float[] DashDotPattern = { 3f, 1f, 1f, 1f };
private static readonly float[] DashDotDotPattern = { 3f, 1f, 1f, 1f, 1f, 1f };
private static readonly float[] DottedPattern = { 1f, 1f };
private static readonly float[] DashedPattern = { 3f, 1f };
internal static readonly float[] EmptyPattern = new float[0];
/// <summary>
/// Create a solid pen with out any drawing patterns

13
src/ImageSharp.Drawing/Drawing/Pens/Pen{TPixel}.cs

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing.Pens
@ -24,11 +22,10 @@ namespace SixLabors.ImageSharp.Drawing.Pens
public class Pen<TPixel> : IPen<TPixel>
where TPixel : struct, IPixel<TPixel>
{
private static readonly float[] EmptyPattern = new float[0];
private readonly float[] pattern;
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
@ -39,7 +36,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
@ -52,7 +49,7 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="color">The color.</param>
/// <param name="width">The width.</param>
@ -62,12 +59,12 @@ namespace SixLabors.ImageSharp.Drawing.Pens
}
/// <summary>
/// Initializes a new instance of the <see cref="ImageSharp.Drawing.Pens.Pen{TPixel}"/> class.
/// Initializes a new instance of the <see cref="Drawing.Pens.Pen{TPixel}"/> class.
/// </summary>
/// <param name="brush">The brush.</param>
/// <param name="width">The width.</param>
public Pen(IBrush<TPixel> brush, float width)
: this(brush, width, EmptyPattern)
: this(brush, width, Pens.EmptyPattern)
{
}

13
src/ImageSharp.Drawing/Processing/Paths/ShapePath.cs → src/ImageSharp.Drawing/Primitives/ShapePath.cs

@ -1,14 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Buffers;
using System.Numerics;
using SixLabors.ImageSharp.Memory;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// A mapping between a <see cref="IPath"/> and a region.
@ -20,10 +15,10 @@ namespace SixLabors.ImageSharp.Drawing
/// </summary>
/// <param name="shape">The shape.</param>
/// <param name="pen">The pen to apply to the shape.</param>
// SixLabors.shape willbe moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(IPath shape, Pens.IPen pen)
// TODO: SixLabors.shape will be moving to a Span/ReadOnlySpan based API shortly use ToArray for now.
public ShapePath(IPath shape, Drawing.Pens.IPen pen)
: base(shape.GenerateOutline(pen.StrokeWidth, pen.StrokePattern.ToArray()))
{
}
}
}
}

4
src/ImageSharp.Drawing/Processing/Paths/ShapeRegion.cs → src/ImageSharp.Drawing/Primitives/ShapeRegion.cs

@ -2,12 +2,10 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Primitives;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Primitives
{
/// <summary>
/// A mapping between a <see cref="IPath"/> and a region.

55
src/ImageSharp.Drawing/Processing/Paths/DrawBezierExtensions.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawBezierExtensions.cs

@ -1,24 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// EAdds extensions that allow the drawing of Bezier paths to the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of Bezier paths to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class DrawBezierExtensions
{
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -28,13 +25,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)), options);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -43,13 +38,11 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new CubicBezierLineSegment(points)));
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -58,13 +51,11 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -74,13 +65,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawBeziers(new SolidBrush<TPixel>(color), thickness, points, options);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -89,13 +78,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new CubicBezierLineSegment(points)), options);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -103,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawBeziers<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new CubicBezierLineSegment(points)));
}
}

66
src/ImageSharp.Drawing/Processing/Overlays/DrawImage.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawImageExtensions.cs

@ -1,34 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of images to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawImageExtensions
{
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options));
return source;
}
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
@ -39,11 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return DrawImage(source, image, Point.Empty, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -56,12 +35,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
options.BlenderMode = blender;
return DrawImage(source, image, Point.Empty, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, opacity, blender));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -74,7 +48,7 @@ namespace SixLabors.ImageSharp
public static IImageProcessingContext<TPixel> Blend<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return DrawImage(source, image, Point.Empty, options);
return source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, options));
}
/// <summary>
@ -88,11 +62,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, float opacity, Point location)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlendPercentage = opacity;
return source.DrawImage(image, location, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
@ -106,11 +76,19 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, PixelBlenderMode blender, float opacity, Point location)
where TPixel : struct, IPixel<TPixel>
{
GraphicsOptions options = GraphicsOptions.Default;
options.BlenderMode = blender;
options.BlendPercentage = opacity;
return source.DrawImage(image, location, options);
}
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, opacity, blender));
/// <summary>
/// Draws the given image together with the current one by blending their pixels.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The options containing the blend mode and opacity.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawImage<TPixel>(this IImageProcessingContext<TPixel> source, Image<TPixel> image, Point location, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new DrawImageProcessor<TPixel>(image, location, options));
}
}

45
src/ImageSharp.Drawing/Processing/Paths/DrawLines.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawLineExtensions.cs

@ -1,21 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of lines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawLineExtensions
{
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -28,10 +25,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -43,10 +38,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Path(new LinearLineSegment(points)));
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -58,10 +51,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawLines(new SolidBrush<TPixel>(color), thickness, points);
/// <summary>
/// Draws the provided Points as an open Linear path at the provided thickness with the supplied brush
@ -74,10 +65,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawLines(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawLines(new SolidBrush<TPixel>(color), thickness, points, options);
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
@ -89,10 +78,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as an open Linear path with the supplied pen
@ -103,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawLines<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Path(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Path(new LinearLineSegment(points)));
}
}

40
src/ImageSharp.Drawing/Processing/Paths/DrawPathCollection.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawPathCollectionExtensions.cs

@ -1,19 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of collections of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPathCollectionExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -44,10 +42,8 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, paths, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, paths, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -60,10 +56,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), paths, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -75,10 +69,8 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), paths);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -91,10 +83,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, paths, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -106,9 +96,7 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, paths);
}
}
}

45
src/ImageSharp.Drawing/Processing/Paths/DrawPath.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawPathExtensions.cs

@ -1,19 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPathExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -25,10 +24,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(pen.StrokeFill, new ShapePath(path, pen), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(pen.StrokeFill, new ShapePath(path, pen), options);
/// <summary>
/// Draws the outline of the polygon with the provided pen.
@ -39,10 +36,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, path, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, path, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -55,10 +50,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), path, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -70,10 +63,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), path);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -86,10 +77,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, path, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
@ -101,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, path);
}
}

47
src/ImageSharp.Drawing/Processing/Paths/DrawPolygon.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawPolygonExtensions.cs

@ -1,21 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of closed linear polygons to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawPolygonExtensions
{
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -28,10 +25,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -43,10 +38,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), new Polygon(new LinearLineSegment(points)));
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -58,10 +51,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided brush at the provided thickness.
@ -74,10 +65,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawPolygon(new SolidBrush<TPixel>(color), thickness, points, options);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
@ -88,10 +77,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Polygon(new LinearLineSegment(points)), GraphicsOptions.Default);
/// <summary>
/// Draws the provided Points as a closed Linear Polygon with the provided Pen.
@ -103,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> DrawPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new Polygon(new LinearLineSegment(points)), options);
}
}
}

59
src/ImageSharp.Drawing/Processing/Paths/DrawRectangle.cs → src/ImageSharp.Drawing/Processing/Overlays/DrawRectangleExtensions.cs

@ -1,22 +1,21 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of rectangles to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class DrawRectangleExtensions
{
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// Draws the outline of the rectangle with the provided pen.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -25,13 +24,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
/// <summary>
/// Draws the outline of the polygon with the provided pen.
/// Draws the outline of the rectangle with the provided pen.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -39,13 +36,11 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IPen<TPixel> pen, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(pen, shape, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(pen, shape, GraphicsOptions.Default);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -55,13 +50,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), shape, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -70,13 +63,11 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, float thickness, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new Pen<TPixel>(brush, thickness), shape);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new Pen<TPixel>(brush, thickness), shape);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -86,13 +77,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, shape, options);
/// <summary>
/// Draws the outline of the polygon with the provided brush at the provided thickness.
/// Draws the outline of the rectangle with the provided brush at the provided thickness.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -101,9 +90,7 @@ namespace SixLabors.ImageSharp
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Draw<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, float thickness, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Draw(new SolidBrush<TPixel>(color), thickness, shape);
}
where TPixel : struct, IPixel<TPixel>
=> source.Draw(new SolidBrush<TPixel>(color), thickness, shape);
}
}
}

35
src/ImageSharp.Drawing/Processing/Paths/FillPathBuilder.cs → src/ImageSharp.Drawing/Processing/Overlays/FillPathBuilderExtensions.cs

@ -2,21 +2,20 @@
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of polygons with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathBuilderExtensions
{
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -42,13 +41,11 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Action<PathBuilder> path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, path, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, path, GraphicsOptions.Default);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -57,13 +54,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Action<PathBuilder> path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path, options);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -71,9 +66,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Action<PathBuilder> path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path);
}
}
}

34
src/ImageSharp.Drawing/Processing/Paths/FillPathCollection.cs → src/ImageSharp.Drawing/Processing/Overlays/FillPathCollectionExtensions.cs

@ -1,21 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of collections of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathCollectionExtensions
{
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -43,13 +41,11 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, paths, GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, paths, GraphicsOptions.Default);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -58,13 +54,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPathCollection paths, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), paths, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), paths, options);
/// <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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -72,9 +66,7 @@ namespace SixLabors.ImageSharp
/// <param name="paths">The paths.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPathCollection paths)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), paths);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), paths);
}
}
}

35
src/ImageSharp.Drawing/Processing/Paths/FillPaths.cs → src/ImageSharp.Drawing/Processing/Overlays/FillPathExtensions.cs

@ -1,18 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPathExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -24,10 +23,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new ShapeRegion(path), options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush.
@ -38,10 +35,8 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new ShapeRegion(path), GraphicsOptions.Default);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -53,10 +48,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPath path, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path, options);
/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush..
@ -67,9 +60,7 @@ namespace SixLabors.ImageSharp
/// <param name="path">The path.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), path);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), path);
}
}
}

36
src/ImageSharp.Drawing/Processing/Paths/FillPolygon.cs → src/ImageSharp.Drawing/Processing/Overlays/FillPolygonExtensions.cs

@ -1,21 +1,17 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of closed linear polygons to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillPolygonExtensions
{
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -27,10 +23,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -41,10 +35,8 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, new Polygon(new LinearLineSegment(points)));
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -56,10 +48,8 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, PointF[] points, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)), options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)), options);
/// <summary>
/// Flood fills the image in the shape of a Linear polygon described by the points
@ -70,9 +60,7 @@ namespace SixLabors.ImageSharp
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> FillPolygon<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, PointF[] points)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)));
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), new Polygon(new LinearLineSegment(points)));
}
}
}

37
src/ImageSharp.Drawing/Processing/Paths/FillRectangle.cs → src/ImageSharp.Drawing/Processing/Overlays/FillRectangleExtensions.cs

@ -1,21 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of rectangles to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillRectangleExtensions
{
/// <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 rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -25,12 +24,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
}
=> source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height), options);
/// <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 rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -39,12 +36,10 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, new SixLabors.Shapes.RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height));
}
=> source.Fill(brush, new RectangularePolygon(shape.X, shape.Y, shape.Width, shape.Height));
/// <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 rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -53,13 +48,11 @@ namespace SixLabors.ImageSharp
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), shape, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), shape, options);
/// <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 rectangle with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -68,8 +61,6 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), shape);
}
=> source.Fill(new SolidBrush<TPixel>(color), shape);
}
}
}

88
src/ImageSharp.Drawing/Processing/Overlays/FillRegion.cs → src/ImageSharp.Drawing/Processing/Overlays/FillRegionExtensions.cs

@ -1,34 +1,18 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Overlays
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the filling of regions with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static class FillRegionExtensions
{
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.ApplyProcessor(new FillProcessor<TPixel>(brush, options));
}
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
@ -38,9 +22,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, GraphicsOptions.Default);
}
=> source.Fill(brush, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image with the specified color.
@ -51,9 +33,7 @@ namespace SixLabors.ImageSharp
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color));
}
=> source.Fill(new SolidBrush<TPixel>(color));
/// <summary>
/// Flood fills the image with in the region with the specified brush.
@ -62,27 +42,23 @@ namespace SixLabors.ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options));
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(brush, region, GraphicsOptions.Default);
/// <summary>
/// Flood fills the image with in the region with the specified brush.
/// Flood fills the image with in the region with the specified color.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(brush, region, GraphicsOptions.Default);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), region, options);
/// <summary>
/// Flood fills the image with in the region with the specified color.
@ -91,26 +67,34 @@ namespace SixLabors.ImageSharp
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <param name="options">The options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), region, options);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), region);
/// <summary>
/// Flood fills the image with in the region with the specified color.
/// Flood fills the image with in the region with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region)
where TPixel : struct, IPixel<TPixel>
{
return source.Fill(new SolidBrush<TPixel>(color), region);
}
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options));
/// <summary>
/// Flood fills the image with the specified brush.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <param name="options">The graphics options.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, GraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillProcessor<TPixel>(brush, options));
}
}
}

70
src/ImageSharp.Drawing/Processing/Overlays/Processors/DrawImageProcessor.cs

@ -9,7 +9,7 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Drawing.Processors
namespace SixLabors.ImageSharp.Processing.Overlays.Processors
{
/// <summary>
/// Combines two images together by blending the pixels.
@ -18,19 +18,79 @@ namespace SixLabors.ImageSharp.Drawing.Processors
internal class DrawImageProcessor<TPixel> : ImageProcessor<TPixel>
where TPixel : struct, IPixel<TPixel>
{
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity)
: this(image, Point.Empty, opacity)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, GraphicsOptions options)
: this(image, Point.Empty, options)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">The opacity of the image to blend. Between 0 and 1.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity)
: this(image, location, opacity, GraphicsOptions.Default.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="options">
/// The options containing the opacity of the image to blend and blending mode.
/// Opacity must be between 0 and 1.
/// </param>
public DrawImageProcessor(Image<TPixel> image, Point location, GraphicsOptions options)
: this(image, location, options.BlendPercentage, options.BlenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, float opacity, PixelBlenderMode blenderMode)
: this(image, Point.Empty, opacity, blenderMode)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="DrawImageProcessor{TPixel}"/> class.
/// </summary>
/// <param name="image">The image to blend with the currently processing image.</param>
/// <param name="location">The location to draw the blended image.</param>
/// <param name="opacity">The opacity of the image to blend. Must be between 0 and 1.</param>
/// <param name="blenderMode">The blending mode to use when drawing the image.</param>
public DrawImageProcessor(Image<TPixel> image, Point location, float opacity, PixelBlenderMode blenderMode)
{
Guard.MustBeBetweenOrEqualTo(options.BlendPercentage, 0, 1, nameof(options.BlendPercentage));
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity));
this.Image = image;
this.Opacity = options.BlendPercentage;
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(options.BlenderMode);
this.Opacity = opacity;
this.Blender = PixelOperations<TPixel>.Instance.GetPixelBlender(blenderMode);
this.Location = location;
}

54
src/ImageSharp.Drawing/Processing/Text/DrawText.Path.cs → src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.Path.cs

@ -1,21 +1,19 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of text along given paths to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static partial class DrawTextExtensions
{
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -30,10 +28,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, color, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, color, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -49,10 +45,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes.Solid(color), null, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, Brushes.Solid(color), null, path, options);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -67,10 +61,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -86,10 +78,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, null, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, null, path, options);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -104,10 +94,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, pen, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, pen, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -123,10 +111,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, IPath path, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, null, pen, path, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, null, pen, path, options);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -142,10 +128,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, IPath path)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, pen, path, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -192,4 +176,4 @@ namespace SixLabors.ImageSharp
return source;
}
}
}
}

56
src/ImageSharp.Drawing/Processing/Text/DrawText.cs → src/ImageSharp.Drawing/Processing/Text/DrawTextExtensions.cs

@ -1,22 +1,20 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Primitives;
using SixLabors.Shapes;
namespace SixLabors.ImageSharp
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Extension methods for the <see cref="Image{TPixel}"/> type.
/// Adds extensions that allow the drawing of text to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static partial class ImageExtensions
public static partial class DrawTextExtensions
{
private static readonly int DefaultTextDpi = 72;
@ -33,10 +31,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, color, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -52,10 +48,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, TPixel color, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, Brushes.Solid(color), null, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, Brushes.Solid(color), null, location, options);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -70,10 +64,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image filled via the brush.
@ -89,10 +81,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, null, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, null, location, options);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -107,10 +97,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, pen, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text onto the the image outlined via the pen.
@ -126,10 +114,8 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IPen<TPixel> pen, PointF location, TextGraphicsOptions options)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, null, pen, location, options);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, null, pen, location, options);
/// <summary>
/// Draws the text onto the the image filled via the brush then outlined via the pen.
@ -145,13 +131,11 @@ namespace SixLabors.ImageSharp
/// The <see cref="Image{TPixel}" />.
/// </returns>
public static IImageProcessingContext<TPixel> DrawText<TPixel>(this IImageProcessingContext<TPixel> source, string text, Font font, IBrush<TPixel> brush, IPen<TPixel> pen, PointF location)
where TPixel : struct, IPixel<TPixel>
{
return source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
}
where TPixel : struct, IPixel<TPixel>
=> source.DrawText(text, font, brush, pen, location, TextGraphicsOptions.Default);
/// <summary>
/// Draws the text 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>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
@ -195,4 +179,4 @@ namespace SixLabors.ImageSharp
return source;
}
}
}
}

7
src/ImageSharp.Drawing/Processing/Text/TextGraphicsOptions.cs

@ -1,9 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.Fonts;
using SixLabors.ImageSharp.PixelFormats;
namespace SixLabors.ImageSharp.Drawing
namespace SixLabors.ImageSharp.Processing.Text
{
/// <summary>
/// Options for influencing the drawing functions.
@ -29,8 +30,8 @@ namespace SixLabors.ImageSharp.Drawing
private float wrapTextWidth;
private SixLabors.Fonts.HorizontalAlignment? horizontalAlignment;
private SixLabors.Fonts.VerticalAlignment? verticalAlignment;
private HorizontalAlignment? horizontalAlignment;
private VerticalAlignment? verticalAlignment;
/// <summary>
/// Initializes a new instance of the <see cref="TextGraphicsOptions" /> struct.

1
src/ImageSharp/Formats/Jpeg/JpegEncoder.cs

@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
/// <summary>
/// Gets or sets the quality, that will be used to encode the image. Quality
/// index must be between 0 and 100 (compression from max to min).
/// Defaults to <value>75</value>.
/// </summary>
public int Quality { get; set; } = 75;

4
src/ImageSharp/Primitives/ValueSize.cs

@ -38,12 +38,12 @@ namespace SixLabors.ImageSharp.Primitives
Absolute,
/// <summary>
/// The value is a percentage of the Images Width
/// The value is a percentage of the image width
/// </summary>
PercentageOfWidth,
/// <summary>
/// The value is a percentage of the Images height
/// The value is a percentage of the images height
/// </summary>
PercentageOfHeight
}

6
src/ImageSharp/Processing/Overlays/Processors/BackgroundColorProcessor.cs

@ -25,7 +25,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
/// <param name="options">The options defining blending algorithm and amount.</param>
public BackgroundColorProcessor(TPixel color, GraphicsOptions options)
{
this.Value = color;
this.Color = color;
this.GraphicsOptions = options;
}
@ -37,7 +37,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
/// <summary>
/// Gets the background color value.
/// </summary>
public TPixel Value { get; }
public TPixel Color { get; }
/// <inheritdoc/>
protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle sourceRectangle, Configuration configuration)
@ -76,7 +76,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
// TODO: Use Span.Fill?
for (int i = 0; i < width; i++)
{
colorSpan[i] = this.Value;
colorSpan[i] = this.Color;
amountSpan[i] = this.GraphicsOptions.BlendPercentage;
}

23
src/ImageSharp/Processing/Overlays/Processors/GlowProcessor.cs

@ -27,10 +27,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
/// </summary>
/// <param name="color">The color or the glow.</param>
public GlowProcessor(TPixel color)
: this(color, 0)
{
this.GlowColor = color;
this.GraphicsOptions = GraphicsOptions.Default;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode);
}
/// <summary>
@ -39,11 +37,18 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
/// <param name="color">The color or the glow.</param>
/// <param name="radius">The radius of the glow.</param>
public GlowProcessor(TPixel color, ValueSize radius)
: this(color, radius, GraphicsOptions.Default)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="GlowProcessor{TPixel}" /> class.
/// </summary>
/// <param name="color">The color or the glow.</param>
/// <param name="options">The options effecting blending and composition.</param>
public GlowProcessor(TPixel color, GraphicsOptions options)
: this(color, 0, options)
{
this.GlowColor = color;
this.Radius = radius;
this.GraphicsOptions = GraphicsOptions.Default;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode);
}
/// <summary>
@ -83,7 +88,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
int startX = sourceRectangle.X;
int endX = sourceRectangle.Right;
TPixel glowColor = this.GlowColor;
Vector2 centre = Rectangle.Center(sourceRectangle);
Vector2 center = Rectangle.Center(sourceRectangle);
float finalRadius = this.Radius.Calculate(source.Size());
@ -130,7 +135,7 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
int offsetX = minX - startX;
for (int i = 0; i < width; i++)
{
float distance = Vector2.Distance(centre, new Vector2(i + offsetX, offsetY));
float distance = Vector2.Distance(center, new Vector2(i + offsetX, offsetY));
amountsSpan[i] = (this.GraphicsOptions.BlendPercentage * (1 - (.95F * (distance / maxDistance)))).Clamp(0, 1);
}

4
src/ImageSharp/Processing/Overlays/Processors/VignetteProcessor.cs

@ -27,10 +27,8 @@ namespace SixLabors.ImageSharp.Processing.Overlays.Processors
/// </summary>
/// <param name="color">The color of the vignette.</param>
public VignetteProcessor(TPixel color)
: this(color, GraphicsOptions.Default)
{
this.VignetteColor = color;
this.GraphicsOptions = GraphicsOptions.Default;
this.blender = PixelOperations<TPixel>.Instance.GetPixelBlender(this.GraphicsOptions.BlenderMode);
}
/// <summary>

17
tests/ImageSharp.Benchmarks/Drawing/DrawBeziers.cs

@ -3,17 +3,16 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
public class DrawBeziers : BenchmarkBase
{
[Benchmark(Baseline = true, Description = "System.Drawing Draw Beziers")]

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

@ -3,6 +3,8 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;

17
tests/ImageSharp.Benchmarks/Drawing/DrawPolygon.cs

@ -3,18 +3,17 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
public class DrawPolygon : BenchmarkBase
{

22
tests/ImageSharp.Benchmarks/Drawing/FillPolygon.cs

@ -3,26 +3,24 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using SixLabors.Shapes;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Numerics;
using SixLabors.Shapes;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
public class FillPolygon : BenchmarkBase
{
private readonly Polygon shape;
public FillPolygon()
{
this.shape = new SixLabors.Shapes.Polygon(new LinearLineSegment(new Vector2(10, 10),
this.shape = new Polygon(new LinearLineSegment(new Vector2(10, 10),
new Vector2(550, 50),
new Vector2(200, 400)));
}

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

@ -3,19 +3,18 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Numerics;
using BenchmarkDotNet.Attributes;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using CoreRectangle = SixLabors.Primitives.Rectangle;
using CoreSize = SixLabors.Primitives.Size;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;
using System.Drawing.Drawing2D;
using BenchmarkDotNet.Attributes;
using CoreRectangle = SixLabors.Primitives.Rectangle;
using CoreSize = SixLabors.Primitives.Size;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
public class FillRectangle : BenchmarkBase
{

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

@ -3,6 +3,8 @@
// Licensed under the Apache License, Version 2.0.
// </copyright>
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Benchmarks
{
using System.Drawing;

15
tests/ImageSharp.Tests/Drawing/BeziersTests.cs

@ -1,20 +1,13 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
public class Beziers : FileTestBase
{
[Fact]
@ -71,9 +64,9 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new Vector2(240, 30),
new Vector2(300, 400)
}));
image.Save($"{path}/Opacity.png");
image.Save($"{path}/Opacity.png");
//shift background color towards forground color by the opacity amount
//shift background color towards foreground color by the opacity amount
Rgba32 mergedColor = new Rgba32(Vector4.Lerp(Rgba32.Blue.ToVector4(), Rgba32.HotPink.ToVector4(), 150f / 255f));
using (PixelAccessor<Rgba32> sourcePixels = image.Lock())

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

@ -4,8 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Primitives;
using Xunit;
@ -16,7 +16,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
public class BlendedShapes
{
public static IEnumerable<object[]> modes = ((PixelBlenderMode[])Enum.GetValues(typeof(PixelBlenderMode)))
.Select(x=> new object[] { x });
.Select(x => new object[] { x });
[Theory]
[WithBlankImages(nameof(modes), 250, 250, PixelTypes.Rgba32)]
@ -27,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{
var scaleX = (img.Width / 100);
var scaleY = (img.Height / 100);
img.Mutate(x=>x
img.Mutate(x => x
.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY))
.Fill(NamedColors<TPixel>.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true)
{
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{
var scaleX = (img.Width / 100);
var scaleY = (img.Height / 100);
img.Mutate(x=>x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0* scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.HotPink, new Rectangle(20 * scaleX, 0 * scaleY, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true)
{
BlenderMode = mode
@ -68,7 +68,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{
var scaleX = (img.Width / 100);
var scaleY = (img.Height / 100);
img.Mutate(x=>x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20* scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40, 100 * scaleX, 20 * scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.HotPink, new Rectangle(20 * scaleX, 0, 30 * scaleX, 100 * scaleY), new ImageSharp.GraphicsOptions(true)
{
BlenderMode = mode
@ -97,7 +97,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
{
var scaleX = (img.Width / 100);
var scaleY = (img.Height / 100);
img.Mutate(x => x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40* scaleY, 100 * scaleX, 20 * scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.DarkBlue, new Rectangle(0 * scaleX, 40 * scaleY, 100 * scaleX, 20 * scaleY)));
img.Mutate(x => x.Fill(NamedColors<TPixel>.Black, new SixLabors.Shapes.EllipsePolygon(40 * scaleX, 50 * scaleY, 50 * scaleX, 50 * scaleY), new ImageSharp.GraphicsOptions(true)
{
BlenderMode = mode

1
tests/ImageSharp.Tests/Drawing/DrawImageTest.cs

@ -5,6 +5,7 @@ using System;
using System.Numerics;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Primitives;
using Xunit;

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

@ -1,19 +1,15 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Shapes;
using Xunit;
using ShapePath = SixLabors.Shapes.Path;
namespace SixLabors.ImageSharp.Tests.Drawing
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
public class DrawPathTests : FileTestBase
{
[Fact]
@ -31,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new Vector2(60, 10),
new Vector2(10, 400));
ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
Path p = new Path(linerSegemnt, bazierSegment);
image.Mutate(x => x
.BackgroundColor(Rgba32.Blue)
@ -69,7 +65,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new Vector2(60, 10),
new Vector2(10, 400));
ShapePath p = new ShapePath(linerSegemnt, bazierSegment);
Path p = new Path(linerSegemnt, bazierSegment);
using (Image<Rgba32> image = new Image<Rgba32>(500, 500))
{

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

@ -7,6 +7,8 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing

6
tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs

@ -2,18 +2,18 @@
// Licensed under the Apache License, Version 2.0.
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.Drawing.Processors;
using Moq;
using Xunit;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Primitives;
namespace SixLabors.ImageSharp.Tests.Drawing
{
using SixLabors.ImageSharp.Processing;
public class FillRegionProcessorTests
{
[Theory]

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

@ -1,12 +1,9 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing;
using SixLabors.Shapes;
using Xunit;

5
tests/ImageSharp.Tests/Drawing/LineTests.cs

@ -1,11 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Pens;
using SixLabors.ImageSharp.PixelFormats;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing

26
tests/ImageSharp.Tests/Drawing/Paths/FillPath.cs

@ -1,13 +1,11 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Shapes;
using Xunit;
@ -28,7 +26,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushAndPath()
{
this.operations.Fill(brush, path);
this.operations.Fill(this.brush, this.path);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -39,28 +37,28 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
[Fact]
public void CorrectlySetsBrushPathOptions()
{
this.operations.Fill(brush, path, noneDefault);
this.operations.Fill(this.brush, this.path, this.noneDefault);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
[Fact]
public void CorrectlySetsColorAndPath()
{
this.operations.Fill(color, path);
this.operations.Fill(this.color, this.path);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
@ -70,23 +68,23 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
this.operations.Fill(color, path, noneDefault);
this.operations.Fill(this.color, this.path, this.noneDefault);
var processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
}
}

24
tests/ImageSharp.Tests/Drawing/Paths/FillPathCollection.cs

@ -8,6 +8,8 @@ using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Shapes;
using Xunit;
@ -35,13 +37,13 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
public FillPathCollection()
{
this.pathCollection = new PathCollection(path1, path2);
this.pathCollection = new PathCollection(this.path1, this.path2);
}
[Fact]
public void CorrectlySetsBrushAndPath()
{
this.operations.Fill(brush, pathCollection);
this.operations.Fill(this.brush, this.pathCollection);
for (var i = 0; i < 2; i++)
{
@ -55,33 +57,33 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
}
[Fact]
public void CorrectlySetsBrushPathOptions()
{
this.operations.Fill(brush, pathCollection, noneDefault);
this.operations.Fill(this.brush, this.pathCollection, this.noneDefault);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
}
[Fact]
public void CorrectlySetsColorAndPath()
{
this.operations.Fill(color, pathCollection);
this.operations.Fill(this.color, this.pathCollection);
for (var i = 0; i < 2; i++)
{
@ -94,27 +96,27 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
}
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
this.operations.Fill(color, pathCollection, noneDefault);
this.operations.Fill(this.color, this.pathCollection, this.noneDefault);
for (var i = 0; i < 2; i++)
{
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>(i);
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segments = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
}
}

29
tests/ImageSharp.Tests/Drawing/Paths/FillPolygon.cs

@ -1,13 +1,12 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Numerics;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Shapes;
using Xunit;
@ -18,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
GraphicsOptions noneDefault = new GraphicsOptions();
Rgba32 color = Rgba32.HotPink;
SolidBrush<Rgba32> brush = Brushes.Solid(Rgba32.HotPink);
SixLabors.Primitives.PointF[] path = new SixLabors.Primitives.PointF[] {
SixLabors.Primitives.PointF[] path = {
new Vector2(10,10),
new Vector2(20,10),
new Vector2(20,10),
@ -29,7 +28,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
[Fact]
public void CorrectlySetsBrushAndPath()
{
this.operations.FillPolygon(brush, path);
this.operations.FillPolygon(this.brush, this.path);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
@ -39,28 +38,28 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
[Fact]
public void CorrectlySetsBrushPathAndOptions()
{
this.operations.FillPolygon(brush, path, noneDefault);
this.operations.FillPolygon(this.brush, this.path, this.noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
Assert.Equal(brush, processor.Brush);
Assert.Equal(this.brush, processor.Brush);
}
[Fact]
public void CorrectlySetsColorAndPath()
{
this.operations.FillPolygon(color, path);
this.operations.FillPolygon(this.color, this.path);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
@ -71,24 +70,24 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
LinearLineSegment segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
[Fact]
public void CorrectlySetsColorPathAndOptions()
{
this.operations.FillPolygon(color, path, noneDefault);
this.operations.FillPolygon(this.color, this.path, this.noneDefault);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(noneDefault, processor.Options);
Assert.Equal(this.noneDefault, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);
Polygon polygon = Assert.IsType<Polygon>(region.Shape);
LinearLineSegment segemnt = Assert.IsType<LinearLineSegment>(polygon.LineSegments[0]);
SolidBrush<Rgba32> brush = Assert.IsType<SolidBrush<Rgba32>>(processor.Brush);
Assert.Equal(color, brush.Color);
Assert.Equal(this.color, brush.Color);
}
}
}

7
tests/ImageSharp.Tests/Drawing/Paths/FillRectangle.cs

@ -1,11 +1,10 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;
using SixLabors.ImageSharp.Processing.Overlays;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing.Paths
@ -58,7 +57,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
this.operations.Fill(color, rectangle);
FillRegionProcessor<Rgba32> processor = this.Verify<FillRegionProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.Options);
ShapeRegion region = Assert.IsType<ShapeRegion>(processor.Region);

2
tests/ImageSharp.Tests/Drawing/Paths/ShapeRegionTests.cs

@ -1,6 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Primitives;
namespace SixLabors.ImageSharp.Tests.Drawing.Paths
{
using System;

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

@ -1,21 +1,14 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing;
using SixLabors.Primitives;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing
{
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp.Processing.Overlays;
public class PolygonTests : FileTestBase
{
[Fact]

4
tests/ImageSharp.Tests/Drawing/RecolorImageTest.cs

@ -1,10 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Linq;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.Primitives;
using Xunit;

5
tests/ImageSharp.Tests/Drawing/SolidBezierTests.cs

@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Shapes;
@ -32,7 +31,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
using (Image<TPixel> image = provider.GetImage())
{
image.Mutate(x => x
.BackgroundColor(blue)
.Fill(hotPink, new Polygon(new CubicBezierLineSegment(simplePath))));
@ -53,7 +52,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
new Vector2(300, 400)
};
Rgba32 color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
var color = new Rgba32(Rgba32.HotPink.R, Rgba32.HotPink.G, Rgba32.HotPink.B, 150);
using (var image = provider.GetImage() as Image<Rgba32>)
{

5
tests/ImageSharp.Tests/Drawing/SolidComplexPolygonTests.cs

@ -1,11 +1,8 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing;
using SixLabors.Shapes;
using Xunit;

7
tests/ImageSharp.Tests/Drawing/SolidPolygonTests.cs

@ -2,13 +2,8 @@
// Licensed under the Apache License, Version 2.0.
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Numerics;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Brushes;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing;
using SixLabors.Shapes;
using Xunit;
@ -23,7 +18,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing
public void ImageShouldBeOverlayedByFilledPolygon()
{
string path = TestEnvironment.CreateOutputDirectory("Drawing", "FilledPolygons");
SixLabors.Primitives.PointF[] simplePath = new SixLabors.Primitives.PointF[] {
SixLabors.Primitives.PointF[] simplePath = {
new Vector2(10, 10),
new Vector2(200, 150),
new Vector2(50, 300)

1
tests/ImageSharp.Tests/Drawing/Text/DrawText.Path.cs

@ -10,6 +10,7 @@ using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing.Paths;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Processing.Text;
using SixLabors.Shapes;
using Xunit;

3
tests/ImageSharp.Tests/Drawing/Text/DrawText.cs

@ -10,6 +10,7 @@ using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tests.Drawing.Paths;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Processing.Text;
using SixLabors.Shapes;
using Xunit;
@ -187,7 +188,7 @@ namespace SixLabors.ImageSharp.Tests.Drawing.Text
}
[Fact]
public void BrushAppliesBeforPen()
public void BrushAppliesBeforePen()
{
this.operations.DrawText(
"1",

2
tests/ImageSharp.Tests/Drawing/Text/OutputText.cs

@ -13,6 +13,8 @@ using SixLabors.ImageSharp.Drawing.Processors;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Processing.Overlays;
using SixLabors.ImageSharp.Processing.Text;
using SixLabors.Shapes;
using Xunit;

2
tests/ImageSharp.Tests/Drawing/Text/TextGraphicsOptionsTests.cs

@ -8,6 +8,8 @@ using System.Numerics;
using System.Threading.Tasks;
using SixLabors.ImageSharp.Drawing;
using SixLabors.Fonts;
using SixLabors.ImageSharp.Processing.Text;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Drawing.Text

10
tests/ImageSharp.Tests/Issues/Issue412.cs

@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using SixLabors.Primitives;
using SixLabors.ImageSharp.Advanced;
using SixLabors.Primitives;
using Xunit;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
namespace SixLabors.ImageSharp.Tests.Issues
{
@ -14,7 +12,7 @@ namespace SixLabors.ImageSharp.Tests.Issues
{
[Theory]
[WithBlankImages(40, 30, PixelTypes.Rgba32)]
public void AllPixelsExpectedToBeRedWhenAntialisedDisabled<TPixel>(TestImageProvider<TPixel> provider) where TPixel : struct, IPixel<TPixel>
public void AllPixelsExpectedToBeRedWhenAntialiasedDisabled<TPixel>(TestImageProvider<TPixel> provider) where TPixel : struct, IPixel<TPixel>
{
using (var image = provider.GetImage())
{

11
tests/ImageSharp.Tests/Processing/Effects/BackgroundColorTest.cs

@ -1,9 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors;
using SixLabors.Primitives;
using Xunit;
namespace SixLabors.ImageSharp.Tests.Processing.Effects
@ -20,7 +17,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>();
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Color);
}
[Fact]
@ -30,7 +27,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>(this.rect);
Assert.Equal(GraphicsOptions.Default, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Color);
}
[Fact]
@ -40,7 +37,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>();
Assert.Equal(this.options, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Color);
}
[Fact]
@ -50,7 +47,7 @@ namespace SixLabors.ImageSharp.Tests.Processing.Effects
var processor = this.Verify<BackgroundColorProcessor<Rgba32>>(this.rect);
Assert.Equal(this.options, processor.GraphicsOptions);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Value);
Assert.Equal(Rgba32.BlanchedAlmond, processor.Color);
}
}
}

1
tests/ImageSharp.Tests/TestUtilities/ImageProviders/SolidProvider.cs

@ -4,6 +4,7 @@
using System;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Overlays;
using Xunit.Abstractions;

Loading…
Cancel
Save