From 61de1fe7e510fdd425686c478439209f6f7a4b73 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Wed, 20 Aug 2014 11:33:55 +0200 Subject: Add full-page color tinting option and key binding to X11 viewer. win32 supports tinting, but cannot change the color from the default. --- source/fitz/pixmap.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'source/fitz') diff --git a/source/fitz/pixmap.c b/source/fitz/pixmap.c index a56fdbd9..9ce8ffba 100644 --- a/source/fitz/pixmap.c +++ b/source/fitz/pixmap.c @@ -414,6 +414,53 @@ fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity) return alpha; } +void +fz_tint_pixmap(fz_context *ctx, fz_pixmap *pix, int r, int g, int b) +{ + unsigned char *s = pix->samples; + int x, y; + + if (pix->colorspace == fz_device_bgr(ctx)) + { + int save = r; + r = b; + b = save; + } + else if (pix->colorspace == fz_device_gray(ctx)) + { + g = (r + g + b) / 3; + } + else if (pix->colorspace != fz_device_rgb(ctx)) + { + fz_throw(ctx, FZ_ERROR_GENERIC, "can only tint RGB, BGR and Gray pixmaps"); + } + + if (pix->n == 4) + { + for (x = 0; x < pix->w; x++) + { + for (y = 0; y < pix->h; y++) + { + s[0] = fz_mul255(s[0], r); + s[1] = fz_mul255(s[1], g); + s[2] = fz_mul255(s[2], b); + s += 4; + } + } + } + else if (pix->n == 2) + { + for (x = 0; x < pix->w; x++) + { + for (y = 0; y < pix->h; y++) + { + *s = fz_mul255(*s, g); + s += 2; + } + } + } +} + void fz_invert_pixmap(fz_context *ctx, fz_pixmap *pix) { -- cgit v1.2.3