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_to_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 * @param frame_id the index of the frame. Used only with animated images, set 0 for normal images 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, lv_color_t color, int32_t frame_id); 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