2024-09-11 09:15 AM
Hello,
It's quite easy to manipulate the CLUT for an L8 uncompressed Bitmap but how could we find the CLUT entries when the Bitmap is compressed with either RLE or LZW methods?
When looking at the .cpp generated for such an image around the extra_data definition, the extra data starts with a 4 bytes header giving the format (here 0x00,0x03 for an LZW compressed image) then the CLUT size (0x100 or 256 entries) ... BUT ... the following bytes are not the CLUT but, I guess, some dictionary entries for the LZW encoder... the actual CLUT is at the end of the extra_data section ... but there is no obvious mean to know where the CLUt starts ...
LOCATION_PRAGMA("ExtFlashSection")
KEEP extern const unsigned char image_worldmap_extra_data[] LOCATION_ATTRIBUTE("ExtFlashSection") = { // 256 ARGB8888 CLUT entries.
0x00, 0x03, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x32,
.....
0x00, 0x00, 0x3a, 0xa2,
0x00, 0x00, 0x3a, 0xd4,
0xf8, 0xfc, 0xf8, 0x00, 0xf8, 0xfc, 0xf8, 0x04, 0xf8, 0xfc, 0xf8, 0x05, // Here is the actual CLUT
0xf8, 0xfc, 0xf8, 0x03, 0xf8, 0xfc, 0xf8, 0x11, 0xf8, 0xfc, 0xf8, 0x4f,
0xf8, 0xfc, 0xf8, 0x59, 0xf8, 0xfc, 0xf8, 0x5a, 0xf8, 0xfc, 0xf8, 0x5b,
Is there a way to know the location of the CLUT ?
Thanks,
Pierre
2024-09-23 01:35 AM
Hello @PJEN ,
The CLUT will be written in long format, the LZW data is will be written by pack of 4bytes only. You can also find the beginning by reading the CLUT from the last entry (you know how many entries you have with the comment).
Best regards,
Louis B.
2024-09-23 05:34 AM
Hello,
This is not very clear for me but digging around I found that, by chance, the extra_data is linked on adresses just before the bitmap data as in this example :
0xd3e575e4 0x40fc ./TouchGFX/generated/images/src/image_worldmap.o
0xd3e575e4 image_worldmap_extra_data
0xd3e57c0c image_worldmap
So, knowing the number of colours in the CLUT we can subtract the CLUT size (4 bytes for each colour) from the pointer returned by Bitmap::getData() (here 0xd3e57c0c) to find the address of the first colour of the CLUT.
It does the trick but that relies on the Linker's choice to put 'extra_data' before 'data' ... Can we be sure it will always be like that ?
BR
Pierre
2024-10-08 04:51 AM
Hello @PJEN ,
Yes you can also relate on that.
BR,