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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.4 by root, Fri Nov 18 12:04:12 2005 UTC vs.
Revision 1.9 by root, Sun Nov 20 01:05:34 2005 UTC

1#!/opt/bin/perl 1#!/opt/bin/perl
2 2
3# cfarch2png - convert crossfire maps to png+metadata
4# Copyright (C) 2005 Marc Lehmann <gvpe@schmorp.de>
5#
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
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with gvpe; if not, write to the Free Software
18# Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
3# tower of stars: missing craters? 20# tower of stars: missing craters?
21
22our $VERSION = '1.01';
4 23
5use strict; 24use strict;
6 25
7use Storable; 26use Storable;
8use List::Util qw(max); 27use List::Util qw(max);
9 28
10use Gtk2; 29use Gtk2;
11
12our $VERSION = '1.0';
13 30
14#init Gtk2::Gdk; 31#init Gtk2::Gdk;
15 32
16my $LIB = $ENV{CROSSFIRE_LIBDIR} 33my $LIB = $ENV{CROSSFIRE_LIBDIR}
17 or die "\$CROSSFIRE_LIBDIR must be set\n"; 34 or die "\$CROSSFIRE_LIBDIR must be set\n";
195 } 212 }
196 213
197 $meta{width} = $mapx; 214 $meta{width} = $mapx;
198 $meta{height} = $mapy; 215 $meta{height} = $mapy;
199 216
200 my %map_face;
201 my %draw_info; 217 my %draw_info;
202 218
203 # first pass, gather face stacking order, border and corner info 219 # first pass, gather face stacking order, border and corner info
204 for my $x (0 .. $mapx - 1) { 220 for my $x (0 .. $mapx - 1) {
205 my $col = $map->[$x]; 221 my $col = $map->[$x];
210 my $a = $as->[$layer]; 226 my $a = $as->[$layer];
211 227
212 my $o = $arch->{$a->{_name}} 228 my $o = $arch->{$a->{_name}}
213 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 229 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
214 230
215 my $A = { %$o, %$a }; 231 my $smoothlevel = exists $a->{smoothlevel} ? $a->{smoothlevel} : $o->{smoothlevel};
216 232 my $is_floor = exists $a->{is_floor} ? $a->{is_floor} : $o->{is_floor};
217 my $smoothlevel = $A->{smoothlevel};
218 my $level = $smoothlevel ? $smoothlevel 233 my $level = $smoothlevel ? $smoothlevel
219 : $A->{is_floor} ? 0 234 : $is_floor ? 0
220 : 256 + $layer; 235 : 256 + $layer;
221 236
222 while ($o) { 237 while ($o) {
238 my $face = $a->{face} || $o->{face};
239
223 my $pb = tile $A->{face} 240 my $pb = tile $face
224 or (warn "$mapname: face '$A->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last; 241 or (warn "$mapname: face '$face' not found for arch '$a->{_name}' at ($x|$y)\n"), last;
225 242
226 my $mx = $x + $o->{x}; 243 my $mx = $x + $o->{x};
227 my $my = $y + $o->{y}; 244 my $my = $y + $o->{y};
228 245
229 last if 0 > $mx || $mx >= $mapx 246 last if 0 > $mx || $mx >= $mapx
230 || 0 > $my || $my >= $mapy; 247 || 0 > $my || $my >= $mapy;
231 248
232 # this is very ugly (some tiles are 32x33 or worse) 249 # this is very ugly (some tiles are 32x33 or worse)
233 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; 250 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2;
234 251
235 if (my $sface = $smooth->{$A->{face}}) { 252 if (my $sface = $smooth->{$face}) {
236 $bigface and die "can't handle bigfaces with smoothing ($A->{face})\n"; 253 $bigface and die "can't handle bigfaces with smoothing ($face)\n";
237 254
238 # full tile 255 # full tile
239 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000; 256 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000;
240 257
241 # borders 258 # borders
252 } 269 }
253 270
254 my $dx = $bigface ? $o->{x} : 0; 271 my $dx = $bigface ? $o->{x} : 0;
255 my $dy = $bigface ? $o->{y} : 0; 272 my $dy = $bigface ? $o->{y} : 0;
256 273
257 $draw_info{$level}{$o->{face}}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16); 274 $draw_info{$level}{$face}{$mx, $my} |= 0x2000 | (($dx + 128) << 24) | (($dy + 128) << 16);
258 275
259 $o = $o->{more}; 276 $o = $o->{more};
260 } 277 }
261 } 278 }
262 } 279 }
263 } 280 }
264 281
265 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T 282 my $map_pb = new Gtk2::Gdk::Pixbuf "rgb", 1, 8, $mapx * T, $mapy * T
266 or die; 283 or die;
267 $map_pb->fill (0x00000000); 284 $map_pb->fill (0xffffff00);
268 285
269 # second pass, render all the stuff 286 # second pass, render all the stuff
270 for my $level (sort { $a <=> $b } keys %draw_info) { 287 for my $level (sort { $a <=> $b } keys %draw_info) {
271 my $v = $draw_info{$level}; 288 my $v = $draw_info{$level};
272 while (my ($sface, $info) = each %$v) { 289 while (my ($sface, $info) = each %$v) {
329for my $file (@ARGV) { 346for my $file (@ARGV) {
330 my $mapa = read_arch $file; 347 my $mapa = read_arch $file;
331 my ($pb, $meta) = cfmap_render $mapa, $file; 348 my ($pb, $meta) = cfmap_render $mapa, $file;
332 $pb->save ("$file.png~", "png"); 349 $pb->save ("$file.png~", "png");
333 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg"; 350 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg";
334 system "mogrify", "-colors" => 65536, "$file.png~"; 351 #system "mogrify", "-colors" => 65536, "$file.png~"; # destroys transparency
335 system "pngcrush", "-q", "-m" => 7, "-rem" => "alla", "-reduce", "$file.png~", "$file.png"; 352 system "pngcrush", "-q", "-m" => 7, "-rem", "alla", "-cc", "-reduce", "$file.png~", "$file.png";
336 unlink "$file.png~"; 353 unlink "$file.png~";
337 Storable::nstore $meta, "$file.pst"; 354 Storable::nstore $meta, "$file.pst";
338} 355}
339 356
340 357

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines