Skip to content

Commit 5d5cf96

Browse files
Cleanup
1 parent b543d83 commit 5d5cf96

7 files changed

Lines changed: 105 additions & 108 deletions

File tree

src/ImageSharp.Drawing/Processing/Extensions/ClearExtensions.cs

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,28 @@
66
namespace SixLabors.ImageSharp.Drawing.Processing
77
{
88
/// <summary>
9-
/// Adds extensions that allow the clearing of regions with various brushes to the <see cref="Image{TPixel}"/> type.
9+
/// Adds extensions that allow the flood filling of images without blending.
1010
/// </summary>
1111
public static class ClearExtensions
1212
{
1313
/// <summary>
14-
/// Clones the graphic options and applies changes required to force clearing.
14+
/// Flood fills the image with the specified color without any blending.
1515
/// </summary>
16-
/// <param name="options">The options to clone</param>
17-
/// <returns>A clone of option with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
18-
internal static GraphicsOptions CloneForClearOperation(this GraphicsOptions options)
19-
{
20-
options = options.DeepClone();
21-
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
22-
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
23-
options.BlendPercentage = 1;
24-
return options;
25-
}
16+
/// <param name="source">The image this method extends.</param>
17+
/// <param name="color">The color.</param>
18+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
19+
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color)
20+
=> source.Clear(new SolidBrush(color));
2621

2722
/// <summary>
28-
/// Flood fills the image with the specified brush without any blending.
23+
/// Flood fills the image with the specified color without any blending.
2924
/// </summary>
3025
/// <param name="source">The image this method extends.</param>
31-
/// <param name="options">The graphics options.</param>
32-
/// <param name="brush">The details how to fill the region of interest.</param>
26+
/// <param name="options">The drawing options.</param>
27+
/// <param name="color">The color.</param>
3328
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
34-
public static IImageProcessingContext Clear(
35-
this IImageProcessingContext source,
36-
GraphicsOptions options,
37-
IBrush brush)
38-
=> source.Fill(options.CloneForClearOperation(), brush);
29+
public static IImageProcessingContext Clear(this IImageProcessingContext source, GraphicsOptions options, Color color)
30+
=> source.Clear(options, new SolidBrush(color));
3931

4032
/// <summary>
4133
/// Flood fills the image with the specified brush without any blending.
@@ -47,25 +39,45 @@ public static IImageProcessingContext Clear(this IImageProcessingContext source,
4739
source.Clear(source.GetGraphicsOptions(), brush);
4840

4941
/// <summary>
50-
/// Flood fills the image with the specified color without any blending.
42+
/// Flood fills the image with the specified brush without any blending.
5143
/// </summary>
5244
/// <param name="source">The image this method extends.</param>
53-
/// <param name="options">The graphics options.</param>
54-
/// <param name="color">The color.</param>
45+
/// <param name="options">The drawing options.</param>
46+
/// <param name="brush">The details how to fill the region of interest.</param>
5547
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
5648
public static IImageProcessingContext Clear(
5749
this IImageProcessingContext source,
58-
GraphicsOptions options,
59-
Color color) =>
60-
source.Clear(options, new SolidBrush(color));
50+
DrawingOptions options,
51+
IBrush brush)
52+
=> source.Fill(options.CloneForClearOperation(), brush);
6153

6254
/// <summary>
63-
/// Flood fills the image with the specified color without any blending.
55+
/// Clones the graphic options and applies changes required to force clearing.
6456
/// </summary>
65-
/// <param name="source">The image this method extends.</param>
66-
/// <param name="color">The color.</param>
67-
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
68-
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color) =>
69-
source.Clear(new SolidBrush(color));
57+
/// <param name="options">The options to clone</param>
58+
/// <returns>A clone of option with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
59+
internal static GraphicsOptions CloneForClearOperation(this GraphicsOptions options)
60+
{
61+
options = options.DeepClone();
62+
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
63+
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
64+
options.BlendPercentage = 1;
65+
return options;
66+
}
67+
68+
/// <summary>
69+
/// Clones the path graphic options and applies changes required to force clearing.
70+
/// </summary>
71+
/// <param name="drawingOptions">The drawing options to clone</param>
72+
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
73+
internal static DrawingOptions CloneForClearOperation(this DrawingOptions drawingOptions)
74+
{
75+
GraphicsOptions options = drawingOptions.GraphicsOptions.DeepClone();
76+
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
77+
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
78+
options.BlendPercentage = 1F;
79+
80+
return new DrawingOptions(options, drawingOptions.ShapeOptions, drawingOptions.TextOptions, drawingOptions.Transform);
81+
}
7082
}
7183
}

src/ImageSharp.Drawing/Processing/Extensions/ClearPathExtensions.cs

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,74 +11,59 @@ namespace SixLabors.ImageSharp.Drawing.Processing
1111
public static class ClearPathExtensions
1212
{
1313
/// <summary>
14-
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush without any blending.
14+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified color without any blending.
1515
/// </summary>
1616
/// <param name="source">The image processing context.</param>
1717
/// <param name="color">The color.</param>
18-
/// <param name="path">The logic path.</param>
18+
/// <param name="region">The region of interest to flood fill.</param>
1919
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2020
public static IImageProcessingContext Clear(
2121
this IImageProcessingContext source,
2222
Color color,
23-
IPath path) =>
24-
source.Clear(new SolidBrush(color), path);
23+
IPath region) =>
24+
source.Clear(new SolidBrush(color), region);
2525

2626
/// <summary>
27-
/// Flood fills the image in the path of the provided polygon with the specified brush without any blending.
27+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified color without any blending.
2828
/// </summary>
2929
/// <param name="source">The image processing context.</param>
3030
/// <param name="options">The drawing options.</param>
3131
/// <param name="color">The color.</param>
32-
/// <param name="path">The logic path.</param>
32+
/// <param name="region">The region of interest to flood fill.</param>
3333
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3434
public static IImageProcessingContext Clear(
3535
this IImageProcessingContext source,
3636
DrawingOptions options,
3737
Color color,
38-
IPath path) =>
39-
source.Clear(options, new SolidBrush(color), path);
38+
IPath region) =>
39+
source.Clear(options, new SolidBrush(color), region);
4040

4141
/// <summary>
42-
/// Flood fills the image in the path of the provided polygon with the specified brush without any blending.
42+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush without any blending.
4343
/// </summary>
4444
/// <param name="source">The image processing context.</param>
4545
/// <param name="brush">The brush.</param>
46-
/// <param name="path">The logic path.</param>
46+
/// <param name="region">The region of interest to flood fill.</param>
4747
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4848
public static IImageProcessingContext Clear(
4949
this IImageProcessingContext source,
5050
IBrush brush,
51-
IPath path) =>
52-
source.Clear(source.GetDrawingOptions(), brush, path);
51+
IPath region) =>
52+
source.Clear(source.GetDrawingOptions(), brush, region);
5353

5454
/// <summary>
55-
/// Flood fills the image in the path of the provided polygon with the specified brush without any blending.
55+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush without any blending.
5656
/// </summary>
5757
/// <param name="source">The image processing context.</param>
5858
/// <param name="options">The drawing options.</param>
5959
/// <param name="brush">The brush.</param>
60-
/// <param name="path">The logic path.</param>
60+
/// <param name="path">The region of interest to flood fill.</param>
6161
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
6262
public static IImageProcessingContext Clear(
6363
this IImageProcessingContext source,
6464
DrawingOptions options,
6565
IBrush brush,
6666
IPath path) =>
6767
source.Fill(options.CloneForClearOperation(), brush, path);
68-
69-
/// <summary>
70-
/// Clones the path graphic options and applies changes required to force clearing.
71-
/// </summary>
72-
/// <param name="shapeOptions">The drawing options to clone</param>
73-
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
74-
internal static DrawingOptions CloneForClearOperation(this DrawingOptions shapeOptions)
75-
{
76-
GraphicsOptions options = shapeOptions.GraphicsOptions.DeepClone();
77-
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
78-
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
79-
options.BlendPercentage = 1F;
80-
81-
return new DrawingOptions(options, shapeOptions.ShapeOptions, shapeOptions.TextOptions, shapeOptions.Transform);
82-
}
8368
}
8469
}

src/ImageSharp.Drawing/Processing/Extensions/ClearRectangleExtensions.cs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,58 @@
66
namespace SixLabors.ImageSharp.Drawing.Processing
77
{
88
/// <summary>
9-
/// Adds extensions that allow the filling of rectangles to the <see cref="Image{TPixel}"/> type.
9+
/// Adds extensions that allow the flood filling of rectangle outlines without blending.
1010
/// </summary>
1111
public static class ClearRectangleExtensions
1212
{
1313
/// <summary>
14-
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
14+
/// Flood fills the image in the rectangle of the provided rectangle with the specified color without any blending.
1515
/// </summary>
1616
/// <param name="source">The image this method extends.</param>
17-
/// <param name="options">The options.</param>
17+
/// <param name="color">The color.</param>
18+
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
19+
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
20+
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, RectangleF rectangle)
21+
=> source.Clear(new SolidBrush(color), rectangle);
22+
23+
/// <summary>
24+
/// Flood fills the image at the given rectangle bounds with the specified brush without any blending.
25+
/// </summary>
26+
/// <param name="source">The image this method extends.</param>
27+
/// <param name="options">The drawing options.</param>
1828
/// <param name="brush">The brush.</param>
19-
/// <param name="shape">The shape.</param>
29+
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
2030
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2131
public static IImageProcessingContext Clear(
2232
this IImageProcessingContext source,
2333
DrawingOptions options,
2434
IBrush brush,
25-
RectangleF shape) =>
26-
source.Clear(options, brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
35+
RectangleF rectangle)
36+
=> source.Clear(options, brush, new RectangularPolygon(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
2737

2838
/// <summary>
29-
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
39+
/// Flood fills the image in the rectangle of the provided rectangle with the specified brush without any blending.
3040
/// </summary>
3141
/// <param name="source">The image this method extends.</param>
3242
/// <param name="brush">The brush.</param>
33-
/// <param name="shape">The shape.</param>
43+
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
3444
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
35-
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, RectangleF shape) =>
36-
source.Clear(brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));
45+
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, RectangleF rectangle)
46+
=> source.Clear(brush, new RectangularPolygon(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
3747

3848
/// <summary>
39-
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
49+
/// Flood fills the image in the rectangle of the provided rectangle with the specified color without any blending.
4050
/// </summary>
4151
/// <param name="source">The image this method extends.</param>
42-
/// <param name="options">The options.</param>
52+
/// <param name="options">The drawing options.</param>
4353
/// <param name="color">The color.</param>
44-
/// <param name="shape">The shape.</param>
54+
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
4555
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4656
public static IImageProcessingContext Clear(
4757
this IImageProcessingContext source,
4858
DrawingOptions options,
4959
Color color,
50-
RectangleF shape) =>
51-
source.Clear(options, new SolidBrush(color), shape);
52-
53-
/// <summary>
54-
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
55-
/// </summary>
56-
/// <param name="source">The image this method extends.</param>
57-
/// <param name="color">The color.</param>
58-
/// <param name="shape">The shape.</param>
59-
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
60-
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, RectangleF shape) =>
61-
source.Clear(new SolidBrush(color), shape);
60+
RectangleF rectangle) =>
61+
source.Clear(options, new SolidBrush(color), rectangle);
6262
}
6363
}

src/ImageSharp.Drawing/Processing/Extensions/ClipPathExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ public static class ClipPathExtensions
1616
/// Applies the processing operation against a given clipping path.
1717
/// </summary>
1818
/// <param name="source">The image processing context.</param>
19-
/// <param name="path">The target path to operate within.</param>
19+
/// <param name="region">The target path to operate within.</param>
2020
/// <param name="operation">The operation to perform on the source.</param>
2121
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2222
public static IImageProcessingContext Clip(
2323
this IImageProcessingContext source,
24-
IPath path,
24+
IPath region,
2525
Action<IImageProcessingContext> operation)
26-
=> source.ApplyProcessor(new RecursiveImageProcessor(source.GetDrawingOptions(), path, operation));
26+
=> source.ApplyProcessor(new RecursiveImageProcessor(source.GetDrawingOptions(), region, operation));
2727
}
2828
}

src/ImageSharp.Drawing/Processing/Extensions/FillExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ public static class FillExtensions
1515
/// Flood fills the image with the specified brush.
1616
/// </summary>
1717
/// <param name="source">The image this method extends.</param>
18-
/// <param name="options">The graphics options.</param>
18+
/// <param name="options">The drawing options.</param>
1919
/// <param name="brush">The details how to fill the region of interest.</param>
2020
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2121
public static IImageProcessingContext Fill(
2222
this IImageProcessingContext source,
23-
GraphicsOptions options,
23+
DrawingOptions options,
2424
IBrush brush) =>
2525
source.ApplyProcessor(new FillProcessor(options, brush));
2626

@@ -31,18 +31,18 @@ public static IImageProcessingContext Fill(
3131
/// <param name="brush">The details how to fill the region of interest.</param>
3232
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3333
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) =>
34-
source.Fill(source.GetGraphicsOptions(), brush);
34+
source.Fill(source.GetDrawingOptions(), brush);
3535

3636
/// <summary>
3737
/// Flood fills the image with the specified color.
3838
/// </summary>
3939
/// <param name="source">The image this method extends.</param>
40-
/// <param name="options">The graphics options.</param>
40+
/// <param name="options">The drawing options.</param>
4141
/// <param name="color">The color.</param>
4242
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4343
public static IImageProcessingContext Fill(
4444
this IImageProcessingContext source,
45-
GraphicsOptions options,
45+
DrawingOptions options,
4646
Color color) =>
4747
source.Fill(options, new SolidBrush(color));
4848

0 commit comments

Comments
 (0)