diff src/shape_image.c @ 778:61c217f8cec8

Fix bug of transformation from user space to image space.
author Thinker K.F. Li <thinker@codemud.net>
date Mon, 30 Aug 2010 13:07:49 +0800
parents cbad519226d4
children 8e9481bf1cc0
line wrap: on
line diff
--- a/src/shape_image.c	Mon Aug 30 08:57:31 2010 +0800
+++ b/src/shape_image.c	Mon Aug 30 13:07:49 2010 +0800
@@ -104,6 +104,7 @@
     paint_t *paint;
     co_aix (*poses)[2];
     co_aix img_matrix[6];
+    co_aix rev_matrix[6];
     co_aix x_factor, y_factor;
     int img_w, img_h;
     int i;
@@ -130,26 +131,25 @@
     
     paint_image_get_size(paint, &img_w, &img_h);
     
-    /* Transformation from user space to image space */
+    /* Transformation from image space to user space */
     img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w;
-    img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w;
-    img_matrix[2] = -poses[0][0];
-    img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h;
+    img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h;
+    img_matrix[2] = poses[0][0];
+    img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w;
     img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h;
-    img_matrix[5] = -poses[0][1];
+    img_matrix[5] = poses[0][1];
     if(img->w != img_w ||
        img->h != img_h) {
 	/* Resize image */
-	x_factor = img_w / img->w;
+	x_factor = img->w / img_w;
 	img_matrix[0] *= x_factor;
 	img_matrix[1] *= x_factor;
-	img_matrix[2] *= x_factor;
-	y_factor = img_h / img->h;
+	y_factor = img->h / img_h;
 	img_matrix[3] *= y_factor;
 	img_matrix[4] *= y_factor;
-	img_matrix[5] *= y_factor;
     }
-    paint_image_set_matrix(sh_get_fill(shape), img_matrix);
+    compute_reverse(img_matrix, rev_matrix);
+    paint_image_set_matrix(sh_get_fill(shape), rev_matrix);
 }
 
 /*! \brief Draw image for an image shape.