Thank you very much for the tips. I let you know what I finally did and the new problem found.
Changes within LittlevGL
- Add new options to image color format. Could be something like this:
/*Image color format*/
enum {
LV_IMG_CF_UNKNOWN = 0,
LV_IMG_CF_RAW, /**< Contains the file as it is. Needs custom decoder function*/
LV_IMG_CF_RAW_ALPHA, /**< Contains the file as it is. The image has alpha. Needs custom decoder
function*/
LV_IMG_CF_RAW_CHROMA_KEYED, /**< Contains the file as it is. The image is chroma keyed. Needs
custom decoder function*/
LV_IMG_CF_TRUE_COLOR, /**< Color format and depth should match with LV_COLOR settings*/
LV_IMG_CF_TRUE_COLOR_ALPHA, /**< Same as `LV_IMG_CF_TRUE_COLOR` but every pixel has an alpha byte*/
LV_IMG_CF_TRUE_COLOR_CHROMA_KEYED, /**< Same as `LV_IMG_CF_TRUE_COLOR` but LV_COLOR_TRANSP pixels
will be transparent*/
LV_IMG_CF_INDEXED_1BIT, /**< Can have 2 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_2BIT, /**< Can have 4 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_4BIT, /**< Can have 16 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_INDEXED_8BIT, /**< Can have 256 different colors in a palette (always chroma keyed)*/
LV_IMG_CF_ALPHA_1BIT, /**< Can have one color and it can be drawn or not*/
LV_IMG_CF_ALPHA_2BIT, /**< Can have one color but 4 different alpha value*/
LV_IMG_CF_ALPHA_4BIT, /**< Can have one color but 16 different alpha value*/
LV_IMG_CF_ALPHA_8BIT, /**< Can have one color but 256 different alpha value*/
LV_IMG_CF_RESERVED_0, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_1, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_2, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_3, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_4, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_5, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_6, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_7, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_8, /**< Reserved for further use. */
LV_IMG_CF_RESERVED_9, /**< Reserved for further use. */
LV_IMG_CF_USER_ENCODED_0, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_1, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_2, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_3, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_4, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_5, /**< User holder encoding format. */
LV_IMG_CF_USER_ENCODED_6, /**< User holder encoding format. */
};
- Make decoding built-in functions public:
extern lv_res_t lv_img_decoder_built_in_info(lv_img_decoder_t * decoder, const void * src, lv_img_header_t * header);
extern lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
extern lv_res_t lv_img_decoder_built_in_read_line(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc, lv_coord_t x, lv_coord_t y, lv_coord_t len, uint8_t * buf);
extern void lv_img_decoder_built_in_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc);
Initialize new decoder
Initializing function looks like this:
static void APP_LVGL_initDecoder (void)
{
appLvglCtx.decoder = lv_img_decoder_create();
lv_img_decoder_set_open_cb(appLvglCtx.decoder, ICON_LVGL_runLength);
lv_img_decoder_set_info_cb(appLvglCtx.decoder, lv_img_decoder_built_in_info);
lv_img_decoder_set_read_line_cb(appLvglCtx.decoder, lv_img_decoder_built_in_read_line);
lv_img_decoder_set_close_cb(appLvglCtx.decoder, lv_img_decoder_built_in_close);
}
Decoder open function
The starting part of the decoding function looks like this:
lv_res_t ICON_LVGL_runLength (lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
{
(void) decoder;
lv_img_dsc_t* pImg = (lv_img_dsc_t*)dsc->src;
/* RLE is only applied to user_encoded_0 images.
*
* Once RLE is applied, LittlevGL should treat image as alpha_4bit
*/
if (pImg->header.cf == LV_IMG_CF_USER_ENCODED_0) {
dsc->header.cf = LV_IMG_CF_ALPHA_4BIT;
} else {
return LV_RES_OK;
}
/**************************************/
/* Make de-compression for RLE icons. */
/**************************************/
...
...
};
Is it working?
Yes and not!
Now the icons are painted as they should (application applies RLE, and lvgl applies 4-bit-alpha), which is great! The problem now comes for those 4-bit-indexed images. Before this change they were painted good.
Any idea or improvement to this method?