comparison 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
comparison
equal deleted inserted replaced
777:72b5bb88979f 778:61c217f8cec8
102 void sh_image_transform(shape_t *shape) { 102 void sh_image_transform(shape_t *shape) {
103 sh_image_t *img = (sh_image_t *)shape; 103 sh_image_t *img = (sh_image_t *)shape;
104 paint_t *paint; 104 paint_t *paint;
105 co_aix (*poses)[2]; 105 co_aix (*poses)[2];
106 co_aix img_matrix[6]; 106 co_aix img_matrix[6];
107 co_aix rev_matrix[6];
107 co_aix x_factor, y_factor; 108 co_aix x_factor, y_factor;
108 int img_w, img_h; 109 int img_w, img_h;
109 int i; 110 int i;
110 111
111 poses = img->poses; 112 poses = img->poses;
128 129
129 ASSERT(paint.pnt_type == MBP_IMAGE); 130 ASSERT(paint.pnt_type == MBP_IMAGE);
130 131
131 paint_image_get_size(paint, &img_w, &img_h); 132 paint_image_get_size(paint, &img_w, &img_h);
132 133
133 /* Transformation from user space to image space */ 134 /* Transformation from image space to user space */
134 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w; 135 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w;
135 img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w; 136 img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h;
136 img_matrix[2] = -poses[0][0]; 137 img_matrix[2] = poses[0][0];
137 img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h; 138 img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w;
138 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h; 139 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h;
139 img_matrix[5] = -poses[0][1]; 140 img_matrix[5] = poses[0][1];
140 if(img->w != img_w || 141 if(img->w != img_w ||
141 img->h != img_h) { 142 img->h != img_h) {
142 /* Resize image */ 143 /* Resize image */
143 x_factor = img_w / img->w; 144 x_factor = img->w / img_w;
144 img_matrix[0] *= x_factor; 145 img_matrix[0] *= x_factor;
145 img_matrix[1] *= x_factor; 146 img_matrix[1] *= x_factor;
146 img_matrix[2] *= x_factor; 147 y_factor = img->h / img_h;
147 y_factor = img_h / img->h;
148 img_matrix[3] *= y_factor; 148 img_matrix[3] *= y_factor;
149 img_matrix[4] *= y_factor; 149 img_matrix[4] *= y_factor;
150 img_matrix[5] *= y_factor;
151 } 150 }
152 paint_image_set_matrix(sh_get_fill(shape), img_matrix); 151 compute_reverse(img_matrix, rev_matrix);
152 paint_image_set_matrix(sh_get_fill(shape), rev_matrix);
153 } 153 }
154 154
155 /*! \brief Draw image for an image shape. 155 /*! \brief Draw image for an image shape.
156 * 156 *
157 * \note Image is not rescaled for size of the shape. 157 * \note Image is not rescaled for size of the shape.