Mercurial > MadButterfly
changeset 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 | cac3f084a9b1 |
children | c96f38ad4bb6 |
files | examples/svg2code_ex/svg2code_ex.svg include/mb_img_ldr.h src/img_ldr.c src/paint.c src/shape_image.c |
diffstat | 5 files changed, 25 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/svg2code_ex/svg2code_ex.svg Sat Jan 24 15:23:42 2009 +0800 +++ b/examples/svg2code_ex/svg2code_ex.svg Sat Jan 24 18:19:02 2009 +0800 @@ -337,8 +337,8 @@ showgrid="true" inkscape:window-width="822" inkscape:window-height="695" - inkscape:window-x="200" - inkscape:window-y="0" /> + inkscape:window-x="608" + inkscape:window-y="181" /> <metadata id="metadata7"> <rdf:RDF> @@ -470,7 +470,7 @@ y="87.316605" x="605.409" id="image2497" - height="66" + height="130.90765" width="100" sodipodi:absref="/usr/home/thinker/progm/MadButterfly/examples/svg2code_ex/dsc_3241.png" xlink:href="dsc_3241.png" />
--- a/include/mb_img_ldr.h Sat Jan 24 15:23:42 2009 +0800 +++ b/include/mb_img_ldr.h Sat Jan 24 18:19:02 2009 +0800 @@ -22,7 +22,7 @@ struct _mb_img_data { /*! \brief Content of the image. */ void *content; - int width, height; + int w, h; int stride; /*!< \brief Number of bytes a row */ mb_img_fmt_t fmt; /*! \brief Release the image that was loaded by the loader. */
--- a/src/img_ldr.c Sat Jan 24 15:23:42 2009 +0800 +++ b/src/img_ldr.c Sat Jan 24 18:19:02 2009 +0800 @@ -46,8 +46,8 @@ return NULL; } img->img.content = cairo_image_surface_get_data(surf); - img->img.width = cairo_image_surface_get_width(surf); - img->img.height = cairo_image_surface_get_height(surf); + img->img.w = cairo_image_surface_get_width(surf); + img->img.h = cairo_image_surface_get_height(surf); img->img.stride = cairo_image_surface_get_stride(surf); fmt = cairo_image_surface_get_format(surf); switch(fmt) {
--- a/src/paint.c Sat Jan 24 15:23:42 2009 +0800 +++ b/src/paint.c Sat Jan 24 18:19:02 2009 +0800 @@ -311,8 +311,8 @@ paint->img = img; paint->surf = cairo_image_surface_create_for_data(img->content, fmt, - img->width, - img->height, + img->w, + img->h, img->stride); if(paint->surf == NULL) { paint_destroy(&paint->paint);
--- a/src/shape_image.c Sat Jan 24 15:23:42 2009 +0800 +++ b/src/shape_image.c Sat Jan 24 18:19:02 2009 +0800 @@ -108,11 +108,15 @@ void sh_image_transform(shape_t *shape) { sh_image_t *img = (sh_image_t *)shape; + mb_img_data_t *img_data; co_aix (*poses)[2]; co_aix img_matrix[6]; + co_aix x_factor, y_factor; cairo_matrix_t cmatrix; int i; - + + img_data = img->img_data; + poses = img->poses; poses[0][0] = img->x; poses[0][1] = img->y; @@ -132,6 +136,18 @@ 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]; + if(img->w != img_data->w || + img->h != img_data->h) { + /* Resize image */ + x_factor = img_data->w / img->w; + img_matrix[0] *= x_factor; + img_matrix[1] *= x_factor; + img_matrix[2] *= x_factor; + y_factor = img_data->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); geo_from_positions(sh_get_geo(shape), 4, poses);