-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSierraDithering.cs
86 lines (71 loc) · 2.64 KB
/
SierraDithering.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
This file implements error pushing of dithering via (Frankie) Sierra kernel.
This is free and unencumbered software released into the public domain.
*/
class SierraDithering : DitheringBase
{
public SierraDithering(FindColor colorfunc) : base(colorfunc)
{
this.methodLongName = "Sierra";
this.fileNameAddition = "_SIE";
}
override protected void PushError(int x, int y, short[] quantError)
{
// Push error
// X 5/32 3/32
// 2/32 4/32 5/32 4/32 2/32
// 2/32 3/32 2/32
int xMinusOne = x - 1;
int xMinusTwo = x - 2;
int xPlusOne = x + 1;
int xPlusTwo = x + 2;
int yPlusOne = y + 1;
int yPlusTwo = y + 2;
// Current row
int currentRow = y;
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, 5.0f / 32.0f);
}
if (this.IsValidCoordinate(xPlusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusTwo, currentRow, quantError, 3.0f / 32.0f);
}
// Next row
currentRow = yPlusOne;
if (this.IsValidCoordinate(xMinusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusTwo, currentRow, quantError, 2.0f / 32.0f);
}
if (this.IsValidCoordinate(xMinusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusOne, currentRow, quantError, 4.0f / 32.0f);
}
if (this.IsValidCoordinate(x, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(x, currentRow, quantError, 5.0f / 32.0f);
}
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, 4.0f / 32.0f);
}
if (this.IsValidCoordinate(xPlusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusTwo, currentRow, quantError, 2.0f / 32.0f);
}
// Next row
currentRow = yPlusTwo;
if (this.IsValidCoordinate(xMinusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusOne, currentRow, quantError, 2.0f / 32.0f);
}
if (this.IsValidCoordinate(x, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(x, currentRow, quantError, 3.0f / 32.0f);
}
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, 2.0f / 32.0f);
}
}
}