How to decode first 4 bytes in a .bin image?

Hello, I eventually decided to walk through the source code of the lv_img_conv library and found the solution. I write it here in case somebody else need to do the same thing. The code that computes the 32-bit header is in the convert.ts file, in the Converter::convert() function:

        ($lv_cf = 4 or 5, based on the color format used)
        var $header_32bit = ($lv_cf | (this.w << 10) | (this.h << 21)) >>> 0;

        var finalBinary = new Uint8Array(this.d_out.length + 4);
        finalBinary[0] = ($header_32bit & 0xFF);
        finalBinary[1] = ($header_32bit & 0xFF00) >> 8;
        finalBinary[2] = ($header_32bit & 0xFF0000) >> 16;
        finalBinary[3] = ($header_32bit & 0xFF000000) >> 24;

I am not aware of the source code that loads the bin image in the device, maybe they use an older version of LVGL, or maybe they use just another version alltogether (LittlevGL I’ve read in the comments). Thank you very much for your interest, however.

1 Like