From 4570f8c1fb31c0bad399ca4e8adecba7a5193a02 Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Mon, 29 Sep 2008 16:22:48 +0100 Subject: [PATCH] [image] Increase range of translate vector in pixman_matrix Exploit the auxiliary offset vector in the attributes to reduce likelihood of range overflow in the translation components when converting the pattern matrix to fixed-point pixman_matrix_t. This can probably move higher into acquire_surface_for_surface() after being cleaned up. --- src/cairo-image-surface.c | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cairo-image-surface.c b/src/cairo-image-surface.c index daae8d1..ad0f31a 100644 --- a/src/cairo-image-surface.c +++ b/src/cairo-image-surface.c @@ -797,9 +797,33 @@ _cairo_image_surface_clone_similar (void *abstract_surface, static cairo_status_t _cairo_image_surface_set_matrix (cairo_image_surface_t *surface, - const cairo_matrix_t *matrix) + cairo_surface_attributes_t *attributes) { + cairo_matrix_t *matrix; pixman_transform_t pixman_transform; + double tx, ty; + + matrix = &attributes->matrix; + tx = ty = 0.; + cairo_matrix_transform_point (matrix, &tx, &ty); + /* reduce likelihood of range overflow with large downscaling */ + if (tx != 0. || ty != 0.) { + int ix = (int) tx; + int iy = (int) ty; + cairo_matrix_t m; + + m = *matrix; + cairo_matrix_invert (&m); + tx = ix; + ty = iy; + cairo_matrix_transform_distance (&m, &tx, &ty); + + attributes->x_offset += tx; + attributes->y_offset += ty; + + cairo_matrix_init_translate (&m, -ix, -iy); + cairo_matrix_multiply (matrix, matrix, &m); + } _cairo_matrix_to_pixman_matrix (matrix, &pixman_transform); @@ -857,7 +881,7 @@ _cairo_image_surface_set_attributes (cairo_image_surface_t *surface, { cairo_int_status_t status; - status = _cairo_image_surface_set_matrix (surface, &attributes->matrix); + status = _cairo_image_surface_set_matrix (surface, attributes); if (status) return status; -- 1.5.6.3