How does an online image converter convert RGB888 to RGB565?

Description

I want to write a tool for converting png to LV_IMG_CF_TRUE_COLOR_ALPHA ,like an online converter.
First I read every pixel of the picture, and then I converted those pixels to TRUE_COLOR_ALPHA format. I compare my tools to the results of online conversions, and they are not the same.
For example, RGB(88, 33, 44), the online tool’s conversion result is: 0x06, 0x59, and my tool’s conversion result is: 0x5, 0x59.

What MCU/Processor/Board and compiler are you using?

x86

What LVGL version are you using?

lvgl8.3

What do you want to achieve?

I just want to know, how does the online converter convert rgb888 to rgb565?

What have you tried so far?

Code to reproduce

Here is my conversion code

        static UInt16 BRGA2RGB565(byte b, byte g, byte r, byte a = 0xFF)
        {
            int ir = r >> 3;
            int ig = g >> 2;
            int ib = b >> 3;
            int v = ib;
            v |= ig << 5;
            v |= ir << 11;
            return (UInt16)v;
        }

Hi @LuAn ,

LVGL’s converters and internals use the standard “truncate and pack” formula for RGB888 → RGB565, but note the channel order and that they work in BGR order in several places.

static UInt16 BRGA2RGB565(byte b, byte g, byte r, byte a = 0xFF)
{
    int ir = r >> 3;   // 5 bits
    int ig = g >> 2;   // 6 bits
    int ib = b >> 3;   // 5 bits
    int v = ib;
    v |= ig << 5;
    v |= ir << 11;
    return (UInt16)v;
}

this matches the LVGL packing formula (B,G,R → RGB565). The 1‑bit difference you see (0x06 vs 0x05 in the high byte) is not explained by any alternative rounding in the LVGL sources: they always use simple shifts and masks, no rounding up