diff options
| author | Miguel <m.i@gmx.at> | 2018-10-13 17:18:49 +0200 |
|---|---|---|
| committer | Miguel <m.i@gmx.at> | 2018-10-13 17:18:49 +0200 |
| commit | 5aeab1c853e487aa0042d5c32200d623efe908d3 (patch) | |
| tree | 51c810e0ce95c2b031b69999be2c0ab4244b2749 /userspace/fonts/binarize.py | |
| parent | 279f3336a8f6b31ca38bdd272c73aebd68fa88fe (diff) | |
fontstuff et al.
Diffstat (limited to 'userspace/fonts/binarize.py')
| -rw-r--r-- | userspace/fonts/binarize.py | 16 |
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 |
