Skip to content

Instantly share code, notes, and snippets.

@drewcassidy
Last active September 18, 2016 00:17
Show Gist options
  • Save drewcassidy/9d5d4b0cf8d79c296324e30750bca645 to your computer and use it in GitHub Desktop.
Save drewcassidy/9d5d4b0cf8d79c296324e30750bca645 to your computer and use it in GitHub Desktop.
import os
dest = open("source/bitmaps.cpp", "w+")
head = open("source/bitmaps.h", "w+")
dest.write("#include \"bitmaps.h\"\n")
head.write("#ifndef BITMAPS_H\n#define BITMAPS_H\n")
for file in os.listdir("bitmaps"):
if file != ".DS_Store":
size = os.stat("bitmaps/" + file).st_size
source = open("bitmaps/" + file, "r+b")
head.write("extern uint8_t " + file.title() + "[" + str(size) + "];\n")
dest.write("const uint8_t " + file.title() + "[" + str(size) + "] = {")
counter = 3
byte = int(source.read(1))
while source.tell() != size:
counter = counter + 1
if counter == 8:
dest.write("\n ")
counter = 0
dest.write(" " + hex(byte))
if source.tell() != size - 1:
dest.write(",")
byte = source.read(1)
dest.write("\n};\n\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment