Skip to content

Commit

Permalink
feat(image_decoder): remove args for open_cb (lvgl#5402)
Browse files Browse the repository at this point in the history
  • Loading branch information
W-Mai authored Jan 22, 2024
1 parent 2297338 commit 40b9a8f
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/draw/lv_image_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ lv_result_t lv_image_decoder_open(lv_image_decoder_dsc_t * dsc, const void * src
if(try_cache(dsc) == LV_RESULT_OK) return LV_RESULT_OK;
#endif

res = decoder->open_cb(decoder, dsc, args);
res = decoder->open_cb(decoder, dsc);

/*Opened successfully. It is a good decoder for this image source*/
if(res == LV_RESULT_OK) return res;
Expand Down
5 changes: 1 addition & 4 deletions src/draw/lv_image_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ typedef lv_result_t (*lv_image_decoder_info_f_t)(lv_image_decoder_t * decoder, c
* 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.
* @param args arguments of how to decode the image. see `lv_image_decoder_args_t`.
*/
typedef lv_result_t (*lv_image_decoder_open_f_t)(lv_image_decoder_t * decoder,
lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
typedef lv_result_t (*lv_image_decoder_open_f_t)(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);

/**
* Decode `len` pixels starting from the given `x`, `y` coordinates and store them in `buf`.
Expand Down
13 changes: 8 additions & 5 deletions src/draw/vg_lite/lv_vg_lite_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ typedef struct {
**********************/

static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_close(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_cache_free(lv_image_cache_data_t * cached_data, void * user_data);
static void image_try_self_pre_mul(lv_image_decoder_dsc_t * dsc);
Expand Down Expand Up @@ -367,10 +366,14 @@ static lv_result_t decoder_open_file(lv_image_decoder_t * decoder, lv_image_deco
return LV_RESULT_INVALID;
}

static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
/**
* Decode an image using the vg_lite gpu.
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(args); /*Unused*/

lv_result_t res = LV_RESULT_INVALID;

Expand Down
10 changes: 7 additions & 3 deletions src/libs/bin_decoder/lv_bin_decoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,15 @@ lv_result_t lv_bin_decoder_info(lv_image_decoder_t * decoder, const void * src,
return LV_RESULT_OK;
}

lv_result_t lv_bin_decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
/**
* Decode an image from a binary file
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
lv_result_t lv_bin_decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder);
LV_UNUSED(args);

lv_fs_res_t res = LV_RESULT_INVALID;
bool use_directly = false; /*If the image is already decoded and can be used directly*/
Expand Down
3 changes: 1 addition & 2 deletions src/libs/bin_decoder/lv_bin_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ lv_result_t lv_bin_decoder_get_area(lv_image_decoder_t * decoder, lv_image_decod
* @param dsc pointer to decoder descriptor. `src`, `style` are already initialized in it.
* @return LV_RESULT_OK: the info is successfully stored in `header`; LV_RESULT_INVALID: unknown format or other error.
*/
lv_result_t lv_bin_decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
lv_result_t lv_bin_decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);

/**
* Close the pending decoding. Free resources etc.
Expand Down
13 changes: 5 additions & 8 deletions src/libs/bmp/lv_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ typedef struct {
* STATIC PROTOTYPES
**********************/
static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);

static lv_result_t decoder_get_area(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_area_t * full_area, lv_area_t * decoded_area);
Expand Down Expand Up @@ -136,15 +135,13 @@ static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src,

/**
* Open a BMP image and return the decided image
* @param src can be file name or pointer to a C array
* @param style style of the image object (unused now but certain formats might use it)
* @return pointer to the decoded image or `LV_IMAGE_DECODER_OPEN_FAIL` if failed
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder);
LV_UNUSED(args);

/*If it's a BMP file...*/
if(dsc->src_type == LV_IMAGE_SRC_FILE) {
Expand Down
13 changes: 8 additions & 5 deletions src/libs/ffmpeg/lv_ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ struct lv_image_pixel_color_s {
**********************/

static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_close(lv_image_decoder_t * dec, lv_image_decoder_dsc_t * dsc);

static struct ffmpeg_context_s * ffmpeg_open_file(const char * path);
Expand Down Expand Up @@ -270,11 +269,15 @@ static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src,
return LV_RESULT_INVALID;
}

static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
/**
* Decode an image using ffmpeg library
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder);
LV_UNUSED(args);

if(dsc->src_type == LV_IMAGE_SRC_FILE) {
const char * path = dsc->src;
Expand Down
13 changes: 5 additions & 8 deletions src/libs/libjpeg_turbo/lv_libjpeg_turbo.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ typedef struct error_mgr_s {
* STATIC PROTOTYPES
**********************/
static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_close(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static lv_draw_buf_t * decode_jpeg_file(const char * filename);
static bool get_jpeg_size(const char * filename, uint32_t * width, uint32_t * height);
Expand Down Expand Up @@ -141,15 +140,13 @@ static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src,

/**
* Open a JPEG image and return the decided image
* @param src can be file name or pointer to a C array
* @param style style of the image object (unused now but certain formats might use it)
* @return pointer to the decoded image or `LV_IMAGE_DECODER_OPEN_FAIL` if failed
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder); /*Unused*/
LV_UNUSED(args); /*Unused*/

/*If it's a JPEG file...*/
if(dsc->src_type == LV_IMAGE_SRC_FILE) {
Expand Down
13 changes: 5 additions & 8 deletions src/libs/libpng/lv_libpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
* STATIC PROTOTYPES
**********************/
static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_close(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static lv_draw_buf_t * decode_png_file(const char * filename);

Expand Down Expand Up @@ -117,15 +116,13 @@ static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src,

/**
* Open a PNG image and return the decided image
* @param src can be file name or pointer to a C array
* @param style style of the image object (unused now but certain formats might use it)
* @return pointer to the decoded image or `LV_IMAGE_DECODER_OPEN_FAIL` if failed
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder); /*Unused*/
LV_UNUSED(args); /*Unused*/

/*If it's a PNG file...*/
if(dsc->src_type == LV_IMAGE_SRC_FILE) {
Expand Down
7 changes: 2 additions & 5 deletions src/libs/lodepng/lv_lodepng.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* STATIC PROTOTYPES
**********************/
static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);
static void decoder_close(lv_image_decoder_t * dec, lv_image_decoder_dsc_t * dsc);
static void convert_color_depth(uint8_t * img_p, uint32_t px_cnt);
static lv_draw_buf_t * decode_png_data(const void * png_data, size_t png_data_size);
Expand Down Expand Up @@ -150,11 +149,9 @@ static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src,
* @param dsc decoded image descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder);
LV_UNUSED(args);

const uint8_t * png_data = NULL;
size_t png_data_size = 0;
Expand Down
13 changes: 8 additions & 5 deletions src/libs/tjpgd/lv_tjpgd.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
* STATIC PROTOTYPES
**********************/
static lv_result_t decoder_info(lv_image_decoder_t * decoder, const void * src, lv_image_header_t * header);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args);
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc);

static lv_result_t decoder_get_area(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_area_t * full_area, lv_area_t * decoded_area);
Expand Down Expand Up @@ -143,11 +142,15 @@ static size_t input_func(JDEC * jd, uint8_t * buff, size_t ndata)
return 0;
}

static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc,
const lv_image_decoder_args_t * args)
/**
* Decode a JPG image and return the decoded data.
* @param decoder pointer to the decoder
* @param dsc pointer to the decoder descriptor
* @return LV_RESULT_OK: no error; LV_RESULT_INVALID: can't open the image
*/
static lv_result_t decoder_open(lv_image_decoder_t * decoder, lv_image_decoder_dsc_t * dsc)
{
LV_UNUSED(decoder);
LV_UNUSED(args);
lv_fs_file_t * f = lv_malloc(sizeof(lv_fs_file_t));
if(dsc->src_type == LV_IMAGE_SRC_VARIABLE) {
#if LV_USE_FS_MEMFS
Expand Down

0 comments on commit 40b9a8f

Please sign in to comment.