Endianness of Spresense RGB565 Image Data

So I think the endianness of the RGB565 Image data from the Spresense is either different from the Nicla Vision or the Arduino Example for it is wrong.

This is the code block from the example that converts RGB565 to RGB888:

bool RBG565ToRGB888(uint8_t *src_buf, uint8_t *dst_buf, uint32_t src_len)
{
    uint8_t hb, lb;
    uint32_t pix_count = src_len / 2;

    for(uint32_t i = 0; i < pix_count; i ++) {
        hb = *src_buf++;
        lb = *src_buf++;

        *dst_buf++ = hb & 0xF8;
        *dst_buf++ = (hb & 0x07) << 5 | (lb & 0xE0) >> 3;
        *dst_buf++ = (lb & 0x1F) << 3;
    }

    return true;
}

I saved the converted image buffer to a file on the MicroSD and then pulled them up in a python notebook.

When I use this block to covert a snapshot on Spresense I get very distorted colors:
15-0 3.53.09 PM

However, when I switch the order of the bytes:

        lb = *src_buf++;
        hb = *src_buf++;

the colors are correct… and the model works as expected:

12-0

Could different sensors/vendor libraries be writing the image data down with different endianness?

1 Like

Hi @lukedc,

Yes. In fact, it seems that every vendor library has a different way of handling RGB data. Some do RGB888, some do RGB565, some do BGR. It’s super frustrating.