]> git.pld-linux.org Git - packages/SD2XC.git/blob - SD2XC-0.0.3.perl
- new
[packages/SD2XC.git] / SD2XC-0.0.3.perl
1 #!/usr/bin/perl
2 #
3 # Copyright Eric Windisch, 2003.
4 # Licensed under the MIT license.
5 #
6 use strict;
7 use Image::Magick;
8 use Getopt::Long;
9 use Config::IniFiles;
10
11 my ($config_file, $path, $tmppath, $generator,$verbose, $inherits,$tmpscheme,$shadow, $opacity, $shadowx, $shadowy, $shadowblur,$shadowblursigma);
12
13 # default for variables
14 $verbose=0;
15 $shadow=0;
16 $opacity=100;
17 $shadowx=2;
18 $shadowy=3;
19 $shadowblur=2;
20 $shadowblursigma=1;
21 $path="theme/";
22 $tmppath="tmp/";
23 $generator="/usr/bin/X11/xcursorgen";
24 # it seems that recursive inheritance does not yet exist.
25 $inherits="whiteglass";
26
27 sub process {
28         print <<EOF;
29 Usage:
30 $0 [-v] [--inherits theme] [--shadow] [--shadow-x pixels] [--shadow-y pixels] [--shadow-blur size] [--shadow-blur-sigma size] [--generator xcursorgen-path] [--tmp temp-dir]
31 EOF
32         exit 0;
33 };
34
35 GetOptions (
36         'inherits=s'=>\$inherits,
37         'tmp=s'=>\$tmppath,
38         'shadow'=>\$shadow,
39         'v'=>\$verbose,
40         'generator=s'=>\$generator,
41         'opacity=i'=>\$opacity,
42         '<>' => \&process,
43         'help'=>\&process,
44         'shadow-x=i'=>\$shadowx,
45         'shadow-y=i'=>\$shadowy,
46         'shadow-blur=i'=>\$shadowblur,
47         'shadow-blur-sigma=i'=>\$shadowblursigma
48 );
49
50 # make sure path and tmppath end in /
51 if ($path =~ /[^\/]$/) {
52         $path=$path."/";
53 }
54 if ($tmppath =~ /[^\/]$/) {
55         $tmppath=$tmppath."/";
56 }
57
58 if (! -d $path) {
59         mkdir ($path);
60 }
61 if (! -d $path."cursors/") {
62         mkdir ($path."cursors/");
63 }
64 if (! -d $tmppath) {
65         mkdir ($tmppath);
66 }
67 $tmpscheme=$tmppath."Scheme.ini";
68
69 # I did this much nicer, but Perl < 5.8 choked.
70 open (INI, "< Scheme.ini") or die ("Cannot open Scheme.ini");
71 open (INF, ">", $tmpscheme);
72 while (<INI>) {
73         unless (!/=/ && !/^\s*\[/) {
74                 #$config_file.=$_;
75                 print INF $_;
76         }
77 }
78 close (INI);
79 close (INF);
80
81 my $cfg=new Config::IniFiles(-file=>$tmpscheme) or die ("Scheme.ini in wrong format? -".$@);
82 my @sections=$cfg->Sections;
83
84 my $filemap={
85         Arrow=>["left_ptr","X_cursor","right_ptr",'4498f0e0c1937ffe01fd06f973665830'],
86         Cross=>["tcross","cross"],
87         Hand=>["hand1", "hand2",'9d800788f1b08800ae810202380a0822','e29285e634086352946a0e7090d73106'],
88         IBeam=>"xterm",
89         UpArrow=>"center_ptr",
90         SizeNWSE=>["bottom_right_corner","top_left_corner",'c7088f0f3e6c8088236ef8e1e3e70000'],
91         SizeNESW=>["bottom_left_corner","top_right_corner",'fcf1c3c7cd4491d801f1e1c78f100000'],
92         SizeWE=>["sb_h_double_arrow", "left_side", "right_side",'028006030e0e7ebffc7f7070c0600140'],
93         SizeNS=>["double_arrow","bottom_side","top_side",'00008160000006810000408080010102'],
94         Help=>["question_arrow",'d9ce0ab605698f320427677b458ad60b'],
95         Handwriting=>"pencil",
96         AppStarting=>["left_ptr_watch", '3ecb610c1bf2410f44200f48c40d3599'],
97         SizeAll=>"fleur",
98         Wait=>"watch",
99         NO=>"03b6e0fcb3499374a867c041f52298f0"
100 };
101
102 foreach my $section (@sections) {
103         my ($filename);
104
105         $filename=$section.".png";
106         unless (-f $filename) {
107                 next;
108         }
109
110         my ($image, $x, $frames, $width, $height, $curout);
111
112         $image=Image::Magick->new;
113         $x=$image->Read($filename);
114         warn "$x" if "$x";
115
116         $frames=$cfg->val($section, 'Frames');
117         $width=$image->Get('width')/$frames;
118         $height=$image->Get('height');
119
120         if (defined($filemap->{$section})) {
121                 $curout=$filemap->{$section};
122         } else {
123                 $curout=$section;
124         }
125
126         my $array=-1;
127         eval {
128                 if (defined (@{$curout}[0])) { };
129         };
130         unless ($@) {
131                 $array=0;
132         } 
133
134         LOOP:
135         my $outfile;
136
137         if ($array > -1) {
138                 if (defined (@{$curout}[0])) {
139                         $outfile=pop @{$curout};
140                 } else {
141                         next;
142                 }
143         } else {
144                 $outfile=$curout;
145         }
146         $outfile=$path."cursors/".$outfile;
147
148         if ($verbose) {
149                 print "Writing to $section -> $outfile\n";
150         }
151
152         open (FH, "| $generator > \"$outfile\"");
153
154         for (my $i=0; $i<$frames; $i++) {
155                 my ($tmpimg, $outfile);
156                 $outfile=$tmppath.$section.'-'.$i.'.png';
157                 $tmpimg=$image->Clone();
158
159                 $x=$tmpimg->Crop(width=>$width, height=>$height, x=>$i*$width, y=>0);
160                 warn "$x" if "$x";
161
162
163
164                 if ($shadow) {
165                         my $shadow=$tmpimg->Clone();
166                         my $orig=$tmpimg->Clone();
167                         my $mask1; # shadow mask
168                         my $mask2=$tmpimg->Clone();
169
170                         $x=$orig->Crop(x=>0, y=>0, height=>$height, width=>$width);
171                          warn "$x" if "$x";
172                         $orig->Set(size=>$width+$shadowx."x".$height+$shadowy);
173                          warn "$x" if "$x";
174
175                         $x=$shadow->Quantize(colorspace=>"Gray");
176                          warn "$x" if "$x";
177                         $x=$shadow->Level(level=>0, gamma=>0);
178                          warn "$x" if "$x";
179                         $x=$shadow->Gamma(gamma=>0);
180                          warn "$x" if "$x";
181                         $x=$shadow->Blur(radius=>$shadowblur, sigma=>$shadowblursigma);
182                          warn "$x" if "$x";
183
184                         $mask1=$shadow->Clone();
185
186                         $x=$mask1->Channel('Matte');
187                          warn "$x" if "$x";
188                         #$x=$mask2->Channel('Matte');
189                         # warn "$x" if "$x";
190                         $x=$mask2->Composite(image=>$mask1, compose=>"Over");
191                          warn "$x" if "$x";
192
193                         #$x=$orig->Composite(image=>$shadow, compose=>"Over", x=>$shadowx, y=>$shadowy, opacity=>0, mask=>$mask2);
194                          warn "$x" if "$x";
195                         #$x=$orig->Composite(image=>$tmpimg, compose=>"Over", x=>0, y=>0, opacity=>0, mask=>$mask2);
196                          warn "$x" if "$x";
197                         #$x=$orig->Composite(image=>$tmpimg, compose=>"Over", x=>0, y=>0, opacity=>0, mask=>$mask1);
198                          #warn "$x" if "$x";
199
200                         #$tmpimg=$shadow;
201                         $tmpimg=$orig;
202                 }
203
204                 # Opacity
205                 if (0) {
206                 my $tmpimg1=$tmpimg->Clone();
207                 my $x=$tmpimg1->Channel('Matte');
208                 warn "$x" if "$x";
209
210                 $tmpimg1->Set(type=>"GrayscaleMatte");
211                 $x=$tmpimg1->Quantize(colorspace=>"Gray");
212                 warn "$x" if "$x";
213                 
214                 $x=$tmpimg->Level(level=>0, gamma=>0);
215                 warn "$x" if "$x";
216
217                 $x=$tmpimg1->Gamma(gamma=>100);
218                 warn "$x" if "$x";
219
220                 $x=$tmpimg->Composite(image=>$tmpimg, compose=>"Over", mask=>$tmpimg1);
221                 warn "$x" if "$x";
222                 # end Opacity
223                 }
224
225                 $x=$tmpimg->Write($outfile);
226                 warn "$x" if "$x";
227
228                 print FH "1 ".
229                         $cfg->val($section,'Hot spot x')." ".
230                         $cfg->val($section,'Hot spot y')." ".
231                         $outfile." ".
232                         $cfg->val($section,'Interval')."\n";
233         }
234
235         if ($array > -1) {
236                 goto LOOP;
237         }
238 }
239
240 print "Writing theme index.\n";
241 open (FH, "> ${path}index.theme");
242 print FH <<EOF;
243 [Icon Theme]
244 Inherits=$inherits
245 EOF
246 close (FH);
247
248 print "Done. Theme wrote to ${path}\n";
This page took 0.067777 seconds and 3 git commands to generate.