|
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 within the provided region defined by an <see cref="IPath"/> using the specified |
| 15 | + /// color without any blending. |
16 | 16 | /// </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 | | - } |
| 17 | + /// <param name="source">The image processing context.</param> |
| 18 | + /// <param name="color">The color.</param> |
| 19 | + /// <param name="region">The <see cref="IPath"/> defining the region to fill.</param> |
| 20 | + /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
| 21 | + public static IImageProcessingContext Clear( |
| 22 | + this IImageProcessingContext source, |
| 23 | + Color color, |
| 24 | + IPath region) |
| 25 | + => source.Clear(new SolidBrush(color), region); |
28 | 26 |
|
29 | 27 | /// <summary> |
30 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush 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. |
31 | 30 | /// </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> |
| 31 | + /// <param name="source">The image processing context.</param> |
| 32 | + /// <param name="options">The drawing options.</param> |
| 33 | + /// <param name="color">The color.</param> |
| 34 | + /// <param name="region">The <see cref="IPath"/> defining the region to fill.</param> |
36 | 35 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
37 | 36 | public static IImageProcessingContext Clear( |
38 | 37 | this IImageProcessingContext source, |
39 | 38 | DrawingOptions options, |
40 | | - IBrush brush, |
41 | | - IPath path) => |
42 | | - source.Fill(options.CloneForClearOperation(), brush, path); |
| 39 | + Color color, |
| 40 | + IPath region) |
| 41 | + => source.Clear(options, new SolidBrush(color), region); |
43 | 42 |
|
44 | 43 | /// <summary> |
45 | | - /// Flood fills the image in the shape of the provided polygon with 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. |
46 | 46 | /// </summary> |
47 | | - /// <param name="source">The image this method extends.</param> |
| 47 | + /// <param name="source">The image processing context.</param> |
48 | 48 | /// <param name="brush">The brush.</param> |
49 | | - /// <param name="path">The path.</param> |
| 49 | + /// <param name="region">The <see cref="IPath"/> defining the region to fill.</param> |
50 | 50 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
51 | | - public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, IPath path) => |
52 | | - source.Clear(source.GetDrawingOptions(), brush, path); |
| 51 | + public static IImageProcessingContext Clear( |
| 52 | + this IImageProcessingContext source, |
| 53 | + IBrush brush, |
| 54 | + IPath region) |
| 55 | + => source.Clear(source.GetDrawingOptions(), brush, region); |
53 | 56 |
|
54 | 57 | /// <summary> |
55 | | - /// Flood fills the image in the shape of the provided polygon with 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. |
56 | 60 | /// </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> |
| 61 | + /// <param name="source">The image processing context.</param> |
| 62 | + /// <param name="options">The drawing options.</param> |
| 63 | + /// <param name="brush">The brush.</param> |
| 64 | + /// <param name="region">The <see cref="IPath"/> defining the region to fill.</param> |
61 | 65 | /// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns> |
62 | 66 | public static IImageProcessingContext Clear( |
63 | 67 | this IImageProcessingContext source, |
64 | 68 | DrawingOptions options, |
65 | | - Color color, |
66 | | - IPath path) => |
67 | | - source.Clear(options, new SolidBrush(color), path); |
68 | | - |
69 | | - /// <summary> |
70 | | - /// Flood fills the image in the shape of the provided polygon with the specified brush without any blending. |
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); |
| 69 | + IBrush brush, |
| 70 | + IPath region) |
| 71 | + => source.Fill(options.CloneForClearOperation(), brush, region); |
78 | 72 | } |
79 | 73 | } |
0 commit comments