diff --git a/menu/drivers/rgui.c b/menu/drivers/rgui.c index b9b6cee016..12cbc3286e 100644 --- a/menu/drivers/rgui.c +++ b/menu/drivers/rgui.c @@ -417,11 +417,32 @@ static uint16_t *rgui_framebuf_data = NULL; static uint16_t argb32_to_abgr1555(uint32_t col) { - unsigned a = ((col >> 24) & 0xff) >> 7; - unsigned r = ((col >> 16) & 0xff) >> 3; - unsigned g = ((col >> 8) & 0xff) >> 3; - unsigned b = ((col & 0xff) ) >> 3; - return (a << 15) | (b << 10) | (g << 5) | r; + /* Extract colour components */ + unsigned a = (col >> 24) & 0xff; + unsigned r = (col >> 16) & 0xff; + unsigned g = (col >> 8) & 0xff; + unsigned b = col & 0xff; + /* Background and border colours are normally semi-transparent + * (so we can see suspended content when opening the quick menu). + * When no content is loaded, the 'image' behind the RGUI background + * and border is black - which has the effect of darkening the + * perceived background/border colours. All the preset theme (and + * default 'custom') colour values have been adjusted to account for + * this, but abgr1555 only has a 1 bit alpha channel. This means all + * colours become fully opaque, and consequently backgrounds/borders + * become abnormally bright. + * We therefore have to darken each RGB value according to the alpha + * component of the input colour... */ + float a_factor = (float)a * (1.0 / 255.0); + r = (unsigned)(((float)r * a_factor) + 0.5) & 0xff; + g = (unsigned)(((float)g * a_factor) + 0.5) & 0xff; + b = (unsigned)(((float)b * a_factor) + 0.5) & 0xff; + /* Convert from 8 bit to 5 bit */ + r = r >> 3; + g = g >> 3; + b = b >> 3; + /* Return final value - alpha always set to 1 */ + return (1 << 15) | (b << 10) | (g << 5) | r; } #define argb32_to_pixel_platform_format(color) argb32_to_abgr1555(color)