2003-03-10 14:56:12 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use GD;
|
|
|
|
|
2003-03-11 20:21:30 +00:00
|
|
|
$input = shift( @ARGV );
|
|
|
|
$output = shift( @ARGV );
|
|
|
|
|
|
|
|
print " < $input > $output\n";
|
2003-03-10 14:56:12 +00:00
|
|
|
|
|
|
|
# load data
|
2003-03-11 20:21:30 +00:00
|
|
|
open( INPUT, "<$input" );
|
|
|
|
$width = <INPUT>; chomp($width);
|
|
|
|
$height = <INPUT>; chomp($height);
|
2003-03-10 14:56:12 +00:00
|
|
|
$min = 9999;
|
|
|
|
$max = -9999;
|
|
|
|
|
|
|
|
for ( $i = 0; $i < $height; $i++ ) {
|
2003-03-11 20:21:30 +00:00
|
|
|
print "$i ";
|
2003-03-10 14:56:12 +00:00
|
|
|
for ( $j = 0; $j < $width; $j++ ) {
|
2003-03-11 20:21:30 +00:00
|
|
|
$d = <INPUT>; chomp($d);
|
2003-03-10 14:56:12 +00:00
|
|
|
if ( $d < -9999 ) {
|
|
|
|
$d = 0;
|
|
|
|
}
|
|
|
|
if ( $d < $min ) {
|
|
|
|
$min = $d;
|
|
|
|
}
|
|
|
|
if ( $d > $max ) {
|
|
|
|
$max = $d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-03-11 20:21:30 +00:00
|
|
|
close(INPUT);
|
2003-03-10 14:56:12 +00:00
|
|
|
print "min = $min max = $max\n";
|
|
|
|
|
|
|
|
$im = new GD::Image( $width, $height );
|
|
|
|
($w, $h) = $im->getBounds();
|
|
|
|
print "create $w x $h\n";
|
|
|
|
|
|
|
|
for ( $i = 0; $i < 255; $i++ ) {
|
|
|
|
$color{$i} = $im->colorAllocate( $i, $i, $i );
|
|
|
|
}
|
|
|
|
$red = $im->colorAllocate( 255, 10, 10 );
|
|
|
|
|
|
|
|
# draw image
|
2003-03-11 20:21:30 +00:00
|
|
|
open( INPUT, "<$input" );
|
|
|
|
$width = <INPUT>; chomp($width);
|
|
|
|
$height = <INPUT>; chomp($height);
|
2003-03-10 14:56:12 +00:00
|
|
|
for ( $i = 0; $i < $height; $i++ ) {
|
|
|
|
for ( $j = 0; $j < $width; $j++ ) {
|
2003-03-11 20:21:30 +00:00
|
|
|
$d = <INPUT>; chomp($d);
|
|
|
|
if ( $d > 0 ) {
|
|
|
|
$level = 55 + int(200 * ( $d - $min ) / ( $max - $min ));
|
2003-03-10 14:56:12 +00:00
|
|
|
} else {
|
|
|
|
$level = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$im->setPixel( $j, $i, $color{$level} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$im->line( 0, 0, $width, 0, $red );
|
|
|
|
$im->line( 0, 1, $width, 1, $red );
|
|
|
|
$im->line( 0, 2, $width, 2, $red );
|
|
|
|
|
|
|
|
# write out gif
|
|
|
|
$data = $im->png;
|
|
|
|
open( OUTPUT, ">$output" ) ||
|
|
|
|
die "cannot open $output\n";
|
|
|
|
binmode OUTPUT;
|
|
|
|
print OUTPUT $data;
|
|
|
|
close OUTPUT;
|