Skip to content

Commit 9a6a0b1

Browse files
More clean up and update tests
1 parent 86348a0 commit 9a6a0b1

24 files changed

+344
-328
lines changed

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

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class ClearExtensions
1313
/// <summary>
1414
/// Flood fills the image with the specified color without any blending.
1515
/// </summary>
16-
/// <param name="source">The image this method extends.</param>
16+
/// <param name="source">The image processing context.</param>
1717
/// <param name="color">The color.</param>
1818
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
1919
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color)
@@ -22,49 +22,32 @@ public static IImageProcessingContext Clear(this IImageProcessingContext source,
2222
/// <summary>
2323
/// Flood fills the image with the specified color without any blending.
2424
/// </summary>
25-
/// <param name="source">The image this method extends.</param>
25+
/// <param name="source">The image processing context.</param>
2626
/// <param name="options">The drawing options.</param>
2727
/// <param name="color">The color.</param>
2828
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
29-
public static IImageProcessingContext Clear(this IImageProcessingContext source, GraphicsOptions options, Color color)
29+
public static IImageProcessingContext Clear(this IImageProcessingContext source, DrawingOptions options, Color color)
3030
=> source.Clear(options, new SolidBrush(color));
3131

3232
/// <summary>
3333
/// Flood fills the image with the specified brush without any blending.
3434
/// </summary>
35-
/// <param name="source">The image this method extends.</param>
36-
/// <param name="brush">The details how to fill the region of interest.</param>
35+
/// <param name="source">The image processing context.</param>
36+
/// <param name="brush">The brush.</param>
3737
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3838
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush) =>
39-
source.Clear(source.GetGraphicsOptions(), brush);
39+
source.Clear(source.GetDrawingOptions(), brush);
4040

4141
/// <summary>
4242
/// Flood fills the image with the specified brush without any blending.
4343
/// </summary>
44-
/// <param name="source">The image this method extends.</param>
44+
/// <param name="source">The image processing context.</param>
4545
/// <param name="options">The drawing options.</param>
46-
/// <param name="brush">The details how to fill the region of interest.</param>
46+
/// <param name="brush">The brush.</param>
4747
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
48-
public static IImageProcessingContext Clear(
49-
this IImageProcessingContext source,
50-
DrawingOptions options,
51-
IBrush brush)
48+
public static IImageProcessingContext Clear(this IImageProcessingContext source, DrawingOptions options, IBrush brush)
5249
=> source.Fill(options.CloneForClearOperation(), brush);
5350

54-
/// <summary>
55-
/// Clones the graphic options and applies changes required to force clearing.
56-
/// </summary>
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-
6851
/// <summary>
6952
/// Clones the path graphic options and applies changes required to force clearing.
7053
/// </summary>

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ 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 color without any blending.
14+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified
15+
/// color without any blending.
1516
/// </summary>
1617
/// <param name="source">The image processing context.</param>
1718
/// <param name="color">The color.</param>
@@ -20,50 +21,53 @@ public static class ClearPathExtensions
2021
public static IImageProcessingContext Clear(
2122
this IImageProcessingContext source,
2223
Color color,
23-
IPath region) =>
24-
source.Clear(new SolidBrush(color), region);
24+
IPath region)
25+
=> source.Clear(new SolidBrush(color), region);
2526

2627
/// <summary>
27-
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified color without any blending.
28+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified color
29+
/// without any blending.
2830
/// </summary>
2931
/// <param name="source">The image processing context.</param>
3032
/// <param name="options">The drawing options.</param>
3133
/// <param name="color">The color.</param>
32-
/// <param name="region">The region of interest to flood fill.</param>
34+
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
3335
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3436
public static IImageProcessingContext Clear(
3537
this IImageProcessingContext source,
3638
DrawingOptions options,
3739
Color color,
38-
IPath region) =>
39-
source.Clear(options, new SolidBrush(color), region);
40+
IPath region)
41+
=> source.Clear(options, new SolidBrush(color), region);
4042

4143
/// <summary>
42-
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush without any blending.
44+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush
45+
/// without any blending.
4346
/// </summary>
4447
/// <param name="source">The image processing context.</param>
4548
/// <param name="brush">The brush.</param>
46-
/// <param name="region">The region of interest to flood fill.</param>
49+
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
4750
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4851
public static IImageProcessingContext Clear(
4952
this IImageProcessingContext source,
5053
IBrush brush,
51-
IPath region) =>
52-
source.Clear(source.GetDrawingOptions(), brush, region);
54+
IPath region)
55+
=> source.Clear(source.GetDrawingOptions(), brush, region);
5356

5457
/// <summary>
55-
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush without any blending.
58+
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush
59+
/// without any blending.
5660
/// </summary>
5761
/// <param name="source">The image processing context.</param>
5862
/// <param name="options">The drawing options.</param>
5963
/// <param name="brush">The brush.</param>
60-
/// <param name="path">The region of interest to flood fill.</param>
64+
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
6165
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
6266
public static IImageProcessingContext Clear(
6367
this IImageProcessingContext source,
6468
DrawingOptions options,
6569
IBrush brush,
66-
IPath path) =>
67-
source.Fill(options.CloneForClearOperation(), brush, path);
70+
IPath region)
71+
=> source.Fill(options.CloneForClearOperation(), brush, region);
6872
}
6973
}

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,49 +15,52 @@ public static class ClearRectangleExtensions
1515
/// </summary>
1616
/// <param name="source">The image this method extends.</param>
1717
/// <param name="color">The color.</param>
18-
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
18+
/// <param name="rectangle">The rectangle defining the region to fill.</param>
1919
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2020
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, RectangleF rectangle)
2121
=> source.Clear(new SolidBrush(color), rectangle);
2222

2323
/// <summary>
24-
/// Flood fills the image at the given rectangle bounds with the specified brush without any blending.
24+
/// Flood fills the image in the rectangle of the provided rectangle with the specified color without any blending.
2525
/// </summary>
2626
/// <param name="source">The image this method extends.</param>
2727
/// <param name="options">The drawing options.</param>
28-
/// <param name="brush">The brush.</param>
29-
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
28+
/// <param name="color">The color.</param>
29+
/// <param name="rectangle">The rectangle defining the region to fill.</param>
3030
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3131
public static IImageProcessingContext Clear(
3232
this IImageProcessingContext source,
3333
DrawingOptions options,
34-
IBrush brush,
34+
Color color,
3535
RectangleF rectangle)
36-
=> source.Clear(options, brush, new RectangularPolygon(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
36+
=> source.Clear(options, new SolidBrush(color), rectangle);
3737

3838
/// <summary>
3939
/// Flood fills the image in the rectangle of the provided rectangle with the specified brush without any blending.
4040
/// </summary>
4141
/// <param name="source">The image this method extends.</param>
4242
/// <param name="brush">The brush.</param>
43-
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
43+
/// <param name="rectangle">The rectangle defining the region to fill.</param>
4444
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
45-
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, RectangleF rectangle)
45+
public static IImageProcessingContext Clear(
46+
this IImageProcessingContext source,
47+
IBrush brush,
48+
RectangleF rectangle)
4649
=> source.Clear(brush, new RectangularPolygon(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
4750

4851
/// <summary>
49-
/// Flood fills the image in the rectangle of the provided rectangle with the specified color without any blending.
52+
/// Flood fills the image at the given rectangle bounds with the specified brush without any blending.
5053
/// </summary>
5154
/// <param name="source">The image this method extends.</param>
5255
/// <param name="options">The drawing options.</param>
53-
/// <param name="color">The color.</param>
54-
/// <param name="rectangle">The rectangle defining the region of interest to flood fill.</param>
56+
/// <param name="brush">The brush.</param>
57+
/// <param name="rectangle">The rectangle defining the region to fill.</param>
5558
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
5659
public static IImageProcessingContext Clear(
5760
this IImageProcessingContext source,
5861
DrawingOptions options,
59-
Color color,
60-
RectangleF rectangle) =>
61-
source.Clear(options, new SolidBrush(color), rectangle);
62+
IBrush brush,
63+
RectangleF rectangle)
64+
=> source.Clear(options, brush, new RectangularPolygon(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height));
6265
}
6366
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ namespace SixLabors.ImageSharp.Drawing.Processing
1313
public static class ClipPathExtensions
1414
{
1515
/// <summary>
16-
/// Applies the processing operation against a given clipping path.
16+
/// Applies the processing operation within the provided region defined by an <see cref="IPath"/>.
1717
/// </summary>
1818
/// <param name="source">The image processing context.</param>
19-
/// <param name="region">The target path to operate within.</param>
20-
/// <param name="operation">The operation to perform on the source.</param>
19+
/// <param name="region">The <see cref="IPath"/> defining the region to operation within.</param>
20+
/// <param name="operation">The operation to perform.</param>
2121
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
2222
public static IImageProcessingContext Clip(
2323
this IImageProcessingContext source,
2424
IPath region,
2525
Action<IImageProcessingContext> operation)
26-
=> source.ApplyProcessor(new RecursiveImageProcessor(source.GetDrawingOptions(), region, operation));
26+
=> source.ApplyProcessor(new ClipPathProcessor(source.GetDrawingOptions(), region, operation));
2727
}
2828
}

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

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,46 @@
77
namespace SixLabors.ImageSharp.Drawing.Processing
88
{
99
/// <summary>
10-
/// Adds extensions that allow the filling of regions with various brushes to the <see cref="Image{TPixel}"/> type.
10+
/// Adds extensions that allow the flood filling of images.
1111
/// </summary>
1212
public static class FillExtensions
1313
{
1414
/// <summary>
15-
/// Flood fills the image with the specified brush.
15+
/// Flood fills the image with the specified color.
1616
/// </summary>
17-
/// <param name="source">The image this method extends.</param>
18-
/// <param name="options">The drawing options.</param>
19-
/// <param name="brush">The details how to fill the region of interest.</param>
17+
/// <param name="source">The image processing context.</param>
18+
/// <param name="color">The color.</param>
2019
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
21-
public static IImageProcessingContext Fill(
22-
this IImageProcessingContext source,
23-
DrawingOptions options,
24-
IBrush brush) =>
25-
source.ApplyProcessor(new FillProcessor(options, brush));
20+
public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color)
21+
=> source.Fill(new SolidBrush(color));
2622

2723
/// <summary>
28-
/// Flood fills the image with the specified brush.
24+
/// Flood fills the image with the specified color.
2925
/// </summary>
30-
/// <param name="source">The image this method extends.</param>
31-
/// <param name="brush">The details how to fill the region of interest.</param>
26+
/// <param name="source">The image processing context.</param>
27+
/// <param name="options">The drawing options.</param>
28+
/// <param name="color">The color.</param>
3229
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
33-
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush) =>
34-
source.Fill(source.GetDrawingOptions(), brush);
30+
public static IImageProcessingContext Fill(this IImageProcessingContext source, DrawingOptions options, Color color)
31+
=> source.Fill(options, new SolidBrush(color));
3532

3633
/// <summary>
37-
/// Flood fills the image with the specified color.
34+
/// Flood fills the image with the specified brush.
3835
/// </summary>
39-
/// <param name="source">The image this method extends.</param>
40-
/// <param name="options">The drawing options.</param>
41-
/// <param name="color">The color.</param>
36+
/// <param name="source">The image processing context.</param>
37+
/// <param name="brush">The brush.</param>
4238
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
43-
public static IImageProcessingContext Fill(
44-
this IImageProcessingContext source,
45-
DrawingOptions options,
46-
Color color) =>
47-
source.Fill(options, new SolidBrush(color));
39+
public static IImageProcessingContext Fill(this IImageProcessingContext source, IBrush brush)
40+
=> source.Fill(source.GetDrawingOptions(), brush);
4841

4942
/// <summary>
50-
/// Flood fills the image with the specified color.
43+
/// Flood fills the image with the specified brush.
5144
/// </summary>
52-
/// <param name="source">The image this method extends.</param>
53-
/// <param name="color">The color.</param>
45+
/// <param name="source">The image processing context.</param>
46+
/// <param name="options">The drawing options.</param>
47+
/// <param name="brush">The brush.</param>
5448
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
55-
public static IImageProcessingContext Fill(this IImageProcessingContext source, Color color) =>
56-
source.Fill(new SolidBrush(color));
49+
public static IImageProcessingContext Fill(this IImageProcessingContext source, DrawingOptions options, IBrush brush)
50+
=> source.ApplyProcessor(new FillProcessor(options, brush));
5751
}
5852
}

0 commit comments

Comments
 (0)