Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 graphicoptions and applies changes required to force clearing.
Comment thread
tocsoft marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="options">The optinos to clone</param>
Comment thread
tocsoft marked this conversation as resolved.
Outdated
/// <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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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,78 @@
// 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>
Comment thread
tocsoft marked this conversation as resolved.
Outdated
/// Clones the graphicoptions and applies changes required to force clearing.
Comment thread
tocsoft marked this conversation as resolved.
Outdated
/// </summary>
/// <param name="shapeOptions">The optinos to clone</param>
Comment thread
tocsoft marked this conversation as resolved.
Outdated
/// <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="Image{TPixel}"/>.</returns>
Comment thread
tocsoft marked this conversation as resolved.
Outdated
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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</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="Image{TPixel}"/>.</returns>
public static IImageProcessingContext Clear(this IImageProcessingContext source, Color color, Region region) =>
source.Clear(new SolidBrush(color), region);
}
}
Loading