Mercurial > MadButterfly
comparison src/shape_image.c @ 265:b42ee279669e
Change function name and add comments.
- sh_image_set_geometry() to replace sh_image_set().
- page "Image and Image Loader".
- comments.
diff -r 1ed06481e9ea img/image_n_ldr.dia
Binary file img/image_n_ldr.dia has changed
diff -r 1ed06481e9ea img/image_n_ldr.png
Binary file img/image_n_ldr.png has changed
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 24 Jan 2009 15:09:03 +0800 |
parents | 29acbd8a0dd0 |
children | af2d3300f8ff |
comparison
equal
deleted
inserted
replaced
264:1ed06481e9ea | 265:b42ee279669e |
---|---|
4 #include "mb_types.h" | 4 #include "mb_types.h" |
5 #include "mb_shapes.h" | 5 #include "mb_shapes.h" |
6 #include "mb_img_ldr.h" | 6 #include "mb_img_ldr.h" |
7 #include "mb_tools.h" | 7 #include "mb_tools.h" |
8 | 8 |
9 /*! \page sh_image_n_image_ldr Image and Image Loader | |
10 * | |
11 * Image (\ref sh_image_t) is a shape to show an image on the output | |
12 * device. Programmers manipulate object of an image shape to show it | |
13 * at specified position with specified size. To create a new instance | |
14 * of sh_iamge_t, an image should be specified. Programmers must have | |
15 * a way to load image from files. The solution proposed by MadButterfly | |
16 * is image loader (\ref mb_img_ldr_t). | |
17 * | |
18 * Image loader is a repository of image files, programmers give him an | |
19 * ID and get an image returned the loader. Image loader decodes image | |
20 * files specified IDs and return them in an internal representation. | |
21 * The internal representation of an array of pixels. Pixels are in | |
22 * order of columns (X-axis) and then row by row (Y-axis). An pixel | |
23 * can be 32bits, for ARGB, 24bits, for RGB, 8bits, for 8bits Alpha or | |
24 * 256-grey-levels, and 1bits, for bitmap. | |
25 * | |
26 * Every row is padded to round to byte boundary, a rounded row is a stride. | |
27 * Bytes a stride occupied is stride size. The internal rpresentation | |
28 * is a series of strides. The data returned by image loader is | |
29 * \ref mb_img_data_t type. mb_img_data_t::content is data in internal | |
30 * representation. | |
31 * | |
32 * \ref simple_mb_img_ldr_t is a simple implementation of image loader. | |
33 * It is a repository of image files in a directory and sub-directories. | |
34 * ID of an image is mapped to a file in the directory and sub-directories. | |
35 * ID it-self is a relative path relate to root directory of the repository. | |
36 * \ref simple_mb_img_ldr_t handle PNG files only, now. | |
37 * | |
38 * \section get_img_ldr Get an Image Loader for Program | |
39 * redraw_man_t::img_ldr is an image loader assigned by backend. | |
40 * X backend, now, create an instance of simple_mb_img_ldr_t and assigns | |
41 * the instance to redraw_man_t::img_ldr. Programmers should get | |
42 * image loader assigned for a rdman by calling rdman_img_ldr(). | |
43 * | |
44 * \image html image_n_ldr.png | |
45 * | |
46 */ | |
47 | |
9 #define ASSERT(x) | 48 #define ASSERT(x) |
10 #define OK 0 | 49 #define OK 0 |
11 #define ERR -1 | 50 #define ERR -1 |
12 | 51 |
52 /*! \brief Image shape. | |
53 */ | |
13 typedef struct _sh_image { | 54 typedef struct _sh_image { |
14 shape_t shape; | 55 shape_t shape; |
15 | 56 |
16 co_aix x, y; | 57 co_aix x, y; |
17 co_aix w, h; | 58 co_aix w, h; |
82 poses[3][0] = img->x; | 123 poses[3][0] = img->x; |
83 poses[3][1] = img->y + img->h; | 124 poses[3][1] = img->y + img->h; |
84 for(i = 0; i < 4; i++) | 125 for(i = 0; i < 4; i++) |
85 coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]); | 126 coord_trans_pos(img->shape.coord, &poses[i][0], &poses[i][1]); |
86 | 127 |
128 /* Transformation from user space to image space */ | |
87 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w; | 129 img_matrix[0] = (poses[1][0] - poses[0][0]) / img->w; |
88 img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w; | 130 img_matrix[1] = (poses[1][1] - poses[0][1]) / img->w; |
89 img_matrix[2] = -poses[0][0]; | 131 img_matrix[2] = -poses[0][0]; |
90 img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h; | 132 img_matrix[3] = (poses[3][0] - poses[0][0]) / img->h; |
91 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h; | 133 img_matrix[4] = (poses[3][1] - poses[0][1]) / img->h; |
110 cairo_line_to(cr, img->poses[2][0], img->poses[2][1]); | 152 cairo_line_to(cr, img->poses[2][0], img->poses[2][1]); |
111 cairo_line_to(cr, img->poses[3][0], img->poses[3][1]); | 153 cairo_line_to(cr, img->poses[3][0], img->poses[3][1]); |
112 cairo_close_path(cr); | 154 cairo_close_path(cr); |
113 } | 155 } |
114 | 156 |
115 void sh_image_set(shape_t *shape, co_aix x, co_aix y, | 157 /*! \brief Change geometry of an image. |
116 co_aix w, co_aix h) { | 158 * |
159 * Set position and size of an image. | |
160 */ | |
161 void sh_image_set_geometry(shape_t *shape, co_aix x, co_aix y, | |
162 co_aix w, co_aix h) { | |
117 sh_image_t *img = (sh_image_t *)shape; | 163 sh_image_t *img = (sh_image_t *)shape; |
118 | 164 |
119 img->x = x; | 165 img->x = x; |
120 img->y = y; | 166 img->y = y; |
121 img->w = w; | 167 img->w = w; |