3. Grayscale Conversion
Before dither can be applied, the RGB colorspace needs to be
converted to grayscale. This pixel2grayscale
function will
take in an RGB pixel and return an integer between 0 and
225.
A standard linear conversion is used (no gamma correction). Not great, but it's fast and good enough.
<<grayscale>>=
static int pixel2grayscale(monolith_pixel *p)
{
double oned255;
double r, g, b;
double gray;
oned255 = 1.0 / 255;
r = p->r * oned255;
g = p->g * oned255;
b = p->b * oned255;
gray = 0.2126 * r + 0.715 * g + 0.0722 * b;
return floor(gray * 255);
}
prev | home | next