-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAtkinsonDithering.cs
67 lines (55 loc) · 1.95 KB
/
AtkinsonDithering.cs
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
/*
This file implements error pushing of dithering via Atkinson kernel.
This is free and unencumbered software released into the public domain.
*/
class AtkinsonDithering : DitheringBase
{
public AtkinsonDithering(FindColor colorfunc) : base(colorfunc)
{
this.methodLongName = "Atkinson";
this.fileNameAddition = "_ATK";
}
override protected void PushError(int x, int y, short[] quantError)
{
// Push error
// X 1/8 1/8
// 1/8 1/8 1/8
// 1/8
int xMinusOne = x - 1;
int xPlusOne = x + 1;
int xPlusTwo = x + 2;
int yPlusOne = y + 1;
int yPlusTwo = y + 2;
float multiplier = 1.0f / 8.0f; // Atkinson Dithering has same multiplier for every item
// Current row
int currentRow = y;
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, multiplier);
}
if (this.IsValidCoordinate(xPlusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusTwo, currentRow, quantError, multiplier);
}
// Next row
currentRow = yPlusOne;
if (this.IsValidCoordinate(xMinusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusOne, currentRow, quantError, multiplier);
}
if (this.IsValidCoordinate(x, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(x, currentRow, quantError, multiplier);
}
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, multiplier);
}
// Next row
currentRow = yPlusTwo;
if (this.IsValidCoordinate(x, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(x, currentRow, quantError, multiplier);
}
}
}