|
|
|
@ -36,6 +36,57 @@ namespace SixLabors.ImageSharp |
|
|
|
this.blendPercentage = 1; |
|
|
|
this.antialiasSubpixelDepth = 16; |
|
|
|
this.antialias = enableAntialiasing; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
|
|
|
|
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
|
|
|
|
public GraphicsOptions(bool enableAntialiasing, float opacity) |
|
|
|
{ |
|
|
|
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); |
|
|
|
|
|
|
|
this.colorBlendingMode = PixelColorBlendingMode.Normal; |
|
|
|
this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; |
|
|
|
this.blendPercentage = opacity; |
|
|
|
this.antialiasSubpixelDepth = 16; |
|
|
|
this.antialias = enableAntialiasing; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
|
|
|
|
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
|
|
|
|
/// <param name="blending">color blending mode to apply to the drawing operation</param>
|
|
|
|
public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, float opacity) |
|
|
|
{ |
|
|
|
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); |
|
|
|
|
|
|
|
this.colorBlendingMode = blending; |
|
|
|
this.alphaCompositionMode = PixelAlphaCompositionMode.SrcOver; |
|
|
|
this.blendPercentage = opacity; |
|
|
|
this.antialiasSubpixelDepth = 16; |
|
|
|
this.antialias = enableAntialiasing; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="GraphicsOptions"/> struct.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="enableAntialiasing">If set to <c>true</c> [enable antialiasing].</param>
|
|
|
|
/// <param name="opacity">blending percentage to apply to the drawing operation</param>
|
|
|
|
/// <param name="blending">color blending mode to apply to the drawing operation</param>
|
|
|
|
/// <param name="composition">alpha composition mode to apply to the drawing operation</param>
|
|
|
|
public GraphicsOptions(bool enableAntialiasing, PixelColorBlendingMode blending, PixelAlphaCompositionMode composition, float opacity) |
|
|
|
{ |
|
|
|
Guard.MustBeBetweenOrEqualTo(opacity, 0, 1, nameof(opacity)); |
|
|
|
|
|
|
|
this.colorBlendingMode = blending; |
|
|
|
this.alphaCompositionMode = composition; |
|
|
|
this.blendPercentage = opacity; |
|
|
|
this.antialiasSubpixelDepth = 16; |
|
|
|
this.antialias = enableAntialiasing; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -85,6 +136,44 @@ namespace SixLabors.ImageSharp |
|
|
|
{ |
|
|
|
get => this.alphaCompositionMode; |
|
|
|
set => this.alphaCompositionMode = value; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Evaluates if a given SOURCE color can completely replace a BACKDROP color given the current blending and composition settings.
|
|
|
|
/// </summary>
|
|
|
|
/// <typeparam name="TPixel">The pixel format</typeparam>
|
|
|
|
/// <param name="color">the color</param>
|
|
|
|
/// <returns>true if the color can be considered opaque</returns>
|
|
|
|
/// <remarks>
|
|
|
|
/// Blending and composition is an expensive operation, in some cases, like
|
|
|
|
/// filling with a solid color, the blending can be avoided by a plain color replacement.
|
|
|
|
/// This method can be useful for such processors to select the fast path.
|
|
|
|
/// </remarks>
|
|
|
|
internal bool IsOpaqueColorWithoutBlending<TPixel>(TPixel color) |
|
|
|
where TPixel : struct, IPixel<TPixel> |
|
|
|
{ |
|
|
|
if (this.ColorBlendingMode != PixelColorBlendingMode.Normal) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.AlphaCompositionMode != PixelAlphaCompositionMode.SrcOver && |
|
|
|
this.AlphaCompositionMode != PixelAlphaCompositionMode.Src) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (this.BlendPercentage != 1f) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
if (color.ToVector4().W != 1f) |
|
|
|
{ |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
} |