diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-08-17 19:27:02 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-08-17 19:27:02 +0200 |
commit | 822ce1df6773e1934f50d035756ecca0f6d4cae1 (patch) | |
tree | 30950a220566092ac35f1367e49b701afa85b3e2 | |
parent | 4214d2a553522a9ebb5c263368131aea813ebe03 (diff) | |
download | mupdf-822ce1df6773e1934f50d035756ecca0f6d4cae1.tar.xz |
pdfdraw: Add command line option to gamma correct and invert images.
-rw-r--r-- | apps/man/pdfdraw.1 | 7 | ||||
-rw-r--r-- | apps/pdfdraw.c | 13 | ||||
-rw-r--r-- | fitz/fitz.h | 2 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 38 |
4 files changed, 59 insertions, 1 deletions
diff --git a/apps/man/pdfdraw.1 b/apps/man/pdfdraw.1 index 67899640..53fbcde9 100644 --- a/apps/man/pdfdraw.1 +++ b/apps/man/pdfdraw.1 @@ -59,6 +59,13 @@ Print the display list used to render each page. .TP .B \-A Disable the use of accelerated functions. +.TP +.B \-G gamma +Gamma correct the output image. +Some typical values are 0.7 or 1.4 to thin or darken text rendering. +.TP +.B \-I +Invert the output image colors. .SH SEE ALSO .BR mupdf (1), .BR pdfclean (1). diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 4dd24ff2..a5f6aa1e 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -22,6 +22,8 @@ int showmd5 = 0; int savealpha = 0; int uselist = 1; int alphabits = 8; +float gamma_value = 1; +int invert = 0; fz_colorspace *colorspace; fz_glyph_cache *glyphcache; @@ -57,6 +59,8 @@ static void usage(void) "\t-d\tdisable use of display list\n" "\t-5\tshow md5 checksums\n" "\t-R -\trotate clockwise by given number of degrees\n" + "\t-G gamma\tgamma correct output\n" + "\t-I\tinvert output\n" "\tpages\tcomma separated list of ranges\n"); exit(1); } @@ -178,6 +182,11 @@ static void drawpage(pdf_xref *xref, int pagenum) pdf_run_page(xref, page, dev, ctm); fz_free_device(dev); + if (invert) + fz_invert_pixmap(pix); + if (gamma_value != 1) + fz_gamma_pixmap(pix, gamma_value); + if (output) { char buf[512]; @@ -295,7 +304,7 @@ int main(int argc, char **argv) fz_error error; int c; - while ((c = fz_getopt(argc, argv, "o:p:r:R:Aab:dgmtx5")) != -1) + while ((c = fz_getopt(argc, argv, "o:p:r:R:Aab:dgmtx5G:I")) != -1) { switch (c) { @@ -312,6 +321,8 @@ int main(int argc, char **argv) case '5': showmd5++; break; case 'g': grayscale++; break; case 'd': uselist = 0; break; + case 'G': gamma_value = atof(fz_optarg); break; + case 'I': invert++; break; default: usage(); break; } } 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) */ |