[Horus] font fixes (#5901)

* avoid generating a blank part for font size that do not have extras

* use “stretch” instead of “jessie”

.. and add libgtest-dev.

* keep space width equal 4, no matter what

* updated generated fonts

* updated reference images

* Replace PyQt completely (#5902)

* ported img2lbm.py to Pillow (and get rid of PyQt)

* removed PyQt from Dockerfile

* fixed travis

* fixed issue with img2lbm and Horus bitmaps
This commit is contained in:
Raphael Coeffic
2018-05-21 19:03:15 +02:00
committed by Bertrand Songis
parent 842b04627a
commit ea898e5122
19 changed files with 65 additions and 51 deletions
+3 -3
View File
@@ -1,11 +1,11 @@
# An Debian image for compiling OpenTX 2.2
FROM debian:jessie
FROM debian:stretch
RUN DEBIAN_FRONTEND=noninteractive apt-get -y update
RUN DEBIAN_FRONTEND=noninteractive apt-get -y install build-essential cmake gcc git lib32ncurses5 lib32z1 libfox-1.6-dev libsdl1.2-dev \
python-qt4 qt5-default qtmultimedia5-dev qttools5-dev qttools5-dev-tools libqt5svg5-dev \
software-properties-common wget zip python-pip python-pil
qt5-default qtmultimedia5-dev qttools5-dev qttools5-dev-tools libqt5svg5-dev \
software-properties-common wget zip python-pip python-pil libgtest-dev
RUN python -m pip install filelock
+8 -7
View File
@@ -33,25 +33,26 @@ def createFontBitmap(filename, fontname, fontsize, fontoffset, foreground, backg
font = ImageFont.truetype(font_filename, fontsize)
extraImage = None
extraWidth, extraHeight = 0, 0
extraFilename = 'fonts/extra_%dpx.png' % fontsize
try:
extraImage = Image.open(extraFilename)
extraImage = extraImage.convert('RGB');
extraWidth, extraHeight = extraImage.size
extraWidth = extraWidth / COUNT_EXTRA_CHARS
except IOError:
print 'Missing extra symbol filename %s' % extraFilename
def getCharWidth(c):
if c in chars_extra:
if ord(c) <= 9:
return 13
if extraImage:
# Extra characters 16px
#if fontsize == 16:
if ord(c) <= 9:
return 13
else:
return 15
else:
return 15
return 0
elif c == " ":
return 4
else:
+48 -35
View File
@@ -3,14 +3,12 @@
from __future__ import division, print_function
import sys
try:
from PyQt5 import Qt, QtGui
except:
from PyQt4 import Qt, QtGui
from PIL import Image
image = QtGui.QImage(sys.argv[1])
width, height = image.size().width(), image.size().height()
image = Image.open(sys.argv[1])
width, height = image.size
image_fmt = image.format
def writeSize(f, width, height):
if lcdwidth > 255:
@@ -34,13 +32,19 @@ with open(sys.argv[2], "w") as f:
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 and image.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
value += 1 << z
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
f.write("0x%02x," % value)
f.write("\n")
elif what == "4/4/4/4":
@@ -48,8 +52,8 @@ with open(sys.argv[2], "w") as f:
values = []
for y in range(height):
for x in range(width):
pixel = image.pixel(x, y)
val = ((Qt.qAlpha(pixel) // 16) << 12) + ((Qt.qRed(pixel) // 16) << 8) + ((Qt.qGreen(pixel) // 16) << 4) + ((Qt.qBlue(pixel) // 16) << 0)
pixel = image.getpixel((x, y))
val = ((pixel[3] // 16) << 12) + ((pixel[0] // 16) << 8) + ((pixel[1] // 16) << 4) + ((pixel[2] // 16) << 0)
values.append(str(val))
f.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant, ",".join(values)))
f.write("const Bitmap %s(BMP_ARGB4444, %d, %d, __%s);\n" % (constant, width, height, constant))
@@ -58,8 +62,8 @@ with open(sys.argv[2], "w") as f:
values = []
for y in range(height):
for x in range(width):
pixel = image.pixel(width-x-1, height-y-1)
val = ((Qt.qAlpha(pixel) // 16) << 12) + ((Qt.qRed(pixel) // 16) << 8) + ((Qt.qGreen(pixel) // 16) << 4) + ((Qt.qBlue(pixel) // 16) << 0)
pixel = image.getpixel((width-x-1, height-y-1))
val = ((pixel[3] // 16) << 12) + ((pixel[0] // 16) << 8) + ((pixel[1] // 16) << 4) + ((pixel[2] // 16) << 0)
values.append(str(val))
f.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant, ",".join(values)))
f.write("const Bitmap %s(BMP_ARGB4444, %d, %d, __%s);\n" % (constant, width, height, constant))
@@ -68,8 +72,8 @@ with open(sys.argv[2], "w") as f:
values = []
for y in range(height):
for x in range(width):
pixel = image.pixel(x, y)
val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)
pixel = image.getpixel((x, y))
val = ((pixel[0] >> 3) << 11) + ((pixel[1] >> 2) << 5) + ((pixel[2] >> 3) << 0)
values.append(str(val))
f.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant, ",".join(values)))
f.write("const Bitmap %s(BMP_RGB565, %d, %d, __%s);\n" % (constant, width, height, constant))
@@ -78,31 +82,32 @@ with open(sys.argv[2], "w") as f:
values = []
for y in range(height):
for x in range(width):
pixel = image.pixel(width-x-1, height-y-1)
val = ((Qt.qRed(pixel) >> 3) << 11) + ((Qt.qGreen(pixel) >> 2) << 5) + ((Qt.qBlue(pixel) >> 3) << 0)
pixel = image.getpixel((width-x-1, height-y-1))
val = ((pixel[0] >> 3) << 11) + ((pixel[1] >> 2) << 5) + ((pixel[2] >> 3) << 0)
values.append(str(val))
f.write("const uint16_t __%s[] __ALIGNED = { %s };\n" % (constant, ",".join(values)))
f.write("const Bitmap %s(BMP_RGB565, %d, %d, __%s);\n" % (constant, width, height, constant))
elif what == "5/6/5/8":
colors = []
writeSize(f, width, height)
for y in range(height):
for x in range(width):
pixel = image.pixel(x, y)
val = ((Qt.qRed(pixel) >> 4) << 12) + ((Qt.qGreen(pixel) >> 4) << 7) + ((Qt.qBlue(pixel) >> 4) << 1)
f.write("%d,%d,%d," % (val % 256, val // 256, Qt.qAlpha(pixel)))
f.write("\n")
# elif what == "5/6/5/8":
# colors = []
# writeSize(f, width, height)
# for y in range(height):
# for x in range(width):
# pixel = image.pixel(x, y)
# val = ((Qt.qRed(pixel) >> 4) << 12) + ((Qt.qGreen(pixel) >> 4) << 7) + ((Qt.qBlue(pixel) >> 4) << 1)
# f.write("%d,%d,%d," % (val % 256, val // 256, Qt.qAlpha(pixel)))
# f.write("\n")
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 = Qt.qGray(image.pixel(x, y))
gray1 = image.getpixel((x, y))
if y + 1 < height:
gray2 = Qt.qGray(image.pixel(x, y + 1))
gray2 = image.getpixel((x, y + 1))
else:
gray2 = Qt.qRgb(255, 255, 255)
gray2 = 255
for i in range(4):
if (gray1 & (1 << (4 + i))):
value -= 1 << i
@@ -113,42 +118,47 @@ with open(sys.argv[2], "w") as f:
elif what == "8bits":
colors = []
writeSize(f, width, height)
image = image.convert(mode='L')
for y in range(height):
for x in range(width):
value = Qt.qGray(image.pixel(x, y))
value = image.getpixel((x, y))
value = 0x0f - (value >> 4)
f.write("0x%02x," % value)
f.write("\n")
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.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
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.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
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.pixel(x, y + z) == Qt.qRgb(0, 0, 0):
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
@@ -156,31 +166,34 @@ with open(sys.argv[2], "w") as f:
value = 0
for z in range(8):
if l + z < 12:
if image.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
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)
#print ("0x%02x (%d,%d,%d)" % (value,x,y,l))
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.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
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.pixel(x, y + l + z) == Qt.qRgb(0, 0, 0):
if image.getpixel((x, y + l + z)) == 0:
value += 1 << z
f.write("0x%02x," % value)
f.write("\n")