x
This commit is contained in:
parent
bfcc5fa70b
commit
433eff8023
91
firmware/png2bi.py
Normal file
91
firmware/png2bi.py
Normal file
@ -0,0 +1,91 @@
|
||||
from PIL import Image as img
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print('Need image path as filename')
|
||||
exit(0)
|
||||
|
||||
fname = sys.argv[1]
|
||||
|
||||
im = img.open(fname, 'r')
|
||||
|
||||
raw_pixels = list(im.getdata())
|
||||
|
||||
width = im.width
|
||||
|
||||
x = 0
|
||||
|
||||
_pix = []
|
||||
|
||||
pixels = []
|
||||
|
||||
for i in raw_pixels:
|
||||
_pix.append(i)
|
||||
x+=1
|
||||
if x == width:
|
||||
x = 0
|
||||
pixels.append(_pix)
|
||||
_pix = []
|
||||
|
||||
for i in range(0, len(pixels)):
|
||||
for j in range(0, len(pixels[i])):
|
||||
if pixels[i][j] < 50:
|
||||
pixels[i][j] = "0"
|
||||
else:
|
||||
pixels[i][j] = "1"
|
||||
|
||||
true_pixels = []
|
||||
|
||||
for i in pixels:
|
||||
st = ''
|
||||
for j in i:
|
||||
st += j
|
||||
true_pixels.append(st)
|
||||
|
||||
final_pixels = []
|
||||
|
||||
|
||||
_bdata = ''
|
||||
mod_length = len(i) % 8
|
||||
full_length = (len(i) / 8) - mod_length
|
||||
|
||||
for iterator in range(0, len(true_pixels)):
|
||||
|
||||
it = 0
|
||||
counter = 0
|
||||
do = True
|
||||
_bdata = 'B'
|
||||
|
||||
while do:
|
||||
if (counter*8+it) < len(i):
|
||||
_bdata += true_pixels[iterator][counter*8 + it]
|
||||
|
||||
elif it != 0:
|
||||
_bdata += '0'
|
||||
|
||||
else:
|
||||
do = False
|
||||
|
||||
it+=1
|
||||
|
||||
if (it == 8) and (counter*8+it) < len(i):
|
||||
it = 0
|
||||
_bdata+=', B'
|
||||
counter+=1
|
||||
|
||||
|
||||
elif (it == 8):
|
||||
it = 0
|
||||
if iterator != len(true_pixels)-1:
|
||||
_bdata+=','
|
||||
counter+=1
|
||||
final_pixels.append(_bdata)
|
||||
|
||||
print("static const unsigned char PROGMEM var_name[] = {")
|
||||
for i in final_pixels:
|
||||
print(" " + i)
|
||||
print("};")
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user