annotate src/shape_image.c @ 1377:8ecee58c85c6

Fix issue of crashing for cloned subtree
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 13 Mar 2011 08:10:57 +0800
parents bae104d8d247
children 7bd6c0e88ec8
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
2 // vim: sw=4:ts=8:sts=4
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <stdio.h>
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <string.h>
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
5 #include "mb_graph_engine.h"
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "mb_types.h"
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7 #include "mb_shapes.h"
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #include "mb_img_ldr.h"
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #include "mb_tools.h"
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
265
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
11 /*! \page sh_image_n_image_ldr Image and Image Loader
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
12 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
13 * Image (\ref sh_image_t) is a shape to show an image on the output
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
14 * device. Programmers manipulate object of an image shape to show it
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
15 * at specified position with specified size. For a sh_image_t, an
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
16 * image should be specified to fill the shape. Programmers must have
265
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
17 * a way to load image from files. The solution proposed by MadButterfly
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
18 * is image loader (\ref mb_img_ldr_t).
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
19 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
20 * Image loader is a repository of image files, programmers give him an
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
21 * ID and get an image returned the loader. Image loader decodes image
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
22 * files specified IDs and return them in an internal representation.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
23 * The internal representation of an array of pixels. Pixels are in
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
24 * order of columns (X-axis) and then row by row (Y-axis). An pixel
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
25 * can be 32bits, for ARGB, 24bits, for RGB, 8bits, for 8bits Alpha or
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
26 * 256-grey-levels, and 1bits, for bitmap.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
27 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
28 * Every row is padded to round to byte boundary, a rounded row is a stride.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
29 * Bytes a stride occupied is stride size. The internal rpresentation
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
30 * is a series of strides. The data returned by image loader is
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
31 * \ref mb_img_data_t type. mb_img_data_t::content is data in internal
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
32 * representation.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
33 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
34 * \ref simple_mb_img_ldr_t is a simple implementation of image loader.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
35 * It is a repository of image files in a directory and sub-directories.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
36 * ID of an image is mapped to a file in the directory and sub-directories.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
37 * ID it-self is a relative path relate to root directory of the repository.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
38 * \ref simple_mb_img_ldr_t handle PNG files only, now.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
39 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
40 * \section get_img_ldr Get an Image Loader for Program
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
41 * redraw_man_t::img_ldr is an image loader assigned by backend.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
42 * X backend, now, create an instance of simple_mb_img_ldr_t and assigns
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
43 * the instance to redraw_man_t::img_ldr. Programmers should get
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
44 * image loader assigned for a rdman by calling rdman_img_ldr().
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
45 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
46 * \image html image_n_ldr.png
266
af2d3300f8ff Add image for document of latex format
Thinker K.F. Li <thinker@branda.to>
parents: 265
diff changeset
47 * \image latex image_n_ldr.eps "Relationship of image and loader" width=10cm
265
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
48 */
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
49
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
50 #define ASSERT(x)
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
51 #define OK 0
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
52 #define ERR -1
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
53
265
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
54 /*! \brief Image shape.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
55 */
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
56 typedef struct _sh_image {
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
57 shape_t shape;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
58
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
59 co_aix x, y;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
60 co_aix w, h;
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
61 co_aix poses[4][2];
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
62
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
63 redraw_man_t *rdman;
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
64 } sh_image_t;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
65
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
66 static void sh_image_free(shape_t *shape);
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
67
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
68 /*! \brief Creae a new image shape.
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
69 *
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
70 * \param img_data is image data whose owner-ship is transfered.
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
71 */
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
72 shape_t *rdman_shape_image_new(redraw_man_t *rdman,
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
73 co_aix x, co_aix y, co_aix w, co_aix h) {
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
74 sh_image_t *img;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
75
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
76 img = O_ALLOC(sh_image_t);
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
77 if(img == NULL)
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
78 return NULL;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
79
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
80 memset(img, 0, sizeof(sh_image_t));
338
6a1b36738d3d sh_image_set_img_data() is a function to change content of a sh_image_t.
Thinker K.F. Li <thinker@branda.to>
parents: 268
diff changeset
81 mb_obj_init((mb_obj_t *)img, MBO_IMAGE);
6a1b36738d3d sh_image_set_img_data() is a function to change content of a sh_image_t.
Thinker K.F. Li <thinker@branda.to>
parents: 268
diff changeset
82 img->rdman = rdman;
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
83 img->shape.free = sh_image_free;
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
84
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
85 img->x = x;
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
86 img->y = y;
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
87 img->w = w;
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
88 img->h = h;
672
cbad519226d4 Make sh_image_t managed, and init property store for managed shapes
Thinker K.F. Li <thinker@branda.to>
parents: 473
diff changeset
89
1062
a8d20bc8ce40 Rename rdman_shape_man() to rdman_man_shape() to mean managing a shape
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
90 rdman_man_shape(rdman, (shape_t *)img);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
91
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
92 return (shape_t *)img;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
93 }
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
94
1370
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
95 shape_t *
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
96 rdman_shape_image_clone(redraw_man_t *rdman, const shape_t *_src_img) {
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
97 const sh_image_t *src_img = (const sh_image_t *)_src_img;
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
98 sh_image_t *new_img;
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
99
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
100 new_img = (sh_image_t *)rdman_shape_image_new(rdman,
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
101 src_img->x, src_img->y,
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
102 src_img->w, src_img->h);
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
103 if(new_img == NULL)
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
104 return NULL;
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
105
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
106 sh_copy_style(rdman, (shape_t *)src_img, (shape_t *)new_img);
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
107
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
108 return (shape_t *)new_img;
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
109 }
bae104d8d247 Add clone functions for shape types
Thinker K.F. Li <thinker@codemud.net>
parents: 1062
diff changeset
110
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
111 void sh_image_free(shape_t *shape) {
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
112 sh_image_t *img = (sh_image_t *)shape;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
113
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
114 mb_obj_destroy(shape);
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
115 free(img);
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
116 }
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
117
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
118 void sh_image_transform(shape_t *shape) {
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
119 sh_image_t *img = (sh_image_t *)shape;
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
120 paint_t *paint;
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
121 co_aix (*poses)[2];
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
122 co_aix img_matrix[6];
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
123 co_aix rev_matrix[6];
268
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
124 co_aix x_factor, y_factor;
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
125 int img_w, img_h;
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
126 int i;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
127
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
128 poses = img->poses;
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
129 poses[0][0] = img->x;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 poses[0][1] = img->y;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
131 poses[1][0] = img->x + img->w;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
132 poses[1][1] = img->y;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
133 poses[2][0] = img->x + img->w;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
134 poses[2][1] = img->y + img->h;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
135 poses[3][0] = img->x;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
136 poses[3][1] = img->y + img->h;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
137 for(i = 0; i < 4; i++)
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
139
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
140 geo_from_positions(sh_get_geo(shape), 4, poses);
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
141
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
142 paint = sh_get_fill(shape);
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
143 if(paint == NULL)
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
144 return;
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
145
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
146 ASSERT(paint.pnt_type == MBP_IMAGE);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
147
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
148 paint_image_get_size(paint, &img_w, &img_h);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
149
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
150 /* Transformation from image space to user space */
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
151 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w;
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
152 img_matrix[1] = (poses[3][0] - poses[3][0]) / img->h;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
153 img_matrix[2] = poses[0][0];
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
154 img_matrix[3] = (poses[1][1] - poses[0][1]) / img->w;
260
29acbd8a0dd0 Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents: 257
diff changeset
155 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h;
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
156 img_matrix[5] = poses[0][1];
356
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
157 if(img->w != img_w ||
3e84458968ec Move mb_img_data_t out from argument list of rdman_shape_image_new().
Thinker K.F. Li <thinker@branda.to>
parents: 348
diff changeset
158 img->h != img_h) {
268
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
159 /* Resize image */
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
160 x_factor = img->w / img_w;
268
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
161 img_matrix[0] *= x_factor;
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
162 img_matrix[1] *= x_factor;
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
163 y_factor = img->h / img_h;
268
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
164 img_matrix[3] *= y_factor;
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
165 img_matrix[4] *= y_factor;
43900cae1d49 Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents: 266
diff changeset
166 }
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
167 compute_reverse(img_matrix, rev_matrix);
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 672
diff changeset
168 paint_image_set_matrix(sh_get_fill(shape), rev_matrix);
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
169 }
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
170
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
171 /*! \brief Draw image for an image shape.
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
172 *
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
173 * \note Image is not rescaled for size of the shape.
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
174 */
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
175 void sh_image_draw(shape_t *shape, mbe_t *cr) {
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
176 sh_image_t *img = (sh_image_t *)shape;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 779
diff changeset
177
448
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
178 mbe_move_to(cr, img->poses[0][0], img->poses[0][1]);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
179 mbe_line_to(cr, img->poses[1][0], img->poses[1][1]);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
180 mbe_line_to(cr, img->poses[2][0], img->poses[2][1]);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
181 mbe_line_to(cr, img->poses[3][0], img->poses[3][1]);
16116d84bc5e Replace Cairo with a abstract layer mb_graph_engine.
Thinker K.F. Li <thinker@branda.to>
parents: 356
diff changeset
182 mbe_close_path(cr);
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
183 }
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
184
265
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
185 /*! \brief Change geometry of an image.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
186 *
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
187 * Set position and size of an image.
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
188 */
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
189 void sh_image_set_geometry(shape_t *shape, co_aix x, co_aix y,
b42ee279669e Change function name and add comments.
Thinker K.F. Li <thinker@branda.to>
parents: 260
diff changeset
190 co_aix w, co_aix h) {
257
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
191 sh_image_t *img = (sh_image_t *)shape;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
192
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
193 img->x = x;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
194 img->y = y;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
195 img->w = w;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
196 img->h = h;
50d253d0fcba Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
197 }