diff options
-rw-r--r-- | include/mupdf/fitz/image.h | 2 | ||||
-rw-r--r-- | source/fitz/colorspace.c | 14 | ||||
-rw-r--r-- | source/fitz/draw-unpack.c | 5 | ||||
-rw-r--r-- | source/fitz/image.c | 7 |
4 files changed, 17 insertions, 11 deletions
diff --git a/include/mupdf/fitz/image.h b/include/mupdf/fitz/image.h index 255337ee..9a8d5309 100644 --- a/include/mupdf/fitz/image.h +++ b/include/mupdf/fitz/image.h @@ -72,7 +72,7 @@ fz_image *fz_new_image_from_buffer(fz_context *ctx, fz_buffer *buffer); fz_image *fz_new_image_from_file(fz_context *ctx, const char *path); void fz_drop_image_imp(fz_context *ctx, fz_storable *image); fz_pixmap *fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image *image, fz_irect *subarea, int indexed, int l2factor); -fz_pixmap *fz_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src); +fz_pixmap *fz_expand_indexed_pixmap(fz_context *ctx, const fz_pixmap *src, int alpha); size_t fz_image_size(fz_context *ctx, fz_image *im); struct fz_image_s diff --git a/source/fitz/colorspace.c b/source/fitz/colorspace.c index b4d511e8..7923446a 100644 --- a/source/fitz/colorspace.c +++ b/source/fitz/colorspace.c @@ -1930,31 +1930,32 @@ fz_new_indexed_colorspace(fz_context *ctx, fz_colorspace *base, int high, unsign } fz_pixmap * -fz_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src) +fz_expand_indexed_pixmap(fz_context *ctx, const fz_pixmap *src, int alpha) { struct indexed *idx; fz_pixmap *dst; - unsigned char *s, *d; + const unsigned char *s; + unsigned char *d; int y, x, k, n, high; unsigned char *lookup; fz_irect bbox; int s_line_inc, d_line_inc; assert(src->colorspace->to_rgb == indexed_to_rgb); - assert(src->n == 2); + assert(src->n == 1 + alpha); idx = src->colorspace->data; high = idx->high; lookup = idx->lookup; n = idx->base->n; - dst = fz_new_pixmap_with_bbox(ctx, idx->base, fz_pixmap_bbox(ctx, src, &bbox), src->alpha); + dst = fz_new_pixmap_with_bbox(ctx, idx->base, fz_pixmap_bbox(ctx, src, &bbox), alpha); s = src->samples; d = dst->samples; s_line_inc = src->stride - src->w * src->n; d_line_inc = dst->stride - dst->w * dst->n; - if (src->alpha) + if (alpha) { for (y = 0; y < src->h; y++) { @@ -1962,9 +1963,10 @@ fz_expand_indexed_pixmap(fz_context *ctx, fz_pixmap *src) { int v = *s++; int a = *s++; + int aa = a + (a>>7); v = fz_mini(v, high); for (k = 0; k < n; k++) - *d++ = fz_mul255(lookup[v * n + k], a); + *d++ = (aa * lookup[v * n + k] + 128)>>8; *d++ = a; } s += s_line_inc; diff --git a/source/fitz/draw-unpack.c b/source/fitz/draw-unpack.c index ccb3c62f..0211b7e4 100644 --- a/source/fitz/draw-unpack.c +++ b/source/fitz/draw-unpack.c @@ -179,7 +179,8 @@ fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, const float *decode, int unsigned char *p = pix->samples; int stride = pix->stride - pix->w * pix->n; int len; - int n = pix->n - 1; + int pn = pix->n; + int n = pn - pix->alpha; int needed; int k; int h; @@ -208,7 +209,7 @@ fz_decode_indexed_tile(fz_context *ctx, fz_pixmap *pix, const float *decode, int int value = (add[k] + (((p[k] << 8) * mul[k]) >> 8)) >> 8; p[k] = fz_clampi(value, 0, 255); } - p += n + 1; + p += pn; } p += stride; } diff --git a/source/fitz/image.c b/source/fitz/image.c index bd6e0b62..c49580bf 100644 --- a/source/fitz/image.c +++ b/source/fitz/image.c @@ -198,7 +198,10 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image fz_try(ctx) { - tile = fz_new_pixmap(ctx, image->colorspace, w, h, 1); + int alpha = (image->colorspace == NULL); + if (image->use_colorkey) + alpha = 1; + tile = fz_new_pixmap(ctx, image->colorspace, w, h, alpha); tile->interpolate = image->interpolate; stride = (w * image->n * image->bpc + 7) / 8; @@ -276,7 +279,7 @@ fz_decomp_image_from_stream(fz_context *ctx, fz_stream *stm, fz_compressed_image { fz_pixmap *conv; fz_decode_indexed_tile(ctx, tile, image->decode, (1 << image->bpc) - 1); - conv = fz_expand_indexed_pixmap(ctx, tile); + conv = fz_expand_indexed_pixmap(ctx, tile, alpha); fz_drop_pixmap(ctx, tile); tile = conv; } |