|
1 | 1 | // Copyright (c) Six Labors. |
2 | 2 | // Licensed under the Apache License, Version 2.0. |
3 | 3 |
|
4 | | -using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing; |
5 | 4 | using SixLabors.ImageSharp.Processing; |
6 | 5 |
|
7 | 6 | namespace SixLabors.ImageSharp.Drawing.Processing |
8 | 7 | { |
9 | 8 | /// <summary> |
10 | | - /// Adds extensions that allow the filling of polygon outlines to the <see cref="Image{TPixel}"/> type. |
| 9 | + /// Adds extensions that allow the flood filling of polygon outlines without blending. |
11 | 10 | /// </summary> |
12 | 11 | public static class ClearPathExtensions |
13 | 12 | { |
14 | 13 | /// <summary> |
15 | | - /// Clones the shape graphic options and applies changes required to force clearing. |
| 14 | + /// Flood fills the image in the path of the provided polygon with the specified brush without any blending. |
16 | 15 | /// </summary> |
17 | | - /// <param name="shapeOptions">The options to clone</param> |
18 | | - /// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns> |
19 | | - internal static DrawingOptions CloneForClearOperation(this DrawingOptions shapeOptions) |
20 | | - { |
21 | | - GraphicsOptions options = shapeOptions.GraphicsOptions.DeepClone(); |
22 | | - options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal; |
23 | | - options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src; |
24 | | - options.BlendPercentage = 1; |
25 | | - |
26 | | - return new DrawingOptions(options, shapeOptions.ShapeOptions, shapeOptions.TextOptions, shapeOptions.Transform); |
27 | | - } |
| 16 | + /// <param name="source">The image processing context.</param> |
| 17 | + /// <param name="color">The color.</param> |
| 18 | + /// <param name="path">The logic path.</param> |
| 19 | + /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
| 20 | + public static IImageProcessingContext Clear( |
| 21 | + this IImageProcessingContext source, |
| 22 | + Color color, |
| 23 | + IPath path) => |
| 24 | + source.Clear(new SolidBrush(color), path); |
28 | 25 |
|
29 | 26 | /// <summary> |
30 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush without any blending. |
| 27 | + /// Flood fills the image in the path of the provided polygon with the specified brush without any blending. |
31 | 28 | /// </summary> |
32 | | - /// <param name="source">The image this method extends.</param> |
33 | | - /// <param name="options">The graphics options.</param> |
34 | | - /// <param name="brush">The brush.</param> |
35 | | - /// <param name="path">The shape.</param> |
| 29 | + /// <param name="source">The image processing context.</param> |
| 30 | + /// <param name="options">The drawing options.</param> |
| 31 | + /// <param name="color">The color.</param> |
| 32 | + /// <param name="path">The logic path.</param> |
36 | 33 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
37 | 34 | public static IImageProcessingContext Clear( |
38 | 35 | this IImageProcessingContext source, |
39 | 36 | DrawingOptions options, |
40 | | - IBrush brush, |
| 37 | + Color color, |
41 | 38 | IPath path) => |
42 | | - source.Fill(options.CloneForClearOperation(), brush, path); |
| 39 | + source.Clear(options, new SolidBrush(color), path); |
43 | 40 |
|
44 | 41 | /// <summary> |
45 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush without any blending. |
| 42 | + /// Flood fills the image in the path of the provided polygon with the specified brush without any blending. |
46 | 43 | /// </summary> |
47 | | - /// <param name="source">The image this method extends.</param> |
| 44 | + /// <param name="source">The image processing context.</param> |
48 | 45 | /// <param name="brush">The brush.</param> |
49 | | - /// <param name="path">The path.</param> |
| 46 | + /// <param name="path">The logic path.</param> |
50 | 47 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
51 | | - public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, IPath path) => |
| 48 | + public static IImageProcessingContext Clear( |
| 49 | + this IImageProcessingContext source, |
| 50 | + IBrush brush, |
| 51 | + IPath path) => |
52 | 52 | source.Clear(source.GetDrawingOptions(), brush, path); |
53 | 53 |
|
54 | 54 | /// <summary> |
55 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush without any blending. |
| 55 | + /// Flood fills the image in the path of the provided polygon with the specified brush without any blending. |
56 | 56 | /// </summary> |
57 | | - /// <param name="source">The image this method extends.</param> |
58 | | - /// <param name="options">The options.</param> |
59 | | - /// <param name="color">The color.</param> |
60 | | - /// <param name="path">The path.</param> |
| 57 | + /// <param name="source">The image processing context.</param> |
| 58 | + /// <param name="options">The drawing options.</param> |
| 59 | + /// <param name="brush">The brush.</param> |
| 60 | + /// <param name="path">The logic path.</param> |
61 | 61 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
62 | 62 | public static IImageProcessingContext Clear( |
63 | 63 | this IImageProcessingContext source, |
64 | 64 | DrawingOptions options, |
65 | | - Color color, |
| 65 | + IBrush brush, |
66 | 66 | IPath path) => |
67 | | - source.Clear(options, new SolidBrush(color), path); |
| 67 | + source.Fill(options.CloneForClearOperation(), brush, path); |
68 | 68 |
|
69 | 69 | /// <summary> |
70 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush without any blending. |
| 70 | + /// Clones the path graphic options and applies changes required to force clearing. |
71 | 71 | /// </summary> |
72 | | - /// <param name="source">The image this method extends.</param> |
73 | | - /// <param name="color">The color.</param> |
74 | | - /// <param name="path">The path.</param> |
75 | | - /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
76 | | - public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, IPath path) => |
77 | | - source.Clear(new SolidBrush(color), path); |
| 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 | + } |
78 | 83 | } |
79 | 84 | } |
0 commit comments