aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/xface2xbm.in
blob: 2c2002a60c41e6b5722883b9cd262951cfccda91 (plain) (blame)
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
48
49
50
51
52
53
54
#!@PERL@

# See http://www.lab3.kuis.kyoto-u.ac.jp/~tsumura/emacs/x-face.html
$UNCOMPFACE = "uncompface";

$xf = "";
while(<>) {
#	s/^X-Face://i if ($xf eq "");
	$xf .= $_;
}

pipe(R, W2);
pipe(R2, W);
if (! fork()) {
	close(R);
	close(W);
	open(STDIN, "<&R2");
        open(STDOUT, ">&W2");
	exec $UNCOMPFACE;
	die;
}
close(R2);
close(W2);
print W $xf;
close(W);
while(<R>) {
	while(s/0x(..)(..)//) {
		push(@bm, hex($1), hex($2));
	}
}
close(R);

$W = 48;
$H = @bm * 8 / $W;	# must be 48
print <<EOF;
#define xf_width $W
#define xf_height $H
static char xf_bits[] = {
EOF
while (@bm) {
	for (1..6) {
		$x = shift @bm;
		$y = 0;
		for $i (1 .. 8) {
			$y |= ($x & 1) << (8 - $i);
			$x >>= 1;
		}
		printf " 0x%02X,", $y;
	}
	print "\n";
}
print <<EOF;
};
EOF