63 lines
1.2 KiB
Python
Executable File
63 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|
|
|
|
# 128x64
|
|
# convert gnaa.png +dither -monochrome -colors 2 image.bmp
|
|
|
|
|
|
from PIL import Image
|
|
import sys
|
|
#import zlib
|
|
|
|
invert = 0
|
|
|
|
def set_bit(value, bit):
|
|
return value | (1<<bit)
|
|
|
|
def clear_bit(value, bit):
|
|
return value & ~(1<<bit)
|
|
|
|
im = Image.open(sys.argv[1])
|
|
buffer = []
|
|
|
|
for bank in range(0, 8):
|
|
for x in range(0, 128):
|
|
bits = ""
|
|
value = 0
|
|
if (invert == 1):
|
|
value = 255
|
|
c = 7
|
|
for y in range(bank * 7 + 7, bank * 7 - 1, -1):
|
|
b = im.getpixel((x,y))
|
|
|
|
if (b == 1 or b == 255):
|
|
value = set_bit(value, c)
|
|
if (invert == 1):
|
|
value = clear_bit(value, c)
|
|
c = c - 1
|
|
buffer.append(value)
|
|
|
|
#buffer = zlib.compress(bytes(buffer))
|
|
|
|
c = 0
|
|
bytes_per_line = 10
|
|
|
|
print('#include "image.h"')
|
|
print()
|
|
print("uint8_t image[" + str(len(buffer)) + "] = {")
|
|
|
|
for v in buffer:
|
|
if c == 0:
|
|
print(" ", end='')
|
|
|
|
print(format(v, '#04x') + ", ", end='')
|
|
c = c + 1
|
|
if (c == bytes_per_line):
|
|
print()
|
|
c = 0
|
|
|
|
if (c <= bytes_per_line):
|
|
print()
|
|
print("};")
|
|
print() |