Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 2 additions & 22 deletions src/ImageSharp/GraphicsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ namespace SixLabors.ImageSharp;

/// <summary>
/// Provides configuration for controlling how graphics operations are rendered,
/// including antialiasing, pixel blending, alpha composition, and coverage thresholding.
/// including antialiasing, pixel blending, and alpha composition.
/// </summary>
public class GraphicsOptions : IDeepCloneable<GraphicsOptions>
{
private float antialiasThreshold = .5F;
private float blendPercentage = 1F;

/// <summary>
Expand All @@ -25,37 +24,18 @@ private GraphicsOptions(GraphicsOptions source)
{
this.AlphaCompositionMode = source.AlphaCompositionMode;
this.Antialias = source.Antialias;
this.AntialiasThreshold = source.AntialiasThreshold;
this.BlendPercentage = source.BlendPercentage;
this.ColorBlendingMode = source.ColorBlendingMode;
}

/// <summary>
/// Gets or sets a value indicating whether antialiasing should be applied.
/// When <see langword="true"/>, edges are rendered with smooth sub-pixel coverage.
/// When <see langword="false"/>, coverage is snapped to binary (fully opaque or fully transparent)
/// using <see cref="AntialiasThreshold"/> as the cutoff.
/// When <see langword="false"/>, coverage is snapped to binary (fully opaque or fully transparent).
/// Defaults to <see langword="true"/>.
/// </summary>
public bool Antialias { get; set; } = true;
Comment on lines 31 to 37

/// <summary>
/// Gets or sets the coverage threshold used when <see cref="Antialias"/> is <see langword="false"/>.
/// Pixels with antialiased coverage above this value are rendered as fully opaque;
/// pixels below are discarded. Valid range is 0 to 1. Lower values preserve more
/// thin features at small sizes. Defaults to <c>0.5F</c>.
/// </summary>
public float AntialiasThreshold
{
get => this.antialiasThreshold;

set
{
Guard.MustBeBetweenOrEqualTo(value, 0F, 1F, nameof(this.AntialiasThreshold));
this.antialiasThreshold = value;
}
}

/// <summary>
/// Gets or sets the blending percentage applied to the drawing operation.
/// A value of <c>1.0</c> applies the operation at full strength; <c>0.0</c> makes it invisible.
Expand Down
10 changes: 0 additions & 10 deletions tests/ImageSharp.Tests/GraphicsOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ public void DefaultGraphicsOptionsAntialias()
Assert.True(this.cloneGraphicsOptions.Antialias);
}

[Fact]
public void DefaultGraphicsOptionsAntialiasThreshold()
{
const float expected = .5F;
Assert.Equal(expected, this.newGraphicsOptions.AntialiasThreshold);
Assert.Equal(expected, this.cloneGraphicsOptions.AntialiasThreshold);
}

[Fact]
public void DefaultGraphicsOptionsBlendPercentage()
{
Expand Down Expand Up @@ -61,7 +53,6 @@ public void NonDefaultClone()
{
AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop,
Antialias = false,
AntialiasThreshold = .33F,
BlendPercentage = .25F,
ColorBlendingMode = PixelColorBlendingMode.HardLight,
};
Expand All @@ -79,7 +70,6 @@ public void CloneIsDeep()

actual.AlphaCompositionMode = PixelAlphaCompositionMode.DestAtop;
actual.Antialias = false;
actual.AntialiasThreshold = .67F;
actual.BlendPercentage = .25F;
actual.ColorBlendingMode = PixelColorBlendingMode.HardLight;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public class GraphicsOptionsComparer : IEqualityComparer<GraphicsOptions>
public bool Equals(GraphicsOptions x, GraphicsOptions y)
=> x.AlphaCompositionMode == y.AlphaCompositionMode
&& x.Antialias == y.Antialias
&& x.AntialiasThreshold == y.AntialiasThreshold
&& x.BlendPercentage == y.BlendPercentage
&& x.ColorBlendingMode == y.ColorBlendingMode;

Expand Down