Mercurial > MadButterfly
diff include/mb_img_ldr.h @ 257:50d253d0fcba
Simple image loader and image shape.
- img_ldr.c is a simple image loader that rooted on a directory
specified when a loader instance been created.
- sh_image_t is corresponding shape of image tag in SVG.
- This changeset is still buggy. It need more testing.
- svg2code.py is not ready for image tag.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Thu, 15 Jan 2009 16:46:47 +0800 |
parents | |
children | 29acbd8a0dd0 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mb_img_ldr.h Thu Jan 15 16:46:47 2009 +0800 @@ -0,0 +1,57 @@ +#ifndef __MB_IMG_LDR_H_ +#define __MB_IMG_LDR_H_ + +typedef struct _mb_img_data mb_img_data_t; +typedef struct _mb_img_ldr mb_img_ldr_t; + +typedef enum _mb_img_fmt { + MB_IFMT_DUMMY, + MB_IFMT_ARGB32, + MB_IFMT_RGB24, + MB_IFMT_A8, + MB_IFMT_A1, + MB_IFMT_RGB16_565 +} mb_img_fmt_t; + +/*! \brief Encapsulate image. + * + * The format and content of an image is encapsulated by imag_data_t. + * We hope someday, we can create an abstract backend layer that + * can deal with image data. + */ +struct _mb_img_data { + /*! \brief Content of the image. */ + void *content; + int width, height; + int stride; /*!< \brief Number of bytes a row */ + mb_img_fmt_t fmt; + /*! \brief Release the image that was loaded by the loader. */ + void (*free)(mb_img_data_t *img); +}; +#define MB_IMG_DATA_FREE(img) (img)->free(img) + +/*! \brief Image loader. + * + * An image loader take a ID and find out the corresponding + * image from filesystem or somewhere. Image ID is a hierachical + * structured path. It is relative to the root of image database. + * Users of a loader do not need to know where the database is. + * The location can be configured when a loader been instantiated. + * But, it is invisible when loading images by an image loader. + */ +struct _mb_img_ldr { + /*! \brief Load a image with specified ID. */ + mb_img_data_t *(*load)(mb_img_ldr_t *ldr, const char *img_id); + /*! \brief Free the loader. */ + void (*free)(mb_img_ldr_t *ldr); +}; +#define MB_IMG_LDR_FREE(ldr) (ldr)->free(ldr) + +/*! \brief Create a simple image loader. + * + * \param img_repository is a repository where images are loaded from. + * \return NULL for error. + */ +extern mb_img_ldr_t *simple_mb_img_ldr_new(const char *img_repository); + +#endif /* __MB_IMG_LDR_H_ */