When using indexed color modes, why was it made so the palette needs to be stored together in the same array as the pixel map data?
Author: dgsgsgdgggCreated Aug 13, 2026Updated Sep 24, 2026
Labelsimage
Introduce the problem
As I understand, if you want an indexed color mode image to be displayed with lv_img_set_src(), it’s palette needs to be stored in the same array as the pixel data, example:
const LV_ATTRIBUTE_MEM_ALIGN uint8_t my_image_map[] PROGMEM = {
0x00, 0x00, 0x00, 0xFF, /* Color of index 0 */
0xFF, 0xC5, 0xFF, 0xFF, /* Color of index 1 */
0x40, 0x20, 0x23, 0xFF, /* Color of index 2 */
0x00, 0x00, 0xFF, 0xFF, /* Color of index 3 */
// Pixel data
0xAA, 0xAA, 0xAA, 0xAA, 0xA9, 0x95, 0x5A, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x56, 0x56, 0x96,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56, 0xAA, 0xAA,
0xAA, 0xAA, 0xA6, 0x65, 0x59, 0x99, 0x99, 0x99, 0x55, 0x55, 0x55, 0x55, 0x5A, 0x96, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x56, 0xAA, 0xAA, 0xAA, 0xAA,
........
};This can be overcome by not using a const if you want to overwrite the colors at runtime, but then the image lives in RAM, instead of const PROGMEM in FLASH.
Proposal
Maybe you could look into storing the palette data outside of the pixel map array so you could easily change the palette globally with a single palette variable at runtime.
Source: lvgl/lvgl