diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-05-23 17:45:21 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-05-24 12:48:35 +0100 |
commit | d0b78f4166a1503ce522944002b3aab035724cd9 (patch) | |
tree | b8c680dc401db56a28be1110759219c7c175dd8d /source/pdf | |
parent | 841952db71d6541a2e98fd4d1d49dede284b2cf8 (diff) | |
download | mupdf-d0b78f4166a1503ce522944002b3aab035724cd9.tar.xz |
fz_pixmap revamp: add stride and make alpha optional
fz_pixmaps now have an explicit stride value. By default no change
from before, but code all copes with extra gaps at the end of the
line.
The alpha data in fz_pixmaps is no longer compulsory.
mudraw: use rgb not rgba (ppmraw), cmyk not cmyka (pkmraw).
Update halftone code to not expect alpha plane.
Update PNG writing to cope with alpha less input.
Also hide repeated params within the png output context.
ARM code needs updating.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-image.c | 43 | ||||
-rw-r--r-- | source/pdf/pdf-resources.c | 10 |
2 files changed, 37 insertions, 16 deletions
diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index 51bb4583..3bba27ad 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -40,12 +40,13 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di fz_pixmap_image *cimg = (fz_pixmap_image *)image; fz_pixmap *mask_pixmap; fz_pixmap *tile = fz_pixmap_image_tile(ctx, cimg); - if (image->n != 2) + if (tile->n != 1) { fz_pixmap *gray; fz_irect bbox; - fz_warn(ctx, "soft mask should be grayscale"); - gray = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), fz_pixmap_bbox(ctx, tile, &bbox)); + if (tile->n != 2) + fz_warn(ctx, "soft mask should be grayscale"); + gray = fz_new_pixmap_with_bbox(ctx, fz_device_gray(ctx), fz_pixmap_bbox(ctx, tile, &bbox), 0); fz_convert_pixmap(ctx, gray, tile); fz_drop_pixmap(ctx, tile); tile = gray; @@ -323,32 +324,44 @@ pdf_add_image(fz_context *ctx, pdf_document *doc, fz_image *image, int mask) else { unsigned int size; - int n; + int n, h; + unsigned char *d, *s; /* Currently, set to maintain resolution; should we consider * subsampling here according to desired output res? */ pixmap = fz_get_pixmap_from_image(ctx, image, NULL, NULL, NULL, NULL); colorspace = pixmap->colorspace; /* May be different to image->colorspace! */ - n = (pixmap->n == 1 ? 1 : pixmap->n - 1); - size = image->w * image->h * n; + n = (pixmap->n == 1 ? 1 : pixmap->n - pixmap->alpha); + d = buffer->data; + s = pixmap->samples; + h = image->h; + size = image->w * n; buffer = fz_new_buffer(ctx, size); buffer->len = size; - if (pixmap->n == 1) + if (pixmap->alpha == 0 || n == 1) { - memcpy(buffer->data, pixmap->samples, size); + while (h--) + { + memcpy(d, s, size); + d += size; + s += pixmap->stride; + } } else { /* Need to remove the alpha plane */ - unsigned char *d = buffer->data; - unsigned char *s = pixmap->samples; int mod = n; - while (size--) + int stride = pixmap->stride - pixmap->w * pixmap->n; + while (h--) { - *d++ = *s++; - mod--; - if (mod == 0) - s++, mod = n; + while (size--) + { + *d++ = *s++; + mod--; + if (mod == 0) + s++, mod = n; + } + s += stride; } } } diff --git a/source/pdf/pdf-resources.c b/source/pdf/pdf-resources.c index 212c57df..b66c0a23 100644 --- a/source/pdf/pdf-resources.c +++ b/source/pdf/pdf-resources.c @@ -27,10 +27,18 @@ res_image_get_md5(fz_context *ctx, fz_image *image, unsigned char *digest) { fz_pixmap *pixmap; fz_md5 state; + int h; + unsigned char *d; pixmap = fz_get_pixmap_from_image(ctx, image, NULL, NULL, 0, 0); fz_md5_init(&state); - fz_md5_update(&state, pixmap->samples, pixmap->w * pixmap->h * pixmap->n); + d = pixmap->samples; + h = pixmap->h; + while (h--) + { + fz_md5_update(&state, d, pixmap->w * pixmap->n); + d += pixmap->stride; + } fz_md5_final(&state, digest); fz_drop_pixmap(ctx, pixmap); } |