Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dfba96f
Rip out region.
JimBobSquarePants Jul 9, 2021
b69365e
Add new Clip extension and tests
JimBobSquarePants Jul 10, 2021
80508c7
Update DrawTextProcessor{TPixel}.cs
JimBobSquarePants Jul 10, 2021
a4c39f2
Merge branch 'master' into js/region-clip
JimBobSquarePants Jul 14, 2021
04dd529
Merge branch 'master' into js/region-clip
JimBobSquarePants Jul 15, 2021
3b8732f
Update src/ImageSharp.Drawing/Processing/Extensions/FillPathExtension…
JimBobSquarePants Jul 16, 2021
08c741a
Update src/ImageSharp.Drawing/Processing/Extensions/FillPathExtension…
JimBobSquarePants Jul 16, 2021
08d8550
Update src/ImageSharp.Drawing/Processing/Processors/Drawing/Recursive…
JimBobSquarePants Jul 16, 2021
fe045b5
Avoid crop
JimBobSquarePants Jul 16, 2021
f4be2f7
Fix comment
JimBobSquarePants Jul 16, 2021
07c3bf1
Better tests
JimBobSquarePants Jul 16, 2021
5743bf9
enable image brush to be only draw a portion of the source image
tocsoft Jul 23, 2021
7686e91
Merge pull request #154 from SixLabors/sw/self-cliping-image-brush
JimBobSquarePants Jul 24, 2021
b543d83
Update src/ImageSharp.Drawing/Processing/Extensions/ClearPathExtensio…
JimBobSquarePants Jul 25, 2021
dfd59bb
Update src/ImageSharp.Drawing/Processing/Extensions/ClearPathExtensio…
JimBobSquarePants Jul 25, 2021
5d5cf96
Cleanup
JimBobSquarePants Jul 25, 2021
86348a0
Merge branch 'js/region-clip' of https://github.com/SixLabors/ImageSh…
JimBobSquarePants Jul 25, 2021
9a6a0b1
More clean up and update tests
JimBobSquarePants Jul 25, 2021
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
21 changes: 0 additions & 21 deletions src/ImageSharp.Drawing/Primitives/Region.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/ImageSharp.Drawing/Primitives/ShapePath.cs

This file was deleted.

38 changes: 0 additions & 38 deletions src/ImageSharp.Drawing/Primitives/ShapeRegion.cs

This file was deleted.

74 changes: 34 additions & 40 deletions src/ImageSharp.Drawing/Processing/Extensions/ClearExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,72 +1,66 @@
// Copyright (c) Six Labors.
// 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.
/// Adds extensions that allow the flood filling of images without blending.
/// </summary>
public static class ClearExtensions
{
/// <summary>
/// Clones the graphic options and applies changes required to force clearing.
/// Flood fills the image with the specified color without any blending.
/// </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;
}
/// <param name="source">The image processing context.</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));

/// <summary>
/// Flood fills the image with the specified brush without any blending.
/// 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="brush">The details how to fill the region of interest.</param>
/// <param name="source">The image processing context.</param>
/// <param name="options">The drawing 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,
IBrush brush)
=> source.Fill(options.CloneForClearOperation(), brush);
public static IImageProcessingContext Clear(this IImageProcessingContext source, DrawingOptions options, Color color)
=> source.Clear(options, new SolidBrush(color));

/// <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>
/// <param name="source">The image processing context.</param>
/// <param name="brush">The brush.</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);
source.Clear(source.GetDrawingOptions(), brush);

/// <summary>
/// Flood fills the image with the specified color without any blending.
/// 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="color">The color.</param>
/// <param name="source">The image processing context.</param>
/// <param name="options">The drawing options.</param>
/// <param name="brush">The brush.</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));
public static IImageProcessingContext Clear(this IImageProcessingContext source, DrawingOptions options, IBrush brush)
=> source.Fill(options.CloneForClearOperation(), brush);

/// <summary>
/// Flood fills the image with the specified color without any blending.
/// Clones the path graphic options and applies changes required to force clearing.
/// </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));
/// <param name="drawingOptions">The drawing options to clone</param>
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
internal static DrawingOptions CloneForClearOperation(this DrawingOptions drawingOptions)
{
GraphicsOptions options = drawingOptions.GraphicsOptions.DeepClone();
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
options.BlendPercentage = 1F;

return new DrawingOptions(options, drawingOptions.ShapeOptions, drawingOptions.TextOptions, drawingOptions.Transform);
}
}
}
84 changes: 39 additions & 45 deletions src/ImageSharp.Drawing/Processing/Extensions/ClearPathExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,79 +1,73 @@
// Copyright (c) Six Labors.
// 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.
/// Adds extensions that allow the flood filling of polygon outlines without blending.
/// </summary>
public static class ClearPathExtensions
{
/// <summary>
/// Clones the shape graphic options and applies changes required to force clearing.
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified
/// color without any blending.
/// </summary>
/// <param name="shapeOptions">The options to clone</param>
/// <returns>A clone of shapeOptions with ColorBlendingMode, AlphaCompositionMode, and BlendPercentage set</returns>
internal static DrawingOptions CloneForClearOperation(this DrawingOptions shapeOptions)
{
GraphicsOptions options = shapeOptions.GraphicsOptions.DeepClone();
options.ColorBlendingMode = PixelFormats.PixelColorBlendingMode.Normal;
options.AlphaCompositionMode = PixelFormats.PixelAlphaCompositionMode.Src;
options.BlendPercentage = 1;

return new DrawingOptions(options, shapeOptions.ShapeOptions, shapeOptions.TextOptions, shapeOptions.Transform);
}
/// <param name="source">The image processing context.</param>
/// <param name="color">The color.</param>
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
Color color,
IPath region)
=> source.Clear(new SolidBrush(color), region);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using 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="brush">The brush.</param>
/// <param name="path">The shape.</param>
/// <param name="source">The image processing context.</param>
/// <param name="options">The drawing options.</param>
/// <param name="color">The color.</param>
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
DrawingOptions options,
IBrush brush,
IPath path) =>
source.Fill(options.CloneForClearOperation(), brush, path);
Color color,
IPath region)
=> source.Clear(options, new SolidBrush(color), region);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using the specified brush
/// without any blending.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="source">The image processing context.</param>
/// <param name="brush">The brush.</param>
/// <param name="path">The path.</param>
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</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.GetDrawingOptions(), brush, path);
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
IBrush brush,
IPath region)
=> source.Clear(source.GetDrawingOptions(), brush, region);

/// <summary>
/// Flood fills the image in the shape of the provided polygon with the specified brush without any blending.
/// Flood fills the image within the provided region defined by an <see cref="IPath"/> using 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>
/// <param name="source">The image processing context.</param>
/// <param name="options">The drawing options.</param>
/// <param name="brush">The brush.</param>
/// <param name="region">The <see cref="IPath"/> defining the region to fill.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext Clear(
this IImageProcessingContext source,
DrawingOptions 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);
IBrush brush,
IPath region)
=> source.Fill(options.CloneForClearOperation(), brush, region);
}
}
Loading