diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2014-05-27 17:13:57 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2014-05-27 17:13:57 +0200 |
commit | 295b1edf02754e668831773769a270c12441cd5d (patch) | |
tree | 5a3ff59c7f644f83f8632cc65f7fadbebaf1edf6 /source | |
parent | 2f1f3840295b8152d44d00a3c14b58a737baefa7 (diff) | |
download | mupdf-295b1edf02754e668831773769a270c12441cd5d.tar.xz |
Fix 693517: Support /SMask/Matte preblended images.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/image.c | 35 | ||||
-rw-r--r-- | source/pdf/pdf-image.c | 9 |
2 files changed, 43 insertions, 1 deletions
diff --git a/source/fitz/image.c b/source/fitz/image.c index 1e6a1183..9fd859e9 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -117,6 +117,34 @@ fz_mask_color_key(fz_pixmap *pix, int n, int *colorkey) } } +static void +fz_unblend_masked_tile(fz_context *ctx, fz_pixmap *tile, fz_image *image) +{ + fz_pixmap *mask = image->mask->get_pixmap(ctx, image->mask, tile->w, tile->h); + unsigned char *s = mask->samples, *end = s + mask->w * mask->h; + unsigned char *d = tile->samples; + int k; + + if (tile->w != mask->w || tile->h != mask->h) + { + fz_warn(ctx, "mask must be of same size as image for /Matte"); + fz_drop_pixmap(ctx, mask); + return; + } + + for (; s < end; s++, d += tile->n) + { + if (*s == 0) + for (k = 0; k < image->n - 1; k++) + d[k] = image->colorkey[k]; + else + for (k = 0; k < image->n - 1; k++) + d[k] = fz_clampi(image->colorkey[k] + (d[k] - image->colorkey[k]) * 255 / *s, 0, 255); + } + + fz_drop_pixmap(ctx, mask); +} + fz_pixmap * fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, int indexed, int l2factor, int native_l2factor) { @@ -163,7 +191,8 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in fz_free(ctx, samples); samples = NULL; - if (image->usecolorkey) + /* color keyed transparency */ + if (image->usecolorkey && !image->mask) fz_mask_color_key(tile, image->n, image->colorkey); if (indexed) @@ -178,6 +207,10 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_image *image, in { fz_decode_tile(tile, image->decode); } + + /* pre-blended matte color */ + if (image->usecolorkey && image->mask) + fz_unblend_masked_tile(ctx, tile, image); } fz_always(ctx) { diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index 9f4195e4..ffd21dd6 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -126,7 +126,16 @@ pdf_load_image_imp(pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, fz_stream *cs else if (forcemask) fz_warn(ctx, "Ignoring recursive image soft mask"); else + { mask = pdf_load_image_imp(doc, rdb, obj, NULL, 1); + obj = pdf_dict_gets(obj, "Matte"); + if (pdf_is_array(obj)) + { + usecolorkey = 1; + for (i = 0; i < n; i++) + colorkey[i] = pdf_to_real(pdf_array_get(obj, i)) * 255; + } + } } else if (pdf_is_array(obj)) { |