static void DoColourFixErrorCorrection(RGBColour[] Colour, byte[] imgData, int sourcePosition, int sourceLineLength, AlphaSettings alphaSetting)
{
RGBColour[] Error = new RGBColour[16];
for (int i = 0; i < 4; i++)
{
int position = sourcePosition + sourceLineLength * i;
for (int j = 0; j < 4; j++)
{
int index = (i << 2) + j;
RGBColour current = ReadColourFromTexel(imgData, position, alphaSetting == AlphaSettings.Premultiply);
if (true) // Dither
{
// Adjust for accumulated error
// This works by figuring out the error between the current pixel colour and the adjusted colour? Dunno what the adjustment is. Looks like a 5:6:5 range adaptation
// Then, this error is distributed across the "next" few pixels and not the previous.
current.r += Error[index].r;
current.g += Error[index].g;
current.b += Error[index].b;
}
// 5:6:5 range adaptation?
Colour[index].r = (int)(current.r * 31f + .5f) * (1f / 31f);
Colour[index].g = (int)(current.g * 63f + .5f) * (1f / 63f);
Colour[index].b = (int)(current.b * 31f + .5f) * (1f / 31f);
DoSomeDithering(current, index, Colour, index, Error);
Colour[index].r *= Luminance.r;
Colour[index].g *= Luminance.g;
Colour[index].b *= Luminance.b;
position += 4;
}
}
}