… | |
… | |
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 (); |
… | |
… | |
154 | fork_sub { |
155 | fork_sub { |
155 | system "convert png:\Q$path\E -depth 8 rgba:-" |
156 | system "convert png:\Q$path\E -depth 8 rgba:-" |
156 | . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" |
157 | . "| $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~" |
158 | . "| 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 $? ($!)"; |
159 | and die "convert/hq2xa pipeline error: status $? ($!)"; |
159 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
160 | system $OPTIPNG, "-i0", "-q", "$other~"; |
160 | die "$other~ has zero size, aborting." unless -s "$other~"; |
161 | die "$other~ has zero size, aborting." unless -s "$other~"; |
161 | rename "$other~", $other; |
162 | rename "$other~", $other; |
162 | }; |
163 | }; |
163 | } |
164 | } |
164 | |
165 | |
… | |
… | |
170 | my $other = "$stem.32x32.png~"; |
171 | my $other = "$stem.32x32.png~"; |
171 | |
172 | |
172 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
173 | if (0 > aio_lstat $other or (-M _) > (-M $path)) { |
173 | fork_sub { |
174 | fork_sub { |
174 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
175 | system "convert png:\Q$path\E -geometry 50% -filter lanczos $QUANTIZE -quality 00 png32:\Q$other\E~"; |
175 | system $OPTIPNG, "-o5", "-i0", "-q", "$other~"; |
176 | system $OPTIPNG, "-i0", "-q", "$other~"; |
|
|
177 | |
|
|
178 | # reduce smoothfaces >10000 bytes |
|
|
179 | if ($stem =~ /_S\./ && (-s "$other~") > 10000) { |
|
|
180 | my $ncolor = 256; |
|
|
181 | while () { |
|
|
182 | system "<\Q$other~\E $PNGNQ -s1 -n$ncolor >\Q$other~~\E"; |
|
|
183 | system $OPTIPNG, "-i0", "-q", "$other~~"; |
|
|
184 | last if 10000 > -s "$other~~"; |
|
|
185 | $ncolor = int $ncolor * 0.9; |
|
|
186 | $ncolor > 8 or die "cannot reduce filesize to < 10000 bytes"; |
|
|
187 | } |
|
|
188 | |
|
|
189 | printf "reduced %s from %d to %d bytes using %d colours.\n", |
|
|
190 | $other, -s "$other~", -s "$other~~", $ncolor |
|
|
191 | if $VERBOSE >= 2; |
|
|
192 | rename "$other~~", "$other~"; |
|
|
193 | } |
|
|
194 | |
176 | die "$other~ has zero size, aborting." unless -s "$other~"; |
195 | die "$other~ has zero size, aborting." unless -s "$other~"; |
177 | rename "$other~", $other; |
196 | rename "$other~", $other; |
178 | }; |
197 | }; |
179 | } |
198 | } |
180 | |
199 | |
… | |
… | |
367 | } elsif ($file =~ /\.trs$/) { |
386 | } elsif ($file =~ /\.trs$/) { |
368 | push @trs, [$path, $file]; |
387 | push @trs, [$path, $file]; |
369 | } elsif ($file =~ /\.arc$/) { |
388 | } elsif ($file =~ /\.arc$/) { |
370 | push @arc, [$path, $file]; |
389 | push @arc, [$path, $file]; |
371 | } else { |
390 | } else { |
372 | warn "ignoring $path/$file\n" if $VERBOSE >= 2; |
391 | warn "ignoring $path/$file\n" if $VERBOSE >= 3; |
373 | } |
392 | } |
374 | } |
393 | } |
375 | }; |
394 | }; |
376 | } |
395 | } |
377 | |
396 | |