For any programmers out there, this is the algorithm I use for shading the pages to apply the color tone to the bitmap of the page:
I don't know if there is a better algorithm to color the background without distorting the image in any negative way, but I'm always open to recommendations.
Thanks,
Mike
Code:
public static void Shade(byte[] pixels, int width, int height, int color)
{
double red = ((color >> 16) & 0xFF) / 255.0;
double green = ((color >> 8) & 0xFF) / 255.0;
double blue = (color & 0xFF) / 255.0;
const int whiteEnough = 0xE0;
for (int x = 0; x < width; ++x)
{
for (int y = 0; y < height; ++y)
{
int index = x * 4 + y * width * 4;
if (pixels[index] > whiteEnough && pixels[index + 1] > whiteEnough &&
pixels[index + 2] > whiteEnough)
{
// Ignore alpha which is the last byte. WriteableBitmap uses BGRA
pixels[index + 2] = (byte)(pixels[index + 2] * red);
pixels[index + 1] = (byte)(pixels[index + 1] * green);
pixels[index] = (byte)(pixels[index] * blue);
}
}
}
}
I don't know if there is a better algorithm to color the background without distorting the image in any negative way, but I'm always open to recommendations.
Thanks,
Mike