1. # Demo: blitting of images in memory with SDL2 in Raspian-Stretch
  2.  
  3. from os import listdir
  4. import sys
  5. import time
  6. from sdl2 import *
  7.  
  8. # Initialize SDL2
  9. SDL_Init(SDL_INIT_VIDEO)
  10.  
  11. try:
  12.   # create fullscreen display
  13.   win = SDL_CreateWindow(b"Fast Blitting", 0,0,0,0, SDL_WINDOW_FULLSCREEN)
  14.   screen = SDL_GetWindowSurface(win)
  15.  
  16.   # load all image files (BMP) in folder 'images' into surfaces in RAM
  17.   images = []
  18.   folder = 'fotos'
  19.   files = listdir(folder)
  20.   for f in files:
  21.     img = SDL_LoadBMP((folder+'/'+f).encode())
  22.     images.append(img)
  23.  
  24.   # blit 100 images
  25.   cnt = len(images)
  26.   t_start = time.time()
  27.   for i in range(100):
  28.  
  29.     # blit next image into screen buffer
  30.     SDL_BlitSurface(images[i % cnt], None, screen, None)
  31.  
  32.     # load screen buffer into actual screen
  33.     SDL_UpdateWindowSurface(win)
  34.  
  35.   # show fps
  36.   sec = time.time()-t_start
  37.   print("fps: "+str(100/sec))
  38.  
  39. except:
  40.   print(sys.exc_info())
  41.  
  42. # clean up
  43. if 'win' in locals():
  44.   if 'images' in locals():
  45.     for img in images: SDL_FreeSurface(img)
  46.   SDL_DestroyWindow(win)
  47. SDL_Quit()
  48.  
[raw code]