summaryrefslogtreecommitdiff
path: root/fitz
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
parent4214d2a553522a9ebb5c263368131aea813ebe03 (diff)
downloadmupdf-822ce1df6773e1934f50d035756ecca0f6d4cae1.tar.xz
pdfdraw: Add command line option to gamma correct and invert images.
Diffstat (limited to 'fitz')
-rw-r--r--fitz/fitz.h2
-rw-r--r--fitz/res_pixmap.c38
2 files changed, 40 insertions, 0 deletions
diff --git a/fitz/fitz.h b/fitz/fitz.h
index 7187094f..dff6b8d4 100644
--- a/fitz/fitz.h
+++ b/fitz/fitz.h
@@ -625,6 +625,8 @@ void fz_copy_pixmap_rect(fz_pixmap *dest, fz_pixmap *src, fz_bbox r);
void fz_premultiply_pixmap(fz_pixmap *pix);
fz_pixmap *fz_alpha_from_gray(fz_pixmap *gray, int luminosity);
fz_bbox fz_bound_pixmap(fz_pixmap *pix);
+void fz_invert_pixmap(fz_pixmap *pix);
+void fz_gamma_pixmap(fz_pixmap *pix, float gamma);
fz_pixmap *fz_scale_pixmap(fz_pixmap *src, float x, float y, float w, float h);
fz_pixmap *fz_scale_pixmap_gridfit(fz_pixmap *src, float x, float y, float w, float h, int gridfit);
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)
*/