make_splash.py 939 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. # pip install pillow to get the PIL module
  3. import sys
  4. from PIL import Image
  5. def main(fn, id):
  6. image = Image.open(fn)
  7. print("\n"
  8. "#define {id}_width {w}\n"
  9. "#define {id}_height {h}\n"
  10. "\n"
  11. "const uint8_t PROGMEM {id}_data[] = {{\n"
  12. .format(id=id, w=image.width, h=image.height), end='')
  13. for y in range(0, image.height):
  14. for x in range(0, (image.width + 7)//8 * 8):
  15. if x == 0:
  16. print(" ", end='')
  17. if x % 8 == 0:
  18. print("0b", end='')
  19. bit = '0'
  20. if x < image.width and image.getpixel((x,y)) != 0:
  21. bit = '1'
  22. print(bit, end='')
  23. if x % 8 == 7:
  24. print(",", end='')
  25. print()
  26. print("};")
  27. if __name__ == '__main__':
  28. if len(sys.argv) < 3:
  29. print("Usage: {} <imagefile> <id>\n".format(sys.argv[0]), file=sys.stderr);
  30. sys.exit(1)
  31. fn = sys.argv[1]
  32. id = sys.argv[2]
  33. main(fn, id)