diff options
-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) |