/[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

Annotation of /stich.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26