[cairo] issue with rotated image sources

Benjamin Otte in7y118 at public.uni-hamburg.de
Mon Jan 8 03:27:26 PST 2007

I mailed this once to Carl, but it apparently got lost in the mist of
time (he warned me it would happen) and I just found it hadn't hit git

Monty's performance improvement to add extents to clone_similar (commit
8d7a02ed58e06584eb09575e6ca11d0a81094ab6) does not verify that the extents
it passes to clone_similar are inside the surface area. If you have a
non-standard rotation matrix (ideally non 90 degree multiples), this
causes clone_similar to be called (from
_cairo_pattern_acquire_surface_for_surface) with extents like (-20, -20,
120, 120) for a 100x100 surface.
If you want a display of this effect, get swfdec and watch

I patched cairo-xlib-surface.c to clamp the extents to the available
image size (see below), but other surface types may have the same issue.
I'll leave it up to you to investigate them or make clone_similar not use
weird extents.


commit 5bb418e54aab739a6f3e3370902bf3fd035d2bb6
Author: Benjamin Otte <otte at gnome.org>
Date:   Thu Dec 7 15:53:20 2006 +0100

    fix copy_similar to not have out-of-bounds extents

diff --git a/src/cairo-xlib-surface.c b/src/cairo-xlib-surface.c
index 4e7f640..86cc01f 100644
--- a/src/cairo-xlib-surface.c
+++ b/src/cairo-xlib-surface.c
@@ -893,6 +893,18 @@ _cairo_xlib_surface_clone_similar (void
        if (clone->base.status)
            return CAIRO_STATUS_NO_MEMORY;

+       if (src_x < 0) {
+           width += src_x;
+           src_x = 0;
+       }
+       if (src_y < 0) {
+           height += src_y;
+           src_y = 0;
+       }
+       if (width > image_src->width)
+           width = image_src->width;
+       if (height > image_src->height)
+           height = image_src->height;
        _draw_image_surface (clone, image_src, src_x, src_y,
                             width, height, src_x, src_y);

More information about the cairo mailing list