/[maps]/stich.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /stich.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 7 - (show annotations)
Mon Oct 15 22:34:20 2007 UTC (14 years ago) by dpavlin
File MIME type: text/plain
File size: 2877 byte(s)
vertical flip is now optional, since Google doesn't need it
1 #!/usr/bin/perl -w
2
3 # stich.pl
4 #
5 # 10/15/07 22:02:18 CEST Dobrica Pavlinusic <dpavlin@rot13.org>
6
7 use strict;
8
9 use File::Find;
10 use Data::Dump qw/dump/;
11 use Imager;
12
13 my $path = shift @ARGV || die "usage: $0 path_to_dump_dir\n";
14
15 # Mireo 1, Google 0
16 my $flip_vertical = 0;
17
18 my ( $range, $usage );
19
20 my @files;
21 my $file_pos;
22
23 find( sub {
24 return unless -f $_;
25
26 if ( $_ =~ m/(\d+)-(\d+)/ ) {
27
28 push @files, $_;
29
30 my ( $x, $y ) = ( $1, $2 );
31
32 $range->{min}->{x} = $x if not defined $range->{min}->{x} or $x < $range->{min}->{x};
33 $range->{max}->{x} = $x if not defined $range->{max}->{x} or $x > $range->{max}->{x};
34
35 $range->{min}->{y} = $y if not defined $range->{min}->{y} or $y < $range->{min}->{y};
36 $range->{max}->{y} = $y if not defined $range->{max}->{y} or $y > $range->{max}->{y};
37
38 $usage->{x}->{$x}++;
39 $usage->{y}->{$y}++;
40
41 $file_pos->{$_} = { x => $x, y => $y };
42
43 warn "## $_\n";
44
45 } else {
46
47 warn "SKIPPED: $_\n";
48 }
49
50
51
52 }, $path );
53
54 print "range = ",dump( $range ), "\n";
55 print "usage = ",dump( $usage ). "\n";
56
57 my $step_size;
58
59 foreach my $axis ( 'x', 'y' ) {
60
61 my $last = $range->{min}->{$axis};
62
63 foreach my $v ( sort keys %{$usage->{$axis}} ) {
64
65 next if $v == $last;
66
67 $step_size->{$axis}->{ $v - $last }++;
68 $last = $v;
69
70 }
71 undef $last;
72 }
73
74 print "step_size = ",dump( $step_size ),"\n";
75
76 my $step = {
77 x => ( sort { $step_size->{x}->{$b} <=> $step_size->{x}->{$a} } keys %{ $step_size->{x} } )[0],
78 y => ( sort { $step_size->{y}->{$b} <=> $step_size->{y}->{$a} } keys %{ $step_size->{y} } )[0],
79 };
80
81 print "selected step = ",dump( $step ),"\n";
82
83
84 my $img = Imager->new();
85 $img->read( file => $path . '/' . $files[0] ) or die $img->errstr();
86 my $tile_size = {
87 x => $img->getwidth,
88 y => $img->getheight,
89 };
90
91 print "tile_size = ",dump( $tile_size ),"\n";
92
93 my $x_tiles = ( $range->{max}->{x} - $range->{min}->{x} ) / $step->{x};
94 my $y_tiles = ( $range->{max}->{y} - $range->{min}->{y} ) / $step->{y};
95
96 my $x_size = $x_tiles * $tile_size->{x};
97 my $y_size = $y_tiles * $tile_size->{y};
98
99 print "final map size: $x_size x $y_size from $x_tiles x $y_tiles tiles\n";
100
101 my $map = Imager->new( xsize => $x_size, ysize => $y_size ) or $img->errstr();
102
103 foreach my $tile_file ( @files ) {
104 $img->read( file => "$path/$tile_file" ) or die $img->errstr();
105
106 # this is specific to globe position, I guess ... this is europe
107 my $x = ( $file_pos->{$tile_file}->{x} - $range->{min}->{x} ) / $step->{x};
108 my $y;
109 if ( $flip_vertical ) {
110 $y = ( $range->{max}->{y} - $file_pos->{$tile_file}->{y} ) / $step->{y};
111 } else {
112 $y = ( $file_pos->{$tile_file}->{y} - $range->{min}->{y} ) / $step->{y};
113 }
114
115 printf("%3dx%-3d %s\n", $x, $y, $tile_file);
116
117 $map->paste(
118 src => $img,
119 left => $x * $tile_size->{x},
120 top => $y * $tile_size->{y},
121 );
122 }
123
124 $path =~ s/\W+/_/g;
125 $path =~ s/^_+//;
126 $path =~ s/_+$//;
127
128 $map->write( file => "$path.png" ) or die $img->errstr();

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26