arduinoprojects

git clone https://git.tarina.org/arduinoprojects
Log | Files | Refs

make_splash.py (938B)


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