diff options
author | Adrian Johnson <ajohnson@redneon.com> | 2011-12-06 20:45:31 +1030 |
---|---|---|
committer | Adrian Johnson <ajohnson@redneon.com> | 2011-12-06 20:45:31 +1030 |
commit | 25e35b46bfd2a71a8cf0484e51351961ad1c82a3 (patch) | |
tree | a3ca376fbd23e073ed5e50695519d6327aa94c07 | |
parent | c7ce1b68d5370f6e804a6edbf5be4bca3a5b7c57 (diff) |
ps: avoid padding images if the padding is not required to fill the extents
-rw-r--r-- | src/cairo-ps-surface.c | 59 |
1 files changed, 35 insertions, 24 deletions
diff --git a/src/cairo-ps-surface.c b/src/cairo-ps-surface.c index 95b3d123..def9e62c 100644 --- a/src/cairo-ps-surface.c +++ b/src/cairo-ps-surface.c @@ -2820,6 +2820,7 @@ _cairo_ps_surface_acquire_surface (cairo_ps_surface_t *surface, cairo_surface_t *pad_image; int x = 0; int y = 0; + int w, h; surface->acquired_image = NULL; surface->image = NULL; @@ -2866,32 +2867,42 @@ _cairo_ps_surface_acquire_surface (cairo_ps_surface_t *surface, _cairo_box_from_rectangle (&box, extents); _cairo_matrix_transform_bounding_box_fixed (&pattern->base.matrix, &box, NULL); _cairo_box_round_to_rectangle (&box, &rect); - x = -rect.x; - y = -rect.y; - - pad_image = - _cairo_image_surface_create_with_pixman_format (NULL, - surface->acquired_image->pixman_format, - rect.width, rect.height, - 0); - if (pad_image->status) { - status = pad_image->status; - goto BAIL; - } - _cairo_pattern_init_for_surface (&pad_pattern, &surface->acquired_image->base); - cairo_matrix_init_translate (&pad_pattern.base.matrix, -x, -y); - pad_pattern.base.extend = CAIRO_EXTEND_PAD; - status = _cairo_surface_paint (pad_image, - CAIRO_OPERATOR_SOURCE, - &pad_pattern.base, - NULL); - _cairo_pattern_fini (&pad_pattern.base); - if (unlikely (status)) { - if (pad_image != &surface->acquired_image->base) - cairo_surface_destroy (pad_image); + /* Check if image needs padding to fill extents. */ + w = surface->acquired_image->width; + h = surface->acquired_image->height; + if (_cairo_fixed_integer_ceil(box.p1.x) < 0 || + _cairo_fixed_integer_ceil(box.p1.y) < 0 || + _cairo_fixed_integer_floor(box.p2.y) > w || + _cairo_fixed_integer_floor(box.p2.y) > h) + { + x = -rect.x; + y = -rect.y; + + pad_image = + _cairo_image_surface_create_with_pixman_format (NULL, + surface->acquired_image->pixman_format, + rect.width, rect.height, + 0); + if (pad_image->status) { + status = pad_image->status; + goto BAIL; + } - goto BAIL; + _cairo_pattern_init_for_surface (&pad_pattern, &surface->acquired_image->base); + cairo_matrix_init_translate (&pad_pattern.base.matrix, -x, -y); + pad_pattern.base.extend = CAIRO_EXTEND_PAD; + status = _cairo_surface_paint (pad_image, + CAIRO_OPERATOR_SOURCE, + &pad_pattern.base, + NULL); + _cairo_pattern_fini (&pad_pattern.base); + if (unlikely (status)) { + if (pad_image != &surface->acquired_image->base) + cairo_surface_destroy (pad_image); + + goto BAIL; + } } } |