make_header.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python
  2. import glob
  3. import os
  4. enc = "utf-8"
  5. # Change to the directory where the script is located,
  6. # so that the script can be run from any location
  7. os.chdir(os.path.dirname(os.path.realpath(__file__)))
  8. # Generate include files
  9. f = open("theme_data.h", "wb")
  10. f.write(b"// THIS FILE HAS BEEN AUTOGENERATED, DON\'T EDIT!!\n")
  11. # Generate png image block
  12. f.write(b"\n// png image block\n")
  13. pixmaps = glob.glob("*.png")
  14. pixmaps.sort()
  15. for x in pixmaps:
  16. var_str = x[:-4] + "_png"
  17. s = "\nstatic const unsigned char " + var_str + "[] = {\n\t"
  18. f.write(s.encode(enc))
  19. pngf = open(x, "rb")
  20. b = pngf.read(1)
  21. while(len(b) == 1):
  22. f.write(hex(ord(b)).encode(enc))
  23. b = pngf.read(1)
  24. if (len(b) == 1):
  25. f.write(b", ")
  26. f.write(b"\n};\n")
  27. pngf.close()
  28. # Generate shaders block
  29. f.write(b"\n// shaders block\n");
  30. shaders = glob.glob("*.gsl")
  31. shaders.sort()
  32. for x in shaders:
  33. var_str = x[:-4] + "_shader_code"
  34. s = "\nstatic const char *" + var_str + " = \n"
  35. f.write(s.encode(enc))
  36. sf = open(x, "rb")
  37. b = sf.readline()
  38. while(b != ""):
  39. if (b.endswith("\r\n")):
  40. b = b[:-2]
  41. if (b.endswith("\n")):
  42. b = b[:-1]
  43. s = ' \"' + b
  44. f.write(s.encode(enc))
  45. b = sf.readline()
  46. if (b != ""):
  47. f.write(b'"\n')
  48. f.write(b'";\n')
  49. sf.close()
  50. f.close()