66namespace 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}
0 commit comments