1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-01 13:15:55 +02:00

tornado/fw/txt/: tools for text conversion

txt2xbm: convert text to XBM, using ghostscript
stretch: resample XBM with rotation correction (x-axis only)
xbm2gp: convert XBM to gnuplot, taking into account rotation
plot: plot xbm2gp output
t: run all the above to display "TEST"
This commit is contained in:
Werner Almesberger 2012-12-04 00:56:36 -03:00
parent 6ccdd5255a
commit a5694eba05
5 changed files with 151 additions and 0 deletions

10
tornado/fw/txt/plot Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
(
cat <<EOF
#set xrange [0:255]
#set yrange [0:63]
set size ratio -1
plot "-" with points pt 7 notitle
EOF
cat
) | gnuplot -persist

78
tornado/fw/txt/stretch Executable file
View File

@ -0,0 +1,78 @@
#!/usr/bin/perl
$L = 15; # bytes per line
sub pick
{
local ($x, $y) = @_;
my $i = $x+$y*$X;
return ((hex $p[$i >> 3]) >> ($i & 7)) & 1;
}
$f = 0.001*shift @ARGV;
while (<>) {
if (/#define\s+(\S+)_width\s+(\d+)/) {
print;
$N = $1;
$X = $2;
next;
}
if (/#define\s+\S+_height\s+(\d+)/) {
print;
$Y = $1;
next;
}
chop;
next unless /\s*0x/;
s/^\s*//;
s/(,|};)$//;
push(@p, split /,/);
}
FIRST: for ($x0 = 0; $x0 != $X; $x0++) {
for ($y = 0; $y != $Y; $y++) {
last FIRST if &pick($x0, $y);
}
}
for ($x = $x0; $x != $X; $x++) {
for ($y = 0; $y != $Y; $y++) {
$x1 = $x if &pick($x, $y);
}
}
$w = ($x1-$x0)+1;
$off = int(($X-$x1+$x0)/2);
#print STDERR "$X $x0 $x1 $w $off\n";
# x' = x*(1+y*f)
# x'/(1+y*f) = x
# x'
for ($y = 0; $y != $Y; $y++) {
for ($x = 0; $x != $X; $x += 8) {
$v = 0;
for ($i = 0; $i != 8; $i++) {
$t = $x+$i-$X/2;
$t = int($t*(1-$y*$f)-$off+$X/2);
next if $t < 0 || $t >= $X;
$v |= 1 << $i if &pick($t, $y);
}
push(@r, sprintf("0x%02x", $v));
}
}
print "static char ${N}_bits[] = {\n";
$i = 0;
for (@r) {
print " " if !($i % $L);
print $_;
last if $i == $#r;
$i++;
print ",";
print "\n" if !($i % $L);
}
print "};\n";

2
tornado/fw/txt/t Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
./txt2xbm TEST | ./stretch 6 | ./xbm2gp "$@" | ./plot

9
tornado/fw/txt/txt2xbm Executable file
View File

@ -0,0 +1,9 @@
#!/bin/sh
gs -sDEVICE=pbmraw -sOutputFile=- -g256x64 -q - <<EOF | pbmtoxbm
/Helvetica-Bold findfont
80 scalefont
setfont
0 4 moveto
($1) show
showpage
EOF

52
tornado/fw/txt/xbm2gp Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/perl
$I = 50; # inner radius (50 cm)
$O = 80; # outer radius (80 cm)
#$Y = 64; # image heights (pixels)
#$X = 256; # image width (pixels)
sub ang
{
local ($r) = @_;
# (O-I)/Y = r*arc(a)
# arc
return ($O-$I)/$Y/$r;
}
if ($ARGV[0] eq "-r") {
shift @ARGV;
$rect = 1;
}
while (<>) {
chop;
if (/#define\s+\S+_width\s+(\d+)/) {
$X = $1;
next;
}
if (/#define\s+\S+_height\s+(\d+)/) {
$Y = $1;
next;
}
next unless /\s*0x/;
s/^\s*//;
s/(,|};)$//;
push(@p, split /,/);
}
for ($x = 0; $x != $X; $x++) {
for ($y = 0; $y != $Y; $y++) {
$i = $x+$y*$X;
$p = ((hex $p[$i >> 3]) >> ($i & 7)) & 1;
next unless $p;
if ($rect) {
print "$x ", $Y-$y-1, "\n";
} else {
$r = ($Y-$y-1)/$Y*($O-$I)+$I;
$a = &ang($O)*($x-$X/2);
print $r*sin($a), " ", $r*cos($a), "\n";
}
}
}