… | |
… | |
9 | |
9 | |
10 | my $CONVERT = "@CONVERT@"; |
10 | my $CONVERT = "@CONVERT@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
11 | my $IDENTIFY = "@IDENTIFY@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
12 | my $OPTIPNG = "@OPTIPNG@"; |
13 | my $RSYNC = "@RSYNC@"; |
13 | my $RSYNC = "@RSYNC@"; |
|
|
14 | my $PNGNQ = "@PNGNQ@"; |
14 | |
15 | |
15 | use Getopt::Long; |
16 | use Getopt::Long; |
16 | use Coro::Event; |
17 | use Coro::Event; |
17 | use AnyEvent; |
18 | use AnyEvent; |
18 | use IO::AIO (); |
19 | use IO::AIO (); |
… | |
… | |
42 | my $CACHE = 0; |
43 | my $CACHE = 0; |
43 | my $FORCE; |
44 | my $FORCE; |
44 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPDIR = "/tmp/cfutil$$~"; |
45 | my $TMPFILE = "aaaa0"; |
46 | my $TMPFILE = "aaaa0"; |
46 | |
47 | |
|
|
48 | our %COLOR = ( |
|
|
49 | black => 0, |
|
|
50 | white => 1, |
|
|
51 | navy => 2, |
|
|
52 | red => 3, |
|
|
53 | orange => 4, |
|
|
54 | blue => 5, |
|
|
55 | darkorange => 6, |
|
|
56 | green => 7, |
|
|
57 | lightgreen => 8, |
|
|
58 | grey => 9, |
|
|
59 | brown => 10, |
|
|
60 | gold => 11, |
|
|
61 | tan => 12, |
|
|
62 | ); |
|
|
63 | |
47 | END { system "rm", "-rf", $TMPDIR } |
64 | END { system "rm", "-rf", $TMPDIR } |
48 | |
65 | |
49 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
66 | Event->signal (signal => "INT", cb => sub { exit 1 }); |
50 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
67 | Event->signal (signal => "TERM", cb => sub { exit 1 }); |
51 | |
68 | |
… | |
… | |
154 | fork_sub { |
171 | fork_sub { |
155 | system "convert png:\Q$path\E -depth 8 rgba:-" |
172 | system "convert png:\Q$path\E -depth 8 rgba:-" |
156 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
173 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
157 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
174 | . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" |
158 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
175 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
159 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
176 | system $OPTIPNG, "-i0", "-q", "$other~"; |
160 | die "$other~ has zero size, aborting." unless -s "$other~"; |
177 | die "$other~ has zero size, aborting." unless -s "$other~"; |
161 | rename "$other~", $other; |
178 | rename "$other~", $other; |
162 | }; |
179 | }; |
163 | } |
180 | } |
164 | |
181 | |
… | |
… | |
170 | my $other = "$stem.32x32.png~"; |
187 | my $other = "$stem.32x32.png~"; |
171 | |
188 | |
172 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
189 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
173 | fork_sub { |
190 | fork_sub { |
174 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
191 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
175 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
192 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
193 | |
|
|
194 | # reduce smoothfaces >10000 bytes |
|
|
195 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
|
|
196 | my $ncolor = 256; |
|
|
197 | while () { |
|
|
198 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
|
|
199 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
|
|
200 | last if 10000 > -s "$other~~"; |
|
|
201 | $ncolor = int $ncolor * 0.9; |
|
|
202 | $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
|
|
203 | } |
|
|
204 | |
|
|
205 | printf "reduced %s from %d to %d bytes using %d colours.\n", |
|
|
206 | $other, -s "$other~", -s "$other~~", $ncolor |
|
|
207 | if $VERBOSE >= 2; |
|
|
208 | rename "$other~~", "$other~"; |
|
|
209 | } |
|
|
210 | |
176 | die "$other~ has zero size, aborting." unless -s "$other~"; |
211 | die "$other~ has zero size, aborting." unless -s "$other~"; |
177 | rename "$other~", $other; |
212 | rename "$other~", $other; |
178 | }; |
213 | }; |
179 | } |
214 | } |
180 | |
215 | |
… | |
… | |
282 | |
317 | |
283 | my $ext = $x|$y ? "+$x+$y" : ""; |
318 | my $ext = $x|$y ? "+$x+$y" : ""; |
284 | |
319 | |
285 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
320 | $o->{face} .= $ext unless /^blank.x11$|^empty.x11$/ || !$o->{face}; |
286 | |
321 | |
287 | my $visibility = delete $o->{visibility} if exists $o->{visibility}; |
322 | $visibility = delete $o->{visibility} if exists $o->{visibility}; |
288 | my $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
323 | $magicmap = delete $o->{magicmap} if exists $o->{magicmap}; |
289 | |
324 | |
290 | my $anim = delete $o->{anim}; |
325 | my $anim = delete $o->{anim}; |
291 | |
326 | |
292 | if ($anim) { |
327 | if ($anim) { |
293 | # possibly add $ext to the animation name to avoid |
328 | # possibly add $ext to the animation name to avoid |
… | |
… | |
367 | } elsif ($file =~ /\.trs$/) { |
402 | } elsif ($file =~ /\.trs$/) { |
368 | push @trs, [$path, $file]; |
403 | push @trs, [$path, $file]; |
369 | } elsif ($file =~ /\.arc$/) { |
404 | } elsif ($file =~ /\.arc$/) { |
370 | push @arc, [$path, $file]; |
405 | push @arc, [$path, $file]; |
371 | } else { |
406 | } else { |
372 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
407 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
373 | } |
408 | } |
374 | } |
409 | } |
375 | }; |
410 | }; |
376 | } |
411 | } |
377 | |
412 | |
… | |
… | |
438 | |
473 | |
439 | last; |
474 | last; |
440 | } |
475 | } |
441 | } |
476 | } |
442 | |
477 | |
|
|
478 | # remove base classes (by naming scheme, should use something like "baseclass xxx" to inherit |
|
|
479 | @ARC = grep $_->{_name} !~ /^(?:type|class)_/, @ARC; |
|
|
480 | |
443 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
481 | open my $fh, ">:utf8", "$DATADIR/archetypes~" |
444 | or die "$DATADIR/archetypes~: $!"; |
482 | or die "$DATADIR/archetypes~: $!"; |
445 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
483 | print $fh Crossfire::archlist_to_string [sort { $a->{_name} cmp $b->{_name} } @ARC]; |
446 | } |
484 | } |
447 | |
485 | |
… | |
… | |
459 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
497 | length $v->{data32} <= 10000 or warn "$k: face32 larger than 10000 bytes, will not work with crossfire client.\n"; |
460 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
498 | #length $v->{data64} <= 10000 or warn "$k: face64 larger than 10000 bytes.\n"; |
461 | |
499 | |
462 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
500 | $v->{chksum32} = Digest::MD5::md5 $v->{data32}; |
463 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
501 | $v->{chksum64} = Digest::MD5::md5 $v->{data64}; |
|
|
502 | |
|
|
503 | if (my $magicmap = $v->{magicmap}) { |
|
|
504 | $magicmap =~ y/A-Z_\-/a-z/d; |
|
|
505 | $v->{magicmap} = $COLOR{$magicmap}; |
|
|
506 | } |
464 | } |
507 | } |
465 | |
508 | |
466 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
509 | open my $fh, ">:perlio", "$DATADIR/facedata~" |
467 | or die "$DATADIR/facedata~: $!"; |
510 | or die "$DATADIR/facedata~: $!"; |
468 | |
511 | |