summaryrefslogtreecommitdiff
path: root/userspace/fonts/binarize.py
diff options
context:
space:
mode:
Diffstat (limited to 'userspace/fonts/binarize.py')
-rw-r--r--userspace/fonts/binarize.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/userspace/fonts/binarize.py b/userspace/fonts/binarize.py
index a992c93..e043106 100644
--- a/userspace/fonts/binarize.py
+++ b/userspace/fonts/binarize.py
@@ -4,7 +4,10 @@ def binarize(file_in, file_out):
""" Create a binary file from an ASCII file. Everything
but '0' and '1' (alternatively '_' and 'X') is ignored
- from the input file. """
+ from the input file.
+
+ The first two lines are width and height and will be saved
+ as the first two bytes of the resulting file"""
print ("binarizing " + file_in + " to "+ file_out + ".")
@@ -18,6 +21,11 @@ def binarize(file_in, file_out):
try:
+ w=int(f.readline())
+ h=int(f.readline())
+ o.write(bytes([w]))
+ o.write(bytes([h]))
+
while True:
b=readnext(f)
@@ -56,7 +64,11 @@ def readnext(f):
c=f.read(1)
if not c:
- return -1
+ if l==0:
+ return -1
+ else:
+ print("trailing only ",b," with ",l," bits");
+ return int(b,2)
if c=="0" or c=='_':
l+=1