I have put a JPEG decoder library on Github that can be used with a Mega or Due to decode and display JPEG images on a TFT display. A commented example is included that could be adapted for any TFT graphics library.
At the moment this is for “Advanced users” as the library is still quite young and I have not yet produced any support documentation, however seasoned users of TFT displays should have no trouble adapting the example for their favorite display and graphics library.
A few JPEG images are included in the “extras” folder and header files containing images are attached to the example sketch.
I have started a project where I wished to store control panel screens in program memory, this is to improve the visual appeal of the projects. To do this I needed to store compressed images in the program memory (FLASH).
After a search on the web I found a library here by Makoto Kurauchi which used picojpeg. Makoto’s library example only generated text output of the decoded file but provided an excellent starting point to add features to display the decoded JPEG images on a TFT screen. So bugs in the original have been fixed and the library is now working very well. It can display images pulled off SD Cards or images stored within arrays in program memory. This permits not only full screen images to be stored in program memory but also smaller graphics icons such as clouds, temperature gauges etc.
JPEG compression is a popular method of significantly reducing the size of image files to reduce storage space needs. So for example a 480 x 320 pixel image in 24 bit colour would occupy 461KBytes, in 16 bit raw format it would occupy 307KBytes. Thus it is impractical to store screen images in program memory and even a Due would only have room for 1 image.
Using JPEG compression can bring a file size down by 20 to 70 times, the included example image of the mouse is 480x320 pixels and has been JPEG compressed only 6.45KByes making it possible to store many startup images and control panel displays in program memory on a Due (or Mega). This means you can design your TFT screen panels on a PC and then just update key areas with information, for example a temperature or other sensor reading, with the Arduino.
There is a catch, the decoding of the compressed images involves a lot of maths so it takes a Due about 1 second to decode and display a 480 x 320 image (500ms for a 320x240 image), also the decoding process uses more RAM than a UNO provides. Thus the library will only work with a Mega or Due.
The example sketch just uses the TFT “setWindow” and “pushColor” member functions of a graphics library, so the example provided should be adaptable to any graphics library.