1. # Converts all image files in folder to a single RAW image data file (in 32-bit
  2. # format ARGB8888) that can be used as input for textures.
  3. # If 'repeat'>1, the image sequence is repeated 'repeat' times (i.e. if folder
  4. # contains 10 pix, repeat=10 means that the RAW file has a total of 100 frames)
  5.  
  6. from os import listdir
  7. from sdl2 import *
  8. from sdl2.sdlimage import IMG_Load as SDL_LoadImage
  9.  
  10. ########################################
  11. # CONFIG
  12. ########################################
  13. image_folder = 'fotos_1366'
  14. raw_file = 'test_1366_32bit_100.raw'
  15. repeat = 10
  16.  
  17. ########################################
  18. # START
  19. ########################################
  20.  
  21. # create RAW file and open it for writing
  22. rw = SDL_RWFromFile(raw_file.encode(), b'wb')
  23.  
  24. files = listdir(image_folder)
  25. for i in range(repeat):
  26.     for f in files:
  27.  
  28.         # load image file
  29.         img = SDL_LoadImage((image_folder+'/'+f).encode())
  30.  
  31.         # convert image to 32-bit (SDL_PIXELFORMAT_ARGB8888)
  32.         img32 = SDL_ConvertSurfaceFormat(img, SDL_PIXELFORMAT_ARGB8888, 0)
  33.         SDL_FreeSurface(img)
  34.  
  35.         # write image data into RAW file
  36.         data_size = img32.contents.w * img.contents.h * 4
  37.         res = SDL_RWwrite(rw.contents, img32.contents.pixels, data_size, 1)
  38.         if res<0:
  39.             print(SDL_GetError().decode())
  40.  
  41.         SDL_FreeSurface(img32)
  42.  
  43. # close the RAW file
  44. SDL_RWclose(rw.contents)
  45.  
  46. print('Done.')
  47.  
[raw code]