From f287bd2b0b99debd8970a53d2813ab71d765511e Mon Sep 17 00:00:00 2001 From: Adrian Johnson Date: Sun, 5 Dec 2010 00:33:03 +1030 Subject: [PATCH] cairo: Use A1 instead of A8 for imagemask The cairo PDF surface now optimizes the case of cairo_mask() with solid source and A1 mask to use a PDF stencil mask. Fixes https://bugs.launchpad.net/ubuntu/+source/libcairo/+bug/680628 where a 65K PDF printed to PDF using poppler-cairo turns into an 8MB PDF. --- poppler/CairoOutputDev.cc | 25 ++++++++++++++++++------- 1 files changed, 18 insertions(+), 7 deletions(-) diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index e7c9dc5..0507f8c 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -1550,7 +1550,7 @@ void CairoOutputDev::drawImageMaskRegular(GfxState *state, Object *ref, Stream * unsigned char *dest; cairo_surface_t *image; cairo_pattern_t *pattern; - int x, y; + int x, y, i, bit; ImageStream *imgStr; Guchar *pix; cairo_matrix_t matrix; @@ -1562,7 +1562,7 @@ void CairoOutputDev::drawImageMaskRegular(GfxState *state, Object *ref, Stream * imgStr = new ImageStream(str, width, 1, 1); imgStr->reset(); - image = cairo_image_surface_create (CAIRO_FORMAT_A8, width, height); + image = cairo_image_surface_create (CAIRO_FORMAT_A1, width, height); if (cairo_surface_status (image)) goto cleanup; @@ -1574,12 +1574,23 @@ void CairoOutputDev::drawImageMaskRegular(GfxState *state, Object *ref, Stream * for (y = 0; y < height; y++) { pix = imgStr->getLine(); dest = buffer + y * row_stride; + i = 0; + bit = 0; for (x = 0; x < width; x++) { - - if (pix[x] ^ invert_bit) - *dest++ = 0; - else - *dest++ = 255; + if (bit == 0) + dest[i] = 0; + if (!(pix[x] ^ invert_bit)) { +#ifdef WORDS_BIGENDIAN + dest[i] |= (1 << (7 - bit)); +#else + dest[i] |= (1 << bit); +#endif + } + bit++; + if (bit > 7) { + bit = 0; + i++; + } } } -- 1.7.1