static uint DoOtherColourFixErrorCorrection(byte[] imgData, int sourcePosition, int sourceLineLength, int uSteps, double alphaRef, AlphaSettings alphaSetting, RGBColour[] step, RGBColour Dir)
{
uint dw = 0;
RGBColour[] Error = new RGBColour[16];
uint[] psteps = uSteps == 3 ? psteps3 : psteps4;
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 ((uSteps == 3) && (current.a < alphaRef))
{
dw = (uint)((3 << 30) | (dw >> 2));
continue;
}
current.r *= Luminance.r;
current.g *= Luminance.g;
current.b *= Luminance.b;
if (true) // dither
{
// Error again
current.r += Error[index].r;
current.g += Error[index].g;
current.b += Error[index].b;
}
float fdot = (current.r - step[0].r) * Dir.r + (current.g - step[0].g) * Dir.g + (current.b - step[0].b) * Dir.b;
uint iStep = 0;
if (fdot <= 0f)
iStep = 0;
else if (fdot >= (uSteps - 1))
iStep = 1;
else
iStep = psteps[(int)(fdot + .5f)];
dw = (iStep << 30) | (dw >> 2); // THIS IS THE MAGIC here. This is the "list" of indicies. Somehow...
DoSomeDithering(current, index, step, (int)iStep, Error);
position += 4;
}
}
return dw;
}