blob: 30253cb2ce5a8398babdca960f1cbf5951356504 (
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#!@PERL@
$USAGE = "xface2xpm [-t] [-fg <color>] [-bg <color>] [<file>]";
# compface/uncompface
# ftp://metalab.unc.edu/pub/Linux/apps/graphics/convert/
$UNCOMPFACE = "uncompface";
$T = "c";
$BG = "white";
$FG = "black";
while (@ARGV) {
$_ = shift @ARGV;
if (/^-h/) {
&usage(0);
} elsif (/^-t/) {
$T = "s";
$BG = "none";
} elsif (/^-bg/) {
@ARGV || &usage(1);
$BG = shift @ARGV;
} elsif (/^-fg/) {
@ARGV || &usage(1);
$FG = shift @ARGV;
} elsif (/^-./) {
&usage(1);
} else {
unshift(@ARGV, $_);
last;
}
}
$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;
exit 1;
}
close(R2);
close(W2);
print W $xf;
close(W);
while(<R>) {
while(s/0x(..)(..)//) {
push(@bm, hex($1), hex($2));
}
}
close(R);
@bm || exit 1;
$W = 48;
$H = @bm * 8 / $W; # must be 48
print <<EOF;
/* XPM */
static char *xf[] = {
/* columns rows colors chars-per-pixel */
"$W $H 2 1",
" $T $BG",
". c $FG",
/* pixels */
EOF
while (@bm) {
print "\"";
for (1..6) {
$x = shift @bm;
for $i (1 .. 8) {
print ((($x >> (8-$i)) & 1) ? "." : " ");
}
}
print (@bm ? "\",\n" : "\"\n");
}
print <<EOF;
};
EOF
sub usage {
local($err) = @_;
if ($err) {
print STDERR "$USAGE\n";
} else {
print "$USAGE\n";
}
exit $err;
}
|