Mercurial > MadButterfly
changeset 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 |
files | include/mb_graph_engine_openvg.h src/graph_engine_openvg.c |
diffstat | 2 files changed, 51 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_graph_engine_openvg.h Sun Jul 04 16:31:39 2010 +0800 +++ b/include/mb_graph_engine_openvg.h Sun Jul 04 21:09:56 2010 +0800 @@ -15,11 +15,10 @@ #define mbe_scaled_font_text_extents(scaled, utf8, extents) #define mbe_image_surface_get_stride(surface) (20) #define mbe_image_surface_get_format(surface) ((mb_img_fmt_t)0) -#define mbe_image_surface_get_height(surface) (1) -#define mbe_image_surface_get_width(surface) (1) +#define mbe_image_surface_get_height(surface) (surface)->h +#define mbe_image_surface_get_width(surface) (surface)->w #define mbe_image_surface_get_data(surface) ((unsigned char *)NULL) #define mbe_scaled_font_reference(scaled) ((mbe_scaled_font_t *)NULL) -#define mbe_pattern_create_image(img) ((mbe_pattern_t *)NULL) #define mbe_scaled_font_destroy(scaled) #define mbe_font_face_reference(face) ((mbe_font_face_t *)NULL) #define mbe_scaled_font_create(face, fnt_mtx, ctm) ((mbe_scaled_font_t *)NULL) @@ -143,6 +142,7 @@ co_aix x1, co_aix y1, grad_stop_t *stops, int stop_cnt); +extern mbe_pattern_t *mbe_pattern_create_image(mb_img_data_t *img); extern void mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, co_comp_t b, co_comp_t a); /* TODO: rename n_areas to areas_cnt and make it after areas */
--- a/src/graph_engine_openvg.c Sun Jul 04 16:31:39 2010 +0800 +++ b/src/graph_engine_openvg.c Sun Jul 04 21:09:56 2010 +0800 @@ -98,6 +98,54 @@ return pattern; } +mbe_pattern_t * +mbe_pattern_create_image(mb_img_data_t *img) { + VGPaint paint; + mbe_pattern_t *pattern; + _ge_openvg_img_t *ge_img; + VGImage vg_img; + VGImageFormat fmt = VG_sARGB_8888; + + /* \note OpenVG implementation supports one \ref MB_IFMT_ARGB32 + * image. + */ + if(img->fmt != MB_IFMT_ARGB32) + return NULL; + + /* Create and copy pixels into VGImage */ + vg_img = vgCreateImage(fmt, img->w, img->h, + VG_IMAGE_QUALITY_NONANTIALIASED); + if(vg_img == VG_INVALID_HANDLE) + return NULL; + vgImageSubData(vg_img, img->content, img->stride, fmt, + 0, 0, img->w, img->h); + + /* Allocate objects */ + ge_img = O_ALLOC(_ge_openvg_img_t); + pattern = O_ALLOC(mbe_pattern_t); + paint = vgCreatePaint(); + if(ge_img == NULL || pattern == NULL || paint == VG_INVALID_HANDLE) + goto err; + + + /* Initialize objects */ + ge_img->img = vg_img; + ge_img->asso_pattern = NULL; + ge_img->asso_surface = NULL; + + pattern->paint = paint; + pattern->asso_img = ge_img; + + return pattern; + + err: + if(ge_img) free(ge_img); + if(pattern) free(pattern); + if(paint != VG_INVALID_HANDLE) vgDestroyPaint(paint); + vgDestroyImage(vg_img); + return NULL; +} + void mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, co_comp_t b, co_comp_t a) {