// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
namespace SixLabors.ImageSharp.Drawing.Processing.Backends {
///
/// Describes whether rasterizers should emit continuous coverage or binary aliased coverage.
///
public enum RasterizationMode
{
///
/// Emit continuous coverage in the range [0, 1].
///
Antialiased = 0,
///
/// Emit binary coverage values (0 or 1).
///
Aliased = 1
}
///
/// Describes where sample coverage is aligned relative to destination pixels.
///
public enum RasterizerSamplingOrigin
{
///
/// Samples are aligned to pixel boundaries.
///
PixelBoundary = 0,
///
/// Samples are aligned to pixel centers.
///
PixelCenter = 1
}
///
/// Immutable options used by rasterizers when scan-converting vector geometry.
///
public readonly struct RasterizerOptions
{
///
/// Initializes a new instance of the struct.
///
/// Destination bounds to rasterize into.
/// Polygon intersection rule.
/// Rasterization coverage mode.
/// Sampling origin alignment.
/// Coverage threshold for aliased mode (0 to 1).
public RasterizerOptions(
Rectangle interest,
IntersectionRule intersectionRule,
RasterizationMode rasterizationMode,
RasterizerSamplingOrigin samplingOrigin,
float antialiasThreshold)
{
this.Interest = interest;
this.IntersectionRule = intersectionRule;
this.RasterizationMode = rasterizationMode;
this.SamplingOrigin = samplingOrigin;
this.AntialiasThreshold = antialiasThreshold;
}
///
/// Gets destination bounds to rasterize into.
///
public Rectangle Interest { get; }
///
/// Gets the polygon intersection rule.
///
public IntersectionRule IntersectionRule { get; }
///
/// Gets the rasterization coverage mode.
///
public RasterizationMode RasterizationMode { get; }
///
/// Gets the sampling origin alignment.
///
public RasterizerSamplingOrigin SamplingOrigin { get; }
///
/// Gets the coverage threshold used when is .
/// Pixels with coverage above this value are rendered as fully opaque; pixels below are discarded.
///
public float AntialiasThreshold { get; }
///
/// Creates a copy of the current options with a different interest rectangle.
///
/// The replacement interest rectangle.
/// A new value.
public RasterizerOptions WithInterest(Rectangle interest)
=> new(interest, this.IntersectionRule, this.RasterizationMode, this.SamplingOrigin, this.AntialiasThreshold);
}
}