-
Notifications
You must be signed in to change notification settings - Fork 1
/
SierraTwoRowDithering.cs
67 lines (55 loc) · 2.04 KB
/
SierraTwoRowDithering.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 (Frankie) Sierra Two Row kernel.
This is free and unencumbered software released into the public domain.
*/
class SierraTwoRowDithering : DitheringBase
{
public SierraTwoRowDithering(FindColor colorfunc) : base(colorfunc)
{
this.methodLongName = "SierraTwoRow";
this.fileNameAddition = "_SIE2R";
}
override protected void PushError(int x, int y, short[] quantError)
{
// Push error
// X 4/16 3/16
// 1/16 2/16 3/16 2/16 1/16
int xMinusOne = x - 1;
int xMinusTwo = x - 2;
int xPlusOne = x + 1;
int xPlusTwo = x + 2;
int yPlusOne = y + 1;
// Current row
int currentRow = y;
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, 4.0f / 16.0f);
}
if (this.IsValidCoordinate(xPlusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusTwo, currentRow, quantError, 3.0f / 16.0f);
}
// Next row
currentRow = yPlusOne;
if (this.IsValidCoordinate(xMinusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusTwo, currentRow, quantError, 1.0f / 16.0f);
}
if (this.IsValidCoordinate(xMinusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xMinusOne, currentRow, quantError, 2.0f / 16.0f);
}
if (this.IsValidCoordinate(x, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(x, currentRow, quantError, 3.0f / 16.0f);
}
if (this.IsValidCoordinate(xPlusOne, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, currentRow, quantError, 2.0f / 16.0f);
}
if (this.IsValidCoordinate(xPlusTwo, currentRow))
{
this.ModifyImageWithErrorAndMultiplier(xPlusTwo, currentRow, quantError, 1.0f / 16.0f);
}
}
}