Mercurial > MadButterfly
comparison src/graph_engine_openvg.c @ 606:e21eb54c7d9c openvg
Implement radial gradient paint.
- Refactory linear gradient creation function to share code with
radial gradient creation function.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 04 Jul 2010 16:31:39 +0800 |
parents | a8fa4c550fe5 |
children | 51dc49fd34a8 |
comparison
equal
deleted
inserted
replaced
605:a8fa4c550fe5 | 606:e21eb54c7d9c |
---|---|
11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ | 11 #define MB_2_VG_COLOR(r, g, b, a) ((((int)(0xf * r) & 0xf) << 24) | \ |
12 (((int)(0xf * g) & 0xf) << 16) | \ | 12 (((int)(0xf * g) & 0xf) << 16) | \ |
13 (((int)(0xf * b) & 0xf) << 16) | \ | 13 (((int)(0xf * b) & 0xf) << 16) | \ |
14 ((int)(0xf * a) & 0xf)) | 14 ((int)(0xf * a) & 0xf)) |
15 | 15 |
16 mbe_pattern_t * | 16 static mbe_pattern_t * |
17 mbe_pattern_create_linear(co_aix x0, co_aix y0, | 17 _mbe_pattern_create_gradient(VGfloat *gradient, int grad_len, |
18 co_aix x1, co_aix y1, | 18 int grad_type, |
19 grad_stop_t *stops, int stop_cnt) { | 19 grad_stop_t *stops, int stop_cnt) { |
20 VGPaint paint; | 20 VGPaint paint; |
21 mbe_pattern_t *pattern; | 21 mbe_pattern_t *pattern; |
22 VGfloat gradient[] = {x0, y0, x1, y1}; | |
23 static VGfloat *ov_stops = 0; | 22 static VGfloat *ov_stops = 0; |
24 static int max_stop_cnt = 0; | 23 static int max_stop_cnt = 0; |
25 VGfloat *cur_ov_stop; | 24 VGfloat *cur_ov_stop; |
26 grad_stop_t *cur_stop; | 25 grad_stop_t *cur_stop; |
27 int i; | 26 int i; |
49 } | 48 } |
50 | 49 |
51 paint = vgCreatePaint(); | 50 paint = vgCreatePaint(); |
52 if(paint == VG_INVALID_HANDLE) | 51 if(paint == VG_INVALID_HANDLE) |
53 return NULL; | 52 return NULL; |
54 vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); | 53 vgSetParameteri(paint, VG_PAINT_TYPE, grad_type); |
55 vgSetParameterfv(paint, VG_PAINT_LINEAR_GRADIENT, 4, gradient); | 54 vgSetParameterfv(paint, VG_PAINT_RADIAL_GRADIENT, grad_len, gradient); |
56 vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, 5 * stop_cnt, ov_stops); | 55 vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, 5 * stop_cnt, ov_stops); |
57 | 56 |
58 pattern = O_ALLOC(mbe_pattern_t); | 57 pattern = O_ALLOC(mbe_pattern_t); |
59 if(pattern == NULL) { | 58 if(pattern == NULL) { |
60 vgPaintDestroy(paint); | 59 vgPaintDestroy(paint); |
62 } | 61 } |
63 | 62 |
64 pattern->paint = paint; | 63 pattern->paint = paint; |
65 pattern->asso_img = NULL; | 64 pattern->asso_img = NULL; |
66 | 65 |
66 return pattern; | |
67 } | |
68 | |
69 /* | |
70 * \note OpenVG does not support start circle, it supports only focal | |
71 * point. It means radius0 is not working. | |
72 */ | |
73 mbe_pattern_t * | |
74 mbe_pattern_create_radial(co_aix cx0, co_aix cy0, | |
75 co_aix radius0, | |
76 co_aix cx1, co_aix cy1, | |
77 co_aix radius1, grad_stop_t *stops, | |
78 int stop_cnt) { | |
79 mbe_pattern_t *pattern; | |
80 VGfloat gradient[] = {cx0, cy0, cx1, cy1, radius1}; | |
81 | |
82 pattern = _mbe_pattern_create_gradient(gradient, 5, | |
83 VG_PAINT_TYPE_RADIAL_GRADIENT, | |
84 stops, stop_cnt); | |
85 return pattern; | |
86 } | |
87 | |
88 mbe_pattern_t * | |
89 mbe_pattern_create_linear(co_aix x0, co_aix y0, | |
90 co_aix x1, co_aix y1, | |
91 grad_stop_t *stops, int stop_cnt) { | |
92 mbe_pattern_t *pattern; | |
93 VGfloat gradient[] = {x0, y0, x1, y1}; | |
94 | |
95 pattern = _mbe_pattern_create_gradient(gradient, 4, | |
96 VG_PAINT_TYPE_LINEAR_GRADIENT, | |
97 stops, stop_cnt); | |
67 return pattern; | 98 return pattern; |
68 } | 99 } |
69 | 100 |
70 void | 101 void |
71 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, | 102 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, |