Mercurial > MadButterfly
comparison src/img_ldr.c @ 448:16116d84bc5e
Replace Cairo with a abstract layer mb_graph_engine.
mb_graph_engine is a layer to separate MadButterfly from Cairo.
It is only a set of macro mapping to cairo implementation, now.
But, it provides a oppotunities to replace cairo with other engines;
likes skia.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 04 Aug 2009 23:35:41 +0800 |
parents | 3e84458968ec |
children | a417fd980228 |
comparison
equal
deleted
inserted
replaced
447:38aae921243f | 448:16116d84bc5e |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <string.h> | 2 #include <string.h> |
3 #include <cairo.h> | 3 #include "mb_graph_engine.h" |
4 #include "mb_tools.h" | 4 #include "mb_tools.h" |
5 #include "mb_paint.h" | 5 #include "mb_paint.h" |
6 #include "mb_img_ldr.h" | 6 #include "mb_img_ldr.h" |
7 | 7 |
8 /*! \brief Simple image loader. | 8 /*! \brief Simple image loader. |
14 }; | 14 }; |
15 typedef struct _simple_mb_img_ldr simple_mb_img_ldr_t; | 15 typedef struct _simple_mb_img_ldr simple_mb_img_ldr_t; |
16 | 16 |
17 struct _simple_mb_img_data { | 17 struct _simple_mb_img_data { |
18 mb_img_data_t img; | 18 mb_img_data_t img; |
19 cairo_surface_t *surf; | 19 mbe_surface_t *surf; |
20 }; | 20 }; |
21 typedef struct _simple_mb_img_data simple_mb_img_data_t; | 21 typedef struct _simple_mb_img_data simple_mb_img_data_t; |
22 | 22 |
23 static void simple_mb_img_ldr_img_free(mb_img_data_t *img); | 23 static void simple_mb_img_ldr_img_free(mb_img_data_t *img); |
24 | 24 |
25 static | 25 static |
26 mb_img_data_t *simple_mb_img_ldr_load(mb_img_ldr_t *ldr, const char *img_id) { | 26 mb_img_data_t *simple_mb_img_ldr_load(mb_img_ldr_t *ldr, const char *img_id) { |
27 simple_mb_img_ldr_t *sldr = (simple_mb_img_ldr_t *)ldr; | 27 simple_mb_img_ldr_t *sldr = (simple_mb_img_ldr_t *)ldr; |
28 simple_mb_img_data_t *img; | 28 simple_mb_img_data_t *img; |
29 cairo_surface_t *surf; | 29 mbe_surface_t *surf; |
30 char *fname; | 30 char *fname; |
31 cairo_format_t fmt; | 31 mbe_format_t fmt; |
32 int sz; | 32 int sz; |
33 | 33 |
34 sz = strlen(sldr->repo); | 34 sz = strlen(sldr->repo); |
35 sz += strlen(img_id); | 35 sz += strlen(img_id); |
36 fname = (char *)malloc(sz + 2); | 36 fname = (char *)malloc(sz + 2); |
37 strcpy(fname, sldr->repo); | 37 strcpy(fname, sldr->repo); |
38 strcat(fname, img_id); | 38 strcat(fname, img_id); |
39 | 39 |
40 surf = cairo_image_surface_create_from_png(fname); | 40 surf = mbe_image_surface_create_from_png(fname); |
41 if(surf == NULL) | 41 if(surf == NULL) |
42 return NULL; | 42 return NULL; |
43 | 43 |
44 img = O_ALLOC(simple_mb_img_data_t); | 44 img = O_ALLOC(simple_mb_img_data_t); |
45 if(img == NULL) { | 45 if(img == NULL) { |
46 cairo_surface_destroy(surf); | 46 mbe_surface_destroy(surf); |
47 return NULL; | 47 return NULL; |
48 } | 48 } |
49 img->img.content = cairo_image_surface_get_data(surf); | 49 img->img.content = mbe_image_surface_get_data(surf); |
50 img->img.w = cairo_image_surface_get_width(surf); | 50 img->img.w = mbe_image_surface_get_width(surf); |
51 img->img.h = cairo_image_surface_get_height(surf); | 51 img->img.h = mbe_image_surface_get_height(surf); |
52 img->img.stride = cairo_image_surface_get_stride(surf); | 52 img->img.stride = mbe_image_surface_get_stride(surf); |
53 fmt = cairo_image_surface_get_format(surf); | 53 fmt = mbe_image_surface_get_format(surf); |
54 switch(fmt) { | 54 switch(fmt) { |
55 case CAIRO_FORMAT_ARGB32: | 55 case CAIRO_FORMAT_ARGB32: |
56 img->img.fmt = MB_IFMT_ARGB32; | 56 img->img.fmt = MB_IFMT_ARGB32; |
57 break; | 57 break; |
58 | 58 |
67 case CAIRO_FORMAT_A1: | 67 case CAIRO_FORMAT_A1: |
68 img->img.fmt = MB_IFMT_A1; | 68 img->img.fmt = MB_IFMT_A1; |
69 break; | 69 break; |
70 | 70 |
71 default: | 71 default: |
72 cairo_surface_destroy(surf); | 72 mbe_surface_destroy(surf); |
73 free(img); | 73 free(img); |
74 return NULL; | 74 return NULL; |
75 } | 75 } |
76 img->img.free = simple_mb_img_ldr_img_free; | 76 img->img.free = simple_mb_img_ldr_img_free; |
77 img->surf = surf; | 77 img->surf = surf; |
80 } | 80 } |
81 | 81 |
82 static | 82 static |
83 void simple_mb_img_ldr_img_free(mb_img_data_t *img) { | 83 void simple_mb_img_ldr_img_free(mb_img_data_t *img) { |
84 simple_mb_img_data_t *simg = (simple_mb_img_data_t *)img; | 84 simple_mb_img_data_t *simg = (simple_mb_img_data_t *)img; |
85 cairo_surface_destroy((cairo_surface_t *)simg->surf); | 85 mbe_surface_destroy((mbe_surface_t *)simg->surf); |
86 free(img); | 86 free(img); |
87 } | 87 } |
88 | 88 |
89 static | 89 static |
90 void simple_mb_img_ldr_free(mb_img_ldr_t *ldr) { | 90 void simple_mb_img_ldr_free(mb_img_ldr_t *ldr) { |