lv_img_decoder.h

Typedefs

typedef _lv_img_src_t lv_img_src_t
typedef lv_res_t (*lv_img_decoder_info_f_t)(struct _lv_img_decoder_t *decoder, const void *src, lv_img_header_t *header)

Get info from an image and store in the header

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)

Param header:

store the info here

Return:

LV_RES_OK: info written correctly; LV_RES_INV: failed

typedef lv_res_t (*lv_img_decoder_open_f_t)(struct _lv_img_decoder_t *decoder, struct _lv_img_decoder_dsc_t *dsc)

Open an image for decoding. Prepare it as it is required to read it later

Param decoder:

pointer to the decoder the function associated with

Param dsc:

pointer to decoder descriptor. src, color are already initialized in it.

typedef lv_res_t (*lv_img_decoder_read_line_f_t)(struct _lv_img_decoder_t *decoder, struct _lv_img_decoder_dsc_t *dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t *buf)

Decode len pixels starting from the given x, y coordinates and store them in buf. Required only if the "open" function can't return with the whole decoded pixel array.

Param decoder:

pointer to the decoder the function associated with

Param dsc:

pointer to decoder descriptor

Param x:

start x coordinate

Param y:

start y coordinate

Param len:

number of pixels to decode

Param buf:

a buffer to store the decoded pixels

Return:

LV_RES_OK: ok; LV_RES_INV: failed

typedef void (*lv_img_decoder_close_f_t)(struct _lv_img_decoder_t *decoder, struct _lv_img_decoder_dsc_t *dsc)

Close the pending decoding. Free resources etc.

Param decoder:

pointer to the decoder the function associated with

Param dsc:

pointer to decoder descriptor

typedef struct _lv_img_decoder_t lv_img_decoder_t
typedef struct _lv_img_decoder_dsc_t lv_img_decoder_dsc_t

Describe an image decoding session. Stores data about the decoding

Enums

enum _lv_img_src_t

Source of image.

Values:

enumerator LV_IMG_SRC_VARIABLE
enumerator LV_IMG_SRC_FILE

Binary/C variable

enumerator LV_IMG_SRC_SYMBOL

File in filesystem

enumerator LV_IMG_SRC_UNKNOWN

Symbol (lv_symbol_def.h)

Functions

void _lv_img_decoder_init(void)

Initialize the image decoder module

lv_res_t lv_img_decoder_get_info(const void *src, lv_img_header_t *header)

Get information about an image. Try the created image decoder one by one. Once one is able to get info that info will be used.

Parameters:
  • src -- the image source. Can be 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via lv_fs_drv_register()) 2) Variable: Pointer to an lv_img_dsc_t variable 3) Symbol: E.g. LV_SYMBOL_OK

  • header -- the image info will be stored here

Returns:

LV_RES_OK: success; LV_RES_INV: wasn't able to get info about the image

lv_res_t lv_img_decoder_open(lv_img_decoder_dsc_t *dsc, const void *src, lv_color_t color, int32_t frame_id)

Open an image. Try the created image decoders one by one. Once one is able to open the image that decoder is saved in dsc

Parameters:
  • dsc -- describes a decoding session. Simply a pointer to an lv_img_decoder_dsc_t variable.

  • src -- the image source. Can be 1) File name: E.g. "S:folder/img1.png" (The drivers needs to registered via lv_fs_drv_register())) 2) Variable: Pointer to an lv_img_dsc_t variable 3) Symbol: E.g. LV_SYMBOL_OK

  • color -- The color of the image with LV_IMG_CF_ALPHA_...

  • frame_id -- the index of the frame. Used only with animated images, set 0 for normal images

Returns:

LV_RES_OK: opened the image. dsc->img_data and dsc->header are set. LV_RES_INV: none of the registered image decoders were able to open the image.

lv_res_t lv_img_decoder_read_line(lv_img_decoder_dsc_t *dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t *buf)

Read a line from an opened image

Parameters:
  • dsc -- pointer to lv_img_decoder_dsc_t used in lv_img_decoder_open

  • x -- start X coordinate (from left)

  • y -- start Y coordinate (from top)

  • len -- number of pixels to read

  • buf -- store the data here

Returns:

LV_RES_OK: success; LV_RES_INV: an error occurred

void lv_img_decoder_close(lv_img_decoder_dsc_t *dsc)

Close a decoding session

Parameters:

dsc -- pointer to lv_img_decoder_dsc_t used in lv_img_decoder_open

lv_img_decoder_t *lv_img_decoder_create(void)

Create a new image decoder

Returns:

pointer to the new image decoder

void lv_img_decoder_delete(lv_img_decoder_t *decoder)

Delete an image decoder

Parameters:

decoder -- pointer to an image decoder

void lv_img_decoder_set_info_cb(lv_img_decoder_t *decoder, lv_img_decoder_info_f_t info_cb)

Set a callback to get information about the image

Parameters:
  • decoder -- pointer to an image decoder

  • info_cb -- a function to collect info about an image (fill an lv_img_header_t struct)

void lv_img_decoder_set_open_cb(lv_img_decoder_t *decoder, lv_img_decoder_open_f_t open_cb)

Set a callback to open an image

Parameters:
  • decoder -- pointer to an image decoder

  • open_cb -- a function to open an image

void lv_img_decoder_set_read_line_cb(lv_img_decoder_t *decoder, lv_img_decoder_read_line_f_t read_line_cb)

Set a callback to a decoded line of an image

Parameters:
  • decoder -- pointer to an image decoder

  • read_line_cb -- a function to read a line of an image

void lv_img_decoder_set_close_cb(lv_img_decoder_t *decoder, lv_img_decoder_close_f_t close_cb)

Set a callback to close a decoding session. E.g. close files and free other resources.

Parameters:
  • decoder -- pointer to an image decoder

  • close_cb -- a function to close a decoding session

lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t *decoder, const void *src, lv_img_header_t *header)

Get info about a built-in image

Parameters:
  • decoder -- the decoder where this function belongs

  • src -- the image source: pointer to an lv_img_dsc_t variable, a file path or a symbol

  • header -- store the image data here

Returns:

LV_RES_OK: the info is successfully stored in header; LV_RES_INV: unknown format or other error.

lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t *decoder, lv_img_decoder_dsc_t *dsc)

Open a built in image

Parameters:
  • decoder -- the decoder where this function belongs

  • dsc -- pointer to decoder descriptor. src, style are already initialized in it.

Returns:

LV_RES_OK: the info is successfully stored in header; LV_RES_INV: unknown format or other error.

void lv_img_decoder_built_in_close(lv_img_decoder_t *decoder, lv_img_decoder_dsc_t *dsc)

Close the pending decoding. Free resources etc.

Parameters:
  • decoder -- pointer to the decoder the function associated with

  • dsc -- pointer to decoder descriptor

struct _lv_img_decoder_t
struct _lv_img_decoder_dsc_t
#include <lv_img_decoder.h>

Describe an image decoding session. Stores data about the decoding

Public Members

lv_img_decoder_t *decoder

The decoder which was able to open the image source

const void *src

The image source. A file path like "S:my_img.png" or pointer to an lv_img_dsc_t variable

lv_color_t color

Color to draw the image. Used when the image has alpha channel only

int32_t frame_id

Frame of the image, using with animated images

lv_img_src_t src_type

Type of the source: file or variable. Can be set in open function if required

lv_img_header_t header

Info about the opened image: color format, size, etc. MUST be set in open function

const uint8_t *img_data

Pointer to a buffer where the image's data (pixels) are stored in a decoded, plain format. MUST be set in open function

const lv_color32_t *palette
uint32_t palette_size
uint32_t time_to_open

How much time did it take to open the image. [ms] If not set lv_img_cache will measure and set the time to open

const char *error_msg

A text to display instead of the image when the image can't be opened. Can be set in open function or set NULL.

void *user_data

Store any custom data here is required