# Konvertiert "PixelFontGenerator_UB.exe"-Dateien
# in lückenlose Bitmaps für proportionale Schriftarten.
# Eingangsdaten: Zeichenbreite, dann Bits zeilenweise MSBfirst
# Ausgangsdaten: Bitmap LSBfirst für HD61830-Display
emitS=0; # Spaltenzähler für Hexdump
function emitHex(v) {
printf("0x%02X,",v);
if (++emitS==16) { # Zeilen nicht überlang werden lassen
print "";
emitS=0;
}
}
lastBits=0; # Bit-Puffer (1 Byte)
lastN=0; # Anzahl Bits im Bit-Puffer
# Bit mit Rightshift einschieben
function emitBit(b) {
lastBits=rshift(lastBits,1);
if (b) lastBits+=0x80;
if (++lastN==8) {
emitHex(lastBits); # ausgeben!
lastN=0;
lastBits=0;
}
}
# rechtsbündige Bits in <v> ausgeben, <v> enthält <n> Bits, max. 32
# Es werden Bytes ausgegeben, die Bits linksbündig
function emitBits(v,n, free,t,b) {
if (and(v,lshift(1,n)-1)!=v) print "Problem!"
for(;--n>=0;) {
emitBit(and(v,lshift(1,n))) # Bits reversieren und ausspucken
}
}
function emitTerm(s) {
emitBits(0,7);
lastN=0;
print s
emitS=0;
}
BEGIN{
FS=",";
cc=0;
wmin=255;
wmax=0;
z=0;
wg=0; # Gesamtbitmapbreite in Pixel bzw. Bits
first=-1;
}
# Nur Datenzeilen nehmen, alles andere verwerfen
/^0x/{
if (first==-1) {
first=gensub(/.*: ?([0-9]+).*/,"\\1",1,$NF);
}
w[cc]=strtonum($1); # Breiten-Array
wg+=w[cc];
if (wmin>w[cc]) wmin=w[cc];
if (wmax<w[cc]) wmax=w[cc];
if (z<NF-3) z=NF-3;
for (i=2; i<NF; i++) {
p[cc,i-2]=strtonum($i); # Pixel-Array
}
cc++;
}
END{
print "#if defined(__AVR__)"
print "#include <avr/pgmspace.h>"
print "typedef uint8_t byte;"
print "#elif defined(__PIC32MX__) || defined(__arm__)"
print "#define PROGMEM"
print "typedef unsigned char byte;"
print "#endif"
print ""
printf("// Character Cell: (%d~%d)x%d\n",wmin,wmax,z);
bb=rshift(wg*z+7,3); # Bitmap-Bytes
b=4+rshift(cc+1,1)+bb;
printf("// Memory usage: %d=0x%X bytes\n",b,b);
printf("// Character Range: %d..%d\n",first,first+cc-1);
printf("// Bitmap dimension: x=%d, y=%d, x*y=%d (%d=0x%X bytes)\n",wg,z,wg*z,bb,bb);
print ""
name=gensub(/\..*/,"",1,ARGV[ARGC-1]);
printf("const byte %s[] PROGMEM ={\n",name);
emitHex(256-wmin);
emitHex(z);
emitHex(first);
emitHex(cc);
emitTerm("");
if (wmax-wmin>15) for (i=0; i<cc; i++) emitHex(w[i]-wmin); # Bytes
else for (i=0; i<cc; i+=2) {
w0=w[i]-wmin;
w1=i+1<cc?w[i+1]-wmin:0;
emitHex(or(lshift(w1,4),w0)); # Nibbles
}
emitTerm("");
for (j=0; j<z; j++) {
for (i=0; i<cc; i++) {
emitBits(p[i,j],w[i]);
}
}
emitTerm("};"); # Restbits ausspucken
}
Detected encoding: UTF-8 | 0
|