Convert image file to data/array?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

*Sorry if I'm in the wrong forum, not sure where this one fits!*

Hi I'm doing a project with a colour LCD where I would like to put an image on it.
Say I wanted to take a JPEG/BMP/whatever file and convert it (on my PC) to an array of values that I can store in the flash and later write to the LCD...

How would I go about creating my array of values from the image file? Are there any programs or web pages that can do it for me automatically?

I don't want to do JPEG decoding in the micro (at least yet)!

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Personally I like xxd.exe that comes with Vim for Windows (you can download the .zip and take just xxd.exe from it).

If you happen to use avr-gcc then avr-obcopy can simply convert a binary file into a linkable object.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

matlab. There is a function called imread to do this.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Imagemagic's 'convert' can convert many image formats into as many image formats -> once your avr can read a format, it becomes rather flexible (works as a command line).

Thanks, Clawson, for making me know xxd (comes with cygwin, too, and GNUlinux) can convert binary into ASCII (hex dumps).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

can convert binary into ASCII (hex dumps).

I guess you spotted the -i option too? That outputs C source. Example of converting foo.bin to C here:

https://www.avrfreaks.net/index.p...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks a lot for the link (before you posted it, I had not noticed it had a man file -I know I should have-). I have been puzzled for years, in reading elektor's C sources for graphical screens, how they had managed to produce such huge C data arrays... And I guess Monsieur Geronimo can decode (almost) any image format on his PC, and get code for his AVR...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What PC tool do you use?
I use delphi and there it's a 5 min job to make a program that read a picture as a array, and make a data file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for the replies so far!

I found a HEX editor and tried making a simple BMP file in mspaint and take a look at it! Looks pretty straight-forward, just dump the first 55 bytes and the rest is the image data in sequential order (starting bottom left), nice and easy!

My LCD must be written in sequential order too so this looks like a super simple solution!

I think I could probably use xxd to do this, I'll try to see if I can make it work!

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm interested in seeing where you store the 320x240->76800 bytes. (with a 256 color palette perhaps). A mega2560 would hold it. I guess one could make a slide show from an sd card.

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bob I don't think I ever said anything about my LCD or micro! ;)

320x240 would be 230,400 bytes (24-bit/pixel)! My LCD is "just" 220x176 pixels and 18 bit/pixel so only roughly 116 kB or about half! It can also run with a reduced colour resolution which I'm considering, as this would mean I could update the LCD faster and it would take less flash memory!

But for now I'm okay with using the full 24-bit information :)

But of course I did the math before asking, no problems! It will "only" use about half my flash!

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yep, I made it work! Thanks all! :)

Attachment(s): 

- Brian

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Very pretty :-)