comparison src/paint.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 530bb7728546
children b42ee279669e
comparison
equal deleted inserted replaced
259:e8a784a306d0 260:29acbd8a0dd0
21 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a); 21 cairo_set_source_rgba(cr, color->r, color->g, color->b, color->a);
22 } 22 }
23 23
24 static void paint_color_free(redraw_man_t *rdman, paint_t *paint) { 24 static void paint_color_free(redraw_man_t *rdman, paint_t *paint) {
25 shnode_list_free(rdman, paint->members); 25 shnode_list_free(rdman, paint->members);
26 paint_destroy(paint);
26 elmpool_elm_free(rdman->paint_color_pool, paint); 27 elmpool_elm_free(rdman->paint_color_pool, paint);
27 } 28 }
28 29
29 paint_t *rdman_paint_color_new(redraw_man_t *rdman, 30 paint_t *rdman_paint_color_new(redraw_man_t *rdman,
30 co_comp_t r, co_comp_t g, 31 co_comp_t r, co_comp_t g,
106 static void paint_linear_free(redraw_man_t *rdman, paint_t *paint) { 107 static void paint_linear_free(redraw_man_t *rdman, paint_t *paint) {
107 paint_linear_t *linear = (paint_linear_t *)paint; 108 paint_linear_t *linear = (paint_linear_t *)paint;
108 109
109 if(linear->ptn) 110 if(linear->ptn)
110 cairo_pattern_destroy(linear->ptn); 111 cairo_pattern_destroy(linear->ptn);
112 paint_destroy(paint);
111 free(paint); 113 free(paint);
112 } 114 }
113 115
114 paint_t *rdman_paint_linear_new(redraw_man_t *rdman, 116 paint_t *rdman_paint_linear_new(redraw_man_t *rdman,
115 co_aix x1, co_aix y1, 117 co_aix x1, co_aix y1,
196 static void paint_radial_free(redraw_man_t *rdman, paint_t *paint) { 198 static void paint_radial_free(redraw_man_t *rdman, paint_t *paint) {
197 paint_radial_t *radial = (paint_radial_t *)paint; 199 paint_radial_t *radial = (paint_radial_t *)paint;
198 200
199 if(radial->ptn) 201 if(radial->ptn)
200 cairo_pattern_destroy(radial->ptn); 202 cairo_pattern_destroy(radial->ptn);
203 paint_destroy(paint);
201 free(paint); 204 free(paint);
202 } 205 }
203 206
204 paint_t *rdman_paint_radial_new(redraw_man_t *rdman, 207 paint_t *rdman_paint_radial_new(redraw_man_t *rdman,
205 co_aix cx, co_aix cy, co_aix r) { 208 co_aix cx, co_aix cy, co_aix r) {
239 radial->flags |= RDF_DIRTY; 242 radial->flags |= RDF_DIRTY;
240 243
241 return old_stops; 244 return old_stops;
242 } 245 }
243 246
247
248 typedef struct _paint_image {
249 paint_t paint;
250 mb_img_data_t *img;
251 cairo_surface_t *surf;
252 cairo_pattern_t *ptn;
253 } paint_image_t;
254
255 static
256 void paint_image_prepare(paint_t *paint, cairo_t *cr) {
257 paint_image_t *paint_img = (paint_image_t *)paint;
258 mb_img_data_t *img_data;
259
260 img_data = paint_img->img;
261 cairo_set_source(cr, paint_img->ptn);
262 }
263
264 static
265 void paint_image_free(redraw_man_t *rdman, paint_t *paint) {
266 paint_image_t *paint_img = (paint_image_t *)paint;
267 mb_img_data_t *img_data;
268
269 cairo_surface_destroy(paint_img->surf);
270 img_data = paint_img->img;
271 MB_IMG_DATA_FREE(img_data);
272 paint_destroy(&paint_img->paint);
273 free(paint);
274 }
275
276 paint_t *rdman_paint_image_new(redraw_man_t *rdman,
277 mb_img_data_t *img) {
278 paint_image_t *paint;
279 int fmt;
280
281 switch(img->fmt) {
282 case MB_IFMT_ARGB32:
283 fmt = CAIRO_FORMAT_ARGB32;
284 break;
285 case MB_IFMT_RGB24:
286 fmt = CAIRO_FORMAT_RGB24;
287 break;
288 case MB_IFMT_A8:
289 fmt = CAIRO_FORMAT_A8;
290 break;
291 case MB_IFMT_A1:
292 fmt = CAIRO_FORMAT_A1;
293 break;
294 default:
295 return NULL;
296 }
297
298 paint = O_ALLOC(paint_image_t);
299 if(paint == NULL)
300 return NULL;
301
302 paint_init(&paint->paint, paint_image_prepare, paint_image_free);
303 paint->img = img;
304 paint->surf = cairo_image_surface_create_for_data(img->content,
305 fmt,
306 img->width,
307 img->height,
308 img->stride);
309 if(paint->surf == NULL) {
310 paint_destroy(&paint->paint);
311 free(paint);
312 return NULL;
313 }
314
315 paint->ptn = cairo_pattern_create_for_surface(paint->surf);
316 if(paint->ptn == NULL) {
317 paint_destroy(&paint->paint);
318 cairo_surface_destroy(paint->surf);
319 free(paint);
320 return NULL;
321 }
322
323 return (paint_t *)paint;
324 }
325
326 void paint_image_set_matrix(paint_t *paint, co_aix matrix[6]) {
327 paint_image_t *img_paint = (paint_image_t *)paint;
328 cairo_matrix_t cmatrix;
329
330 cmatrix.xx = matrix[0];
331 cmatrix.xy = matrix[1];
332 cmatrix.x0 = matrix[2];
333 cmatrix.yx = matrix[3];
334 cmatrix.yy = matrix[4];
335 cmatrix.y0 = matrix[5];
336 cairo_pattern_set_matrix(img_paint->ptn, &cmatrix);
337 }