summaryrefslogtreecommitdiff
path: root/source/fitz
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2014-08-20 11:33:55 +0200
committerTor Andersson <tor.andersson@artifex.com>2014-08-20 11:33:55 +0200
commit61de1fe7e510fdd425686c478439209f6f7a4b73 (patch)
treeef6994ceb17a14e29b5b2dc20e7b5bfc58e0f2dc /source/fitz
parent44efa7e4a451793dd2357a65c92bc47719da1ad2 (diff)
downloadmupdf-61de1fe7e510fdd425686c478439209f6f7a4b73.tar.xz
Add full-page color tinting option and key binding to X11 viewer.
win32 supports tinting, but cannot change the color from the default.
Diffstat (limited to 'source/fitz')
-rw-r--r--source/fitz/pixmap.c47
1 files changed, 47 insertions, 0 deletions
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
@@ -415,6 +415,53 @@ fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity)
}
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)
{
unsigned char *s = pix->samples;