summaryrefslogtreecommitdiff
path: root/fitz/res_pixmap.c
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-08-17 19:27:02 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-08-17 19:27:02 +0200
commit822ce1df6773e1934f50d035756ecca0f6d4cae1 (patch)
tree30950a220566092ac35f1367e49b701afa85b3e2 /fitz/res_pixmap.c
parent4214d2a553522a9ebb5c263368131aea813ebe03 (diff)
downloadmupdf-822ce1df6773e1934f50d035756ecca0f6d4cae1.tar.xz
pdfdraw: Add command line option to gamma correct and invert images.
Diffstat (limited to 'fitz/res_pixmap.c')
-rw-r--r--fitz/res_pixmap.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c
index fdd5c357..83f46526 100644
--- a/fitz/res_pixmap.c
+++ b/fitz/res_pixmap.c
@@ -251,6 +251,44 @@ fz_alpha_from_gray(fz_pixmap *gray, int luminosity)
return alpha;
}
+void
+fz_invert_pixmap(fz_pixmap *pix)
+{
+ unsigned char *s = pix->samples;
+ int k, x, y;
+
+ for (y = 0; y < pix->h; y++)
+ {
+ for (x = 0; x < pix->w; x++)
+ {
+ for (k = 0; k < pix->n - 1; k++)
+ s[k] = 255 - s[k];
+ s += pix->n;
+ }
+ }
+}
+
+void
+fz_gamma_pixmap(fz_pixmap *pix, float gamma)
+{
+ unsigned char gamma_map[256];
+ unsigned char *s = pix->samples;
+ int k, x, y;
+
+ for (k = 0; k < 256; k++)
+ gamma_map[k] = pow(k / 255.0f, gamma) * 255;
+
+ for (y = 0; y < pix->h; y++)
+ {
+ for (x = 0; x < pix->w; x++)
+ {
+ for (k = 0; k < pix->n - 1; k++)
+ s[k] = gamma_map[s[k]];
+ s += pix->n;
+ }
+ }
+}
+
/*
* Write pixmap to PNM file (without alpha channel)
*/