New UI merged

This commit is contained in:
Bertrand Songis
2019-08-28 20:50:14 +02:00
parent 1f41076b0e
commit f4f8893ae9
806 changed files with 30836 additions and 11704 deletions
+6 -7
View File
@@ -24,9 +24,7 @@ chars = chars_en + chars_extra + chars_fr + chars_de + chars_cz + chars_es + cha
def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, background, coordsfile=True):
coords = []
coords = [fontsize + 4]
font_filename = 'fonts/' + fontname + '.ttf'
print("Font filename: %s" % font_filename)
@@ -37,7 +35,7 @@ def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, backg
try:
extraImage = Image.open(extraFilename)
extraImage = extraImage.convert('RGB');
extraImage = extraImage.convert('RGB')
except IOError:
print("Missing extra symbol filename %s" % extraFilename)
@@ -67,6 +65,8 @@ def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, backg
width = getFontWidth()
image = Image.new('RGB', (width, fontsize + 4), background)
print(fontsize + 4)
draw = ImageDraw.Draw(image)
width = 0
@@ -75,7 +75,7 @@ def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, backg
if c in chars_extra:
if extraImage and c == chars_extra[0]:
image.paste(extraImage.copy(),(width,1))
image.paste(extraImage.copy(), (width, fontsize % 2))
elif c == " ":
pass
else:
@@ -92,6 +92,5 @@ def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, backg
f.write(",".join(str(tmp) for tmp in coords))
# Main
if __name__ == "__main__":
createFontBitmap(sys.argv[4], sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), (0,0,0), (255,255,255))
createFontBitmap(sys.argv[4], sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), (0, 0, 0), (255, 255, 255))
+188 -177
View File
@@ -6,9 +6,10 @@ import sys
import os.path
from PIL import Image
class RLE_encoder:
RLE_BYTE = 0
RLE_SEQ = 1
RLE_SEQ = 1
def __init__(self, out):
self.state = self.RLE_BYTE
@@ -22,7 +23,6 @@ class RLE_encoder:
return in_byte == self.prev_byte
def encode_byte(self, in_byte):
if self.state == self.RLE_BYTE:
self.out(in_byte)
if self.eq_prev_byte(in_byte):
@@ -48,7 +48,8 @@ class RLE_encoder:
if self.state == self.RLE_SEQ:
self.out(self.count)
class dummy_encoder:
class DummyEncoder:
def __init__(self, out):
self.out = out
@@ -58,207 +59,217 @@ class dummy_encoder:
def encode_end(self):
pass
def writeSize(f, width, height):
if lcdwidth > 255:
def write_size(f, width, height):
if lcd_width > 255:
f.write("%d,%d,%d,%d,\n" % (width % 256, width // 256, height % 256, height // 256))
else:
f.write("%d,%d,\n" % (width, height))
def F_writeValue(f):
def writeValue(value):
f.write("0x%02x," % value)
return writeValue
def F_getPixelCoord():
def getCoord(x,y):
return (x,y)
def getCoord(x, y):
return x, y
return getCoord
def F_getPixelCoord_R(w,h):
def getCoord(x,y):
return (w-x-1, h-y-1)
def F_getPixelCoord_R(w, h):
def getCoord(x, y):
return w-x-1, h-y-1
return getCoord
## MAIN ##
image = Image.open(sys.argv[1])
width, height = image.size
def main():
global lcd_width
image = Image.open(sys.argv[1])
width, height = image.size
image_fmt = image.format
output_filename = sys.argv[2]
image_fmt = image.format
output_filename = sys.argv[2]
with open(output_filename, "w") as f:
lcdwidth = int(sys.argv[3])
with open(output_filename, "w") as f:
lcd_width = int(sys.argv[3])
if len(sys.argv) > 4:
s = sys.argv[4].split('-')
what = s[0]
pixel_coord = F_getPixelCoord()
if (len(s) > 1) and (s[1] == 'R'):
pixel_coord = F_getPixelCoord_R(width,height)
else:
for s in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"):
if s in sys.argv[2]:
what = s
break
if len(sys.argv) > 4:
s = sys.argv[4].split('-')
what = s[0]
pixel_coord = F_getPixelCoord()
if (len(s) > 1) and (s[1] == 'R'):
pixel_coord = F_getPixelCoord_R(width,height)
else:
for s in ("03x05", "04x06", "05x07", "08x10", "10x14", "22x38"):
if s in sys.argv[2]:
what = s
break
extension = os.path.splitext(output_filename)[1]
out = F_writeValue(f)
extension = os.path.splitext(output_filename)[1]
out = F_writeValue(f)
if extension == ".rle" or ((len(sys.argv) > 5) and (sys.argv[5] == "rle")):
encoder = RLE_encoder(out)
else:
encoder = dummy_encoder(out)
if extension == ".rle" or ((len(sys.argv) > 5) and (sys.argv[5] == "rle")):
encoder = RLE_encoder(out)
else:
encoder = DummyEncoder(out)
if what == "1bit":
rows = 1
if len(sys.argv) > 5:
rows = int(sys.argv[5])
image = image.convert(mode='1')
writeSize(f, width, height // rows)
for y in range(0, height, 8):
for x in range(width):
value = 0
for z in range(8):
if y + z < height:
if image_fmt == 'XBM':
if image.getpixel((x, y + z)) > 0:
value += 1 << z
else:
if image.getpixel((x, y + z)) == 0:
value += 1 << z
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "4bits":
colors = []
writeSize(f, width, height)
image = image.convert(mode='L')
for y in range(0, height, 2):
for x in range(width):
value = 0xFF
gray1 = image.getpixel((x, y))
if y + 1 < height:
gray2 = image.getpixel((x, y + 1))
else:
gray2 = 255
for i in range(4):
if (gray1 & (1 << (4 + i))):
value -= 1 << i
if (gray2 & (1 << (4 + i))):
value -= 1 << (4 + i)
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "8bits":
colors = []
writeSize(f, width, height)
image = image.convert(mode='L')
for y in range(height):
for x in range(width):
value = image.getpixel((x, y))
value = 0x0f - (value >> 4)
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "4/4/4/4":
constant = sys.argv[2].upper()[:-4]
values = []
writeSize(f, width, height)
for y in range(height):
for x in range(width):
pixel = image.getpixel(pixel_coord(x, y))
val = ((pixel[3] // 16) << 12) + ((pixel[0] // 16) << 8) + ((pixel[1] // 16) << 4) + ((pixel[2] // 16) << 0)
encoder.encode_byte(val & 255)
encoder.encode_byte(val >> 8)
encoder.encode_end()
#f.write("\n};\n")
#if extension != ".rle":
# f.write("const Bitmap %s(BMP_ARGB4444, %d, %d, (uint16_t*)__%s);\n" % (constant, width, height, constant))
elif what == "5/6/5":
constant = sys.argv[2].upper()[:-4]
values = []
writeSize(f, width, height)
for y in range(height):
for x in range(width):
pixel = image.getpixel(pixel_coord(x, y))
val = ((pixel[0] >> 3) << 11) + ((pixel[1] >> 2) << 5) + ((pixel[2] >> 3) << 0)
encoder.encode_byte(val & 255)
encoder.encode_byte(val >> 8)
encoder.encode_end()
#f.write("\n};\n")
#if extension != ".rle":
# f.write("const Bitmap %s(BMP_RGB565, %d, %d, (uint16_t*)__%s);\n" % (constant, width, height, constant))
elif what == "03x05":
image = image.convert(mode='L')
for y in range(0, height, 5):
for x in range(width):
value = 0
for z in range(5):
if image.getpixel((x, y + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
elif what == "04x06":
image = image.convert(mode='L')
for y in range(0, height, 7):
for x in range(width):
value = 0
for z in range(7):
if image.getpixel((x, y + z)) == 0:
value += 1 << z
if value == 0x7f:
value = 0xff
f.write("0x%02x," % value)
f.write("\n")
elif what == "05x07":
image = image.convert(mode='L')
for y in range(0, height, 8):
for x in range(width):
value = 0
for z in range(8):
if image.getpixel((x, y + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
elif what == "08x10":
image = image.convert(mode='L')
for y in range(0, height, 12):
for x in range(width):
skip = True
for l in range(0, 12, 8):
if what == "1bit":
rows = 1
if len(sys.argv) > 5:
rows = int(sys.argv[5])
image = image.convert(mode='1')
write_size(f, width, height // rows)
for y in range(0, height, 8):
for x in range(width):
value = 0
for z in range(8):
if l + z < 12:
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
if y + z < height:
if image_fmt == 'XBM':
if image.getpixel((x, y + z)) > 0:
value += 1 << z
else:
skip = False
if skip and l == 8:
if image.getpixel((x, y + z)) == 0:
value += 1 << z
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "4bits":
colors = []
write_size(f, width, height)
image = image.convert(mode='L')
for y in range(0, height, 2):
for x in range(width):
value = 0xFF
gray1 = image.getpixel((x, y))
if y + 1 < height:
gray2 = image.getpixel((x, y + 1))
else:
gray2 = 255
for i in range(4):
if gray1 & (1 << (4 + i)):
value -= 1 << i
if gray2 & (1 << (4 + i)):
value -= 1 << (4 + i)
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "8bits":
colors = []
write_size(f, width, height)
image = image.convert(mode='L')
for y in range(height):
for x in range(width):
value = image.getpixel((x, y))
value = 0x0f - (value >> 4)
encoder.encode_byte(value)
f.write("\n")
encoder.encode_end()
elif what == "4/4/4/4":
constant = sys.argv[2].upper()[:-4]
values = []
write_size(f, width, height)
for y in range(height):
for x in range(width):
pixel = image.getpixel(pixel_coord(x, y))
val = ((pixel[3] // 16) << 12) + ((pixel[0] // 16) << 8) + ((pixel[1] // 16) << 4) + ((pixel[2] // 16) << 0)
encoder.encode_byte(val & 255)
encoder.encode_byte(val >> 8)
encoder.encode_end()
# f.write("\n};\n")
# if extension != ".rle":
# f.write("const Bitmap %s(BMP_ARGB4444, %d, %d, (uint16_t*)__%s);\n" % (constant, width, height, constant))
elif what == "5/6/5":
constant = sys.argv[2].upper()[:-4]
values = []
write_size(f, width, height)
for y in range(height):
for x in range(width):
pixel = image.getpixel(pixel_coord(x, y))
val = ((pixel[0] >> 3) << 11) + ((pixel[1] >> 2) << 5) + ((pixel[2] >> 3) << 0)
encoder.encode_byte(val & 255)
encoder.encode_byte(val >> 8)
encoder.encode_end()
#f.write("\n};\n")
#if extension != ".rle":
# f.write("const Bitmap %s(BMP_RGB565, %d, %d, (uint16_t*)__%s);\n" % (constant, width, height, constant))
elif what == "03x05":
image = image.convert(mode='L')
for y in range(0, height, 5):
for x in range(width):
value = 0
for z in range(5):
if image.getpixel((x, y + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
elif what == "04x06":
image = image.convert(mode='L')
for y in range(0, height, 7):
for x in range(width):
value = 0
for z in range(7):
if image.getpixel((x, y + z)) == 0:
value += 1 << z
if value == 0x7f:
value = 0xff
f.write("0x%02x," % value)
f.write("\n")
elif what == "10x14":
image = image.convert(mode='L')
for y in range(0, height, 16):
for x in range(width):
for l in range(0, 16, 8):
f.write("\n")
elif what == "05x07":
image = image.convert(mode='L')
for y in range(0, height, 8):
for x in range(width):
value = 0
for z in range(8):
if image.getpixel((x, y + l + z)) == 0:
if image.getpixel((x, y + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
elif what == "22x38":
image = image.convert(mode='L')
for y in range(0, height, 40):
for x in range(width):
for l in range(0, 40, 8):
value = 0
for z in range(8):
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
else:
print("wrong argument", sys.argv[4])
f.write("\n")
elif what == "08x10":
image = image.convert(mode='L')
for y in range(0, height, 12):
for x in range(width):
skip = True
for l in range(0, 12, 8):
value = 0
for z in range(8):
if l + z < 12:
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
else:
skip = False
if skip and l == 8:
value = 0xff
f.write("0x%02x," % value)
f.write("\n")
elif what == "10x14":
image = image.convert(mode='L')
for y in range(0, height, 16):
for x in range(width):
for l in range(0, 16, 8):
value = 0
for z in range(8):
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
elif what == "22x38":
image = image.convert(mode='L')
for y in range(0, height, 40):
for x in range(width):
for l in range(0, 40, 8):
value = 0
for z in range(8):
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")
else:
print("wrong argument", sys.argv[4])
if __name__ == "__main__":
main()