-
-
Notifications
You must be signed in to change notification settings - Fork 893
Expand file tree
/
Copy pathBinaryDitherExtensions.cs
More file actions
73 lines (68 loc) · 3.63 KB
/
Copy pathBinaryDitherExtensions.cs
File metadata and controls
73 lines (68 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.
using SixLabors.ImageSharp.Processing.Processors.Dithering;
namespace SixLabors.ImageSharp.Processing
{
/// <summary>
/// Defines extensions to apply binary dithering on an <see cref="Image"/>
/// using Mutate/Clone.
/// </summary>
public static class BinaryDitherExtensions
{
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext
BinaryDither(this IImageProcessingContext source, IDither dither) =>
BinaryDither(source, dither, Color.White, Color.Black);
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IDither dither,
Color upperColor,
Color lowerColor) =>
source.ApplyProcessor(new PaletteDitherProcessor(dither, new[] { upperColor, lowerColor }));
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IDither dither,
Rectangle rectangle) =>
BinaryDither(source, dither, Color.White, Color.Black, rectangle);
/// <summary>
/// Dithers the image reducing it to two colors using ordered dithering.
/// </summary>
/// <param name="source">The image this method extends.</param>
/// <param name="dither">The ordered ditherer.</param>
/// <param name="upperColor">The color to use for pixels that are above the threshold.</param>
/// <param name="lowerColor">The color to use for pixels that are below the threshold</param>
/// <param name="rectangle">
/// The <see cref="Rectangle"/> structure that specifies the portion of the image object to alter.
/// </param>
/// <returns>The <see cref="IImageProcessingContext"/> to allow chaining of operations.</returns>
public static IImageProcessingContext BinaryDither(
this IImageProcessingContext source,
IDither dither,
Color upperColor,
Color lowerColor,
Rectangle rectangle) =>
source.ApplyProcessor(new PaletteDitherProcessor(dither, new[] { upperColor, lowerColor }), rectangle);
}
}