Pages: [1]   Go Down
Author Topic: UTFT_tinyFAT Load Bitmap into Array  (Read 560 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Has anyone written a routine to load an image from an SD card into an array?

What I want is something like the "loadBitmap" function from the UTFT_tinyFAT library except I want to store the image in an array instead of displaying it directly on the TFT display.  Once I have all the images from the flash stored in arrays, I would use the "drawBitmap" function from the UTFT library to minipulate which image(s)/array(s) to put where on the screen.

Any ideas?

thank you in advance.

Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Calculate the size of the array? Will it fit on your Arduino?

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, there are 8 arrays (0xE10 each) on an Arduino Mega 2560.  If I hard code these arrays in the program, it compiles to a total size of 181,846 (of 258,048 bytes) with program and libraries and everything so I know it fits.  The problem is, at this size the program won't actually upload to the Mega; it just grinds on it for about 5 minutes and eventually times out.

I figure if I have the program just pull in the arrays from the SD, and then use the arrays as I am now it will compile and upload fine and then if I ever want to change the graphics, I can just update the images on the SD and not have to re-compile the program).

Thanks in advance for your help,
Ron

Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The size reported by the IDE does not include the the data space /RAM usage. What 8x0xe10 (converting it to decimal would help) is much greater than the available RAM.

Quote
If I hard code these arrays in the program

Are you using progmem?.

Mark
Logged

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1011
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have a program "ImageConverter565" in the UTFT/Tools folder, you can choose to save the image as a .c file that contain the progmem array.

Just saying, I'm currently writing a plugin for Paint.NET that does the same thing (and much more, with a UTFT addon). Release soon in my sig smiley-wink
« Last Edit: October 29, 2013, 09:57:39 am by guix » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The images are 60x60 which puts it at 3600 bytes/image (0xE10) for 16 images = 57.6k bytes.  (sorry I had put 8 images in the last post; there is an ON and an OFF image for each of the 8 so there are 16 total)

Yes, I am using ImageConverter 565 to create the .c files for each image.  Then I am then loading the .c files as external variables (see here).

extern unsigned int brake_off[0xE10];
extern unsigned int brake_on[0xE10];
extern unsigned int choke_off[0xE10];
extern unsigned int choke_on[0xE10];
extern unsigned int door_off[0xE10];
extern unsigned int door_on[0xE10];
extern unsigned int engine_off[0xE10];
extern unsigned int engine_on[0xE10];
extern unsigned int hatch_off[0xE10];
extern unsigned int hatch_on[0xE10];
extern unsigned int overdrive_off[0xE10];
extern unsigned int overdrive_on[0xE10];
extern unsigned int security_off[0xE10];
extern unsigned int security_on[0xE10];

Next, I am loading a pointer to those external variables from my own class as shown here:

MyControl._ButtonImages[0]=belts_off;
  MyControl._ButtonImages[1]=belts_on;
  MyControl._ButtonImages[2]=brake_off;
  MyControl._ButtonImages[3]=brake_on;
  MyControl._ButtonImages[4]=choke_off;
  MyControl._ButtonImages[5]=choke_on;
  MyControl._ButtonImages[6]=door_off;
  MyControl._ButtonImages[7]=door_on;
  MyControl._ButtonImages[8]=engine_off;
  MyControl._ButtonImages[9]=engine_on;
  MyControl._ButtonImages[10]=hatch_off;
  MyControl._ButtonImages[11]=hatch_on;
  MyControl._ButtonImages[12]=overdrive_off;
  MyControl._ButtonImages[13]=overdrive_on;
  MyControl._ButtonImages[14]=security_off;
  MyControl._ButtonImages[15]=security_on;

Finally, I use the drawButmap function from the UTFTtf library to draw the image from the array on the screen.

myGLCD.drawBitmap (LeftX, TopY, SizeX, SizeY, _ButtonImages[IndexOfImage2Display]);

With a couple images, this all works, but with all 16 it just locks up during upload (as previously stated).  Isn't there a better way?  Isn't loading the images from the SD a better option for populating the arrays?
Logged

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1011
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why don't you just use UTFT_TinyFAT?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I could use that to load an image directly to the screen, but for a control panel interface where the images will toggle back and forth, I was going to try and avoid the delay of reading images from flash every time an image changes.  My thought was that during initialization, I would just load the images into arrays and then just use "drawBitmap" to write the image from the arrays to the screen.

Starting with the "loadBitmap" function that you mention, I took a shot at a routine to load the bitmap to an array instead of the screen but I haven't tested it yet.  Here is my guess at what the function could look like.

word UTFTtf::loadBitmapArr(char *filename, unsigned int *bitmaparray[]){
/*************************************************************************************************************
filename = filename of "raw" file to load from SD card
bitmaparray = array to put data into
*************************************************************************************************************/
   int res;
   int cx, cy, cp;
   word temp, result;
   byte r,g,b;

   res=file.openFile(filename, FILEMODE_BINARY);
   if (res==NO_ERROR)
   {
      cbi(P_CS, B_CS);
      result=512;
      while (result==512)
      {
         result=file.readBinary();
         switch(result)
         {
            case ERROR_WRONG_FILEMODE:
               return ERROR_WRONG_FILEMODE;
               break;
            case ERROR_NO_FILE_OPEN:
               return ERROR_NO_FILE_OPEN;
               break;
            default:
               
               for (int i=0; i<result; i+=1)
               // bitmaparray=file.buffer;

               //LCD_Write_DATA(file.buffer,file.buffer[i+1]);
               break;
         }             
      }

      file.closeFile();
      sbi(P_CS, B_CS);
      return 0;
   }
   else
   {
      return res;
   }
};
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tell us what you think "extern" does, all it means is that it will be declared in another file, it does not mean put the data space on the SD card or in progmem so you still use up your 8k of ram.

Mark
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know where you're coming from... the code I posted shows the declaration of the external variables, and then the storing of those externs in arrays.  I pass those arrays to the "drawBitmap" function to display the data.  Now that the size of the images has grown pretty close to the available memory, the compiler is unable to upload the program to the device (even though it compiles fine without upload).  To work around this, I want to load the arrays from SD memory instead of grabbing them externally.

Do you know how I can do that?

Thank You
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Programs of the avr's split in two program in flash/eeprom and data in SRAM. Your arrays are in SRAM of which you have only 8k
to my count you have 14 arrays of 3600 bytes and thats a lot more than 8k. Externs still go in RAM!

Quote
Do you know how I can do that?

You cant. You cant copy them hrom the SD card or any where else to Sram that you do not have!.

Mark

Logged

France
Offline Offline
Edison Member
*
Karma: 38
Posts: 1011
Scientia potentia est.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ahh, sorry I finally understood what you want to do. I should stop smoking my garden xD. Yeah you basically can't do that with an arduino because not enough memory... Also an RGB565 image of size 60x60 is not 3600 bytes but twice more because one pixel color is 2 bytes.

Then my UTFT addon, when ready, could really interest you, for some simple graphic images where the colors repeat a lot (like for example a button with horizontal gradient) the size can be reduced a lot, meaning that it will be much faster to read it from the SD. It produces a filesize almost like .png, and in many cases much smaller, and should be very quick to draw on the screen but I haven't tested that yet.
« Last Edit: October 29, 2013, 06:23:42 pm by guix » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks soo much to everyone; I had already spent way too much time trying to write the routine, which could never work.  I'll try just loading from Flash and see how fast it ends up being.

Thanks
Logged

Poole, Dorset, UK
Offline Offline
Edison Member
*
Karma: 52
Posts: 2313
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There are at least two other ways around your problem.

A. Use program memory this creates the arrays in the flash/eeprom of the arduino and not in ram for details look in the playground. this requires that you convert the bmp in code which the IDE when builds in for you. guix offered to code to convert the bmp files. See the section on storage in the playground or/and google "progmem".

B. Take look at this for the Megas http://ruggedcircuits.com/html/megaram.html

Mark
Logged

Pages: [1]   Go Up
Jump to: