cancel
Showing results for 
Search instead for 
Did you mean: 

How to use TouchGFX on compressed images ?

Aksl
Associate III

Have anyone succeeded in using compressed images with TouchGFX ? Here is what I tried to do (spoiler : didn't work)

I've been trying to implement a GUI with TouchGFX for an STM32L4R5 with 2 MB of FLASH memory, but all the images take 8 MB and so don't fit in the FLASH.

By compressing the images using RLE & LZW simple algorithms, I would achieve a more than ten-fold reduction in image sizes, but they cannot be used as-is by TouchGFX. So I thought I would write a decompression layer to dynamically decompress the images into dynamically allocated RAM, and free it when the images are not displayed anymore. This would happen upon each screen transition : discarding the images of the former screen and bring in the new ones.

Fortunately, we have the sources of the part of TouchGFX which handles image loading : the constructor & destructor of the Bitmap class, in Bitmap.hpp, deep into the "Middleware" folder brough up by TouchGFX Generator. So the easy part is replacing the raw images with the compressed ones in TouchGFX/generated/images/src, where we can find a file for each image containing an array of values : we just have to changes those values whith the statically compressed image. Of course this makes much shorter arrays. This we, the FLASH is loaded with compressed images, but TouchGFX doesn't know it and will display garbage if nothing is done.

Then, not much harder, upon image loading, we have to get the FLASH adress of the compressed image, find its size from the bitmap_database global structure, allocate the necessary size for the decompressed image (in RAM), and actually decompress it.

Great, now we have to tell TouchGFX to use this brand new decompressed image instead of the compressed image in FLASH. This is the part I stumbled upon. The bitmap_database is originally in FLASH, so I copied it in RAM to modify it while shadowing the FLASH version. Then, when an image is decompressed, I update the bitmap pointer in bitmap_database from the FLASH compressed image to the RAM decompressed one, and then... nothing happens. The framebuffer is still filled with the compressed version. Most changes I made are in the file Bitmap.cpp attached here.

So either parts of TouchGFX elsewhere than the Bitmap class hold independent references to the FLASH location, either (more probably) the static library of which we don't have the source (or where ?) have been compiled with references to image locations declared as const, and thus the executed code simply doesn't read the new location I made. I actually had to play with the consts while making my changes, so it doesn't really come as a a surprise. If this is the case I have little hope to implement my dynamic decompression layer myself with half the sources not available or by trying to patch the libtouchgfx binary...

Has anyone else tried this kind of thing ? Maybe succeeded ?

Anyway, it would be a great idea for the TouchGFX team to implement it natively, even just as an optional functionnality...

0 REPLIES 0