Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions src/ImageSharp.Drawing/Processing/Extensions/ClearExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Processing;

namespace SixLabors.ImageSharp.Drawing.Processing
{
/// <summary>
/// Adds extensions that allow the clearing of regions with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class ClearExtensions
{
/// <summary>
/// Clones the graphic options and applies changes required to force clearing.
/// </summary>
/// <param name="options">The options to clone</param>
/// <returns>A clone of option with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
internal static GraphicsOptions CloneForClearOperation(this GraphicsOptions options)
{
options = options.DeepClone();
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
options.BlendPercentage = 1;
return options;
}

/// <summary>
/// Flood fills the image with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
GraphicsOptions options,
IBrush brush)
=> source.Fill(options.CloneForClearOperation(), brush);

/// <summary>
/// Flood fills the image with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The details how to fill the region of interest.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush) =>
source.Clear(source.GetGraphicsOptions(), brush);

/// <summary>
/// Flood fills the image with the specified color without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param>
/// <param name="color">The color.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
GraphicsOptions options,
Color color) =>
source.Clear(options, new SolidBrush(color));

/// <summary>
/// Flood fills the image with the specified color without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color) =>
source.Clear(new SolidBrush(color));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Processing;

namespace SixLabors.ImageSharp.Drawing.Processing
{
/// <summary>
/// Adds extensions that allow the filling of polygon outlines to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class ClearPathExtensions
{
/// <summary>
/// Clones the shape graphic options and applies changes required to force clearing.
/// </summary>
/// <param name="shapeOptions">The options to clone</param>
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
internal static ShapeGraphicsOptions CloneForClearOperation(this ShapeGraphicsOptions shapeOptions)
{
var options = shapeOptions.GraphicsOptions.DeepClone();
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
options.BlendPercentage = 1;

return new ShapeGraphicsOptions(options, shapeOptions.ShapeOptions);
}

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param>
/// <param name="path">The shape.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
IBrush brush,
IPath path) =>
source.Fill(options.CloneForClearOperation(), brush, path);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, IPath path) =>
source.Clear(source.GetShapeGraphicsOptions(), brush, path);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param>
/// <param name="color">The color.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Color color,
IPath path) =>
source.Clear(options, new SolidBrush(color), path);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="path">The path.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, IPath path) =>
source.Clear(new SolidBrush(color), path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.Processing;

namespace SixLabors.ImageSharp.Drawing.Processing
{
/// <summary>
/// Adds extensions that allow the filling of rectangles to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class ClearRectangleExtensions
{
/// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
IBrush brush,
RectangleF shape) =>
source.Clear(options, brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));

/// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, RectangleF shape) =>
source.Clear(brush, new RectangularPolygon(shape.X, shape.Y, shape.Width, shape.Height));

/// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Color color,
RectangleF shape) =>
source.Clear(options, new SolidBrush(color), shape);

/// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="shape">The shape.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, RectangleF shape) =>
source.Clear(new SolidBrush(color), shape);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.Drawing.Processing.Processors.Drawing;
using SixLabors.ImageSharp.Processing;

namespace SixLabors.ImageSharp.Drawing.Processing
{
/// <summary>
/// Adds extensions that allow the filling of regions with various brushes to the <see cref="Image{TPixel}"/> type.
/// </summary>
public static class ClearRegionExtensions
{
/// <summary>
/// Flood fills the image with in the region with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, IBrush brush, Region region) =>
source.Clear(source.GetShapeGraphicsOptions(), brush, region);

/// <summary>
/// Flood fills the image with in the region with the specified brush without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The graphics options.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
IBrush brush,
Region region) =>
source.Fill(options.CloneForClearOperation(), brush, region);

/// <summary>
/// Flood fills the image with in the region with the specified color without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="options">The options.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Color color,
Region region) =>
source.Clear(options, new SolidBrush(color), region);

/// <summary>
/// Flood fills the image with in the region with the specified color without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="color">The color.</param>
/// <param name="region">The region.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, Region region) =>
source.Clear(new SolidBrush(color), region);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static class DrawBezierExtensions
/// <param name="options">The options.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Expand All @@ -31,7 +31,7 @@ public static IImageProcessingContext DrawBeziers(
/// <param name="source">The image this method extends.</param>
/// <param name="pen">The pen.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
IPen pen,
Expand All @@ -46,7 +46,7 @@ public static IImageProcessingContext DrawBeziers(
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Expand All @@ -62,7 +62,7 @@ public static IImageProcessingContext DrawBeziers(
/// <param name="brush">The brush.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
IBrush brush,
Expand All @@ -77,7 +77,7 @@ public static IImageProcessingContext DrawBeziers(
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
Color color,
Expand All @@ -93,7 +93,7 @@ public static IImageProcessingContext DrawBeziers(
/// <param name="color">The color.</param>
/// <param name="thickness">The thickness.</param>
/// <param name="points">The points.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext DrawBeziers(
this IImageProcessingContext source,
ShapeGraphicsOptions options,
Expand Down
Loading