diff --git a/poppler/CairoOutputDev.cc b/poppler/CairoOutputDev.cc index 9a0f3be..917e5d8 100644 --- a/poppler/CairoOutputDev.cc +++ b/poppler/CairoOutputDev.cc @@ -1555,15 +1555,14 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream invert_bit = invert ? 1 : 0; - image = cairo_image_surface_create (CAIRO_FORMAT_A8, scaledWidth, scaledHeight); - if (cairo_surface_status (image)) { - imgStr->close(); - delete imgStr; + row_stride = (scaledWidth + 3) & ~3; + buffer = (unsigned char *) malloc (scaledHeight * row_stride); + if (buffer == NULL) { + error(-1, "Unable to allocate memory for image."); return; } - buffer = cairo_image_surface_get_data (image); - row_stride = cairo_image_surface_get_stride (image); + int yp = height / scaledHeight; int yq = height % scaledHeight; @@ -1678,10 +1677,22 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream } free(pixBuf); - cairo_surface_mark_dirty (image); + +// cairo_surface_mark_dirty (image); +// ^ was not in bad commit, removed anyhow + + //XXX: we should handle error's better than this + image = cairo_image_surface_create_for_data (buffer, CAIRO_FORMAT_A8, + scaledWidth, scaledHeight, row_stride); + if (image == NULL) { + imgStr->close(); + delete imgStr; + return; + } + pattern = cairo_pattern_create_for_surface (image); - cairo_surface_destroy (image); - if (cairo_pattern_status (pattern)) { + +if (pattern == NULL) { imgStr->close(); delete imgStr; return; @@ -1692,7 +1703,6 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream * images with CAIRO_FILTER_NEAREST to look really bad */ cairo_pattern_set_filter (pattern, interpolate ? CAIRO_FILTER_BEST : CAIRO_FILTER_FAST); - cairo_pattern_set_extend (pattern, CAIRO_EXTEND_PAD); if (state->getFillColorSpace()->getMode() == csPattern) { cairo_matrix_init_translate (&matrix, 0, scaledHeight); @@ -1712,8 +1722,6 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream if (yScale > 0) cairo_scale(cairo, 1, -1); - cairo_rectangle (cairo, 0., 0., scaledWidth, scaledHeight); - cairo_clip (cairo); cairo_mask (cairo, pattern); //cairo_get_matrix(cairo, &matrix); @@ -1732,14 +1740,13 @@ void CairoOutputDev::drawImageMaskPrescaled(GfxState *state, Object *ref, Stream cairo_translate (cairo_shape, tx - matrix.x0, ty2 - matrix.y0); if (yScale > 0) cairo_scale(cairo_shape, 1, -1); - - cairo_rectangle (cairo_shape, 0., 0., scaledWidth, scaledHeight); - cairo_fill (cairo_shape); - - cairo_restore(cairo_shape); + cairo_mask (cairo_shape, pattern); + cairo_restore(cairo_shape); } cairo_pattern_destroy (pattern); + cairo_surface_destroy (image); + free(buffer); imgStr->close(); delete imgStr;