Trouble with pointers and datatypes

05 May 2012

So I'm trying to display an image using a VGA lcd. The function is defined as follows:

void TSLCDShowPic2(sx,ex,sy,ey,const unsigned short *pic,mode);

It's asking for the image to be const unsigned short* . I have the pic in my local file system as "/local/pic.bmp" but this is a string. Basically I'm asking how am I supposed to do this??

I'm using the library from http://mbed.org/users/robodude666/programs/QVGATest/5zjbr

Everything else is working fine such as shapes text and lines but i cant get the image to work

Thanks!

06 May 2012

Christian Valenti wrote:

Basically I'm asking how am I supposed to do this??

Well, there's the manual way and the "get inspiration" way. If you want to do it all yourself, the stages are:

  1. Use filesystem calls to open the "local/pic.bmp".
  2. Read it in and parse its datastructures (wiki is a good start http://en.wikipedia.org/wiki/BMP_file_format, but may not be the best reference for implementation).
  3. If you have control over the file, it looks like you can save in a version of BMP which won't need any conversion (16-bit: 5 bits red, 6 bits green, 5 bits blue). In this case once you find where the data is in the file you can probably load it and pass it directly to TSLCDShowPic2.
  4. Otherwise, you'll have to convert it in the mbed yourself, which could get nasty.

For inspiration, this page: http://mbed.org/cookbook/SPI-driven-QVGA-TFT seems to have links to very similar code (BMP_16 in particular. The LCD code is likely completely different).

At a pure C level, what you read from the file will be (at least easily convertible to) "char *" which you can cast to "unsigned short *" to pass in directly. The trick is getting the right data.

Tim