core: add the splashy2fbsplash theme converter
[fbsplash.git] / core / scripts / splash_resize.in
blob54b83461aeaa3d26bbcec92ccbf229dcb4cd6b68
1 #!/usr/bin/perl
3 # splash_resize -- a helper script to automatically create theme configs
4 # for different resolutions
6 # (c) 2004 Michal Januszewski <spock@gentoo.org>
8 # NOTE: This script only creates config files, it doesn't provide the necessary
9 # images - they have to be created by hand.
11 # Usage: splash_resize <theme> <old_res> <new_res>
13 # $Header: /srv/cvs/splash/utils/scripts/splash_resize,v 1.2 2004/11/12 17:42:16 spock Exp $
15 if ($#ARGV < 2) {
16 print "splash_resize/splashutils-@PACKAGE_VERSION@\n";
17 print "Usage: splash_resize <theme> <old_res> <new_res>\n";
18 exit 0;
21 $theme = $ARGV[0];
22 $old_res = $ARGV[1];
23 $new_res = $ARGV[2];
25 open IN,"<@themedir@/$theme/$old_res.cfg" || die "Can't open source config file.";
26 open OUT,">@themedir@/$theme/$new_res.cfg" || die "Can't write to destination config file.";
28 $old_res =~ /(\d+)x(\d+)/; $old_x = $1; $old_y = $2;
29 $new_res =~ /(\d+)x(\d+)/; $new_x = $1; $new_y = $2;
31 while(<IN>) {
33 if (/^\s*tx=(\d+)/ || /^\s*tw=(\d+)/ || /^\s*text_x=(\d+)/) {
34 $t = int(($1/$old_x)*$new_x);
35 s/=\d+/=$t/;
36 } elsif (/^\s*ty=(\d+)/ || /^\s*th=(\d+)/ || /^\s*text_y=(\d+)/) {
37 $t = int(($1/$old_y)*$new_y);
38 s/=\d+/=$t/;
39 } elsif (/^\s*text_size=(\d+)/) {
40 $t = int(($1/$old_y)*$new_y);
41 s/=\d+/=$t/;
43 } elsif (/^\s*box\s*[a-zA-Z ]*\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
45 $x0 = int(($1/$old_x)*$new_x);
46 $x1 = int(($3/$old_x)*$new_x);
47 $y0 = int(($2/$old_y)*$new_y);
48 $y1 = int(($4/$old_y)*$new_y);
49 s/box\s*([a-zA-Z ]*)\s*\d+\s+\d+\s+\d+\s+\d+\s*(.*)/box $1 $x0 $y0 $x1 $y1 $2/;
51 } elsif (/^\s*(silent)?pic(256)?=(.*)\n/) {
53 $sil = $1;
54 $col = $2;
55 $src = $3;
57 if ($src =~ /$max_res/) {
58 $dest = $src;
59 $dest =~ s/$old_res/$new_res/g;
60 } else {
61 $dest = $src;
62 $dest =~ s/\.[^\.]+$//g;
63 $dest .= "-$new_res.jpeg";
67 s/$old_res/$new_res/g;
69 print OUT $_;
72 close IN;
73 close OUT;
75 print "Resized config file for theme '$theme' for '$new_res' resolution successfully created.\n";