Permalink
Browse files

cleanup

  • Loading branch information...
Jochen Topf
Jochen Topf committed May 6, 2010
1 parent 5278eb4 commit 1abcf31605880451444527debf01688c0b42d3a8
Showing with 67 additions and 46 deletions.
  1. +5 −9 test/randomtest.pl
  2. +62 −37 utils/viewmeta.pl
@@ -56,14 +56,10 @@
my $maxy = 22739*2;
my $status = eval { Tirex::Status->new(); };
die("Can't connect to shared memory. Is the tirex-master running?\n") if ($@);
die("Cannot connect to shared memory. Is the tirex-master running?\n") if ($@);
my $socket = IO::Socket::INET->new(
LocalAddr => 'localhost',
Proto => 'udp',
) or die("Cannot open UDP socket: $!\n");
my $master = Socket::pack_sockaddr_in( $Tirex::MASTER_UDP_PORT, Socket::inet_aton('localhost') );
my $socket = IO::Socket::INET->new(LocalAddr => 'localhost', Proto => 'udp') or die("Cannot open UDP socket: $!\n");
$socket->connect( Socket::pack_sockaddr_in($Tirex::MASTER_UDP_PORT, Socket::inet_aton('localhost')) );
my $count = 0;
while (1)
@@ -82,14 +78,14 @@
my $msg = Tirex::Message->new( type => 'metatile_enqueue_request', prio => $prio, map => 'test', z => $z, x => $x, y => $y );
print "sending msg ", $msg->to_s(), "\n";
$msg->send($socket, $master);
$msg->send($socket);
Time::HiRes::usleep( rand($RANDOM_SLEEP) );
if ($count++ % 10 == 0)
{
my $s = $status->read();
die("Can't read status\n") unless (defined $s);
die("Cannot read status\n") unless (defined $s);
my $queue_size = JSON::from_json($s)->{'queue'}->{'size'};
print "queue_size=$queue_size\n";
@@ -1,20 +1,32 @@
#!/usr/bin/perl
# viewmeta.pl
# -----------
#-----------------------------------------------------------------------------
#
# Tirex Tile Rendering System
#
# viewmeta.pl
#
#-----------------------------------------------------------------------------
#
# Script to display a meta tile file.
# The full filename has to be given on the command line:
#
# Script to display a meta tile file.
# The full filename has to be given on the command line:
# viewmeta.pl /some/path/0/0/0/68/128.meta
#
# viewmeta.pl /some/path/0/0/0/68/128.meta
# By default, display is scaled by factor 2; use "-s factor" to change.
#
# By default, display is scaled by factor 2; use "-s factor" to change.
# Written by Frederik Ramm <frederik.ramm@geofabrik.de>, public domain.
#
# Written by Frederik Ramm <frederik.ramm@geofabrik.de>, public domain.
#-----------------------------------------------------------------------------
use strict;
use warnings;
use GD;
use Fcntl qw(SEEK_SET SEEK_CUR O_RDONLY);
use strict;
#-----------------------------------------------------------------------------
my $VIEWER = 'eog';
my $filename;
my $scale = 2;
@@ -24,7 +36,7 @@
if ($arg =~ /^-s(\d*)/)
{
$scale = $1 || shift;
die "-s requires numeric value" if ($scale <= 0);
die("-s requires numeric value") if ($scale <= 0);
}
elsif ($arg =~ /^-/)
{
@@ -37,73 +49,86 @@
}
}
die "no filename given" unless defined($filename);
sysopen(F, $filename, O_RDONLY) or die "cannot open $filename for reading";
die("no filename given") unless defined($filename);
sysopen(META, $filename, O_RDONLY) or die("cannot open $filename for reading: $!");
my $header;
my $offsets;
sysread(F, $header, 20);
die "not a meta file" unless (substr($header, 0, 4) eq "META");
sysread(META, $header, 20);
die("not a meta file") unless (substr($header, 0, 4) eq "META");
my ($magic, $count, $tilex, $tiley, $tilez) = unpack("lllll", $header);
sysread(F, $offsets, 8 * $count);
sysread(META, $offsets, 8 * $count);
my $rows = int(sqrt($count));
my $cols = int(sqrt($count));
die "cannot determine number of rows and colums" unless ($rows * $cols == $count);
my $cols = $rows;
die("cannot determine number of rows and colums") unless ($rows * $cols == $count);
my @offset = unpack("ll" x $count, $offsets);
my @img;
my $tilewidth;
my $tileheight;
for (my $i = 0; $i < $count; $i++)
foreach my $i (0 .. $count-1)
{
die "problem with file offsets" unless (sysseek(F,0,SEEK_CUR) == $offset[$i*2]);
die("problem with file offsets") unless (sysseek(META, 0, SEEK_CUR) == $offset[$i*2]);
my $png;
sysread(F, $png, $offset[$i*2+1]);
sysread(META, $png, $offset[$i*2+1]);
$img[$i] = GD::Image->newFromPngData($png);
if (defined($tileheight))
if (defined $tileheight)
{
die "tile $i has non-matching size"
die("tile $i has non-matching size")
unless ($img[$i]->width == $tilewidth && $img[$i]->height == $tileheight);
}
else
{
$tileheight = $img[$i]->height;
$tilewidth = $img[$i]->width;
$tilewidth = $img[$i]->width;
}
}
close(F);
close(META);
my $scaled_tilewidth = $tilewidth / $scale;
my $scaled_tilewidth = $tilewidth / $scale;
my $scaled_tileheight = $tileheight / $scale;
my $meta = new GD::Image($cols*$scaled_tilewidth+$cols-1,
$rows*$scaled_tileheight+$rows-1, 1);
my $black = $meta->colorAllocate(0,0,0);
my $meta = new GD::Image($cols*$scaled_tilewidth + $cols - 1,
$rows*$scaled_tileheight + $rows - 1, 1);
my $black = $meta->colorAllocate(0, 0, 0);
for (my $i=0; $i<$count; $i++)
{
my $x = int($i/$rows) * ($scaled_tilewidth+1);
my $y = ($i%$rows) * ($scaled_tileheight+1);
my $x = int($i/$rows) * ($scaled_tilewidth + 1);
my $y = ($i%$rows) * ($scaled_tileheight + 1);
$meta->copyResampled($img[$i], $x, $y, 0, 0,
$scaled_tilewidth, $scaled_tileheight, $tilewidth, $tileheight);
}
for (my $i=0; $i<$rows; $i++)
{
$meta->string(gdMediumBoldFont, 5, ($i+.5)*($scaled_tileheight+1), $tiley+$i,$black);
$meta->string(gdMediumBoldFont, 5, ($i+.5)*($scaled_tileheight+1), $tiley+$i, $black);
}
for (my $i=0; $i<$cols; $i++)
{
$meta->string(gdMediumBoldFont, ($i+.5)*($scaled_tilewidth+1)-15, 5, $tilex+$i,$black);
$meta->string(gdMediumBoldFont, ($i+.5)*($scaled_tilewidth+1)-15, 5, $tilex+$i, $black);
}
my $p=int(100/$scale);
$meta->string(gdMediumBoldFont, $cols*($scaled_tilewidth+1)-140,
$rows*($scaled_tileheight+1)-18, "zoom=$tilez scaled $p%", $black);
open (P, ">/tmp/viewmeta.$$.png");
print P $meta->png;
close(P);
system("display /tmp/viewmeta.$$.png") || system("eog /tmp/viewmeta.$$.png");
unlink "/tmp/viewmeta.$$.png";
my $imagefile = "/tmp/viewmeta.$$.png";
open(IMAGE, '>', $imagefile) or die("cannot open $imagefile: $!");
binmode(IMAGE);
print IMAGE $meta->png();
close(IMAGE);
system("$VIEWER $imagefile");
unlink($imagefile);
#-- THE END ----------------------------------------------------------------------------

0 comments on commit 1abcf31

Please sign in to comment.