esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
413 stars 26 forks source link

Support for 16bit color on ili9341 displays #1451

Closed davet2001 closed 1 year ago

davet2001 commented 2 years ago

Describe the problem you have/What new integration you would like

The ILI9341 display works with esphome.

It would be great if we could use 16bit color.

Please describe your use case for this integration and alternatives you've tried:

The physical module supports 65536 colors (16bit) but the driver only writes up to 256 (8bit) colors.

This makes images and color gradients look poor quality.

Additional context

Internally I see that the display driver esphome/components/ili9341/ili9341display.cpp is actually writing 16bit color values to the display, but the `buffer` variable is an 8bit array and they are converted before sending.

So my conclusion is that this is only due to a RAM limitation (would not affect write speed).

When I tried modifying to increase the buffer size, I got a runtime error saying that the display buffer could not be allocated.

If I got a device with more RAM (eg ESP-WROVER with SPI RAM) could this be feasible?

I couldn't easily tell if esphome can use external RAM, and would value comments before I start down this path. (eg maybe not a good idea if the RAM is using the same SPI port as the display).

My thought would be to add something similar to the eight_bit_color flag that the ST7735 has.

davet2001 commented 2 years ago

Since posting I had another idea - maybe could use 256 indexed colors?

That would use 256*3bytes of flash, and use the same 8bit array for the buffer.

I see that the pillow library already has some support for indexed/pallet images and can export the raw index.

Could use Euclidean distance (omitting sqrt() for speed) to find the best match, and this could be via additional helper functions added to display_color_utils.h to support an indexed color mode.

This would not improve full color photos much but would improve icons/logos etc significantly.

davet2001 commented 2 years ago

I did a small experiment by forcing the buffer to be smaller than the screen, but operating in 16bit mode. Then tried loading an image - as per attached. Confirms this display can indeed display full 16bit colors when run through esphome (It's just the ram limitation). ili9341_sample

davet2001 commented 1 year ago

The PRS have been merged. This issue can be closed.