-
Notifications
You must be signed in to change notification settings - Fork 1
/
FloydSteinbergDithering.cs
46 lines (39 loc) · 1.35 KB
/
FloydSteinbergDithering.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
/*
This file implements error pushing of dithering via (Robert) Floyd and (Louis) Steinberg kernel.
This is free and unencumbered software released into the public domain.
*/
public class FloydSteinbergDithering : DitheringBase
{
public FloydSteinbergDithering(FindColor colorfunc) : base(colorfunc)
{
this.methodLongName = "Floyd-Steinberg";
this.fileNameAddition = "_FS";
}
override protected void PushError(int x, int y, short[] quantError)
{
// Push error
// X 7/16
// 3/16 5/16 1/16
int xMinusOne = x - 1;
int xPlusOne = x + 1;
int yPlusOne = y + 1;
// Current row
if (this.IsValidCoordinate(xPlusOne, y))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, y, quantError, 7.0f / 16.0f);
}
// Next row
if (this.IsValidCoordinate(xMinusOne, yPlusOne))
{
this.ModifyImageWithErrorAndMultiplier(xMinusOne, yPlusOne, quantError, 3.0f / 16.0f);
}
if (this.IsValidCoordinate(x, yPlusOne))
{
this.ModifyImageWithErrorAndMultiplier(x, yPlusOne, quantError, 5.0f / 16.0f);
}
if (this.IsValidCoordinate(xPlusOne, yPlusOne))
{
this.ModifyImageWithErrorAndMultiplier(xPlusOne, yPlusOne, quantError, 1.0f / 16.0f);
}
}
}