update ui_seperation.txt
[claws.git] / tools / gif2xface.pl
1 #!/usr/bin/perl
2 #
3 # gif2xface -- converts a 48x48 GIF file to an X-Face mail header
4 #
5 # Author:  Ricardo Mones Lastra <mones@aic.uniovi.es>
6 #
7 # URL:     http://www.aic.uniovi.es/mones
8 #
9 #   This is a hack over the original xbm2face script. The xbm files generated
10 #   by some graphic tools (notably The Gimp version 1.2.1) aren't suitable to
11 #   feed the compface program. Starting with a GIF and using some filters does
12 #   the trick. A little help screen also added.
13 #   This requieres giftopnm and pbmtoxbm (both in libgr-progs package). 
14 #
15 #   The original xbm2face author's comment follows: 
16 #
17 # xbm2xface -- converts a 48x48 xbm file to an X-Face mail header
18 #
19 # Author:  Jonathan Stigelman <Stig@hackvan.com>
20 #
21 # URL:     http://hackvan.com/pub/stig/src/linux/
22 # FTP:     hackvan.com:/pub/stig/src/linux/
23 #
24 #   This is a Perl script that I wrote to convert 48x48 xbm (X bitmap) files
25 #   into X-Face: headers suitable for inclusion in RFC822 internet
26 #   electronic mail.  A 48x48 bitmap is awfully small, but X-Faces are still
27 #   good enough for other people to visually establish your identity in
28 #   email without having to carefully read your name.
29
30 #   Basically, it gets you noticed...either as the person with the cool
31 #   X-Face or as that jerk with modem noise in all of his email messages.
32
33 #   People will start looking over your shoulder and say "Hey Cool!  How'd
34 #   you do that?"  When they do, you just send 'em to my URL for this
35 #   utility and tell 'em to upgrade to a real mail reader: XEmacs and VM.
36 #
37 # It also requires the 'compface' utility.
38 #
39
40 sub check_for_help {
41   local($param) = @_;
42
43   # is a filter, no args must be present
44   if (defined($param))
45   { 
46     print "\n", 'gif2xface -- A filter for converting an 48x48 gif into a xface string', "\n\n" ;
47     print 'Usage:  gif2xface < input.gif > output.xface', "\n\n";
48     exit;
49   }
50 }
51
52 sub reverse_byte {
53     local($byte) = @_;
54     local($n, $b);
55     for ( $b= $n= 0; $b<8; ++$b) {
56         $n |= (($byte & 1) << (7-$b));
57         $byte >>= 1;
58     }
59     return($n);
60 }
61
62
63 &check_for_help($ARGV[0]);
64
65 # printf "0x%02x\n", &reverse_byte(0xF0);
66
67 $ra = rand;
68 $tf = "/tmp/gif2xface.$ra";
69 open(GP,"|giftopnm|pbmtoxbm>$tf");
70
71 while (<>) {
72   print GP $_;
73 }
74 close(GP);
75 open(GP,"<$tf");
76 <GP>;
77 m/^#define \w+_width (\d+)/ && ($width=$1);
78 <GP>;
79 m/^#define \w+_height (\d+)/ && ($height=$1);
80 <GP>;
81 m/^static.* = \{/ && (( $width == 48 && $height == 48 )
82                       || die $0, ": sorry, xfaces must be 48x48 pixels" );
83
84 $| = 1; print "X-Face:";
85
86 open(CF,"|compface");
87
88 while (<GP>) {
89     $st="";
90     while (s/(0x..)(,|\};)\s*//) {
91         $st .= sprintf("0x%02x, ", &reverse_byte(eval($1)));
92     }
93     $_=$st;
94     s/(0x..), 0x(..)/\1\2/g;
95     s/\s*(0x...., 0x...., 0x....)(,|\};)\s/\1,\n/g;
96     print CF $_;
97 }
98 close (CF);
99 close (GP);
100 unlink $tf;