comparison src/shape_image.c @ 268:43900cae1d49

Support resizing for image. - Programmers can change size of image that showed on the output device.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 24 Jan 2009 18:19:02 +0800
parents af2d3300f8ff
children 6a1b36738d3d
comparison
equal deleted inserted replaced
267:cac3f084a9b1 268:43900cae1d49
106 free(img); 106 free(img);
107 } 107 }
108 108
109 void sh_image_transform(shape_t *shape) { 109 void sh_image_transform(shape_t *shape) {
110 sh_image_t *img = (sh_image_t *)shape; 110 sh_image_t *img = (sh_image_t *)shape;
111 mb_img_data_t *img_data;
111 co_aix (*poses)[2]; 112 co_aix (*poses)[2];
112 co_aix img_matrix[6]; 113 co_aix img_matrix[6];
114 co_aix x_factor, y_factor;
113 cairo_matrix_t cmatrix; 115 cairo_matrix_t cmatrix;
114 int i; 116 int i;
115 117
118 img_data = img->img_data;
119
116 poses = img->poses; 120 poses = img->poses;
117 poses[0][0] = img->x; 121 poses[0][0] = img->x;
118 poses[0][1] = img->y; 122 poses[0][1] = img->y;
119 poses[1][0] = img->x + img->w; 123 poses[1][0] = img->x + img->w;
120 poses[1][1] = img->y; 124 poses[1][1] = img->y;
130 img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w; 134 img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w;
131 img_matrix[2] = -poses[0][0]; 135 img_matrix[2] = -poses[0][0];
132 img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h; 136 img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h;
133 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h; 137 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h;
134 img_matrix[5] = -poses[0][1]; 138 img_matrix[5] = -poses[0][1];
139 if(img->w != img_data->w ||
140 img->h != img_data->h) {
141 /* Resize image */
142 x_factor = img_data->w / img->w;
143 img_matrix[0] *= x_factor;
144 img_matrix[1] *= x_factor;
145 img_matrix[2] *= x_factor;
146 y_factor = img_data->h / img->h;
147 img_matrix[3] *= y_factor;
148 img_matrix[4] *= y_factor;
149 img_matrix[5] *= y_factor;
150 }
135 paint_image_set_matrix(sh_get_fill(shape), img_matrix); 151 paint_image_set_matrix(sh_get_fill(shape), img_matrix);
136 152
137 geo_from_positions(sh_get_geo(shape), 4, poses); 153 geo_from_positions(sh_get_geo(shape), 4, poses);
138 } 154 }
139 155