import sys from PIL import Image image = Image.open(sys.argv[1]) assert image.size == (84, 48), "image size is not 84x48" def binarize(pixel): r, g, b, a = pixel assert a == 255, "image has a transparent pixel" assert (r, g, b) == (0, 0, 0) or (r, g, b) == (255, 255, 255), "image is not a binary image" return r // 255 pixels = list(map(binarize, image.getdata())) frame_buffer = [0] * 504 def set_buffer(x, y, pixel): global frame_buffer p = x + y // 8 * 84 if pixel: frame_buffer[p] |= 2 ** (y % 8) else: frame_buffer[p] &= ~(2 ** (y % 8)) for x in range(84): for y in range(48): i = y * 84 + x set_buffer(83 - x, 47 - y, not pixels[i]) # Rotate 180 degrees and invert the color print("const uint8_t image[504] PROGMEM = {") for byte in frame_buffer: print(f" 0x{byte:02x},") print("};")