--- deliantra/server/utils/cfutil.in 2007/07/25 22:30:38 1.46 +++ deliantra/server/utils/cfutil.in 2007/08/18 22:25:35 1.52 @@ -21,6 +21,7 @@ use Crossfire; use Coro; use Coro::AIO; +use Coro::Util; use POSIX (); use Digest::MD5; use Carp; @@ -172,12 +173,54 @@ my $other = "$stem.64x64.png~"; if (0 > aio_lstat $other or (-M _) > (-M $path)) { - my $wrap = 0; # for the time being fork_sub { - system "convert png:\Q$path\E -depth 8 rgba:-" - . "| $exec_prefix/bin/cfhq2xa $w $h $wrap" - . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $QUANTIZE -quality 00 png32:\Q$other\E~" - and die "convert/hq2xa pipeline error: status $? ($!)"; + my $CROP; + my $SRC = "png:\Q$path\E"; + + # check if this is a wall. ultra-ugly. ultra-ultra-ugly. + if ($path =~ /^(.*\/wall\/.*_)([0-9A-F])(\.x11.*\.png)$/) { + my ($pfx, $dir, $sfx) = ($1, hex $2, $3); + #check for 0..F images to be sure(?) this is a wall + unless (grep { !-e sprintf "%s%X%s", $pfx, $_, $sfx } 0..15) { + # add a 4px border and add other images around it + $CROP = "-shave 8x8 +repage"; + + $w += 8; + $h += 8; + + $SRC = "-size ${w}x${h} xc:transparent"; + $SRC .= " png:\Q$path\E -geometry +4+4 -composite"; + + # 8 surrounding images + for ( + # x y b r0 r1 + [-1, -1, 0, 6], + [ 0, -1, 1, 10, 14], + [+1, -1, 0, 12], + + [-1, 0, 8, 5, 7], + # + [+1, 0, 2, 5, 13], + + [-1, +1, 0, 3], + [ 0, +1, 4, 10, 11], + [+1, +1, 0, 9], + ) { + my ($x, $y, $d, $r0, $r1) = @$_; + $SRC .= sprintf " png:%s%X%s -geometry %+d%+d -composite", + "\Q$pfx", + ($dir & $d) ? $r1 : $r0, + "\Q$sfx", + $x * ($w - 8) + 4, + $y * ($h - 8) + 4; + } + } + } + + system "convert -depth 8 $SRC rgba:-" + . "| $exec_prefix/bin/cfhq2xa $w $h 0" + . "| convert -depth 8 -size ".($w * 2)."x".($h * 2)." rgba:- $CROP $QUANTIZE -quality 00 png32:\Q$other\E~" + and die "convert/cfhq2xa pipeline error: status $? ($!)"; system $OPTIPNG, "-i0", "-q", "$other~"; die "$other~ has zero size, aborting." unless -s "$other~"; rename "$other~", $other; @@ -396,8 +439,10 @@ unless (exists $FILECACHE{$_[0]}) { my $data; if (0 < aio_load $_[0], $data) { - $data = $_[1]->($data) - if $_[1]; + if ($_[1]) { + $data = eval { $_[1]->($data) }; + warn "$_[0]: $@" if $@; + } } $FILECACHE{$_[0]} = $data; @@ -415,16 +460,29 @@ my $meta = load_cached "$dir/meta", sub { JSON::XS::from_json shift }; - $file =~ s/\.res$//; - $file =~ s/\.(ogg|wav|jpg|png)$//; - - substr $dir, 0, 1 + length $PATH, ""; + next if $meta && !exists $meta->{$file}; $meta = { %{ $meta->{"" } || {} }, %{ $meta->{$file} || {} }, }; + if ($meta->{license} =~ s/^#//) { + $meta->{license} = ({ + "pd" => "Public Domain", + "gpl" => "GNU General Public License, version 3.0 or any later", + "cc/by/2.0" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.0/", + "cc/by/2.5" => "Licensed under Creative Commons Attribution 2.0 http://creativecommons.org/licenses/by/2.5/", + "cc/by/3.0" => "Licensed under Creative Commons Attribution 3.0 http://creativecommons.org/licenses/by/3.0/", + })->{$meta->{license}} + || warn "$dir/$file: license tag '$meta->{license}' not found."; + } + + $file =~ s/\.res$//; + $file =~ s/\.(ogg|wav|jpg|png)$//; + + substr $dir, 0, 1 + length $PATH, ""; + $RESOURCE{"$dir/$file"} = { type => (delete $meta->{type}) || $type, data => $data, @@ -453,7 +511,7 @@ push @res, [$path, $file, 3] # FT_MUSIC if $file =~ /\.(ogg)$/; - } elsif ($dir =~ /^sounds(?:\/|$)/) { + } elsif ($dir =~ /^sound(?:\/|$)/) { push @res, [$path, $file, 5] # FT_SOUND if $file =~ /\.(wav|ogg)$/;