diff --git a/src/ImageSharp/GraphicsOptions.cs b/src/ImageSharp/GraphicsOptions.cs index 1e18edb4ae..1673057b86 100644 --- a/src/ImageSharp/GraphicsOptions.cs +++ b/src/ImageSharp/GraphicsOptions.cs @@ -11,83 +11,23 @@ namespace SixLabors.ImageSharp /// public class GraphicsOptions { - private static readonly Lazy Lazy = new Lazy(); - private int antialiasSubpixelDepth; - private float blendPercentage; - - /// - /// Initializes a new instance of the class. - /// - public GraphicsOptions() - : this(true) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// If set to true [enable antialiasing]. - public GraphicsOptions(bool enableAntialiasing) - : this(enableAntialiasing, 1F) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// If set to true [enable antialiasing]. - /// The blending percentage to apply to the drawing operation - public GraphicsOptions(bool enableAntialiasing, float blendPercentage) - : this(enableAntialiasing, PixelColorBlendingMode.Normal, blendPercentage) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// If set to true [enable antialiasing]. - /// The color blending mode to apply to the drawing operation - /// The blending percentage to apply to the drawing operation - public GraphicsOptions( - bool enableAntialiasing, - PixelColorBlendingMode blending, - float blendPercentage) - : this(enableAntialiasing, blending, PixelAlphaCompositionMode.SrcOver, blendPercentage) - { - } - - /// - /// Initializes a new instance of the class. - /// - /// If set to true [enable antialiasing]. - /// The color blending mode to apply to the drawing operation - /// The alpha composition mode to apply to the drawing operation - /// The blending percentage to apply to the drawing operation - public GraphicsOptions( - bool enableAntialiasing, - PixelColorBlendingMode blending, - PixelAlphaCompositionMode composition, - float blendPercentage) - { - this.ColorBlendingMode = blending; - this.AlphaCompositionMode = composition; - this.BlendPercentage = blendPercentage; - this.AntialiasSubpixelDepth = 16; - this.Antialias = enableAntialiasing; - } + private int antialiasSubpixelDepth = 16; + private float blendPercentage = 1F; /// /// Gets the default instance. /// - public static GraphicsOptions Default { get; } = Lazy.Value; + public static GraphicsOptions Default { get; } = new GraphicsOptions(); /// /// Gets or sets a value indicating whether antialiasing should be applied. + /// Defaults to true. /// - public bool Antialias { get; set; } + public bool Antialias { get; set; } = true; /// /// Gets or sets a value indicating the number of subpixels to use while rendering with antialiasing enabled. + /// Defaults to 16. /// public int AntialiasSubpixelDepth { @@ -104,7 +44,8 @@ namespace SixLabors.ImageSharp } /// - /// Gets or sets a value indicating the blending percentage to apply to the drawing operation. + /// Gets or sets a value between indicating the blending percentage to apply to the drawing operation. + /// Range 0..1; Defaults to 1. /// public float BlendPercentage { @@ -120,18 +61,32 @@ namespace SixLabors.ImageSharp } } - // In the future we could expose a PixelBlender directly on here - // or some forms of PixelBlender factory for each pixel type. Will need - // some API thought post V1. - /// - /// Gets or sets a value indicating the color blending mode to apply to the drawing operation + /// Gets or sets a value indicating the color blending mode to apply to the drawing operation. + /// Defaults to . /// - public PixelColorBlendingMode ColorBlendingMode { get; set; } + public PixelColorBlendingMode ColorBlendingMode { get; set; } = PixelColorBlendingMode.Normal; /// /// Gets or sets a value indicating the alpha composition mode to apply to the drawing operation + /// Defaults to . + /// + public PixelAlphaCompositionMode AlphaCompositionMode { get; set; } = PixelAlphaCompositionMode.SrcOver; + + /// + /// Creates a shallow copy of the . /// - public PixelAlphaCompositionMode AlphaCompositionMode { get; set; } + /// A new options instance. + public GraphicsOptions Clone() + { + return new GraphicsOptions + { + AlphaCompositionMode = this.AlphaCompositionMode, + Antialias = this.Antialias, + AntialiasSubpixelDepth = this.AntialiasSubpixelDepth, + BlendPercentage = this.BlendPercentage, + ColorBlendingMode = this.ColorBlendingMode + }; + } } }