mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
5.4 KiB
99 lines
5.4 KiB
// Copyright (c) Six Labors and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
using SixLabors.ImageSharp.Primitives;
|
|
using SixLabors.ImageSharp.Processing.Processors.Drawing;
|
|
|
|
namespace SixLabors.ImageSharp.Processing
|
|
{
|
|
/// <summary>
|
|
/// Adds extensions that allow the filling of regions with various brushes to the <see cref="Image{TPixel}"/> type.
|
|
/// </summary>
|
|
public static class FillRegionExtensions
|
|
{
|
|
/// <summary>
|
|
/// Flood fills the image with the specified brush.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.Fill(GraphicsOptions.Default, brush);
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with the specified color.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.Fill(new SolidBrush<TPixel>(color));
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with in the region with the specified brush.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Region region)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.Fill(GraphicsOptions.Default, brush, region);
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with in the region with the specified color.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, Region region)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.Fill(options, new SolidBrush<TPixel>(color), region);
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with in the region with the specified color.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Region region)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.Fill(new SolidBrush<TPixel>(color), region);
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with in the region with the specified brush.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, Region region)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.ApplyProcessor(new FillRegionProcessor<TPixel>(brush, region, options));
|
|
|
|
/// <summary>
|
|
/// Flood fills the image with the specified brush.
|
|
/// </summary>
|
|
/// <typeparam name="TPixel">The type of the color.</typeparam>
|
|
/// <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<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush)
|
|
where TPixel : struct, IPixel<TPixel>
|
|
=> source.ApplyProcessor(new FillProcessor<TPixel>(brush, options));
|
|
}
|
|
}
|