From c2a96747b93e72caeec1e04c489dd1323d3d23eb Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 23 Dec 2019 19:55:40 +0100 Subject: [PATCH] Added bitmap font generator --- font/characters16.txt | 1 + font/convert.py | 71 ++++++++++++++++++++++++++++++++++++++++++ font/font_h16.xcf | Bin 0 -> 5944 bytes 3 files changed, 72 insertions(+) create mode 100644 font/characters16.txt create mode 100755 font/convert.py create mode 100644 font/font_h16.xcf diff --git a/font/characters16.txt b/font/characters16.txt new file mode 100644 index 0000000..6a9245a --- /dev/null +++ b/font/characters16.txt @@ -0,0 +1 @@ +0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.:!?+-*/= diff --git a/font/convert.py b/font/convert.py new file mode 100755 index 0000000..418199d --- /dev/null +++ b/font/convert.py @@ -0,0 +1,71 @@ +#!/usr/bin/env python3 + +from PIL import Image +import sys + +if len(sys.argv) < 3: + print("usage: {} ") + exit(1) + +inputfile = sys.argv[1] +charfile = sys.argv[2] +outputfile = sys.argv[3] + +im = Image.open(inputfile) + +cols, rows = im.size + +offset = 4 # hardcoded 'space' +startpos = offset + +fixedwidth = 9 + +charpos = [0] # hardcoded 'space' +chardata = [0x00] * offset # hardcoded 'space' +charwidth = [offset] # hardcoded 'space' + +for col in range(cols): + coldata = 0 + + for row in range(rows): + px = 0 if im.getpixel( (col, row) ) else 1 + coldata |= (px << row) + + print("{:016b}".format(coldata)) + + width = offset - startpos + + chardata.append(coldata) + + if width == fixedwidth: + charpos.append(startpos) + charwidth.append(width) + startpos = offset + else: + offset += 1 + +dataarray = ", ".join([hex(n) for n in chardata]) +posarray = ", ".join([str(n) for n in charpos]) +widtharray = ", ".join([str(n) for n in charwidth]) + +asciimap = [0 for i in range(256)] + +with open(charfile, "r") as cfile: + s = " " + cfile.read().strip() + for i in range(len(s)): + asciimap[ord(s[i])] = i + +asciimaparray = ", ".join([str(n) for n in asciimap]) + +with open(outputfile, "w") as ofile: + ofile.write(""" +#include "font16_data.h" + +const uint16_t font_data[{}] = {{ {} }}; +const uint16_t font_pos[{}] = {{ {} }}; +const uint8_t font_width[{}] = {{ {} }}; + +const uint8_t font_lut[256] = {{ {} }}; + +const uint8_t font_height = {}; +""".format(len(chardata), dataarray, len(charpos), posarray, len(charwidth), widtharray, asciimaparray, rows)) diff --git a/font/font_h16.xcf b/font/font_h16.xcf new file mode 100644 index 0000000000000000000000000000000000000000..39f46f379a9957934472d2ed0bcb22ad3c024c2f GIT binary patch literal 5944 zcmd5=NpBoQ6t3BACx&3W5J0FifH2EAHd$EYBmx2p_I^&D~Dky(p9KM^@z|Yx&V6}UW0gz;B~do!2Pcn z1CmE@CM$HC(72N^#+cBLLc?`Yq*Q4wE&0u^lFVj$kDlDXxU+* z!BV;Im+I}Hs_6G7JKeR0?{!*@pnB`jWUXFlHCk3HeHqF`tp-fgS}R^vC!&J6V{y z39`f7n2BZcKhKVos%^qzV-BicqA~@!LU7 z>q^kXo7w9iw#dX;4p#jJvaHDVs%y>iQc!VKHq|2~76Q>i*2WqV zAKp(q*;8>L%3YU{**DlWdY*g?87j{h@*DgHa=fFyB4>YPeg19ofs^Ee-;i&6jeOYk zzv6S2cYHuT@-F!(vdli~*|TQdd}PvL&ZLAgVOFRha@ypqoRy4C3uVlop^+N2q{5V~ zNl7_vTL)}Ck?4`6f-R#r#u*S|4N*g`oH2jMy08#5518Ljv{Qy5K>5VfX;~u~b0HL6 zGd;jT0YWF$nwmo|>W#AM22G$hZGmhx(5?!DHbXGpH6!LBB19479zv3(uP*{K zfCV?ZOPe0B%^XP{_#N7+za3~3Y-}Nug|SkPYAiKg;02q7Tr%fzy7YN2j@zf=3pier zom#POxUYUx%Bb6E>ygSi@nbr4Ga%y`8w>(9G$5L03>3{l8$HNiK>^f}qNIpnSfrJL}eEtV$SOD+na`E;kzF zqVybHq3T%t1A+i1cy^k*ucy`FW$6? z_)FZaHw&YZnrI!DGnd{0KDkshw!D9ZR%02cUW2*O!AFj7yggcR0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