Repository navigation
'Clear()' image operation #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4720c39
Add 'Clear' extensions matching Fill
tocsoft bbc1afe
Merge branch 'master' into sw/clear
tocsoft eda9825
Merge branch 'master' into sw/clear
tocsoft cf387ef
update return type comment for all exterions
tocsoft 8928ef6
fixed xml comment 'options' spellings
tocsoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
72 changes: 72 additions & 0 deletions
72
src/ImageSharp.Drawing/Processing/Extensions/ClearExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| /// </summary> | ||
| /// <param name="options">The optinos to clone</param> | ||
|
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)); | ||
| } | ||
| } | ||
78 changes: 78 additions & 0 deletions
78
src/ImageSharp.Drawing/Processing/Extensions/ClearPathExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> | ||
|
tocsoft marked this conversation as resolved.
Outdated
|
||
| /// Clones the graphicoptions and applies changes required to force clearing. | ||
|
tocsoft marked this conversation as resolved.
Outdated
|
||
| /// </summary> | ||
| /// <param name="shapeOptions">The optinos to clone</param> | ||
|
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> | ||
|
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); | ||
| } | ||
| } | ||
63 changes: 63 additions & 0 deletions
63
src/ImageSharp.Drawing/Processing/Extensions/ClearRectangleExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
64 changes: 64 additions & 0 deletions
64
src/ImageSharp.Drawing/Processing/Extensions/ClearRegionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.