Mercurial > MadButterfly
changeset 450:a417fd980228
Replace cairo_format_t with mb_img_fmt_t.
- Replace all CAIRO_FORAMT_* with MB_IFMT_*
- wrap functions return or are argumented with image format.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 05 Aug 2009 15:54:44 +0800 |
parents | c525edac917e |
children | 5c9e2a8a4bd8 |
files | include/mb_graph_engine.h src/X_main.c src/X_supp.c src/event.c src/img_ldr.c src/paint.c src/redraw_man.c src/shape_image.c src/shape_stext.c |
diffstat | 9 files changed, 131 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_graph_engine.h Tue Aug 04 23:47:34 2009 +0800 +++ b/include/mb_graph_engine.h Wed Aug 05 15:54:44 2009 +0800 @@ -1,23 +1,29 @@ #ifndef __MBE_H_ #define __MBE_H_ +#include <stdio.h> #include <cairo.h> +#include "mb_img_ldr.h" + +/*! \defgroup mb_graph_engine MadButterfly Graphic Engine + * @{ + */ +#define MBE_OPERATOR_CLEAR CAIRO_OPERATOR_CLEAR +#define MBE_OPERATOR_SOURCE CAIRO_OPERATOR_SOURCE +#define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS #define mbe_ft_font_face_create_for_pattern cairo_ft_font_face_create_for_pattern #define mbe_image_surface_create_from_png cairo_image_surface_create_from_png -#define mbe_image_surface_create_for_data cairo_image_surface_create_for_data #define mbe_pattern_add_color_stop_rgba cairo_pattern_add_color_stop_rgba #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 #define mbe_image_surface_get_height cairo_image_surface_get_height -#define mbe_image_surface_get_format cairo_image_surface_get_format #define mbe_image_surface_get_width cairo_image_surface_get_width #define mbe_image_surface_get_data cairo_image_surface_get_data #define mbe_scaled_font_reference cairo_scaled_font_reference #define mbe_pattern_create_radial cairo_pattern_create_radial #define mbe_pattern_create_linear cairo_pattern_create_linear -#define mbe_image_surface_create cairo_image_surface_create #define mbe_xlib_surface_create cairo_xlib_surface_create #define mbe_scaled_font_destroy cairo_scaled_font_destroy #define mbe_font_options_create cairo_font_options_create @@ -34,33 +40,23 @@ #define mbe_set_scaled_font cairo_set_scaled_font #define mbe_pattern_destroy cairo_pattern_destroy #define mbe_get_scaled_font cairo_get_scaled_font -#define mbe_text_extents_t cairo_text_extents_t #define mbe_set_source_rgb cairo_set_source_rgb #define mbe_set_line_width cairo_set_line_width -#define mbe_font_options_t cairo_font_options_t -#define mbe_scaled_font_t cairo_scaled_font_t #define mbe_get_font_face cairo_get_font_face #define mbe_fill_preserve cairo_fill_preserve #define mbe_set_operator cairo_set_operator #define mbe_get_operator cairo_get_operator #define mbe_arc_negative cairo_arc_negative -#define mbe_font_face_t cairo_font_face_t #define mbe_set_source cairo_set_source #define mbe_reset_clip cairo_reset_clip -#define mbe_operator_t cairo_operator_t #define mbe_get_target cairo_get_target #define mbe_close_path cairo_close_path #define mbe_translate cairo_translate #define mbe_text_path cairo_text_path -#define mbe_surface_t cairo_surface_t #define mbe_show_text cairo_show_text #define mbe_rectangle cairo_rectangle -#define mbe_pattern_t cairo_pattern_t #define mbe_in_stroke cairo_in_stroke -#define mbe_status_t cairo_status_t #define mbe_new_path cairo_new_path -#define mbe_matrix_t cairo_matrix_t -#define mbe_format_t cairo_format_t #define mbe_curve_to cairo_curve_to #define mbe_restore cairo_restore #define mbe_move_to cairo_move_to @@ -69,7 +65,6 @@ #define mbe_destroy cairo_destroy #define mbe_stroke cairo_stroke #define mbe_rotate cairo_rotate -#define mbe_line_t cairo_line_t #define mbe_create cairo_create #define mbe_scale cairo_scale #define mbe_paint cairo_paint @@ -77,6 +72,96 @@ #define mbe_fill cairo_fill #define mbe_clip cairo_clip #define mbe_arc cairo_arc -#define mbe_t cairo_t + +typedef cairo_text_extents_t mbe_text_extents_t; +typedef cairo_font_options_t mbe_font_options_t; +typedef cairo_scaled_font_t mbe_scaled_font_t; +typedef cairo_font_face_t mbe_font_face_t; +typedef cairo_operator_t mbe_operator_t; +typedef cairo_surface_t mbe_surface_t; +typedef cairo_pattern_t mbe_pattern_t; +typedef cairo_status_t mbe_status_t; +typedef cairo_matrix_t mbe_matrix_t; +typedef cairo_t mbe_t; + +static mbe_surface_t * +mbe_image_surface_create_for_data(unsigned char *data, + mb_img_fmt_t fmt, + int width, int height, + int stride) { + cairo_format_t _fmt; + + switch(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; + default: + return NULL; + } + return cairo_image_surface_create_for_data(data, _fmt, + width, height, stride); +} + +static mb_img_fmt_t +mbe_image_surface_get_format(mbe_surface_t *surface) { + cairo_format_t _fmt; + mb_img_fmt_t fmt; + + _fmt = cairo_image_surface_get_format(surface); + switch(_fmt) { + case CAIRO_FORMAT_ARGB32: + fmt = MB_IFMT_ARGB32; + break; + case CAIRO_FORMAT_RGB24: + fmt = MB_IFMT_RGB24; + break; + case CAIRO_FORMAT_A8: + fmt = MB_IFMT_A8; + break; + case CAIRO_FORMAT_A1: + fmt = MB_IFMT_A1; + break; + default: + fmt = MB_IFMT_DUMMY; + break; + } + + return fmt; +} + +static mbe_surface_t * +mbe_image_surface_create(mb_img_fmt_t fmt, int width, int height) { + cairo_format_t _fmt; + + switch(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; + default: + return NULL; + } + + return cairo_image_surface_create(_fmt, width, height); +} + +/* @} */ #endif /* __MBE_H_ */
--- a/src/X_main.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/X_main.c Wed Aug 05 15:54:44 2009 +0800 @@ -141,7 +141,7 @@ mb_action_t *act; PangoAttrList *attrs = pango_attr_list_new(); - tmpsuf = mbe_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + tmpsuf = mbe_image_surface_create(MB_IFMT_ARGB32, w, h); tmpcr = mbe_create(tmpsuf); mbe_set_source_surface(cr, tmpsuf, 0, 0);
--- a/src/X_supp.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/X_supp.c Wed Aug 05 15:54:44 2009 +0800 @@ -441,7 +441,7 @@ &xmb_rt->visual, &xmb_rt->win); xmb_rt->surface = - mbe_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + mbe_image_surface_create(MB_IFMT_ARGB32, w, h); xmb_rt->backend_surface = mbe_xlib_surface_create(xmb_rt->display,
--- a/src/event.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/event.c Wed Aug 05 15:54:44 2009 +0800 @@ -28,17 +28,17 @@ typedef float co_aix; typedef struct shape shape_t; -typedef struct cairo_surface mbe_surface_t; +typedef struct _mbe_surface mbe_surface_t; typedef struct coord coord_t; -typedef struct cairo mbe_t; -struct cairo { +typedef struct _mbe mbe_t; +struct _mbe { STAILQ(shape_t) drawed; STAILQ(shape_t) clip_pathes; mbe_surface_t *tgt; }; -struct cairo_surface { +struct _mbe_surface { mbe_t *cr; int w, h; unsigned char *data; @@ -85,7 +85,8 @@ #define mbe_surface_destroy(surface) \ do { free((surface)->data); free(surface); } while(0) #define mbe_image_surface_get_stride(surface) 1 -#define CAIRO_FORMAT_A1 1 +#undef MB_IFMT_A1 +#define MB_IFMT_A1 1 typedef struct _area area_t; @@ -676,7 +677,7 @@ w = mbe_image_surface_get_width(rdman_surface); h = mbe_image_surface_get_height(rdman_surface); - surface = mbe_image_surface_create(CAIRO_FORMAT_A1, w, h); + surface = mbe_image_surface_create(MB_IFMT_A1, w, h); if(surface == NULL) return NULL; @@ -876,7 +877,7 @@ mbe_t *cr, *backend; mbe_surface_t *surf; - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); backend = mbe_create(surf); rdman = redraw_man_new(cr, backend); @@ -962,7 +963,7 @@ shape_add_point(shape2, 5, 5); shape_add_point(shape3, 4, 3); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)coord2, cr); CU_ASSERT(!r); @@ -970,7 +971,7 @@ mbe_surface_destroy(surf); sh_clear_flags(coord2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)coord2, cr); CU_ASSERT(!r); @@ -978,7 +979,7 @@ mbe_surface_destroy(surf); sh_clear_flags(coord2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape2, cr); CU_ASSERT(!r); @@ -986,7 +987,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape2, cr); CU_ASSERT(!r); @@ -994,7 +995,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape3, cr); CU_ASSERT(!r); @@ -1002,7 +1003,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape3, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape3, cr); CU_ASSERT(!r); @@ -1012,7 +1013,7 @@ shape_add_point(shape1, 5, 5); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)coord2, cr); CU_ASSERT(r); @@ -1020,7 +1021,7 @@ mbe_surface_destroy(surf); sh_clear_flags(coord2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)coord2, cr); CU_ASSERT(r); @@ -1028,7 +1029,7 @@ mbe_surface_destroy(surf); sh_clear_flags(coord2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape2, cr); CU_ASSERT(r); @@ -1036,7 +1037,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape2, cr); CU_ASSERT(r); @@ -1044,7 +1045,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape2, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)shape1, (mb_obj_t *)shape3, cr); CU_ASSERT(!r); @@ -1052,7 +1053,7 @@ mbe_surface_destroy(surf); sh_clear_flags(shape3, GEF_OV_DRAW); - surf = mbe_image_surface_create(CAIRO_FORMAT_A1, 100, 100); + surf = mbe_image_surface_create(MB_IFMT_A1, 100, 100); cr = mbe_create(surf); r = _is_obj_objs_overlay((mb_obj_t *)coord1, (mb_obj_t *)shape3, cr); CU_ASSERT(r);
--- a/src/img_ldr.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/img_ldr.c Wed Aug 05 15:54:44 2009 +0800 @@ -28,7 +28,6 @@ simple_mb_img_data_t *img; mbe_surface_t *surf; char *fname; - mbe_format_t fmt; int sz; sz = strlen(sldr->repo); @@ -50,29 +49,7 @@ img->img.w = mbe_image_surface_get_width(surf); img->img.h = mbe_image_surface_get_height(surf); img->img.stride = mbe_image_surface_get_stride(surf); - fmt = mbe_image_surface_get_format(surf); - switch(fmt) { - case CAIRO_FORMAT_ARGB32: - img->img.fmt = MB_IFMT_ARGB32; - break; - - case CAIRO_FORMAT_RGB24: - img->img.fmt = MB_IFMT_RGB24; - break; - - case CAIRO_FORMAT_A8: - img->img.fmt = MB_IFMT_A8; - break; - - case CAIRO_FORMAT_A1: - img->img.fmt = MB_IFMT_A1; - break; - - default: - mbe_surface_destroy(surf); - free(img); - return NULL; - } + img->img.fmt = mbe_image_surface_get_format(surf); img->img.free = simple_mb_img_ldr_img_free; img->surf = surf;
--- a/src/paint.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/paint.c Wed Aug 05 15:54:44 2009 +0800 @@ -290,25 +290,7 @@ paint_t *rdman_paint_image_new(redraw_man_t *rdman, mb_img_data_t *img) { paint_image_t *paint; - int 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; - default: - return NULL; - } - paint = O_ALLOC(paint_image_t); if(paint == NULL) return NULL; @@ -317,7 +299,7 @@ paint_image_prepare, paint_image_free); paint->img = img; paint->surf = mbe_image_surface_create_for_data(img->content, - fmt, + img->fmt, img->w, img->h, img->stride);
--- a/src/redraw_man.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/redraw_man.c Wed Aug 05 15:54:44 2009 +0800 @@ -512,7 +512,7 @@ mbe_surface_t *surface; mbe_t *cr; - surface = mbe_image_surface_create(CAIRO_FORMAT_ARGB32, + surface = mbe_image_surface_create(MB_IFMT_ARGB32, w, h); cr = mbe_create(surface); @@ -1868,7 +1868,7 @@ mbe_operator_t old_op; old_op = mbe_get_operator(canvas); - mbe_set_operator(canvas, CAIRO_OPERATOR_CLEAR); + mbe_set_operator(canvas, MBE_OPERATOR_CLEAR); mbe_paint(canvas); mbe_set_operator(canvas, old_op); } @@ -1898,7 +1898,7 @@ make_clip(rdman->backend, n_dirty_areas, dirty_areas); saved_op = mbe_get_operator(rdman->backend); - mbe_set_operator(rdman->backend, CAIRO_OPERATOR_SOURCE); + mbe_set_operator(rdman->backend, MBE_OPERATOR_SOURCE); mbe_paint(rdman->backend); mbe_set_operator(rdman->backend, saved_op); }
--- a/src/shape_image.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/shape_image.c Wed Aug 05 15:54:44 2009 +0800 @@ -70,7 +70,7 @@ shape_t *rdman_shape_image_new(redraw_man_t *rdman, co_aix x, co_aix y, co_aix w, co_aix h) { sh_image_t *img; - mbe_format_t fmt; + mb_img_fmt_t fmt; int r; img = O_ALLOC(sh_image_t);
--- a/src/shape_stext.c Tue Aug 04 23:47:34 2009 +0800 +++ b/src/shape_stext.c Wed Aug 05 15:54:44 2009 +0800 @@ -710,7 +710,7 @@ face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); CU_ASSERT(face != NULL); status = mbe_font_face_status((mbe_font_face_t *)face); - CU_ASSERT(status == CAIRO_STATUS_SUCCESS); + CU_ASSERT(status == MBE_STATUS_SUCCESS); free_font_face(face); } @@ -725,12 +725,12 @@ face = query_font_face("serif", MB_FONT_SLANT_ROMAN, 100); CU_ASSERT(face != NULL); status = mbe_font_face_status((mbe_font_face_t *)face); - CU_ASSERT(status == CAIRO_STATUS_SUCCESS); + CU_ASSERT(status == MBE_STATUS_SUCCESS); scaled = make_scaled_font_face_matrix(face, matrix); CU_ASSERT(scaled != NULL); status = mbe_scaled_font_status((mbe_scaled_font_t *)scaled); - CU_ASSERT(status == CAIRO_STATUS_SUCCESS); + CU_ASSERT(status == MBE_STATUS_SUCCESS); scaled_font_free(scaled); free_font_face(face);