From d881e1f5801ca0aefecccb43db05db539b3080d5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=B8ren=20Sandmann=20Pedersen?= Date: Sun, 11 Nov 2012 14:05:54 -0500 Subject: [PATCH] Allow src and dst to be identical in pixman_f_transform_invert() It is useful to be able to invert a matrix in place, but currently pixman_f_transform_invert() will produce wrong results if you pass the same matrix as both source and destination. Fix that by inverting into a temporary matrix and then copying that to the destination. --- pixman/pixman-matrix.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/pixman/pixman-matrix.c b/pixman/pixman-matrix.c index a029ab7..d2ab609 100644 --- a/pixman/pixman-matrix.c +++ b/pixman/pixman-matrix.c @@ -336,14 +336,14 @@ PIXMAN_EXPORT pixman_bool_t pixman_transform_invert (struct pixman_transform * dst, const struct pixman_transform *src) { - struct pixman_f_transform m, r; + struct pixman_f_transform m; pixman_f_transform_from_pixman_transform (&m, src); - if (!pixman_f_transform_invert (&r, &m)) + if (!pixman_f_transform_invert (&m, &m)) return FALSE; - if (!pixman_transform_from_pixman_f_transform (dst, &r)) + if (!pixman_transform_from_pixman_f_transform (dst, &m)) return FALSE; return TRUE; @@ -469,10 +469,11 @@ PIXMAN_EXPORT pixman_bool_t pixman_f_transform_invert (struct pixman_f_transform * dst, const struct pixman_f_transform *src) { - double det; - int i, j; static const int a[3] = { 2, 2, 1 }; static const int b[3] = { 1, 0, 0 }; + pixman_f_transform_t d; + double det; + int i, j; det = 0; for (i = 0; i < 3; i++) @@ -507,10 +508,12 @@ pixman_f_transform_invert (struct pixman_f_transform * dst, if (((i + j) & 1) != 0) p = -p; - dst->m[j][i] = det * p; + d.m[j][i] = det * p; } } + *dst = d; + return TRUE; } -- 2.7.4