diff options
author | Robin Watts <robin.watts@artifex.com> | 2011-12-08 12:04:43 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2011-12-08 12:04:43 +0000 |
commit | 13dc7237ff5177b75fc6d5c1289eabc68cc7504b (patch) | |
tree | ebbcac2c91835576555d9e1c7130ad7bd1f2df0e | |
parent | d0724c562bb7ae6ad81eb89b064d59a73685f3a8 (diff) | |
parent | ba531f60532022e3419628e506462b6b84279478 (diff) | |
download | mupdf-13dc7237ff5177b75fc6d5c1289eabc68cc7504b.tar.xz |
Merge branch 'master' into context
-rw-r--r-- | apps/pdfdraw.c | 3 | ||||
-rw-r--r-- | fitz/base_object.c | 2 | ||||
-rw-r--r-- | fitz/fitz.h | 1 | ||||
-rw-r--r-- | fitz/res_pixmap.c | 20 | ||||
-rw-r--r-- | pdf/pdf_image.c | 7 |
5 files changed, 32 insertions, 1 deletions
diff --git a/apps/pdfdraw.c b/apps/pdfdraw.c index 69fae0ba..c1d2a779 100644 --- a/apps/pdfdraw.c +++ b/apps/pdfdraw.c @@ -199,6 +199,9 @@ static void drawpage(pdf_xref *xref, int pagenum) if (gamma_value != 1) fz_gamma_pixmap(pix, gamma_value); + if (savealpha) + fz_unmultiply_pixmap(pix); + if (output) { char buf[512]; diff --git a/fitz/base_object.c b/fitz/base_object.c index 2876f363..8c79e4c6 100644 --- a/fitz/base_object.c +++ b/fitz/base_object.c @@ -208,7 +208,7 @@ int fz_to_int(fz_obj *obj) if (fz_is_int(obj)) return obj->u.i; if (fz_is_real(obj)) - return obj->u.f; + return (int)(obj->u.f + 0.5f); /* No roundf in MSVC */ return 0; } diff --git a/fitz/fitz.h b/fitz/fitz.h index c3c33487..70d14086 100644 --- a/fitz/fitz.h +++ b/fitz/fitz.h @@ -709,6 +709,7 @@ void fz_clear_pixmap_with_color(fz_pixmap *pix, int value); void fz_clear_pixmap_rect_with_color(fz_pixmap *pix, int value, fz_bbox r); void fz_copy_pixmap_rect(fz_pixmap *dest, fz_pixmap *src, fz_bbox r); void fz_premultiply_pixmap(fz_pixmap *pix); +void fz_unmultiply_pixmap(fz_pixmap *pix); fz_pixmap *fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity); fz_bbox fz_bound_pixmap(fz_pixmap *pix); void fz_invert_pixmap(fz_pixmap *pix); diff --git a/fitz/res_pixmap.c b/fitz/res_pixmap.c index 471dcc72..1dfc8ad0 100644 --- a/fitz/res_pixmap.c +++ b/fitz/res_pixmap.c @@ -226,6 +226,26 @@ fz_premultiply_pixmap(fz_pixmap *pix) } } +void +fz_unmultiply_pixmap(fz_pixmap *pix) +{ + unsigned char *s = pix->samples; + int a, inva; + int k, x, y; + + for (y = 0; y < pix->h; y++) + { + for (x = 0; x < pix->w; x++) + { + a = s[pix->n - 1]; + inva = a ? 255 * 256 / a : 0; + for (k = 0; k < pix->n - 1; k++) + s[k] = (s[k] * inva) >> 8; + s += pix->n; + } + } +} + fz_pixmap * fz_alpha_from_gray(fz_context *ctx, fz_pixmap *gray, int luminosity) { diff --git a/pdf/pdf_image.c b/pdf/pdf_image.c index 849f703e..41be8fac 100644 --- a/pdf/pdf_image.c +++ b/pdf/pdf_image.c @@ -143,7 +143,14 @@ pdf_load_image_imp(pdf_xref *xref, fz_obj *rdb, fz_obj *dict, fz_stream *cstm, i { usecolorkey = 1; for (i = 0; i < n * 2; i++) + { + if (!fz_is_int(fz_array_get(obj, i))) + { + fz_warn(ctx, "invalid value in color key mask"); + usecolorkey = 0; + } colorkey[i] = fz_to_int(fz_array_get(obj, i)); + } } /* Allocate now, to fail early if we run out of memory */ |