Uhm, somewhere in November last year i decided to make a major update to Simulate Color Depth after being somewhere with lots of errors and crashes i got away from it and onto something else. A few days ago i decided to take it up again and decided just to write a whole new easier customizable error diffusion dithering class, success in nearly first try, and as planned i began to add XML support for custom dithers. On my way home from school today my computer had a bluescreen while it was sleeping, but luckily i had my project saved so it wasn't a big problem, so i came home turned on my computer, saw the bluescreen, restarted. Then i worked hard to get the XML stuff working but when i finally worked the result from the error diffusion had too much contrast based on how it was before i implented the XML support, that counts both for the same algorithm called from the data from the XML file and with the values i used before coded in directly, heres the class (default algorithm is Floyd-Steinberg, and the result is long away from what it have been, for a good guidance of how it should look like click here)
internal class ErrorDiffusionSimple
{
const int ERROR = -190;
int divisor;
int[][] multiply;
int boffset = ERROR;
int foffset = ERROR;
internal ErrorDiffusionSimple()
{
divisor = 16;
multiply = new int[2][];
multiply[0] = new int[1] { 7 };
multiply[1] = new int[3] { 3, 5, 1 };
}
internal ErrorDiffusionSimple(int divisor, int[][] multiply)
{
this.divisor = divisor;
this.multiply = multiply;
}
internal ErrorDiffusionSimple(int boffset, int foffset, int divisor, int[][] multiply)
{
this.boffset = boffset;
this.foffset = foffset;
this.divisor = divisor;
this.multiply = multiply;
}
internal unsafe void ProcessDither(Surface src, Surface dst, PdnRegion reg, Rectangle rect, int BitDepth)
{
int sl = multiply[0].Length;
int ll = multiply[1].Length;
for (int y = rect.Top; y < rect.Bottom; y++)
{
for (int x = rect.Left; x < rect.Right; x++)
{
ColorBgra cp = *(src.GetPointAddressUnchecked(x, y));
ColorBgra np = Dithering.GetClosestColor(cp, BitDepth);
for (int x2 = x+1; x2 <= x + sl; x2++)
{
if (reg.IsVisible(x2, y))
if (multiply[0][x2-1-x] != 0)
*(src.GetPointAddress(x2, y)) = errorDiffuse(cp, np, *(src.GetPointAddress(x2, y)), multiply[0][x2 - 1 - x]);
}
for (int y2 = y + 1; y2 < y + multiply.Length; y2++)
{
for (int x2 = x - (boffset == ERROR ? sl : boffset); x2 <= x + (foffset == ERROR ? sl : foffset); x2++)
{
if (reg.IsVisible(x2, y2))
if (multiply[y2 - y][x2 + (boffset == ERROR ? sl : boffset) - x] != 0)
*(src.GetPointAddress(x2, y2)) = errorDiffuse(cp, np, *(src.GetPointAddress(x2, y2)), multiply[y2 - y][x2 + (boffset == ERROR ? sl : boffset) - x]);
}
}
*(dst.GetPointAddressUnchecked(x, y)) = np;
}
}
}
private ColorBgra errorDiffuse(ColorBgra c1, ColorBgra c2, ColorBgra c3, int multiplier)
{
int b, g, r;
b = c1.B - c2.B;
g = c1.G - c2.G;
r = c1.R - c2.R;
return ColorBgra.FromBgr(Clamp(c3.B + ((multiplier * / divisor)), Clamp(c3.G + ((multiplier * g) / divisor)), Clamp(c3.R + ((multiplier * r) / divisor)));
}
private byte Clamp(int
{
return Convert.ToByte(b < 0 ? 0 : b > 255 ? 255 : ;
}
}
Im now sure why it have changed contrast wise but it have (before the bluescreen, custom UI and XML stuff it worked fine and looked quite much, only with minor differences, like the picture i linked to above)