aboutsummaryrefslogtreecommitdiff
path: root/src/col80_modified/cruft/font2xbm.pl
blob: 33371397015423ac00488e901ff2ec21040f4d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/perl -w

use bytes;

$name = "xbm";
$width = 8;
$height = 384;
$cwidth = $width / 8;
$cheight = $height / 8;

print <<EOF;
#define ${name}_width ${width}
#define ${name}_height ${height}
static unsigned char ${name}_bits[] = {
EOF

undef $/;
$_ = <>;
@inbytes = split "";

# reverse bits, print 12 bytes/line

$c = 0;
for($i=0; $i<@inbytes; $i++) {
	$byte = ord $inbytes[$i];
	if(!$c) {
		print "   ";
	}

	printf "0x%02x", reverse_bits($byte);
	if($i != $#inbytes) {
		if($c == 12) {
			print ",\n";
			$c = 0;
		} else {
			print ", ";
			$c++;
		}
	}
}

print " };\n";

sub reverse_bits {
	my $bitstr = reverse sprintf("%08b", $_[0]);
	return eval "0b$bitstr";
}