Animated bitmaps


#1

Hi guys’

While im very slowly figuring out how to do gifs on the teensy flash i wanted to try using bitmaps to display an animation. I added the below to the BITMAP example and it does work displaying 5 animated 16x16 color bitmaps going from right to left accross the screen in a line following one another, it however is painfully slow. What ive done im sure is a dodgy way to do it so that may well be why it is slow or im just doing it wrong. Any suggestions on how to improve would be very welcome… The slow down was gradual as i added each separate bitmap as with one animated 16x16 bitmap alone the speed was way to fast requiring delays…

` void BITMAP() {
 matrix.setBrightness(30);
int x, y;

 x = 64; 
 y = 12;

while (x > -82) {
 


 drawBitmap(x,y,&yellowframe1left);        
  dackgroundLayer.swapBuffers();

 drawBitmap(x+25,y,&redleftframe1);          
  backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe2);          
 backgroundLayer.swapBuffers();

drawBitmap(x+55,y,&blueleftframe1);          
 backgroundLayer.swapBuffers();

drawBitmap(x+70,y,&orangeleftframe2);           
 backgroundLayer.swapBuffers();


//delay(20);
 x = x-1;
drawBitmap(x,y,&yellowframe1left);           
 backgroundLayer.swapBuffers();



drawBitmap(x+25,y,&redleftframe1);          
 backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+55,y,&blueleftframe1);          
 backgroundLayer.swapBuffers();

drawBitmap(x+70,y,&orangeleftframe2);        
 backgroundLayer.swapBuffers();


//delay(20);

   x = x-1; 

drawBitmap(x,y,&yellowframe2left);          
 backgroundLayer.swapBuffers();


drawBitmap(x+25,y,&redleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe1);          
 backgroundLayer.swapBuffers();

drawBitmap(x+55,y,&blueleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+70,y,&orangeleftframe1);           
 backgroundLayer.swapBuffers();

//delay(20);

  x = x-1; 

drawBitmap(x,y,&yelloframe2left);           
 backgroundLayer.swapBuffers();


drawBitmap(x+25,y,&redleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe1);          
 backgroundLayer.swapBuffers();

drawBitmap(x+55,y,&blueleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+70,y,&orangeleftframe1);           
 backgroundLayer.swapBuffers();

//delay(20);



  x = x-1;

  drawBitmap(x,y,&yellowframe3);          
  backgroundLayer.swapBuffers();

drawBitmap(x+25,y,&redleftframe2);          
 backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe1);          
 backgroundLayer.swapBuffers();

  drawBitmap(x+55,y,&blueleftframe2);           
 backgroundLayer.swapBuffers();
//delay(20);

drawBitmap(x+70,y,&orangeleftframe1);           
 backgroundLayer.swapBuffers();





 x = x-1;
  drawBitmap(x,y,&yellowframe3);     
 backgroundLayer.swapBuffers();

drawBitmap(x+25,y,&redleftframe2);           
 backgroundLayer.swapBuffers();

drawBitmap(x+40,y,&pinkleftframe1);           
 backgroundLayer.swapBuffers();

//delay(200);

drawBitmap(x+55,y,&blueleftframe2);          
 backgroundLayer.swapBuffers();

drawBitmap(x+70,y,&orangeleftframe1);           
 backgroundLayer.swapBuffers();


x = x-1;
}






delay(1000);

 backgroundLayer.fillScreen({0,0,0});







}

`


#2

Dan, you don’t need to do swapBuffers() after each draw. You can do one swap call per frame, so from what you described, you can do 5x drawBitmap() calls drawing the bitmaps to the buffer, then one swapBuffers() call that draws it to the screen.


#3

Thanks Louis’

I did try playing around with swapBuffers() with some weird results that i couldn’t quite understand…looks like i was doing it wrong… Ill try what you say tonight and see how it goes…

Thanks again


#4

Gday Louis’

Thanks, removing the unnecessary swapbuffers() increased the frame rate to an acceptable level, still not super fast as im using a 64x64 panel but acceptable.

Now my only problem is the teensy complaining about the ram being almost used up at 97%…


#5

You can lower the kRefreshDepth and kDmaBufferRows to try to reduce ram. There’s some documentation in the AnimatedGIFs example, but 64x64 is pushing the limits of the Teensy 3.2


#6

unfortunately if i lower either of them gif playback is not acceptable…

The gif decoder option lzwMaxBits i think is the memory hog for me, but setting it lower than 12 causes most GIFS to start displaying wrong…tearing etc…