Copyright (C) 1995 Spencer Kimball and Peter Mattis . GPL GIMP colorize.c
.
.
.
void
colorize (Colorize *colorize,
PixelRegion *srcPR,
PixelRegion *destPR)
{
const guchar *src, *s;
guchar *dest, *d;
gboolean alpha;
gint w, h;
gint lum;
/* Set the transfer arrays (for speed) */
h = srcPR->h;
src = srcPR->data;
dest = destPR->data;
alpha = (srcPR->bytes == 4) ? TRUE : FALSE;
while (h--)
{
w = srcPR->w;
s = src;
d = dest;
while (w--)
{
lum = (colorize->lum_red_lookup[s[RED_PIX]] +
colorize->lum_green_lookup[s[GREEN_PIX]] +
colorize->lum_blue_lookup[s[BLUE_PIX]]); /* luminosity */
if (colorize->lightness > 0)
{
lum = (gdouble) lum * (100.0 - colorize->lightness) / 100.0;
lum += 255 - (100.0 - colorize->lightness) * 255.0 / 100.0;
}
else if (colorize->lightness lightness + 100.0) / 100.0;
}
d[RED_PIX] = colorize->final_red_lookup[lum];
d[GREEN_PIX] = colorize->final_green_lookup[lum];
d[BLUE_PIX] = colorize->final_blue_lookup[lum];
if (alpha)
d[ALPHA_PIX] = s[ALPHA_PIX];
s += srcPR->bytes;
d += destPR->bytes;
}
src += srcPR->rowstride;
dest += destPR->rowstride;
}
}
http://www.jeffgraphics.in/2010/12/09/cd-cover-colorize-in-gimp/