1 /**
2  * @file lv_img_cache.h
3  *
4  */
5 
6 #ifndef LV_IMG_CACHE_H
7 #define LV_IMG_CACHE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "lv_img_decoder.h"
17 
18 /*********************
19  *      DEFINES
20  *********************/
21 
22 /**********************
23  *      TYPEDEFS
24  **********************/
25 
26 /**
27  * When loading images from the network it can take a long time to download and decode the image.
28  *
29  * To avoid repeating this heavy load images can be cached.
30  */
31 typedef struct
32 {
33     lv_img_decoder_dsc_t dec_dsc; /**< Image information */
34 
35     /** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used.
36      * Decrement all lifes by one every in every ::lv_img_cache_open.
37      * If life == 0 the entry can be reused */
38     int32_t life;
39 } lv_img_cache_entry_t;
40 
41 /**********************
42  * GLOBAL PROTOTYPES
43  **********************/
44 
45 /**
46  * Open an image using the image decoder interface and cache it.
47  * The image will be left open meaning if the image decoder open callback allocated memory then it will remain.
48  * The image is closed if a new image is opened and the new image takes its place in the cache.
49  * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable
50  * @param style style of the image
51  * @return pointer to the cache entry or NULL if can open the image
52  */
53 lv_img_cache_entry_t * lv_img_cache_open(const void * src, const lv_style_t * style);
54 
55 /**
56  * Set the number of images to be cached.
57  * More cached images mean more opened image at same time which might mean more memory usage.
58  * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache.
59  * @param new_entry_cnt number of image to cache
60  */
61 void lv_img_cache_set_size(uint16_t new_slot_num);
62 
63 /**
64  * Invalidate an image source in the cache.
65  * Useful if the image source is updated therefore it needs to be cached again.
66  * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable.
67  */
68 void lv_img_cache_invalidate_src(const void * src);
69 
70 /**********************
71  *      MACROS
72  **********************/
73 
74 #ifdef __cplusplus
75 } /* extern "C" */
76 #endif
77 
78 #endif /*LV_IMG_CACHE_H*/
79