Hey all
I wonder if any of the collective genious out there can help me?
I have a project that requires drawing a small portion (240x240px) of a large image (4000x4000px) to TFT. I have figured out the offset maths and produced valid screen displays, BUT it is taking approx 18 seconds to draw this 240x240px image!!! This is way too slow for what I want.
Back in my younger days of BBC Micro B programming, I remember 'peeking' and 'poking' operating system memory, which was MUCH faster than OS calls to do the same thing.....Is there anything similar on Arduino?
My current setup is a MEGA2560/ITDB32S/Touch/SD.
My present code is thus :-
void drawmap(unsigned int offsetx, unsigned int moffsetx, unsigned int msizex, unsigned int offsety, unsigned int moffsety, unsigned int msizey, char filename)
{
unsigned long thisroutine, singleLine, foffset;
byte b,g,r;
thisroutine=millis();
offsetx=offsetx3;
// myprintf("Mapref %s\n",mapref);
// myprintf("Filename %s\n",filename);
// myprintf("mylocation (x,y) (%d,%d)",mylocation.x,mylocation.y);
// myprintf("maplocation (x,y) (%d,%d)",maplocation.x,maplocation.y);
// myprintf("screenlocation (x,y) (%d,%d)",screenlocation.x,screenlocation.y);
File dataFile = SD.open(filename);
// file.initFAT(SPISPEED_VERYHIGH);
if (!dataFile) {myprintf("File Open failed, or not present\n");return;}
else
{
// myprintf("Opened bmp successfully!! Time taken %d ms\n",millis()-thisroutine);
// thisroutine=millis();
dataFile.read(&header.type,2);
dataFile.read(&header.size,4);
dataFile.read(&header.reserved1,2);
dataFile.read(&header.reserved2,2);
dataFile.read(&header.offset,4);
dataFile.read(&infoheader.size,4);
dataFile.read(&infoheader.width,2);
dataFile.read(&infoheader.height,2);
dataFile.read(&infoheader.planes,2);
dataFile.read(&infoheader.bits,2);
singleLine=(infoheader.width)*3;
// myprintf("BMP Headers read in %d ms\n",millis()-thisroutine);
// thisroutine=millis();
for (int y=moffsety; y<moffsety+msizey; y++)
{
timer.run();
foffset=((y+offsety)*singleLine)+offsetx+header.offset;
dataFile.seek(foffset);
for (int x=moffsetx; x<moffsetx+msizex;x++)
{
b=dataFile.read();
g=dataFile.read();
r=dataFile.read();
myGLCD.setColor(r,g,b);
myGLCD.drawPixel(x,240-y);
}
}
}
//ticker=0;
dataFile.close();
// myprintf("Closed bmp successfully!!\n");
// end of drawmap
myprintf("Routine finished in %d ms\n",millis()-thisroutine);
}
I am using the fabulous Henning Karlson libraries, but still it is way too slow.....
The average re-draw time using the code shown is 17963ms per re-draw.....
Could anyone propose an alternative method of doing this with faster results please?
Thanks in advance!
Graham