Mercurial > MadButterfly
diff src/shape_image.c @ 260:29acbd8a0dd0
Integrate sh_image with svg2code.py.
diff -r e8a784a306d0 examples/svg2code_ex/dsc_3241.png
Binary file examples/svg2code_ex/dsc_3241.png has changed
diff -r e8a784a306d0 examples/svg2code_ex/dsc_3241.png
Binary file examples/svg2code_ex/dsc_3241.png has changed
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 23 Jan 2009 23:00:23 +0800 |
parents | 50d253d0fcba |
children | b42ee279669e |
line wrap: on
line diff
--- a/src/shape_image.c Thu Jan 22 18:10:47 2009 +0800 +++ b/src/shape_image.c Fri Jan 23 23:00:23 2009 +0800 @@ -15,9 +15,11 @@ co_aix x, y; co_aix w, h; + co_aix poses[4][2]; mb_img_data_t *img_data; - cairo_surface_t *surf; + paint_t *paint; + redraw_man_t *rdman; } sh_image_t; static void sh_image_free(shape_t *shape); @@ -30,6 +32,7 @@ co_aix x, co_aix y, co_aix w, co_aix h) { sh_image_t *img; cairo_format_t fmt; + paint_t *paint; img = O_ALLOC(sh_image_t); if(img == NULL) @@ -45,61 +48,31 @@ img->h = h; img->img_data = img_data; - switch(img_data->fmt) { - case MB_IFMT_ARGB32: - fmt = CAIRO_FORMAT_ARGB32; - break; - - case MB_IFMT_RGB24: - fmt = CAIRO_FORMAT_RGB24; - break; - - case MB_IFMT_A8: - fmt = CAIRO_FORMAT_A8; - break; + paint = rdman_paint_image_new(rdman, img_data); + rdman_paint_fill(rdman, paint, (shape_t *)img); + img->paint = paint; + img->rdman = rdman; - case MB_IFMT_A1: - fmt = CAIRO_FORMAT_A1; - break; - - case MB_IFMT_RGB16_565: - fmt = CAIRO_FORMAT_RGB16_565; - break; - - default: - mb_obj_destroy(img); - free(img); - return NULL; - } - - img->surf = cairo_image_surface_create_for_data(img_data->content, - fmt, - img_data->width, - img_data->height, - img_data->stride); - if(img->surf == NULL) { - mb_obj_destroy(img); - free(img); - return NULL; - } - return (shape_t *)img; } void sh_image_free(shape_t *shape) { sh_image_t *img = (sh_image_t *)shape; + rdman_paint_free(img->rdman, img->paint); mb_obj_destroy(shape); MB_IMG_DATA_FREE(img->img_data); - cairo_surface_destroy(img->surf); free(img); } void sh_image_transform(shape_t *shape) { sh_image_t *img = (sh_image_t *)shape; - co_aix poses[4][2]; + co_aix (*poses)[2]; + co_aix img_matrix[6]; + cairo_matrix_t cmatrix; int i; + poses = img->poses; poses[0][0] = img->x; poses[0][1] = img->y; poses[1][0] = img->x + img->w; @@ -110,6 +83,14 @@ poses[3][1] = img->y + img->h; for(i = 0; i < 4; i++) coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]); + + 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[4] = (poses[3][1] - poses[0][1]) / img->h; + img_matrix[5] = -poses[0][1]; + paint_image_set_matrix(sh_get_fill(shape), img_matrix); geo_from_positions(sh_get_geo(shape), 4, poses); } @@ -124,30 +105,11 @@ cairo_matrix_t matrix, saved_matrix; co_aix *aggr; - aggr = coord_get_aggr_matrix(sh_get_coord(shape)); - cairo_matrix_init(&matrix, - aggr[0], aggr[3], - aggr[1], aggr[4], - aggr[2], aggr[5]); - - /* set matrix */ - cairo_get_matrix(cr, &saved_matrix); - cairo_set_matrix(cr, &matrix); - - /* set source */ - saved_source = cairo_get_source(cr); - cairo_pattern_reference(saved_source); - - /* draw image */ - cairo_set_source_surface(cr, img->surf, 0, 0); - cairo_paint(cr); - - /* restore source */ - cairo_set_source(cr, saved_source); - cairo_pattern_destroy(saved_source); - - /* restore matrix */ - cairo_set_matrix(cr, &saved_matrix); + cairo_move_to(cr, img->poses[0][0], img->poses[0][1]); + cairo_line_to(cr, img->poses[1][0], img->poses[1][1]); + cairo_line_to(cr, img->poses[2][0], img->poses[2][1]); + cairo_line_to(cr, img->poses[3][0], img->poses[3][1]); + cairo_close_path(cr); } void sh_image_set(shape_t *shape, co_aix x, co_aix y,