Root/tornado/fw/txt/stretch

1#!/usr/bin/perl
2
3$L = 15; # bytes per line
4
5
6sub pick
7{
8    local ($x, $y) = @_;
9
10    my $i = $x+$y*$X;
11    return ((hex $p[$i >> 3]) >> ($i & 7)) & 1;
12}
13
14
15$f = 0.001*shift @ARGV;
16
17while (<>) {
18    if (/#define\s+(\S+)_width\s+(\d+)/) {
19        print;
20        $N = $1;
21        $X = $2;
22        next;
23    }
24    if (/#define\s+\S+_height\s+(\d+)/) {
25        print;
26        $Y = $1;
27        next;
28    }
29    chop;
30    next unless /\s*0x/;
31    s/^\s*//;
32    s/(,|};)$//;
33    push(@p, split /,/);
34}
35
36FIRST: for ($x0 = 0; $x0 != $X; $x0++) {
37    for ($y = 0; $y != $Y; $y++) {
38        last FIRST if &pick($x0, $y);
39    }
40}
41
42for ($x = $x0; $x != $X; $x++) {
43    for ($y = 0; $y != $Y; $y++) {
44        $x1 = $x if &pick($x, $y);
45    }
46}
47
48$w = ($x1-$x0)+1;
49$off = int(($X-$x1+$x0)/2);
50#print STDERR "$X $x0 $x1 $w $off\n";
51
52# x' = x*(1+y*f)
53# x'/(1+y*f) = x
54# x'
55for ($y = 0; $y != $Y; $y++) {
56    for ($x = 0; $x != $X; $x += 8) {
57        $v = 0;
58        for ($i = 0; $i != 8; $i++) {
59            $t = $x+$i-$X/2;
60            $t = int($t*(1-$y*$f)-$off+$X/2);
61            next if $t < 0 || $t >= $X;
62            $v |= 1 << $i if &pick($t, $y);
63        }
64        push(@r, sprintf("0x%02x", $v));
65    }
66}
67
68print "static char ${N}_bits[] = {\n";
69$i = 0;
70for (@r) {
71    print " " if !($i % $L);
72    print $_;
73    last if $i == $#r;
74    $i++;
75    print ",";
76    print "\n" if !($i % $L);
77}
78print "};\n";
79

Archive Download this file

Branches:
master
tornado-v1



interactive