Mercurial > MadButterfly
annotate include/mb_img_ldr.h @ 1479:92a8497d0361
Make FSM editor scrollable
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 27 Apr 2011 15:41:47 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
268
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
268
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #ifndef __MB_IMG_LDR_H_ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #define __MB_IMG_LDR_H_ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 typedef struct _mb_img_data mb_img_data_t; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 typedef struct _mb_img_ldr mb_img_ldr_t; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 typedef enum _mb_img_fmt { |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
10 MB_IFMT_DUMMY, |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
11 MB_IFMT_ARGB32, |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 MB_IFMT_RGB24, |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 MB_IFMT_A8, |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
14 MB_IFMT_A1, |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
15 MB_IFMT_RGB16_565 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
16 } mb_img_fmt_t; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
17 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
18 /*! \brief Encapsulate image. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
19 * |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
20 * The format and content of an image is encapsulated by imag_data_t. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
21 * We hope someday, we can create an abstract backend layer that |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
22 * can deal with image data. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
23 */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
24 struct _mb_img_data { |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
25 /*! \brief Content of the image. */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
26 void *content; |
268
43900cae1d49
Support resizing for image.
Thinker K.F. Li <thinker@branda.to>
parents:
260
diff
changeset
|
27 int w, h; |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
28 int stride; /*!< \brief Number of bytes a row */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
29 mb_img_fmt_t fmt; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
30 /*! \brief Release the image that was loaded by the loader. */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
31 void (*free)(mb_img_data_t *img); |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
32 }; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
33 #define MB_IMG_DATA_FREE(img) (img)->free(img) |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
34 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
35 /*! \brief Image loader. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
36 * |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
37 * An image loader take a ID and find out the corresponding |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
38 * image from filesystem or somewhere. Image ID is a hierachical |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
39 * structured path. It is relative to the root of image database. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
40 * Users of a loader do not need to know where the database is. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
41 * The location can be configured when a loader been instantiated. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
42 * But, it is invisible when loading images by an image loader. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
43 */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
44 struct _mb_img_ldr { |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
45 /*! \brief Load a image with specified ID. */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
46 mb_img_data_t *(*load)(mb_img_ldr_t *ldr, const char *img_id); |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
47 /*! \brief Free the loader. */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
48 void (*free)(mb_img_ldr_t *ldr); |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
49 }; |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
50 #define MB_IMG_LDR_FREE(ldr) (ldr)->free(ldr) |
260
29acbd8a0dd0
Integrate sh_image with svg2code.py.
Thinker K.F. Li <thinker@branda.to>
parents:
257
diff
changeset
|
51 #define MB_IMG_LDR_LOAD(ldr, img_id) (ldr)->load(ldr, img_id) |
257
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
53 /*! \brief Create a simple image loader. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
54 * |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
55 * \param img_repository is a repository where images are loaded from. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
56 * \return NULL for error. |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
57 */ |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
58 extern mb_img_ldr_t *simple_mb_img_ldr_new(const char *img_repository); |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 |
50d253d0fcba
Simple image loader and image shape.
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 #endif /* __MB_IMG_LDR_H_ */ |