Arduino Forum

Using Arduino => Programming Questions => Topic started by: sonic656 on Dec 14, 2012, 07:21 pm

Title: Display images (jpg/png) on a 3.2" display from SD card
Post by: sonic656 on Dec 14, 2012, 07:21 pm
Hi. I wrote a topic (http://arduino.cc/forum/index.php/topic,137437.0.html) few hours later. So here is my other question. Can I displlay jpg or png images from SD card on a 3.2" display using arduino? I have bought this display module (http://www.ebay.com/itm/3-2-inch-TFT-LCD-Module-Display-320x240-Touch-Panel-PCB-Adapter-SD-Card-Cage-/281008929016?pt=LH_DefaultDomain_0&hash=item416d6ff8f8) and I have arduino mega. Is there any way to do that? PS: If I can use UTFT library (http://www.henningkarlsen.com/electronics/library.php?id=51) to do this I will be very happy :) because I have all pins connected to mega this way as displayed on this site (http://www.geeetech.com/wiki/index.php/3.2TFT_LCD).
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: PaulS on Dec 14, 2012, 07:33 pm
Quote
Can I displlay jpg or png images from SD card on a 3.2" display using arduino?

Using that library, no. Jpeg and PNG images are compressed. You would first need to decompress them. The Arduino does not have enough memory to do that.

You could display a bitmap file. It would be possible, if you have enough memory, to read the whole bitmap file into memory, and display it using drawBitmap(), since you are using a mega.

You could read the bitmap file one byte at a time, and determine where that byte corresponded to on the screen, and what color that pixel should be, and use drawPixel() to color that pixel.
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: sonic656 on Dec 14, 2012, 07:43 pm
But..... If you mean to do .c file from that image I already tried to do that but I need to have 320x240 image and can't burn it into mega because of not enough memory.....
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: AWOL on Dec 14, 2012, 08:13 pm
Quote
If you mean to do .c file from that image I already tried to do that

I can just about imagine doing JPEG decoding on a Mega, for a very restricted set of JPEG files.
It would be exceedingly slow, and an exercise in advanced hair-loss.

It may be possible to do some other form of compression on the image, but it really depends on the image content.

If you've already got an SD card, store the image in a file as a BMP.
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: KeithRB on Dec 14, 2012, 08:25 pm
Change the .c file to a .txt file and store it on the SD card.

Open the file, parse it a line at a time, and send it to the display one byte at a time, as mentioned earlier.
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: GoForSmoke on Dec 14, 2012, 08:50 pm
What Paul posted, use a .BMP file which can be read a pixel at a time... you -can- change a pixel at a time on the display?

Format Factory is free and will do the conversion.

Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: guix on Dec 14, 2012, 09:58 pm
There is the library UTFT_tinyFAT, it's an addon for the UTFT and tinyFAT libraries, it adds the function loadBitmap, which will do all the work for you... but, .bmp images only!

http://www.henningkarlsen.com/electronics/library.php?id=53
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: doc_norway on Dec 15, 2012, 02:44 am

but, .bmp images only!


Not quite correct there :)

loadBitmap() will only load raw, pre-processed files, but a conversion tool for Windows is included with UTFT, and there is also an online version on my website.

/Henning
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: foxbat on Dec 15, 2012, 08:16 am

Quote
If you mean to do .c file from that image I already tried to do that

I can just about imagine doing JPEG decoding on a Mega, for a very restricted set of JPEG files.
It would be exceedingly slow, and an exercise in advanced hair-loss.

It may be possible to do some other form of compression on the image, but it really depends on the image content.

If you've already got an SD card, store the image in a file as a BMP.


It's possible on the Mega for almost all JPEGs (only progressive jpegs are not supported), costs only 2.5Kb of SRAM while decoding and it's surprisingly fast. See my demo video at the bottom of  this article (http://andybrown.me.uk/wk/2012/08/19/nokia-n82-arduino). It won't work on the standard (2Kb SRAM) arduino - the huffman tables are just too large.
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: guix on Dec 15, 2012, 10:45 am

Not quite correct there :)

loadBitmap() will only load raw, pre-processed files, but a conversion tool for Windows is included with UTFT, and there is also an online version on my website.

/Henning


Sorry! I think you could easily add .bmp support, skip the first 54 bytes of the .bmp file, the rest is pixel data (you probably know that already!)..or is it more complex than that?


It's possible on the Mega for almost all JPEGs (only progressive jpegs are not supported), costs only 2.5Kb of SRAM while decoding and it's surprisingly fast. See my demo video at the bottom of  this article (http://andybrown.me.uk/wk/2012/08/19/nokia-n82-arduino). It won't work on the standard (2Kb SRAM) arduino - the huffman tables are just too large.


Very cool :)
Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: GoForSmoke on Dec 15, 2012, 12:19 pm
You might want to read the header to be more sure of the file (always check for errors! alternative is crash, lock or show garbage on error. our world is not perfect!) and handle different size pictures.

Title: Re: Display images (jpg/png) on a 3.2" display from SD card
Post by: doc_norway on Dec 15, 2012, 12:43 pm

..or is it more complex than that?


I am afraid it is quite a bit more complex... Take a look at this: http://en.wikipedia.org/wiki/BMP_file_format (http://en.wikipedia.org/wiki/BMP_file_format)

/Henning