Mercurial > MadButterfly
comparison src/graph_engine_openvg.c @ 607:51dc49fd34a8 openvg
Create pattern from an image
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 04 Jul 2010 21:09:56 +0800 |
parents | e21eb54c7d9c |
children | 6c74bc371e37 |
comparison
equal
deleted
inserted
replaced
606:e21eb54c7d9c | 607:51dc49fd34a8 |
---|---|
94 | 94 |
95 pattern = _mbe_pattern_create_gradient(gradient, 4, | 95 pattern = _mbe_pattern_create_gradient(gradient, 4, |
96 VG_PAINT_TYPE_LINEAR_GRADIENT, | 96 VG_PAINT_TYPE_LINEAR_GRADIENT, |
97 stops, stop_cnt); | 97 stops, stop_cnt); |
98 return pattern; | 98 return pattern; |
99 } | |
100 | |
101 mbe_pattern_t * | |
102 mbe_pattern_create_image(mb_img_data_t *img) { | |
103 VGPaint paint; | |
104 mbe_pattern_t *pattern; | |
105 _ge_openvg_img_t *ge_img; | |
106 VGImage vg_img; | |
107 VGImageFormat fmt = VG_sARGB_8888; | |
108 | |
109 /* \note OpenVG implementation supports one \ref MB_IFMT_ARGB32 | |
110 * image. | |
111 */ | |
112 if(img->fmt != MB_IFMT_ARGB32) | |
113 return NULL; | |
114 | |
115 /* Create and copy pixels into VGImage */ | |
116 vg_img = vgCreateImage(fmt, img->w, img->h, | |
117 VG_IMAGE_QUALITY_NONANTIALIASED); | |
118 if(vg_img == VG_INVALID_HANDLE) | |
119 return NULL; | |
120 vgImageSubData(vg_img, img->content, img->stride, fmt, | |
121 0, 0, img->w, img->h); | |
122 | |
123 /* Allocate objects */ | |
124 ge_img = O_ALLOC(_ge_openvg_img_t); | |
125 pattern = O_ALLOC(mbe_pattern_t); | |
126 paint = vgCreatePaint(); | |
127 if(ge_img == NULL || pattern == NULL || paint == VG_INVALID_HANDLE) | |
128 goto err; | |
129 | |
130 | |
131 /* Initialize objects */ | |
132 ge_img->img = vg_img; | |
133 ge_img->asso_pattern = NULL; | |
134 ge_img->asso_surface = NULL; | |
135 | |
136 pattern->paint = paint; | |
137 pattern->asso_img = ge_img; | |
138 | |
139 return pattern; | |
140 | |
141 err: | |
142 if(ge_img) free(ge_img); | |
143 if(pattern) free(pattern); | |
144 if(paint != VG_INVALID_HANDLE) vgDestroyPaint(paint); | |
145 vgDestroyImage(vg_img); | |
146 return NULL; | |
99 } | 147 } |
100 | 148 |
101 void | 149 void |
102 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, | 150 mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, |
103 co_comp_t b, co_comp_t a) { | 151 co_comp_t b, co_comp_t a) { |