ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cfmaps/cfmap2png
(Generate patch)

Comparing cfmaps/cfmap2png (file contents):
Revision 1.10 by root, Sun Nov 20 01:31:21 2005 UTC vs.
Revision 1.21 by root, Wed Feb 14 02:33:47 2007 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# cfarch2png - convert crossfire maps to png+metadata 3# cfarch2png - convert crossfire maps to png+metadata
4# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de> 4# Copyright (C) 2005,2007 Marc Lehmann <cfmaps@schmorp.de>
5# 5#
6# CFARCH2PNG is free software; you can redistribute it and/or modify 6# CFARCH2PNG is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by 7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or 8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version. 9# (at your option) any later version.
15# 15#
16# You should have received a copy of the GNU General Public License 16# You should have received a copy of the GNU General Public License
17# along with gvpe; if not, write to the Free Software 17# along with gvpe; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 19
20# tower of stars: missing craters? 20# Quoth The master himself:
21#
22# Object ordering is basically like this:
23# top face: players or monsters. If none on the space, object with highest
24# visibility value - if equal, then top object in terms of object stacking on the map.
25# middle face: Object with highest visibility (of monster/player on a space). If
26# no monster/player, then object with second highest visibility, or if all equal,
27# second top object relative to map stacking.
28# Bottom object: the highest object that is a floor type object.
29#
30# ... i believe that anytime, but it still doesn't mention the smoothlevel
31# interaction :(
21 32
22our $VERSION = '1.1'; 33our $VERSION = '1.211';
23 34
24use strict; 35use strict;
25 36
26use Storable; 37use Storable;
27use List::Util qw(max); 38use List::Util qw(max);
42 -M "$path.pst" < -M $path 53 -M "$path.pst" < -M $path
43 && Storable::retrieve "$path.pst" 54 && Storable::retrieve "$path.pst"
44 } or do { 55 } or do {
45 my %pak; 56 my %pak;
46 57
47 open my $fh, "<:raw", $path 58 open my $fh, "<:raw:perlio", $path
48 or die "$_[0]: $!"; 59 or die "$_[0]: $!";
49 while (<$fh>) { 60 while (<$fh>) {
50 my ($type, $id, $len, $path) = split; 61 my ($type, $id, $len, $path) = split;
51 $path =~ s/.*\///; 62 $path =~ s/.*\///;
52 read $fh, $pak{$path}, $len; 63 read $fh, $pak{$path}, $len;
65 -M "$path.pst" < -M $path 76 -M "$path.pst" < -M $path
66 && Storable::retrieve "$path.pst" 77 && Storable::retrieve "$path.pst"
67 } or do { 78 } or do {
68 my %smooth; 79 my %smooth;
69 80
70 open my $fh, "<:raw", $path 81 open my $fh, "<:raw:perlio", $path
71 or die "$path: $!"; 82 or die "$path: $!";
72 while (<$fh>) { 83 while (<$fh>) {
73 next if /^\s*($|#)/; 84 next if /^\s*($|#)/;
74 85
75 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/; 86 $smooth{$1} = $2 if /^(\S+)\s+(\S+)$/;
76 } 87 }
77 88
78 Storable::nstore \%smooth, "$path.pst"; 89 Storable::nstore \%smooth, "$path.pst";
90 utime +(stat $path)[8,9], "$path.pst";
79 91
80 \%smooth 92 \%smooth
81 } 93 }
82} 94}
83 95
90 && Storable::retrieve "$path.pst" 102 && Storable::retrieve "$path.pst"
91 } or do { 103 } or do {
92 my %arc; 104 my %arc;
93 my ($more, $prev); 105 my ($more, $prev);
94 106
95 open my $fh, "<:raw", $path 107 open my $fh, "<:utf8", $path
96 or die "$path: $!"; 108 or die "$path: $!";
97 109
98 my $parse_block; $parse_block = sub { 110 my $parse_block; $parse_block = sub {
99 my %arc = @_; 111 my %arc = @_;
100 112
151 } 163 }
152 } 164 }
153 165
154 undef $parse_block; # work around bug in perl not freeing $fh etc. 166 undef $parse_block; # work around bug in perl not freeing $fh etc.
155 167
168 if ($cache) {
156 Storable::nstore \%arc, "$path.pst" 169 Storable::nstore \%arc, "$path.pst";
157 if $cache; 170 utime +(stat $path)[8,9], "$path.pst";
171 }
158 172
159 \%arc 173 \%arc
160 } 174 }
161} 175}
162 176
222 # first pass, gather face stacking order, border and corner info 236 # first pass, gather face stacking order, border and corner info
223 for my $x (0 .. $mapx - 1) { 237 for my $x (0 .. $mapx - 1) {
224 my $col = $map->[$x]; 238 my $col = $map->[$x];
225 for my $y (0 .. $mapy - 1) { 239 for my $y (0 .. $mapy - 1) {
226 my $as = $col->[$y] || []; 240 my $as = $col->[$y] || [];
227 241
242 my $minsmooth = 0;
243
228 for my $layer (0 .. $#$as) { 244 for my $layer (0 .. $#$as) {
229 my $a = $as->[$layer]; 245 my $a = $as->[$layer];
230 246
231 my $o = $arch->{$a->{_name}} 247 my $o = $arch->{$a->{_name}}
232 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 248 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
233 249
234 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel}; 250 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
251
252 # hack to ensure somewhat correct ordering in case of conflicting
253 # smoothlevel/stacking order
254 $smoothlevel = $minsmooth + 0.01 if $minsmooth >= $smoothlevel;
255 $minsmooth = $smoothlevel;
256
235 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor}; 257 #my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
236 my $level = $smoothlevel ? $smoothlevel 258 my $level = $smoothlevel + $layer * 256;
237 : $is_floor ? 0 259
238 : 256 + $layer; 260 $level -= 100 * 256 if $o->{_name} eq "blocked";
239 261
240 while ($o) { 262 while ($o) {
241 my $face = $a->{face} || $o->{face}; 263 my $face = $a->{face} || $o->{face};
242 264
243 my $pb = tile $face 265 my $pb = tile $face
277 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400; 299 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
278 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800; 300 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
279 } 301 }
280 302
281 $o = $o->{more}; 303 $o = $o->{more};
304 $level = ($layer + 1000) * 2; # put "big things" on top, no matter what
282 } 305 }
283 } 306 }
284 } 307 }
285 } 308 }
286 309
299 my ($x, $y) = split $;, $xy; 322 my ($x, $y) = split $;, $xy;
300 323
301 next if $x < 0 || $x >= $mapx 324 next if $x < 0 || $x >= $mapx
302 || $y < 0 || $y >= $mapy; 325 || $y < 0 || $y >= $mapy;
303 326
304 # bits is 00XX XXXX YYYY YYFX cccc CCCC BBBB 327 # bits is xxxx xxxx yyyy yyyy __fn cccc CCCC bbbb
305 # X don't draw
306 # F full tile draw with x|y bigface displacement 328 # f full tile draw with x|y bigface displacement
307 # c maybe draw these corners
308 # C do not draw these corners 329 # n do not draw borders&corners
330 # c draw these corners, but...
331 # C ... not these
309 # b draw these borders 332 # b draw these borders
310 333
311 if ($bits & 0x2000) { 334 if ($bits & 0x2000) {
312 my $dx = (($bits >> 24) & 0xff) - 128; 335 my $dx = (($bits >> 24) & 0xff) - 128;
313 my $dy = (($bits >> 16) & 0xff) - 128; 336 my $dy = (($bits >> 16) & 0xff) - 128;
362 ($map_pb, \%meta) 385 ($map_pb, \%meta)
363} 386}
364 387
365for my $file (@ARGV) { 388for my $file (@ARGV) {
366 my $mapa = read_arch $file; 389 my $mapa = read_arch $file;
390 $file =~ s/\.map$//;
367 my ($pb, $meta) = cfmap_render $mapa, $file; 391 my ($pb, $meta) = cfmap_render $mapa, $file;
368 $pb->save ("$file.png~", "png"); 392 $pb->save ("$file.png~~", "png");
369 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; 393 system "gm", "convert", "$file.png~~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg";
370 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency 394 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency
371 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png"; 395 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~~", "$file.png~";
396# system "pngnq <\Q$file.png~\E >\Q$file.png\E";
372 unlink "$file.png~"; 397 unlink "$file.png~~";
373 Storable::nstore $meta, "$file.pst"; 398 Storable::nstore $meta, "$file.pst";
399 utime +(stat $file)[8,9], "$file.pst";
400 utime +(stat $file)[8,9], "$file.jpg";
401 utime +(stat $file)[8,9], "$file.png~";
402 rename "$file.png~", "$file.png";
374} 403}
375 404
376 405
377 406
378 407

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines