Skip to content

Commit b58a245

Browse files
Merge pull request #150 from SixLabors/js/region-clip
Remove Region and add new Clip Extension
2 parents 1bf8714 + 9a6a0b1 commit b58a245

57 files changed

Lines changed: 795 additions & 1078 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageSharp.Drawing/Primitives/Region.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/ImageSharp.Drawing/Primitives/ShapePath.cs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/ImageSharp.Drawing/Primitives/ShapeRegion.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,66 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
54
using SixLabors.ImageSharp.Processing;
65

76
namespace SixLabors.ImageSharp.Drawing.Processing
87
{
98
/// <summary>
10-
/// 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.
1110
/// </summary>
1211
public static class ClearExtensions
1312
{
1413
/// <summary>
15-
/// Clones the graphic options and applies changes required to force clearing.
14+
/// Flood fills the image with the specified color without any blending.
1615
/// </summary>
17-
/// <param name="options">The options to clone</param>
18-
/// <returns>A clone of option with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
19-
internal static GraphicsOptions CloneForClearOperation(this GraphicsOptions options)
20-
{
21-
options = options.DeepClone();
22-
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
23-
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
24-
options.BlendPercentage = 1;
25-
return options;
26-
}
16+
/// <param name="source">The image processing context.</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));
2721

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

4132
/// <summary>
4233
/// Flood fills the image with the specified brush without any blending.
4334
/// </summary>
44-
/// <param name="source">The image this method extends.</param>
45-
/// <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>
4637
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
4738
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush) =>
48-
source.Clear(source.GetGraphicsOptions(), brush);
39+
source.Clear(source.GetDrawingOptions(), brush);
4940

5041
/// <summary>
51-
/// Flood fills the image with the specified color without any blending.
42+
/// Flood fills the image with the specified brush without any blending.
5243
/// </summary>
53-
/// <param name="source">The image this method extends.</param>
54-
/// <param name="options">The graphics options.</param>
55-
/// <param name="color">The color.</param>
44+
/// <param name="source">The image processing context.</param>
45+
/// <param name="options">The drawing options.</param>
46+
/// <param name="brush">The brush.</param>
5647
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
57-
public static IImageProcessingContext Clear(
58-
this IImageProcessingContext source,
59-
GraphicsOptions options,
60-
Color color) =>
61-
source.Clear(options, new SolidBrush(color));
48+
public static IImageProcessingContext Clear(this IImageProcessingContext source, DrawingOptions options, IBrush brush)
49+
=> source.Fill(options.CloneForClearOperation(), brush);
6250

6351
/// <summary>
64-
/// Flood fills the image with the specified color without any blending.
52+
/// Clones the path graphic options and applies changes required to force clearing.
6553
/// </summary>
66-
/// <param name="source">The image this method extends.</param>
67-
/// <param name="color">The color.</param>
68-
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
69-
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color) =>
70-
source.Clear(new SolidBrush(color));
54+
/// <param name="drawingOptions">The drawing options to clone</param>
55+
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
56+
internal static DrawingOptions CloneForClearOperation(this DrawingOptions drawingOptions)
57+
{
58+
GraphicsOptions options = drawingOptions.GraphicsOptions.DeepClone();
59+
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
60+
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
61+
options.BlendPercentage = 1F;
62+
63+
return new DrawingOptions(options, drawingOptions.ShapeOptions, drawingOptions.TextOptions, drawingOptions.Transform);
64+
}
7165
}
7266
}
Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,73 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Apache License, Version 2.0.
33

4-
using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
54
using SixLabors.ImageSharp.Processing;
65

76
namespace SixLabors.ImageSharp.Drawing.Processing
87
{
98
/// <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.
1110
/// </summary>
1211
public static class ClearPathExtensions
1312
{
1413
/// <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.
1616
/// </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);
2826

2927
/// <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.
3130
/// </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>
3635
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
3736
public static IImageProcessingContext Clear(
3837
this IImageProcessingContext source,
3938
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);
4342

4443
/// <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.
4646
/// </summary>
47-
/// <param name="source">The image this method extends.</param>
47+
/// <param name="source">The image processing context.</param>
4848
/// <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>
5050
/// <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);
5356

5457
/// <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.
5660
/// </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>
6165
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
6266
public static IImageProcessingContext Clear(
6367
this IImageProcessingContext source,
6468
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);
7872
}
7973
}

0 commit comments

Comments
 (0)