diff options
Diffstat (limited to 'source/fitz/load-png.c')
-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) { |