diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2017-08-16 13:04:02 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2017-08-17 16:09:07 +0200 |
commit | 11076d8c6be7b7a3421ba9f86cd5ea9b68e4ffeb (patch) | |
tree | b13bf10bd9ec9a18c86a2d941e5df64b5d553309 /source | |
parent | c930c80f31a13c2aea907a0d8b4ec24271ca5276 (diff) | |
download | mupdf-11076d8c6be7b7a3421ba9f86cd5ea9b68e4ffeb.tar.xz |
Only load the alpha channel in PNG images when it is present.
Diffstat (limited to 'source')
-rw-r--r-- | source/fitz/load-png.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/source/fitz/load-png.c b/source/fitz/load-png.c index b774672a..eabcf2d6 100644 --- a/source/fitz/load-png.c +++ b/source/fitz/load-png.c @@ -502,7 +502,7 @@ png_read_image(fz_context *ctx, struct info *info, unsigned char *p, size_t tota static fz_pixmap * png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) { - fz_pixmap *dst = fz_new_pixmap(ctx, fz_device_rgb(ctx), src->w, src->h, NULL, 1); + fz_pixmap *dst = fz_new_pixmap(ctx, fz_device_rgb(ctx), src->w, src->h, NULL, info->transparency); unsigned char *sp = src->samples; unsigned char *dp = dst->samples; unsigned int x, y; @@ -520,8 +520,9 @@ png_expand_palette(fz_context *ctx, struct info *info, fz_pixmap *src) *dp++ = info->palette[v]; *dp++ = info->palette[v + 1]; *dp++ = info->palette[v + 2]; - *dp++ = info->palette[v + 3]; - sp += 2; + if (info->transparency) + *dp++ = info->palette[v + 3]; + ++sp; } sp += sstride; dp += dstride; @@ -562,6 +563,7 @@ fz_load_png(fz_context *ctx, unsigned char *p, size_t total) fz_colorspace *colorspace; struct info png; int stride; + int alpha; png_read_image(ctx, &png, p, total, 0); @@ -571,10 +573,11 @@ fz_load_png(fz_context *ctx, unsigned char *p, size_t total) colorspace = fz_device_gray(ctx); stride = (png.width * png.n * png.depth + 7) / 8; + alpha = (png.n == 2 || png.n == 4); fz_try(ctx) { - image = fz_new_pixmap(ctx, colorspace, png.width, png.height, NULL, 1); + image = fz_new_pixmap(ctx, colorspace, png.width, png.height, NULL, alpha); } fz_catch(ctx) { |