60 lines
1.1 KiB
Python
Executable File
60 lines
1.1 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
|
|
|
|
invert = 0
|
|
|
|
def set_bit(value, bit):
|
|
return value | (1<<bit)
|
|
|
|
def clear_bit(value, bit):
|
|
return value & ~(1<<bit)
|
|
|
|
im = Image.open("image.bmp")
|
|
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)
|
|
|
|
|
|
c = 0
|
|
bytes_per_line = 10
|
|
|
|
print('#include "image.h"')
|
|
print()
|
|
print("uint8_t image[1024] = {")
|
|
|
|
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() |