/// <summary> /// Initializes a new instance of the <see cref="RandomNoiseDitherer"/> class. /// <br/>See the <strong>Examples</strong> section for some examples. /// </summary> /// <param name="strength">The strength of the dithering effect between 0 and 1 (inclusive bounds). /// Specify 0 to use an auto value for each dithering session based on the used quantizer. /// <br/>See the <strong>Remarks</strong> section of the <see cref="OrderedDitherer"/> class for more details and some examples regarding dithering strength. /// The same applies also for the <see cref="RandomNoiseDitherer"/> class. This parameter is optional. /// <br/>Default value: <c>0</c>.</param> /// <param name="seed">If <see langword="null"/>, then a <a href="https://docs.kgysoft.net/corelibraries/?topic=html/T_KGySoft_CoreLibraries_ThreadSafeRandom.htm" target="_blank">ThreadSafeRandom</a> /// instance will be used internally with a time-dependent seed value, and the dithering session will allow parallel processing. /// If not <see langword="null"/>, then a <see cref="Random"/> instance will be created for each dithering session with the specified <paramref name="seed"/>, and the dithering session will not allow parallel processing.</param> /// <example> /// The following example demonstrates how to use the <see cref="RandomNoiseDitherer"/> class. /// <code lang="C#"><![CDATA[ /// public static Bitmap ToDitheredRandomNoise(Bitmap source, IQuantizer quantizer) /// { /// IDitherer ditherer = new RandomNoiseDitherer(); /// /// // a.) this solution returns a new bitmap and does not change the original one: /// return source.ConvertPixelFormat(quantizer.PixelFormatHint, quantizer, ditherer); /// /// // b.) alternatively, you can perform the dithering directly on the source bitmap: /// source.Dither(quantizer, ditherer); /// return source; /// }]]></code> /// <para>The example above may produce the following results: /// <list type="table"> /// <listheader><term>Original image</term><term>Quantized and dithered image</term></listheader> /// <item> /// <term><div style="text-align:center;width:512px"> /// <para><img src="../Help/Images/AlphaGradient.png" alt="Color hues with alpha gradient"/> /// <br/>Color hues with alpha gradient</para></div></term> /// <term> /// <div style="text-align:center;width:512px"> /// <para><img src="../Help/Images/AlphaGradientDefault8bppSilverDitheredRN.gif" alt="Color hues with system default 8 BPP palette, using silver background and random noise dithering"/> /// <br/>Quantizing with <see cref="PredefinedColorsQuantizer.SystemDefault8BppPalette">system default 8 BPP palette</see></para></div></term> /// </item> /// <item> /// <term><div style="text-align:center;width:512px"> /// <para><img src="../Help/Images/GrayShades.gif" alt="Grayscale color shades with different bit depths"/> /// <br/>Grayscale color shades</para></div></term> /// <term> /// <div style="text-align:center;width:512px"> /// <para><img src="../Help/Images/GrayShadesBWDitheredRN.gif" alt="Grayscale color shades with black and white palette using random noise dithering"/> /// <br/>Quantizing with <see cref="PredefinedColorsQuantizer.BlackAndWhite">black and white palette</see></para></div></term> /// </item> /// </list></para> /// </example> public RandomNoiseDitherer(float strength = 0f, int?seed = null) { if (Single.IsNaN(strength) || strength < 0f || strength > 1f) { throw new ArgumentOutOfRangeException(nameof(strength), PublicResources.ArgumentMustBeBetween(0, 1)); } this.strength = strength; this.seed = seed; }
private OptimizedPaletteQuantizer(Algorithm algorithm, int maxColors, Color backColor, byte alphaThreshold) { if (maxColors < 2 || maxColors > 256) { throw new ArgumentOutOfRangeException(nameof(maxColors), PublicResources.ArgumentMustBeBetween(2, 256)); } this.algorithm = algorithm; this.maxColors = maxColors; this.backColor = new Color32(backColor).ToOpaque(); this.alphaThreshold = alphaThreshold; }
/// <summary> /// Initializes a new instance of the <see cref="DrawingProgress"/> struct. /// </summary> /// <param name="operationType">Specifies the type of the drawing operation.</param> /// <param name="maximumValue">The maximum value.</param> /// <param name="currentValue">The current value.</param> public DrawingProgress(DrawingOperation operationType, int maximumValue, int currentValue) { if (!operationType.IsDefined()) { throw new ArgumentOutOfRangeException(nameof(operationType), PublicResources.EnumOutOfRange(operationType)); } if (maximumValue < 0) { throw new ArgumentOutOfRangeException(nameof(maximumValue), PublicResources.ArgumentMustBeGreaterThanOrEqualTo(0)); } if ((uint)currentValue > (uint)maximumValue) { throw new ArgumentOutOfRangeException(nameof(currentValue), PublicResources.ArgumentMustBeBetween(0, maximumValue)); } OperationType = operationType; MaximumValue = maximumValue; CurrentValue = currentValue; }