w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

xface2xpm.in (1377B)


      1 #!@PERL@
      2 
      3 $USAGE = "xface2xpm [-t] [-fg <color>] [-bg <color>] [<file>]";
      4 
      5 # compface/uncompface
      6 #   ftp://metalab.unc.edu/pub/Linux/apps/graphics/convert/
      7 $UNCOMPFACE = "uncompface";
      8 
      9 $T = "c";
     10 $BG = "white";
     11 $FG = "black";
     12 while (@ARGV) {
     13 	$_ = shift @ARGV;
     14 	if (/^-h/) {
     15 		&usage(0);
     16 	} elsif (/^-t/) {
     17 		$T = "s";
     18 		$BG = "none";
     19 	} elsif (/^-bg/) {
     20 		@ARGV || &usage(1);
     21 		$BG = shift @ARGV;
     22 	} elsif (/^-fg/) {
     23 		@ARGV || &usage(1);
     24 		$FG = shift @ARGV;
     25 	} elsif (/^-./) {
     26 		&usage(1);
     27 	} else {
     28 		unshift(@ARGV, $_);
     29 		last;
     30 	}
     31 }
     32 
     33 $xf = "";
     34 while(<>) {
     35 #	s/^X-Face://i if ($xf eq "");
     36 	$xf .= $_;
     37 }
     38 
     39 pipe(R, W2);
     40 pipe(R2, W);
     41 if (! fork()) {
     42 	close(R);
     43 	close(W);
     44 	open(STDIN, "<&R2");
     45 	open(STDOUT, ">&W2");
     46 	exec $UNCOMPFACE;
     47 	exit 1;
     48 }
     49 close(R2);
     50 close(W2);
     51 print W $xf;
     52 close(W);
     53 while(<R>) {
     54 	while(s/0x(..)(..)//) {
     55 		push(@bm, hex($1), hex($2));
     56 	}
     57 }
     58 close(R);
     59 @bm || exit 1;
     60 
     61 $W = 48;
     62 $H = @bm * 8 / $W;	# must be 48
     63 print <<EOF;
     64 /* XPM */
     65 static char *xf[] = {
     66 /* columns rows colors chars-per-pixel */
     67 "$W $H 2 1",
     68 "  $T $BG",
     69 ". c $FG",
     70 /* pixels */
     71 EOF
     72 while (@bm) {
     73 	print "\"";
     74 	for (1..6) {
     75 		$x = shift @bm;
     76 		for $i (1 .. 8) {
     77 			print ((($x >> (8-$i)) & 1) ? "." : " ");
     78 		}
     79 	}
     80 	print (@bm ? "\",\n" : "\"\n");
     81 }
     82 print <<EOF;
     83 };
     84 EOF
     85 
     86 sub usage {
     87 	local($err) = @_;
     88 	if ($err) {
     89 		print STDERR "$USAGE\n";
     90 	} else {
     91 		print "$USAGE\n";
     92 	}
     93 	exit $err;
     94 }