From 9a87ef85fe92a1be62211ea8af8afd08dc460562 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 13 Oct 2016 21:14:01 +0800 Subject: pnm: Premultiply alpha for use in pixmap. --- source/fitz/load-pnm.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'source') diff --git a/source/fitz/load-pnm.c b/source/fitz/load-pnm.c index f585cd8a..7c31c4df 100644 --- a/source/fitz/load-pnm.c +++ b/source/fitz/load-pnm.c @@ -531,6 +531,31 @@ pam_binary_read_image(fz_context *ctx, struct info *pnm, unsigned char *p, unsig p += 2; } } + + if (pnm->alpha) + { + /* CMYK is a subtractive colorspace, we want additive for premul alpha */ + if (img->n > 4) + { + fz_pixmap *rgb = fz_new_pixmap(ctx, fz_device_rgb(ctx), img->w, img->h, 1); + rgb->xres = img->xres; + rgb->yres = img->yres; + + fz_try(ctx) + { + fz_convert_pixmap(ctx, rgb, img); + fz_drop_pixmap(ctx, img); + img = rgb; + rgb = NULL; + } + fz_always(ctx) + fz_drop_pixmap(ctx, rgb); + fz_catch(ctx) + fz_rethrow(ctx); + } + + fz_premultiply_pixmap(ctx, img); + } } return img; -- cgit v1.2.3