Skip to content
Closed
Changes from 1 commit
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
55 changes: 53 additions & 2 deletions src/ImageSharp.Drawing/Processing/FillRectangleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0.

using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.Primitives;
using SixLabors.Shapes;

Expand Down Expand Up @@ -38,7 +39,7 @@ public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessing
=> source.Fill(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.
/// Flood fills the image in the shape of the provided rectangle with the specified color.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
Expand All @@ -51,7 +52,7 @@ public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessing
=> source.Fill(options, new SolidBrush<TPixel>(color), shape);

/// <summary>
/// Flood fills the image in the shape of the provided rectangle with the specified brush.
/// Flood fills the image in the shape of the provided rectangle with the specified color.
/// </summary>
/// <typeparam name="TPixel">The type of the color.</typeparam>
/// <param name="source">The image this method extends.</param>
Expand All @@ -61,5 +62,55 @@ public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessing
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, RectangleF shape)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(new SolidBrush<TPixel>(color), shape);

/// <summary>
/// Fills the image in the shape of the provided rectangle 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="rectangle">The rectangle shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, TPixel color, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(GraphicsOptions.Default, new SolidBrush<TPixel>(color), rectangle);

/// <summary>
/// Fills the image in the shape of the provided rectangle 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>
/// <param name="rectangle">The rectangle shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, IBrush<TPixel> brush, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(GraphicsOptions.Default, brush, rectangle);

/// <summary>
/// Fills the image in the shape of the provided rectangle 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 graphics options.</param>
/// <param name="color">The color.</param>
/// <param name="rectangle">The rectangle shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, TPixel color, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.Fill(options, new SolidBrush<TPixel>(color), rectangle);

/// <summary>
/// Fills the image in the shape of the provided rectangle 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>
/// <param name="rectangle">The rectangle shape.</param>
/// <returns>The <see cref="Image{TPixel}"/>.</returns>
public static IImageProcessingContext<TPixel> Fill<TPixel>(this IImageProcessingContext<TPixel> source, GraphicsOptions options, IBrush<TPixel> brush, Rectangle rectangle)
where TPixel : struct, IPixel<TPixel>
=> source.ApplyProcessor(new FillProcessor<TPixel>(brush, options), rectangle);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand @tocsoft 's comment well, it would be the best to select between FillRegionProcessor and FillProcessor at this point, depending on the value of options.Antialias. All overloads should delegate into this method, including the ones which haven't been touched.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been thinking about this, and now I'm unsure about the expected default behavior for these use cases.

  • If a rectangle is being filled with a solid color, is it expected to antialias corners by default?
  • What about non-solid brushes?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought the internal processor code checked to see if the bush was a solid color?

}
}