[V9]LV_COLOR_DEPTH 8: RGB332 support

I have seen it in older versions, but that option is gone. I modified V9.3 based on the old version and I can use it with the help of STM32 CLUT table. This means we get 256 different colors(8bpp) and we can simply reference the color. I know it’s a low level, but it can be useful if you have little memory and simple usage.

In v9 we really don’t have an 8bit color rendering support in software render. We have 1 bit indexed and L8 tough as target color formats, and when I1/2/4/8 is used as source formats (with images) they are converted to ARGB8888 in advance.

Adding I8 seems seems reasonable to me with these limitations:

  • Support only opacity > 128 will be full covering and opacity <= 128 will be transparent
  • Allow blending only I8 images

To do this a file similar to this needs to added. Are you interested in contributing with such a feature?

Unfortunately, I don’t delve into the subject that deeply. This would be mostly a STM32+LTDC specific thing. LTDC has many advantages, it manages 2 layers. Hardware parallel 16bit, but the first layer can be set to L8, while the second layer can remain RGB565. So lvgl draws into the buffer (first layer). With the second layer we can display images, these are stored in an array and there is no extra work, only an address needs to be set. The arrays can be stored in external qspi flash memory, which takes up little space on the pcb and uses few mcu pins. So you don’t have to give up the color image because of 8bpp. RGB332 is not enough for anti-aliasing, so my attention was definitely focused on the monochrome font, only the 0x00 and 0xff bpp values work.
LTDC is set to L8 and expects a value of 0-255 per pixel, RGB332 is 3bit red+3bit green+2bit blue, but its binary value can match the pre-written CLUT table. The CLUT table is stored as 8bit address+8bit red+8bit green+8bit blue, so division is required.
I can’t actively participate, but I’m happy to share what I’ve achieved so far with the community.

These are the external necessary things, besides that, you only need to modify lvgl, but that can be easily copied from an older version. It’s okay if it’s not included in the new version, I put it here in case it might be useful to someone.

//main.c
#include "color_table_rgb332.h"
HAL_LTDC_ConfigCLUT(&hltdc, (uint32_t*)my_rgb332, 256, LTDC_LAYER_1);
HAL_LTDC_EnableCLUT(&hltdc, LTDC_LAYER_1);

//color_table_rgb332.h

/* RGB332, 3bit RED + 3bit GREEN + 2bit BLUE
 * 8bit per pixel
 * palette address = color bin number
 * palette data RED 8bit + GREEN 8bit + BLUE 8bit
 * ----------------------------------------------------
 * RED    BIN      000, 001, 010, 011, 100, 101, 110, 111
 *        256/8 ->   0,  36,  73, 109, 146, 182, 219, 255
 *        HEX        0,  24,  49,  6D,  92,  B6,  DB,  FF
 * -----------------------------------------------------
 * GREEN  BIN      000, 001, 010, 011, 100, 101, 110, 111
 *        256/8 ->   0,  36,  73, 109, 146, 182, 219, 255
 *        HEX        0,  24,  49,  6D,  92,  B6,  DB,  FF
 * -----------------------------------------------------
 * BLUE   BIN       00,  01,  10,  11
 *        256/4 ->   0,  85, 170, 255
 *        HEX        0,  55,  AA,  FF
 * -----------------------------------------------------
 */



#include <stdint.h>

const uint32_t my_rgb332[256] = {
		0x000000,  //0    000-000-00
		0x000055,  //1    000-000-01
		0x0000AA,  //2    000-000-10
		0x0000FF,  //3    000-000-11
		0x002400,  //4    000-001-00
		0x002455,  //5    000-001-01
		0x0024AA,  //6    000-001-10
		0x0024FF,  //7    000-001-11
		0x004900,  //8    000-010-00
		0x004955,  //9    000-010-01
		0x0049AA,  //10   000-010-10
		0x0049FF,  //11   000-010-11
		0x006D00,  //12   000-011-00
		0x006D55,  //13   000-011-01
		0x006DAA,  //14   000-011-10
		0x006DFF,  //15   000-011-11
		0x009200,  //16   000-100-00
		0x009255,  //17   000-100-01
		0x0092AA,  //18   000-100-10
		0x0092FF,  //19   000-100-11
		0x00B600,  //20   000-101-00
		0x00B655,  //21   000-101-01
		0x00B6AA,  //22   000-101-10
		0x00B6FF,  //23   000-101-11
		0x00DB00,  //24   000-110-00
		0x00DB55,  //25   000-110-01
		0x00DBAA,  //26   000-110-10
		0x00DBFF,  //27   000-110-11
		0x00FF00,  //28   000-111-00
		0x00FF55,  //29   000-111-01
		0x00FFAA,  //30   000-111-10
		0x00FFFF,  //31   000-111-11
		0x240000,  //32   001-000-00
		0x240055,  //33   001-000-01
		0x2400AA,  //34   001-000-10
		0x2400FF,  //35   001-000-11
		0x242400,  //36   001-001-00
		0x242455,  //37   001-001-01
		0x2424AA,  //38   001-001-10
		0x2424FF,  //39   001-001-11
		0x244900,  //40   001-010-00
		0x244955,  //41   001-010-01
		0x2449AA,  //42   001-010-10
		0x2449FF,  //43   001-010-11
		0x246D00,  //44   001-011-00
		0x246D55,  //45   001-011-01
		0x246DAA,  //46   001-011-10
		0x246DFF,  //47   001-011-11
		0x249200,  //48   001-100-00
		0x249255,  //49   001-100-01
		0x2492AA,  //50   001-100-10
		0x2492FF,  //51   001-100-11
		0x24B600,  //52   001-101-00
		0x24B655,  //53   001-101-01
		0x24B6AA,  //54   001-101-10
		0x24B6FF,  //55   001-101-11
		0x24DB00,  //56   001-110-00
		0x24DB55,  //57   001-110-01
		0x24DBAA,  //58   001-110-10
		0x24DBFF,  //59   001-110-11
		0x24FF00,  //60   001-111-00
		0x24FF55,  //61   001-111-01
		0x24FFAA,  //62   001-111-10
		0x24FFFF,  //63   001-111-11
		0x490000,  //64   010-000-00
		0x490055,  //65   010-000-01
		0x4900AA,  //66   010-000-10
		0x4900FF,  //67   010-000-11
		0x492400,  //68   010-001-00
		0x492455,  //69   010-001-01
		0x4924AA,  //70   010-001-10
		0x4924FF,  //71   010-001-11
		0x494900,  //72   010-010-00
		0x494955,  //73   010-010-01
		0x4949AA,  //74   010-010-10
		0x4949FF,  //75   010-010-11
		0x496D00,  //76   010-011-00
		0x496D55,  //77   010-011-01
		0x496DAA,  //78   010-011-10
		0x496DFF,  //79   010-011-11
		0x499200,  //80   010-100-00
		0x499255,  //81   010-100-01
		0x4992AA,  //82   010-100-10
		0x4992FF,  //83   010-100-11
		0x49B600,  //84   010-101-00
		0x49B655,  //85   010-101-01
		0x49B6AA,  //86   010-101-10
		0x49B6FF,  //87   010-101-11
		0x49DB00,  //88   010-110-00
		0x49DB55,  //89   010-110-01
		0x49DBAA,  //90   010-110-10
		0x49DBFF,  //91   010-110-11
		0x49FF00,  //92   010-111-00
		0x49FF55,  //93   010-111-01
		0x49FFAA,  //94   010-111-10
		0x49FFFF,  //95   010-111-11
		0x6D0000,  //96   011-000-00*
		0x6D0055,  //97   011-000-01
		0x6D00AA,  //98   011-000-10
		0x6D00FF,  //99   011-000-11
		0x6D2400,  //100  011-001-00
		0x6D2455,  //101  011-001-01
		0x6D24AA,  //102  011-001-10
		0x6D24FF,  //103  011-001-11
		0x6D4900,  //104  011-010-00
		0x6D4955,  //105  011-010-01
		0x6D49AA,  //106  011-010-10
		0x6D49FF,  //107  011-010-11
		0x6D6D00,  //108  011-011-00
		0x6D6D55,  //109  011-011-01
		0x6D6DAA,  //110  011-011-10
		0x6D6DFF,  //111  011-011-11
		0x6D9200,  //112  011-100-00
		0x6D9255,  //113  011-100-01
		0x6D92AA,  //114  011-100-10
		0x6D92FF,  //115  011-100-11
		0x6DB600,  //116  011-101-00
		0x6DB655,  //117  011-101-01
		0x6DB6AA,  //118  011-101-10
		0x6DB6FF,  //119  011-101-11
		0x6DDB00,  //120  011-110-00
		0x6DDB55,  //121  011-110-01
		0x6DDBAA,  //122  011-110-10
		0x6DDBFF,  //123  011-110-11
		0x6DFF00,  //124  011-111-00
		0x6DFF55,  //125  011-111-01
		0x6DFFAA,  //126  011-111-10
		0x6DFFFF,  //127  011-111-11
		0x920000,  //128  100-000-00
		0x920055,  //129  100-000-01
		0x9200AA,  //130  100-000-10
		0x9200FF,  //131  100-000-11
		0x922400,  //132  100-001-00
		0x922455,  //133  100-001-01
		0x9224AA,  //134  100-001-10
		0x9224FF,  //135  100-001-11
		0x924900,  //136  100-010-00
		0x924955,  //137  100-010-01
		0x9249AA,  //138  100-010-10
		0x9249FF,  //139  100-010-11
		0x926D00,  //140  100-011-00
		0x926D55,  //141  100-011-01
		0x926DAA,  //142  100-011-10
		0x926DFF,  //143  100-011-11
		0x929200,  //144  100-100-00
		0x929255,  //145  100-100-01
		0x9292AA,  //146  100-100-10
		0x9292FF,  //147  100-100-11
		0x92B600,  //148  100-101-00
		0x92B655,  //149  100-101-01
		0x92B6AA,  //150  100-101-10
		0x92B6FF,  //151  100-101-11
		0x92DB00,  //152  100-110-00
		0x92DB55,  //153  100-110-01
		0x92DBAA,  //154  100-110-10
		0x92DBFF,  //155  100-110-11
		0x92FF00,  //156  100-111-00
		0x92FF55,  //157  100-111-01
		0x92FFAA,  //158  100-111-10
		0x92FFFF,  //159  100-111-11
		0xB60000,  //160  101-000-00
		0xB60055,  //161  101-000-01
		0xB600AA,  //162  101-000-10
		0xB600FF,  //163  101-000-11
		0xB62400,  //164  101-001-00
		0xB62455,  //165  101-001-01
		0xB624AA,  //166  101-001-10
		0xB624FF,  //167  101-001-11
		0xB64900,  //168  101-010-00
		0xB64955,  //169  101-010-01
		0xB649AA,  //170  101-010-10
		0xB649FF,  //171  101-010-11
		0xB66D00,  //172  101-011-00
		0xB66D55,  //173  101-011-01
		0xB66DAA,  //174  101-011-10
		0xB66DFF,  //175  101-011-11
		0xB69200,  //176  101-100-00
		0xB69255,  //177  101-100-01
		0xB692AA,  //178  101-100-10
		0xB692FF,  //179  101-100-11
		0xB6B600,  //180  101-101-00
		0xB6B655,  //181  101-101-01
		0xB6B6AA,  //182  101-101-10
		0xB6B6FF,  //183  101-101-11
		0xB6DB00,  //184  101-110-00
		0xB6DB55,  //185  101-110-01
		0xB6DBAA,  //186  101-110-10
		0xB6DBFF,  //187  101-110-11
		0xB6FF00,  //188  101-111-00
		0xB6FF55,  //189  101-111-01
		0xB6FFAA,  //190  101-111-10
		0xB6FFFF,  //191  101-111-11
		0xDB0000,  //192  110-000-00
		0xDB0055,  //193  110-000-01
		0xDB00AA,  //194  110-000-10
		0xDB00FF,  //195  110-000-11
		0xDB2400,  //196  110-001-00
		0xDB2455,  //197  110-001-01
		0xDB24AA,  //198  110-001-10
		0xDB24FF,  //199  110-001-11
		0xDB4900,  //200  110-010-00
		0xDB4955,  //201  110-010-01
		0xDB49AA,  //202  110-010-10
		0xDB49FF,  //203  110-010-11
		0xDB6D00,  //204  110-011-00
		0xDB6D55,  //205  110-011-01
		0xDB6DAA,  //206  110-011-10
		0xDB6DFF,  //207  110-011-11
		0xDB9200,  //208  110-100-00
		0xDB9255,  //209  110-100-01
		0xDB92AA,  //210  110-100-10
		0xDB92FF,  //211  110-100-11
		0xDBB600,  //212  110-101-00
		0xDBB655,  //213  110-101-01
		0xDBB6AA,  //214  110-101-10
		0xDBB6FF,  //215  110-101-11
		0xDBDB00,  //216  110-110-00
		0xDBDB55,  //217  110-110-01
		0xDBDBAA,  //218  110-110-10
		0xDBDBFF,  //219  110-110-11
		0xDBFF00,  //220  110-111-00
		0xDBFF55,  //221  110-111-01
		0xDBFFAA,  //222  110-111-10
		0xDBFFFF,  //223  110-111-11
		0xFF0000,  //224  111-000-00
		0xFF0055,  //225  111-000-01
		0xFF00AA,  //226  111-000-10
		0xFF00FF,  //227  111-000-11
		0xFF2400,  //228  111-001-00
		0xFF2455,  //229  111-001-01
		0xFF24AA,  //230  111-001-10
		0xFF24FF,  //231  111-001-11
		0xFF4900,  //232  111-010-00
		0xFF4955,  //233  111-010-01
		0xFF49AA,  //234  111-010-10
		0xFF49FF,  //235  111-010-11
		0xFF6D00,  //236  111-011-00
		0xFF6D55,  //237  111-011-01
		0xFF6DAA,  //238  111-011-10
		0xFF6DFF,  //239  111-011-11
		0xFF9200,  //240  111-100-00
		0xFF9255,  //241  111-100-01
		0xFF92AA,  //242  111-100-10
		0xFF92FF,  //243  111-100-11
		0xFFB600,  //244  111-101-00
		0xFFB655,  //245  111-101-01
		0xFFB6AA,  //246  111-101-10
		0xFFB6FF,  //247  111-101-11
		0xFFDB00,  //248  111-110-00
		0xFFDB55,  //249  111-110-01
		0xFFDBAA,  //250  111-110-10
		0xFFDBFF,  //251  111-110-11
		0xFFFF00,  //252  111-111-00
		0xFFFF55,  //253  111-111-01
		0xFFFFAA,  //254  111-111-10
		0xFFFFFF,  //255  111-111-11


};



Thanks!
Unfortunately (or fortunately) we have a lot of customer and partner support things to work on now so can’t jump into it, but we will keep it on our radar.

If more requests come we will prioritize it for sure.

If you change you mind and get interested in working on it, just let us know.

1 Like