The code here does not have any warranty. It is recommended that before using any of this code, you look into it and try to understand what it does, what input it needs, etc. Do not blindly execute anything!
The Piddle method of Band object can be used to read and write band data from a piddle or into a piddle. The PDL module provides ways to manipulate piddles.
use strict;
use v5.10;
use PDL;
my $filename = 'some.tiff';
my $update = 'UPDATE';
my ($W,$H) = $band->
Size;
my ($w,$h) = $band->GetBlockSize;
my ($xoff,$yoff) = (0,0);
while (1) {
progress($yoff/$H);
if ($xoff >= $W) {
$xoff = 0;
$yoff += $h;
last if $yoff >= $H;
}
my $a = $band->Piddle($xoff, $yoff, my_min($W-$xoff,$w), my_min($H-$yoff,$h));
# do something with a
$a = ($a < 0) + ($a < -30) + ($a < -60);
$band->Piddle($a, $xoff, $yoff);
$xoff += $w;
}
progress(1);
say;
sub progress {
state $s = -1; # requires 'use v5.10;'
my $p = int($_[0]*100);
return 1 if $p == $s;
$s = 0 if $s < 0;
while ($s < $p) {
print $s%10 == 0 ? $s : ($s%2 == 0 ? '.' : '');
++$s;
}
return 1;
}
sub my_min {
return $_[0] < $_[1] ? $_[0] : $_[1];
}