/**1* @file lv_draw_img.h2*3*/45#ifndef LV_DRAW_IMG_H6#define LV_DRAW_IMG_H78#ifdef __cplusplus9extern "C" {10#endif1112/*********************13* INCLUDES14*********************/15#include "lv_draw.h"16#include "../lv_core/lv_obj.h"1718/*********************19* DEFINES20*********************/21#define LV_IMG_DECODER_OPEN_FAIL ((void*)(-1))2223/**********************24* TYPEDEFS25**********************/26struct _lv_img_t;2728typedef struct {2930/* The first 8 bit is very important to distinguish the different source types.31* For more info see `lv_img_get_src_type()` in lv_img.c */32uint32_t cf :5; /* Color format: See `lv_img_color_format_t`*/33uint32_t always_zero :3; /*It the upper bits of the first byte. Always zero to look like a non-printable character*/3435uint32_t reserved :2; /*Reserved to be used later*/3637uint32_t w:11; /*Width of the image map*/38uint32_t h:11; /*Height of the image map*/39} lv_img_header_t;4041/*Image color format*/42enum {43LV_IMG_CF_UNKOWN = 0,4445LV_IMG_CF_RAW, /*Contains the file as it is. Needs custom decoder function*/46LV_IMG_CF_RAW_ALPHA, /*Contains the file as it is. The image has alpha. Needs custom decoder function*/47LV_IMG_CF_RAW_CHROMA_KEYED, /*Contains the file as it is. The image is chroma keyed. Needs custom decoder function*/4849LV_IMG_CF_TRUE_COLOR, /*Color format and depth should match with LV_COLOR settings*/50LV_IMG_CF_TRUE_COLOR_ALPHA, /*Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/51LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /*Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels will be transparent*/5253LV_IMG_CF_INDEXED_1BIT, /*Can have 2 different colors in a palette (always chroma keyed)*/54LV_IMG_CF_INDEXED_2BIT, /*Can have 4 different colors in a palette (always chroma keyed)*/55LV_IMG_CF_INDEXED_4BIT, /*Can have 16 different colors in a palette (always chroma keyed)*/56LV_IMG_CF_INDEXED_8BIT, /*Can have 256 different colors in a palette (always chroma keyed)*/5758LV_IMG_CF_ALPHA_1BIT, /*Can have one color and it can be drawn or not*/59LV_IMG_CF_ALPHA_2BIT, /*Can have one color but 4 different alpha value*/60LV_IMG_CF_ALPHA_4BIT, /*Can have one color but 16 different alpha value*/61LV_IMG_CF_ALPHA_8BIT, /*Can have one color but 256 different alpha value*/62};63typedef uint8_t lv_img_cf_t;6465/* Image header it is compatible with66* the result image converter utility*/67typedef struct68{69lv_img_header_t header;70uint32_t data_size;71const uint8_t * data;72} lv_img_dsc_t;7374/* Decoder function definitions */757677/**78* Get info from an image and store in the `header`79* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)80* @param header store the info here81* @return LV_RES_OK: info written correctly; LV_RES_INV: failed82*/83typedef lv_res_t (*lv_img_decoder_info_f_t)(const void * src, lv_img_header_t * header);8485/**86* Open an image for decoding. Prepare it as it is required to read it later87* @param src the image source. Can be a pointer to a C array or a file name (Use `lv_img_src_get_type` to determine the type)88* @param style the style of image (maybe it will be required to determine a color or something)89* @return there are 3 possible return values:90* 1) buffer with the decoded image91* 2) if can decode the whole image NULL. decoder_read_line will be called to read the image line-by-line92* 3) LV_IMG_DECODER_OPEN_FAIL if the image format is unknown to the decoder or an error occurred93*/94typedef const uint8_t * (*lv_img_decoder_open_f_t)(const void * src, const lv_style_t * style);9596/**97* Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.98* Required only if the "open" function can't return with the whole decoded pixel array.99* @param x start x coordinate100* @param y startt y coordinate101* @param len number of pixels to decode102* @param buf a buffer to store the decoded pixels103* @return LV_RES_OK: ok; LV_RES_INV: failed104*/105typedef lv_res_t (*lv_img_decoder_read_line_f_t)(lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);106107/**108* Close the pending decoding. Free resources etc.109*/110typedef void (*lv_img_decoder_close_f_t)(void);111112/**********************113* GLOBAL PROTOTYPES114**********************/115116/**117* Draw an image118* @param coords the coordinates of the image119* @param mask the image will be drawn only in this area120* @param src pointer to a lv_color_t array which contains the pixels of the image121* @param style style of the image122* @param opa_scale scale down all opacities by the factor123*/124void lv_draw_img(const lv_area_t * coords, const lv_area_t * mask,125const void * src, const lv_style_t * style, lv_opa_t opa_scale);126127128/**129* Get the type of an image source130* @param src pointer to an image source:131* - pointer to an 'lv_img_t' variable (image stored internally and compiled into the code)132* - a path to a file (e.g. "S:/folder/image.bin")133* - or a symbol (e.g. SYMBOL_CLOSE)134* @return type of the image source LV_IMG_SRC_VARIABLE/FILE/SYMBOL/UNKOWN135*/136lv_img_src_t lv_img_src_get_type(const void * src);137138/**139* Set custom decoder functions. See the typdefs of the function typed above for more info about them140* @param info_fp info get function141* @param open_fp open function142* @param read_fp read line function143* @param close_fp clode function144*/145void lv_img_decoder_set_custom(lv_img_decoder_info_f_t info_fp, lv_img_decoder_open_f_t open_fp,146lv_img_decoder_read_line_f_t read_fp, lv_img_decoder_close_f_t close_fp);147148lv_res_t lv_img_dsc_get_info(const char * src, lv_img_header_t * header);149150uint8_t lv_img_color_format_get_px_size(lv_img_cf_t cf);151152bool lv_img_color_format_is_chroma_keyed(lv_img_cf_t cf);153154bool lv_img_color_format_has_alpha(lv_img_cf_t cf);155156157/**********************158* MACROS159**********************/160161162#ifdef __cplusplus163} /* extern "C" */164#endif165166#endif /*LV_TEMPL_H*/167168169