I seem to have a sepia tone that is almost working properly. For some reason a portion of the image turns out to be lime green! Does anyone know what i might be doing wrong? Met
To fix the issue, change the loop like this:
for (int i = 0; i < rgbValues.Length; i += 4)
{
int red = rgbValues[i + 2];
int green = rgbValues[i + 1];
int blue = rgbValues[i + 0];
rgbValues[i + 2] = (byte)Math.Min((.393 * red) + (.769 * green) + (.189 * blue), 255.0); // red
rgbValues[i + 1] = (byte)Math.Min((.349 * red) + (.686 * green) + (.168 * blue), 255.0); // green
rgbValues[i + 0] = (byte)Math.Min((.272 * red) + (.534 * green) + (.131 * blue), 255.0); // blue
}
There are arithmetic overflows occurring in your calculations, that's the reason for the wrong colors. An expression of type double
is being explicitly cast to byte
before it is compared to 255, therefore it will never be greater than 255.