1 /**
2  * @file lv_image_decoder_private.h
3  *
4  */
5 
6 #ifndef LV_IMAGE_DECODER_PRIVATE_H
7 #define LV_IMAGE_DECODER_PRIVATE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "lv_image_decoder.h"
17 #include "../misc/cache/lv_cache.h"
18 
19 /*********************
20  *      DEFINES
21  *********************/
22 
23 /**********************
24  *      TYPEDEFS
25  **********************/
26 
27 /**
28  * Image decoder args.
29  * It determines how to decoder an image, e.g. whether to premultiply the alpha or not.
30  * It should be passed to lv_img_decoder_open() function. If NULL is provided, default
31  * args are used.
32  *
33  * Default args:
34  * all field are zero or false.
35  */
36 struct _lv_image_decoder_args_t {
37     bool stride_align;      /**< Whether stride should be aligned */
38     bool premultiply;       /**< Whether image should be premultiplied or not after decoding */
39     bool no_cache;          /**< When set, decoded image won't be put to cache, and decoder open will also ignore cache. */
40     bool use_indexed;       /**< Decoded indexed image as is. Convert to ARGB8888 if false. */
41     bool flush_cache;       /**< Whether to flush the data cache after decoding */
42 };
43 
44 struct _lv_image_decoder_t {
45     lv_image_decoder_info_f_t info_cb;
46     lv_image_decoder_open_f_t open_cb;
47     lv_image_decoder_get_area_cb_t get_area_cb;
48     lv_image_decoder_close_f_t close_cb;
49 
50     const char * name;
51 
52     void * user_data;
53 };
54 
55 struct _lv_image_cache_data_t {
56     lv_cache_slot_size_t slot;
57 
58     const void * src;
59     lv_image_src_t src_type;
60 
61     const lv_draw_buf_t * decoded;
62     const lv_image_decoder_t * decoder;
63     void * user_data;
64 };
65 
66 struct _lv_image_header_cache_data_t {
67     const void * src;
68     lv_image_src_t src_type;
69 
70     lv_image_header_t header;
71     lv_image_decoder_t * decoder;
72 };
73 
74 /**Describe an image decoding session. Stores data about the decoding*/
75 struct _lv_image_decoder_dsc_t {
76     /**The decoder which was able to open the image source*/
77     lv_image_decoder_t * decoder;
78 
79     /**A copy of parameters of how this image is decoded*/
80     lv_image_decoder_args_t args;
81 
82     /**The image source. A file path like "S:my_img.png" or pointer to an `lv_image_dsc_t` variable*/
83     const void * src;
84 
85     /**Type of the source: file or variable. Can be set in `open` function if required*/
86     lv_image_src_t src_type;
87 
88     lv_fs_file_t file;
89 
90     /**Info about the opened image: color format, size, etc. MUST be set in `open` function*/
91     lv_image_header_t header;
92 
93     /** Pointer to a draw buffer where the image's data (pixels) are stored in a decoded, plain format.
94      *  MUST be set in `open` or `get_area_cb`function*/
95     const lv_draw_buf_t * decoded;
96 
97     const lv_color32_t * palette;
98     uint32_t palette_size;
99 
100     /** How much time did it take to open the image. [ms]
101      *  If not set `lv_image_cache` will measure and set the time to open*/
102     uint32_t time_to_open;
103 
104     /**A text to display instead of the image when the image can't be opened.
105      * Can be set in `open` function or set NULL.*/
106     const char * error_msg;
107 
108     lv_cache_t * cache;
109 
110     /**Point to cache entry information*/
111     lv_cache_entry_t * cache_entry;
112 
113     /**Store any custom data here is required*/
114     void * user_data;
115 };
116 
117 
118 /**********************
119  * GLOBAL PROTOTYPES
120  **********************/
121 
122 /**
123  * Initialize the image decoder module
124  * @param image_cache_size    Image cache size in bytes. 0 to disable cache.
125  * @param image_header_count  Number of header cache entries. 0 to disable header cache.
126  */
127 void lv_image_decoder_init(uint32_t image_cache_size, uint32_t image_header_count);
128 
129 /**
130  * Deinitialize the image decoder module
131  */
132 void lv_image_decoder_deinit(void);
133 
134 /**********************
135  *      MACROS
136  **********************/
137 
138 #ifdef __cplusplus
139 } /*extern "C"*/
140 #endif
141 
142 #endif /*LV_IMAGE_DECODER_PRIVATE_H*/
143