diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2011-04-01 13:54:55 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2011-04-01 13:59:43 +0200 |
commit | eda3e9f5cd54b54bbd773f2594a82b60104efb34 (patch) | |
tree | 3777cfc7b4ba2591c28778d346630e682b1d7c17 /fitz | |
parent | 6e3e5bef0e262152ca71866e0059d0089b317a69 (diff) | |
download | mupdf-eda3e9f5cd54b54bbd773f2594a82b60104efb34.tar.xz |
draw: Convert and scale images in the cheapest order.
Grayscale images should be converted to RGB after downscaling,
and vice versa for CMYK -> RGB. Separation and DeviceN based
images have very expensive color conversions and should also
be converted after scaling.
Diffstat (limited to 'fitz')
-rw-r--r-- | fitz/dev_draw.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/fitz/dev_draw.c b/fitz/dev_draw.c index d419c2af..b30508c8 100644 --- a/fitz/dev_draw.c +++ b/fitz/dev_draw.c @@ -580,6 +580,7 @@ fz_drawfillimage(void *user, fz_pixmap *image, fz_matrix ctm, float alpha) fz_colorspace *model = dev->dest->colorspace; fz_pixmap *converted = nil; fz_pixmap *scaled = nil; + int after; int dx, dy; if (!model) @@ -591,7 +592,19 @@ fz_drawfillimage(void *user, fz_pixmap *image, fz_matrix ctm, float alpha) if (image->w == 0 || image->h == 0) return; - if (image->colorspace != model) + /* convert images with more components (cmyk->rgb) before scaling */ + /* convert images with fewer components (gray->rgb after scaling */ + /* convert images with expensive colorspace transforms after scaling */ + + after = 0; + if (image->colorspace->n < model->n) + after = 1; + if (!strcmp(image->colorspace->name, "Separation")) + after = 1; + if (!strcmp(image->colorspace->name, "DeviceN")) + after = 1; + + if (image->colorspace != model && !after) { converted = fz_newpixmap(model, image->x, image->y, image->w, image->h); fz_convertpixmap(image, converted); @@ -601,7 +614,7 @@ fz_drawfillimage(void *user, fz_pixmap *image, fz_matrix ctm, float alpha) #ifdef SMOOTHSCALE dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b); dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d); - if (dx < image->w || dy < image->h) + if (dx < image->w && dy < image->h) { scaled = fz_smoothtransformpixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy); if (scaled == nil) @@ -623,6 +636,13 @@ fz_drawfillimage(void *user, fz_pixmap *image, fz_matrix ctm, float alpha) } #endif + if (image->colorspace != model && after) + { + converted = fz_newpixmap(model, image->x, image->y, image->w, image->h); + fz_convertpixmap(image, converted); + image = converted; + } + fz_paintimage(dev->dest, dev->scissor, image, ctm, alpha * 255); if (scaled) @@ -649,7 +669,7 @@ fz_drawfillimagemask(void *user, fz_pixmap *image, fz_matrix ctm, #ifdef SMOOTHSCALE dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b); dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d); - if (dx < image->w || dy < image->h) + if (dx < image->w && dy < image->h) { scaled = fz_smoothtransformpixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy); if (scaled == nil) @@ -720,7 +740,7 @@ fz_drawclipimagemask(void *user, fz_pixmap *image, fz_matrix ctm) #ifdef SMOOTHSCALE dx = sqrtf(ctm.a * ctm.a + ctm.b * ctm.b); dy = sqrtf(ctm.c * ctm.c + ctm.d * ctm.d); - if (dx < image->w || dy < image->h) + if (dx < image->w && dy < image->h) { scaled = fz_smoothtransformpixmap(image, &ctm, dev->dest->x, dev->dest->y, dx, dy); if (scaled == nil) |