Mercurial > MadButterfly
changeset 602:ac2e6468a22a openvg
Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image()
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Fri, 02 Jul 2010 13:42:22 +0800 |
parents | 8863d23cea4b |
children | 39d27911c3ae |
files | examples/menu/filebrowser.c include/mb_graph_engine_cairo.h include/mb_graph_engine_dummy.h include/mb_graph_engine_openvg.h include/mb_graph_engine_skia.h src/graph_engine_cairo.c src/graph_engine_skia.cpp src/paint.c |
diffstat | 8 files changed, 61 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/filebrowser.c Fri Jul 02 11:59:17 2010 +0800 +++ b/examples/menu/filebrowser.c Fri Jul 02 13:42:22 2010 +0800 @@ -51,14 +51,14 @@ if (strcmp(data->titles[select],"..")==0) { strcpy(path, data->curDir); len = strlen(path); - for(i=len-1;i>0;i--) { + for(i=len-2;i>0;i--) { if (path[i] == '/') { path[i] = 0; break; } } } else { - snprintf(path,1024,"%s/%s", data->curDir,data->titles[select]); + snprintf(path,1024,"%s%s", data->curDir,data->titles[select]); } MyApp_fillDirInfo(app, path); @@ -147,6 +147,8 @@ DIR *dir; struct dirent *e; struct fileinfo *f; + char *path; + int sz; int i; dir = opendir(curdir); @@ -157,7 +159,14 @@ if (data->curDir) free(data->curDir); - data->curDir = strdup(curdir); + + sz = strlen(curdir); + if(curdir[sz - 1] != '/') + sz++; + data->curDir = (char *)malloc(sz + 1); + strcpy(data->curDir, curdir); + if(curdir[sz - 1] == '\0') + strcat(data->curDir, "/"); if (data->files) { for(i=0;i<data->nFiles;i++) {
--- a/include/mb_graph_engine_cairo.h Fri Jul 02 11:59:17 2010 +0800 +++ b/include/mb_graph_engine_cairo.h Fri Jul 02 13:42:22 2010 +0800 @@ -10,7 +10,6 @@ /*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo * @{ */ -#define mbe_image_surface_create_from_png cairo_image_surface_create_from_png #define mbe_pattern_create_for_surface cairo_pattern_create_for_surface #define mbe_scaled_font_text_extents cairo_scaled_font_text_extents #define mbe_image_surface_get_stride cairo_image_surface_get_stride @@ -82,6 +81,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_scissoring(mbe_t *canvas, int n_areas, area_t **areas);
--- a/include/mb_graph_engine_dummy.h Fri Jul 02 11:59:17 2010 +0800 +++ b/include/mb_graph_engine_dummy.h Fri Jul 02 13:42:22 2010 +0800 @@ -11,7 +11,6 @@ /*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo * @{ */ -#define mbe_image_surface_create_from_png(fn) ((mbe_surface_t *)NULL) #define mbe_image_surface_create_for_data(data, fmt, w, h, stride) \ ((mbe_surface_t *)NULL) #define mbe_pattern_create_for_surface(canvas) ((mbe_pattern_t *)NULL) @@ -30,6 +29,7 @@ ((mbe_pattern_t *)NULL) #define mbe_pattern_create_linear(x0, y0, x1, y1, stops, stop_cnt) \ ((mbe_pattern_t *)NULL) +#define mbe_pattern_create_image(img) ((mbe_pattern_t *)NULL) #define mbe_image_surface_create(fmt, w, h) ((mbe_surface_t *)NULL) #define mbe_scaled_font_destroy(scaled) #define mbe_font_face_reference(face) ((mbe_font_face_t *)NULL)
--- a/include/mb_graph_engine_openvg.h Fri Jul 02 11:59:17 2010 +0800 +++ b/include/mb_graph_engine_openvg.h Fri Jul 02 13:42:22 2010 +0800 @@ -11,7 +11,6 @@ /*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo * @{ */ -#define mbe_image_surface_create_from_png(fn) ((mbe_surface_t *)NULL) #define mbe_image_surface_create_for_data(data, fmt, w, h, stride) \ ((mbe_surface_t *)NULL) #define mbe_pattern_create_for_surface(canvas) ((mbe_pattern_t *)NULL) @@ -27,6 +26,7 @@ ((mbe_pattern_t *)NULL) #define mbe_pattern_create_linear(x0, y0, x1, y1, stops, stop_cnt) \ ((mbe_pattern_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)
--- a/include/mb_graph_engine_skia.h Fri Jul 02 11:59:17 2010 +0800 +++ b/include/mb_graph_engine_skia.h Fri Jul 02 13:42:22 2010 +0800 @@ -40,6 +40,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_pattern_set_matrix(mbe_pattern_t *ptn, const co_aix matrix[6]); extern void mbe_pattern_destroy(mbe_pattern_t *ptn); @@ -48,7 +49,6 @@ extern int mbe_image_surface_get_height(mbe_surface_t *surface); extern int mbe_image_surface_get_width(mbe_surface_t *surface); extern unsigned char *mbe_image_surface_get_data(mbe_surface_t *surface); -extern mbe_surface_t *mbe_image_surface_create_from_png(const char *filename); extern mbe_surface_t * mbe_image_surface_create_for_data(unsigned char *data, mb_img_fmt_t fmt,
--- a/src/graph_engine_cairo.c Fri Jul 02 11:59:17 2010 +0800 +++ b/src/graph_engine_cairo.c Fri Jul 02 13:42:22 2010 +0800 @@ -153,6 +153,45 @@ return ptn; } +mbe_pattern_t * +mbe_pattern_create_image(mb_img_data_t *img) { + cairo_surface_t *surf; + cairo_pattern_t *ptn; + cairo_format_t fmt; + + switch(img->fmt) { + case MB_IFMT_ARGB32: + fmt = CAIRO_FORMAT_ARGB32; + break; + + case MB_IFMT_RGB24: + fmt = CAIRO_FORMAT_RGB24; + break; + + case MB_IFMT_A8: + fmt = CAIRO_FORMAT_A8; + break; + + case MB_IFMT_A1: + fmt = CAIRO_FORMAT_A1; + break; + + case MB_IFMT_RGB16_565: + fmt = CAIRO_FORMAT_RGB16_565; + break; + + default: + return NULL; + } + + surf = cairo_image_surface_create_for_data(img->content, fmt, + img->w, img->h, img->stride); + ptn = cairo_pattern_create_for_surface(surf); + cairo_surface_destroy(surf); + + return ptn; +} + void mbe_scissoring(mbe_t *canvas, int n_areas, area_t **areas) { area_t *area;
--- a/src/graph_engine_skia.cpp Fri Jul 02 11:59:17 2010 +0800 +++ b/src/graph_engine_skia.cpp Fri Jul 02 13:42:22 2010 +0800 @@ -351,6 +351,11 @@ return NULL; } +mbe_pattern_t * +mbe_pattern_create_image(mb_img_data_t *img) { + return NULL; +} + void mbe_pattern_set_matrix(mbe_pattern_t *ptn, const co_aix matrix[6]) { SkMatrix skmatrix; @@ -381,8 +386,6 @@ return (unsigned char *)((SkBitmap *)surface)->getPixels(); } -mbe_surface_t *mbe_image_surface_create_from_png(const char *filename) {} - mbe_surface_t * mbe_image_surface_create_for_data(unsigned char *data, mb_img_fmt_t fmt,
--- a/src/paint.c Fri Jul 02 11:59:17 2010 +0800 +++ b/src/paint.c Fri Jul 02 13:42:22 2010 +0800 @@ -246,7 +246,6 @@ typedef struct _paint_image { paint_t paint; mb_img_data_t *img; - mbe_surface_t *surf; mbe_pattern_t *ptn; } paint_image_t; @@ -264,7 +263,6 @@ paint_image_t *paint_img = (paint_image_t *)paint; mb_img_data_t *img_data; - mbe_surface_destroy(paint_img->surf); img_data = paint_img->img; MB_IMG_DATA_FREE(img_data); paint_destroy(&paint_img->paint); @@ -289,21 +287,10 @@ paint_init(&paint->paint, MBP_IMAGE, paint_image_prepare, paint_image_free); paint->img = img; - paint->surf = mbe_image_surface_create_for_data(img->content, - img->fmt, - img->w, - img->h, - img->stride); - if(paint->surf == NULL) { - paint_destroy(&paint->paint); - free(paint); - return NULL; - } - paint->ptn = mbe_pattern_create_for_surface(paint->surf); + paint->ptn = mbe_pattern_create_image(img); if(paint->ptn == NULL) { paint_destroy(&paint->paint); - mbe_surface_destroy(paint->surf); free(paint); return NULL; }