1 /**
2  * @file lv_image_dsc.h
3  *
4  */
5 
6 #ifndef LV_IMAGE_DSC_H
7 #define LV_IMAGE_DSC_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../lv_conf_internal.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 
22 /** Magic number for lvgl image, 9 means lvgl version 9
23  *  It must be neither a valid ASCII character nor larger than 0x80. See `lv_image_src_get_type`.
24  */
25 #define LV_IMAGE_HEADER_MAGIC (0x19)
26 LV_EXPORT_CONST_INT(LV_IMAGE_HEADER_MAGIC);
27 
28 /**********************
29  *      TYPEDEFS
30  **********************/
31 
32 typedef enum _lvimage_flags_t {
33     /**
34      * For RGB map of the image data, mark if it's pre-multiplied with alpha.
35      * For indexed image, this bit indicated palette data is pre-multiplied with alpha.
36      */
37     LV_IMAGE_FLAGS_PREMULTIPLIED    = 0x0001,
38     /**
39      * The image data is compressed, so decoder needs to decode image firstly.
40      * If this flag is set, the whole image will be decompressed upon decode, and
41      * `get_area_cb` won't be necessary.
42      */
43     LV_IMAGE_FLAGS_COMPRESSED       = 0x0008,
44 
45     /*Below flags are applicable only for draw buffer header.*/
46 
47     /**
48      * The image is allocated from heap, thus should be freed after use.
49      */
50     LV_IMAGE_FLAGS_ALLOCATED        = 0x0010,
51 
52     /**
53      * If the image data is malloced and can be processed in place.
54      * In image decoder post processing, this flag means we modify it in-place.
55      */
56     LV_IMAGE_FLAGS_MODIFIABLE       = 0x0020,
57 
58     /**
59      * Flags reserved for user, lvgl won't use these bits.
60      */
61     LV_IMAGE_FLAGS_USER1            = 0x0100,
62     LV_IMAGE_FLAGS_USER2            = 0x0200,
63     LV_IMAGE_FLAGS_USER3            = 0x0400,
64     LV_IMAGE_FLAGS_USER4            = 0x0800,
65     LV_IMAGE_FLAGS_USER5            = 0x1000,
66     LV_IMAGE_FLAGS_USER6            = 0x2000,
67     LV_IMAGE_FLAGS_USER7            = 0x4000,
68     LV_IMAGE_FLAGS_USER8            = 0x8000,
69 } lv_image_flags_t;
70 
71 typedef enum {
72     LV_IMAGE_COMPRESS_NONE = 0,
73     LV_IMAGE_COMPRESS_RLE,      /**< LVGL custom RLE compression */
74     LV_IMAGE_COMPRESS_LZ4,
75 } lv_image_compress_t;
76 
77 #if LV_BIG_ENDIAN_SYSTEM
78 typedef struct {
79     uint32_t reserved_2: 16;    /**< Reserved to be used later*/
80     uint32_t stride: 16;        /**< Number of bytes in a row*/
81     uint32_t h: 16;
82     uint32_t w: 16;
83     uint32_t flags: 16;         /**< Image flags, see `lv_image_flags_t`*/
84     uint32_t cf : 8;            /**< Color format: See `lv_color_format_t`*/
85     uint32_t magic: 8;          /**< Magic number. Must be LV_IMAGE_HEADER_MAGIC*/
86 } lv_image_header_t;
87 #else
88 typedef struct {
89     uint32_t magic: 8;          /**< Magic number. Must be LV_IMAGE_HEADER_MAGIC*/
90     uint32_t cf : 8;            /**< Color format: See `lv_color_format_t`*/
91     uint32_t flags: 16;         /**< Image flags, see `lv_image_flags_t`*/
92 
93     uint32_t w: 16;
94     uint32_t h: 16;
95     uint32_t stride: 16;        /**< Number of bytes in a row*/
96     uint32_t reserved_2: 16;    /**< Reserved to be used later*/
97 } lv_image_header_t;
98 #endif
99 
100 typedef struct {
101     void * buf;
102     uint32_t stride;            /**< Number of bytes in a row*/
103 } lv_yuv_plane_t;
104 
105 typedef union {
106     lv_yuv_plane_t yuv;         /**< packed format*/
107     struct {
108         lv_yuv_plane_t y;
109         lv_yuv_plane_t u;
110         lv_yuv_plane_t v;
111     } planar;                   /**< planar format with 3 plane*/
112     struct {
113         lv_yuv_plane_t y;
114         lv_yuv_plane_t uv;
115     } semi_planar;              /**< planar format with 2 plane*/
116 } lv_yuv_buf_t;
117 
118 /**
119  * Struct to describe a constant image resource.
120  * It's similar to lv_draw_buf_t, but the data is constant.
121  */
122 typedef struct {
123     lv_image_header_t header;   /**< A header describing the basics of the image*/
124     uint32_t data_size;         /**< Size of the image in bytes*/
125     const uint8_t * data;       /**< Pointer to the data of the image*/
126     const void * reserved;      /**< A reserved field to make it has same size as lv_draw_buf_t*/
127 } lv_image_dsc_t;
128 
129 /**********************
130  * GLOBAL PROTOTYPES
131  **********************/
132 
133 /**********************
134  *      MACROS
135  **********************/
136 
137 #ifdef __cplusplus
138 } /*extern "C"*/
139 #endif
140 
141 #endif /*LV_IMAGE_DSC_H*/
142