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 lv_img_decoder_dsc_t dec_dsc; /**< Image information */ 33 34 /** Count the cache entries's life. Add `time_tio_open` to `life` when the entry is used. 35 * Decrement all lifes by one every in every ::lv_img_cache_open. 36 * If life == 0 the entry can be reused */ 37 int32_t life; 38 } lv_img_cache_entry_t; 39 40 /********************** 41 * GLOBAL PROTOTYPES 42 **********************/ 43 44 /** 45 * Open an image using the image decoder interface and cache it. 46 * The image will be left open meaning if the image decoder open callback allocated memory then it will remain. 47 * The image is closed if a new image is opened and the new image takes its place in the cache. 48 * @param src source of the image. Path to file or pointer to an `lv_img_dsc_t` variable 49 * @param color The color of the image with `LV_IMG_CF_ALPHA_...` 50 * @return pointer to the cache entry or NULL if can open the image 51 */ 52 lv_img_cache_entry_t * _lv_img_cache_open(const void * src, lv_color_t color); 53 54 /** 55 * Set the number of images to be cached. 56 * More cached images mean more opened image at same time which might mean more memory usage. 57 * E.g. if 20 PNG or JPG images are open in the RAM they consume memory while opened in the cache. 58 * @param new_entry_cnt number of image to cache 59 */ 60 void lv_img_cache_set_size(uint16_t new_slot_num); 61 62 /** 63 * Invalidate an image source in the cache. 64 * Useful if the image source is updated therefore it needs to be cached again. 65 * @param src an image source path to a file or pointer to an `lv_img_dsc_t` variable. 66 */ 67 void lv_img_cache_invalidate_src(const void * src); 68 69 /********************** 70 * MACROS 71 **********************/ 72 73 #ifdef __cplusplus 74 } /* extern "C" */ 75 #endif 76 77 #endif /*LV_IMG_CACHE_H*/ 78