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

Comparing cfmaps/cfmap2png (file contents):
Revision 1.2 by root, Thu Nov 17 12:15:19 2005 UTC vs.
Revision 1.3 by root, Fri Nov 18 06:57:15 2005 UTC

85 while (<$fh>) { 85 while (<$fh>) {
86 s/\s+$//; 86 s/\s+$//;
87 if (/^end$/i) { 87 if (/^end$/i) {
88 last; 88 last;
89 } elsif (/^arch (\S+)$/) { 89 } elsif (/^arch (\S+)$/) {
90 push @{ $arc{subarch} }, $parse_block->(_name => $1); 90 push @{ $arc{inventory} }, $parse_block->(_name => $1);
91 } elsif (/^msg$/) { 91 } elsif (/^msg$/) {
92 while (<$fh>) { 92 while (<$fh>) {
93 last if /^endmsg\s*$/i; 93 last if /^endmsg\s*$/i;
94 $arc{msg} .= $_; 94 $arc{msg} .= $_;
95 } 95 }
191 $meta{height} = $mapy; 191 $meta{height} = $mapy;
192 192
193 my %map_face; 193 my %map_face;
194 my %draw_info; 194 my %draw_info;
195 195
196 my $OBJ_LEVEL = 2**32; # higher than any valid (or in-use) smooth_level
197
198 # first pass, gather face stacking order, border and corner info 196 # first pass, gather face stacking order, border and corner info
199 for my $x (0 .. $mapx - 1) { 197 for my $x (0 .. $mapx - 1) {
200 my $col = $map->[$x]; 198 my $col = $map->[$x];
201 for my $y (0 .. $mapy - 1) { 199 for my $y (0 .. $mapy - 1) {
202 my $as = $col->[$y] || []; 200 my $as = $col->[$y] || [];
203 201
204 for my $layer (0 .. $#$as) { 202 for my $layer (0 .. $#$as) {
205 my $a = $as->[$layer]; 203 my $a = $as->[$layer];
206 204
207 my $o = $a;
208 delete $o->{x};
209 delete $o->{y};
210
211 my $os = $arch->{$a->{_name}} 205 my $o = $arch->{$a->{_name}}
212 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next; 206 or (warn "$mapname: arch '$a->{_name}' not found at ($x|$y)\n"), next;
213 207
214 for (1..10) {
215 $o = { %$os, %$o }; 208 my $A = { %$o, %$a };
216 last unless exists $os->{other_arch};
217 $o = $arch->{$os->{other_arch}};
218 }
219 209
220 my $smooth_level = $o->{smoothlevel}; 210 my $smoothlevel = $A->{smoothlevel};
221 my $level = $smooth_level ? $smooth_level 211 my $level = $smoothlevel ? $smoothlevel
222 : $o->{is_floor} ? 0 212 : $A->{is_floor} ? 0
223 : $OBJ_LEVEL + $layer; 213 : 256 + $layer;
224 214
225 while ($o) { 215 while ($o) {
226 my $pb = tile $o->{face} 216 my $pb = tile $A->{face}
227 or (warn "$mapname: face '$o->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last; 217 or (warn "$mapname: face '$A->{face}' not found for arch '$a->{_name}' at ($x|$y)\n"), last;
228 218
229 my $mx = $x + $o->{x}; 219 my $mx = $x + $o->{x};
230 my $my = $y + $o->{y}; 220 my $my = $y + $o->{y};
231 221
232 last if 0 > $mx || $mx >= $mapx 222 last if 0 > $mx || $mx >= $mapx
233 || 0 > $my || $my >= $mapy; 223 || 0 > $my || $my >= $mapy;
234 224
235 # this is very ugly (some tiles are 32x33 or worse) 225 # this is very ugly (some tiles are 32x33 or worse)
236 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2; 226 my $bigface = $pb->get_width >= T*2 || $pb->get_height >= T*2;
237 227
238 if (my $sface = $smooth->{$o->{face}}) { 228 if (my $sface = $smooth->{$A->{face}}) {
239 $bigface and die "can't handle big faces with smoothing ($o->{face})\n"; 229 $bigface and die "can't handle bigfaces with smoothing ($A->{face})\n";
240 230
241 # full tile 231 # full tile
242 $draw_info{$smooth_level}{$sface}{$mx , $my } |= 0x1000; 232 $draw_info{$smoothlevel}{$sface}{$mx , $my } |= 0x1000;
243 233
244 # borders 234 # borders
245 $draw_info{$smooth_level}{$sface}{$mx + 1, $my } |= 0x0031; 235 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my } |= 0x0031;
246 $draw_info{$smooth_level}{$sface}{$mx , $my + 1} |= 0x0092; 236 $draw_info{$smoothlevel}{$sface}{$mx , $my + 1} |= 0x0092;
247 $draw_info{$smooth_level}{$sface}{$mx - 1, $my } |= 0x0064; 237 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my } |= 0x0064;
248 $draw_info{$smooth_level}{$sface}{$mx , $my - 1} |= 0x00c8; 238 $draw_info{$smoothlevel}{$sface}{$mx , $my - 1} |= 0x00c8;
249 239
250 # corners 240 # corners
251 $draw_info{$smooth_level}{$sface}{$mx + 1, $my + 1} |= 0x0100; 241 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my + 1} |= 0x0100;
252 $draw_info{$smooth_level}{$sface}{$mx - 1, $my + 1} |= 0x0200; 242 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my + 1} |= 0x0200;
253 $draw_info{$smooth_level}{$sface}{$mx - 1, $my - 1} |= 0x0400; 243 $draw_info{$smoothlevel}{$sface}{$mx - 1, $my - 1} |= 0x0400;
254 $draw_info{$smooth_level}{$sface}{$mx + 1, $my - 1} |= 0x0800; 244 $draw_info{$smoothlevel}{$sface}{$mx + 1, $my - 1} |= 0x0800;
255 } else {
256 $smooth_level = 0;
257 } 245 }
258 246
259 my $dx = $bigface ? $o->{x} : 0; 247 my $dx = $bigface ? $o->{x} : 0;
260 my $dy = $bigface ? $o->{y} : 0; 248 my $dy = $bigface ? $o->{y} : 0;
261 249
332} 320}
333 321
334for my $file (@ARGV) { 322for my $file (@ARGV) {
335 my $mapa = read_arch $file; 323 my $mapa = read_arch $file;
336 my ($pb, $meta) = cfmap_render $mapa, $file; 324 my ($pb, $meta) = cfmap_render $mapa, $file;
337 $pb->save ("$file.png", "png"); 325 $pb->save ("$file.png~", "png");
326 system "convert", "$file.png~", "-filter" => "lanczos", "-geometry" => "3.125%", "-quality" => 85, "$file.jpg";
327 system "mogrify", "-colors" => 65536, "$file.png~";
328 system "pngcrush", "-q", "-m" => 7, "-rem" => "alla", "-reduce", "$file.png~", "$file.png";
329 unlink "$file.png~";
338 Storable::nstore $meta, "$file.pst"; 330 Storable::nstore $meta, "$file.pst";
339} 331}
340 332
341 333
342 334

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines