I have implemented a prototype of this here: https://github.com/tgillbe/lvgl/commit/2cd322bf4735d6410f981559f0ecc8a086b82189
It seems sensible to have support for this. Unfortunately my implementation has a few issues so I was hoping to get some feedback before submitting a PR. The issues I can see with my current implementation are as follows:
- lv_img_color_format_has_alpha has been changed to take a lv_img_decoder_dsc_t and it scans the decoder user_data to check if any of the palette colors have an alpha component. This could potentially speed up drawing of non-transparent indexed images but my current implementation isn’t viable as it assumes the layout of lv_img_decoder_built_in_data_t (I have LV_USE_FILESYSTEM set to 0). Is there a better way of implementing this? I could just assume has_alpha = true regardless and it will work.
- I have created a lv_color_full_t type which contains a lv_color_t and lv_opa_t. This is so the colors only need to be translated into the correct format for the display once (on image load), but I would have assumed a type like this already exists. Am I missing it?
- The current image converter (img_conv_core.php) doesn’t support images with an alpha channel, so I’ve made a python version which does here. Unfortunately it’s hacked together so it’s slow at the moment.
Another benefit is that chroma keyed indexed images could be canned. It would be easier just to use the alpha channel (which is present in indexed images already!)
If you want to test this, there’s an example image provided in the commit in both png format and as c code.
Test image drawn by LVGL on top of a blue background and a string saying “TEST”: