# HG changeset patch # User Thinker K.F. Li # Date 1278049342 -28800 # Node ID ac2e6468a22ae748d8f12cdbb579ab40a9770fe2 # Parent 8863d23cea4b1a2dfa1384fec223ff8b67b42f21 Replace mbe_image_surface_create_from_png() with mbe_pattern_create_image() diff -r 8863d23cea4b -r ac2e6468a22a examples/menu/filebrowser.c --- 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;inFiles;i++) { diff -r 8863d23cea4b -r ac2e6468a22a include/mb_graph_engine_cairo.h --- 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); diff -r 8863d23cea4b -r ac2e6468a22a include/mb_graph_engine_dummy.h --- 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) diff -r 8863d23cea4b -r ac2e6468a22a include/mb_graph_engine_openvg.h --- 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) diff -r 8863d23cea4b -r ac2e6468a22a include/mb_graph_engine_skia.h --- 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, diff -r 8863d23cea4b -r ac2e6468a22a src/graph_engine_cairo.c --- 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; diff -r 8863d23cea4b -r ac2e6468a22a src/graph_engine_skia.cpp --- 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, diff -r 8863d23cea4b -r ac2e6468a22a src/paint.c --- 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; }