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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.16 by root, Mon Dec 12 01:37:11 2005 UTC vs.
Revision 1.22 by root, Fri Apr 13 18:09:23 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.2'; 33our $VERSION = '1.212';
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+)$/;
91 && Storable::retrieve "$path.pst" 102 && Storable::retrieve "$path.pst"
92 } or do { 103 } or do {
93 my %arc; 104 my %arc;
94 my ($more, $prev); 105 my ($more, $prev);
95 106
96 open my $fh, "<:raw", $path 107 open my $fh, "<:utf8", $path
97 or die "$path: $!"; 108 or die "$path: $!";
98 109
99 my $parse_block; $parse_block = sub { 110 my $parse_block; $parse_block = sub {
100 my %arc = @_; 111 my %arc = @_;
101 112
275 286
276 # full tile 287 # full tile
277 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; 288 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000;
278 289
279 # borders 290 # borders
280 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0031; 291 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0091;
281 $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0092; 292 $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0032;
282 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064; 293 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064;
283 $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8; 294 $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8;
284 295
285 # corners 296 # corners
286 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my + 1} |= 0x0100; 297 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my + 1} |= 0x0100;
374 ($map_pb, \%meta) 385 ($map_pb, \%meta)
375} 386}
376 387
377for my $file (@ARGV) { 388for my $file (@ARGV) {
378 my $mapa = read_arch $file; 389 my $mapa = read_arch $file;
390 $file =~ s/\.map$//;
379 my ($pb, $meta) = cfmap_render $mapa, $file; 391 my ($pb, $meta) = cfmap_render $mapa, $file;
380 $pb->save ("$file.png~~", "png"); 392 $pb->save ("$file.png~~", "png");
381 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";
382 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency 394 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency
383 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~";
384# system "pngnq <\Q$file.png~\E >\Q$file.png\E"; 396# system "pngnq <\Q$file.png~\E >\Q$file.png\E";
385 unlink "$file.png~~"; 397 unlink "$file.png~~";
386 Storable::nstore $meta, "$file.pst"; 398 Storable::nstore $meta, "$file.pst";
387 utime +(stat $file)[8,9], "$file.pst"; 399 utime +(stat $file)[8,9], "$file.pst";
400 utime +(stat $file)[8,9], "$file.jpg";
388 utime +(stat $file)[8,9], "$file.png~"; 401 utime +(stat $file)[8,9], "$file.png~";
389 rename "$file.png~", "$file.png"; 402 rename "$file.png~", "$file.png";
390} 403}
391 404
392 405

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines