Go Down

Topic: What is the buffer when reading in a file ? (Read 337 times) previous topic - next topic

debzsud

Hello everyone,

I'm loading pictures from a USB device to plot them on a screen with an arduino Mega 256. Basically, it takes 4000 ms to do it. The pictures are 320*240px BMP file of 24 bit depth.
Here is the code: 
 
Code: [Select]

for (row=0; row<h; row++) { // For each scanline...
          if(bmpFile.position() != pos) {
            bmpFile.seek(pos);
            buffidx = sizeof(sdbuffer);
          }

          for (col=0; col<w; col++) { // For each pixel...
            if (buffidx >= sizeof(sdbuffer)) {
              bmpFile.read(sdbuffer, sizeof(sdbuffer));
              buffidx = 0;
            }
           
            //read the buffer
            b = sdbuffer[buffidx++];
            g = sdbuffer[buffidx++];
            r = sdbuffer[buffidx++];

            //send the pixel to the screen
            tft.pushColor(tft.color565(r,g,b));
          } // end pixel
        } // end scanline


I realised that if I comment the tree lines, it takes only 2000ms to load the picture:

Code: [Select]

b = sdbuffer[buffidx++];
g = sdbuffer[buffidx++];
r = sdbuffer[buffidx++];


So I wonder if the buffer is stored on the arduino or if it is a buffer on the USB shield, which would explain this loss of time.


fat16lib

It goes faster since you don't read the file when those line are commented out.

When the lines are commented out, buffidx is not incremented so this tests fails after the first column.
Code: [Select]

if (buffidx >= sizeof(sdbuffer)) {


What is the purpose of the test?

Go Up