| 1 | package Geo::GDAL::FFI::Band; | ||||||||||||||||||||
| 2 | 13 | ▶ | use v5.10; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 13 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 13 | ▶ | use FFI::Platypus::Buffer; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 13 | ▶ | use base 'Geo::GDAL::FFI::Object'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 13 | our $VERSION = '0.15'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | sub DESTROY { | ||||||||||||||||||||
| 12 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 13 | 0 | Geo::GDAL::FFI::_deregister_parent_ref ($$self); | |||||||||||||||||||
| 14 | } | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub GetDataType { | ||||||||||||||||||||
| 17 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetDataType: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 18 | 0 | return $Geo::GDAL::FFI::data_types_reverse{Geo::GDAL::FFI::GDALGetRasterDataType($$self)}; | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | sub GetWidth { | ||||||||||||||||||||
| 22 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetWidth: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 23 | 0 | Geo::GDAL::FFI::GDALGetRasterBandXSize($$self); | |||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | sub GetHeight { | ||||||||||||||||||||
| 27 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetHeight: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 28 | 0 | Geo::GDAL::FFI::GDALGetRasterBandYSize($$self); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | sub GetSize { | ||||||||||||||||||||
| 32 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetSize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 33 | return ( | ||||||||||||||||||||
| 34 | 0 | Geo::GDAL::FFI::GDALGetRasterBandXSize($$self), | |||||||||||||||||||
| 35 | Geo::GDAL::FFI::GDALGetRasterBandYSize($$self) | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub GetCategoryNames { | ||||||||||||||||||||
| 40 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetCategoryNames: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 41 | 0 | my $csl = Geo::GDAL::FFI::GDALGetRasterCategoryNames($$self); | |||||||||||||||||||
| 42 | 0 | my @names; | |||||||||||||||||||
| 43 | 0 | for my $i (0..Geo::GDAL::FFI::CSLCount($csl)-1) { | |||||||||||||||||||
| 44 | 0 | push @names, Geo::GDAL::FFI::CSLGetField($csl, $i); | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | 0 | return @names; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | sub SetCategoryNames { | ||||||||||||||||||||
| 50 | 0 | ▶ | my ($self, @names) = @_; | ||||||||||||||||||
|
Subroutine
SetCategoryNames: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 51 | 0 | my $csl = 0; | |||||||||||||||||||
| 52 | 0 | for my $n (@names) { | |||||||||||||||||||
| 53 | 0 | $csl = Geo::GDAL::FFI::CSLAddString($csl, $n); | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | Geo::GDAL::FFI::GDALSetRasterCategoryNames($$self, $csl); | |||||||||||||||||||
| 56 | 0 | Geo::GDAL::FFI::CSLDestroy($csl); | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | sub GetNoDataValue { | ||||||||||||||||||||
| 60 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetNoDataValue: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 61 | 0 | my $b = 0; | |||||||||||||||||||
| 62 | 0 | my $v = Geo::GDAL::FFI::GDALGetRasterNoDataValue($$self, \$b); | |||||||||||||||||||
| 63 | 0 | ▶ | return unless $b; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 64 | 0 | return $v; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub SetNoDataValue { | ||||||||||||||||||||
| 68 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
SetNoDataValue: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 69 | 0 | ▶ | unless (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 70 | 0 | Geo::GDAL::FFI::GDALDeleteRasterNoDataValue($$self); | |||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||
| 72 | } | ||||||||||||||||||||
| 73 | 0 | my $v = shift; | |||||||||||||||||||
| 74 | 0 | my $e = Geo::GDAL::FFI::GDALSetRasterNoDataValue($$self, $v); | |||||||||||||||||||
| 75 | 0 | ▶ | return unless $e; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 0 | ▶ | confess Geo::GDAL::FFI::error_msg() // "SetNoDataValue not supported by the driver."; | ||||||||||||||||||
|
Condition0%0/2
Geo::GDAL::FFI::error_msg() // "SetNoDataValue not supported by the driver."
MC/DC0%0/1
Geo::GDAL::FFI::error_msg() // "SetNoDataValue not supported by the driver."
Geo::GDAL::FFI::error_msg()
Truth table0%0/2
A
A= Geo::GDAL::FFI::error_msg()
| |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | sub GetBlockSize { | ||||||||||||||||||||
| 80 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetBlockSize: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 81 | 0 | my ($w, $h); | |||||||||||||||||||
| 82 | 0 | Geo::GDAL::FFI::GDALGetBlockSize($$self, \$w, \$h); | |||||||||||||||||||
| 83 | 0 | return ($w, $h); | |||||||||||||||||||
| 84 | } | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub pack_char { | ||||||||||||||||||||
| 87 | 0 | ▶ | my $t = shift; | ||||||||||||||||||
|
Subroutine
pack_char: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||
| 88 | 0 | my $is_big_endian = unpack("h*", pack("s", 1)) =~ /01/; # from Programming Perl | |||||||||||||||||||
| 89 | 0 | ▶ | return ('C', 1) if $t == 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | ▶ | return ($is_big_endian ? ('n', 2) : ('v', 2)) if $t == 2; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 91 | 0 | ▶ | return ('s', 2) if $t == 3; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 92 | 0 | ▶ | return ($is_big_endian ? ('N', 4) : ('V', 4)) if $t == 4; | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 93 | 0 | ▶ | return ('l', 4) if $t == 5; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 94 | 0 | ▶ | return ('f', 4) if $t == 6; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 95 | 0 | ▶ | return ('d', 8) if $t == 7; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 96 | # CInt16 => 8, | ||||||||||||||||||||
| 97 | # CInt32 => 9, | ||||||||||||||||||||
| 98 | # CFloat32 => 10, | ||||||||||||||||||||
| 99 | # CFloat64 => 11 | ||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | sub Read { | ||||||||||||||||||||
| 103 | 0 | ▶ | my ($self, $xoff, $yoff, $xsize, $ysize, $bufxsize, $bufysize) = @_; | ||||||||||||||||||
|
Subroutine
Read: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 104 | 0 | ▶ | $xoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$xoff //= 0
MC/DC0%0/1
$xoff //= 0
$xoff
Truth table0%0/2
A
A= $xoff
| |||||||||||||||||||||
| 105 | 0 | ▶ | $yoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$yoff //= 0
MC/DC0%0/1
$yoff //= 0
$yoff
Truth table0%0/2
A
A= $yoff
| |||||||||||||||||||||
| 106 | 0 | my $t = Geo::GDAL::FFI::GDALGetRasterDataType($$self); | |||||||||||||||||||
| 107 | 0 | my ($pc, $bytes_per_cell) = pack_char($t); | |||||||||||||||||||
| 108 | 0 | my $w; | |||||||||||||||||||
| 109 | 0 | ▶ | $xsize //= Geo::GDAL::FFI::GDALGetRasterBandXSize($$self); | ||||||||||||||||||
|
Condition0%0/3
$xsize //= Geo::GDAL::FFI::GDALGetRasterBandXSize($$self)
MC/DC0%0/2
$xsize //= Geo::GDAL::FFI::GDALGetRasterBandXSize($$self)
$xsize
Geo::GDAL::FFI::GDALGetRasterBandXSize($$self)
Truth table0%0/3
A //= B
A= $xsizeB= Geo::GDAL::FFI::GDALGetRasterBandXSize($$self)
| |||||||||||||||||||||
| 110 | 0 | ▶ | $ysize //= Geo::GDAL::FFI::GDALGetRasterBandYSize($$self); | ||||||||||||||||||
|
Condition0%0/3
$ysize //= Geo::GDAL::FFI::GDALGetRasterBandYSize($$self)
MC/DC0%0/2
$ysize //= Geo::GDAL::FFI::GDALGetRasterBandYSize($$self)
$ysize
Geo::GDAL::FFI::GDALGetRasterBandYSize($$self)
Truth table0%0/3
A //= B
A= $ysizeB= Geo::GDAL::FFI::GDALGetRasterBandYSize($$self)
| |||||||||||||||||||||
| 111 | 0 | ▶ | $bufxsize //= $xsize; | ||||||||||||||||||
|
Condition0%0/3
$bufxsize //= $xsize
MC/DC0%0/2
$bufxsize //= $xsize
$bufxsize
$xsize
Truth table0%0/3
A //= B
A= $bufxsizeB= $xsize
| |||||||||||||||||||||
| 112 | 0 | ▶ | $bufysize //= $ysize; | ||||||||||||||||||
|
Condition0%0/3
$bufysize //= $ysize
MC/DC0%0/2
$bufysize //= $ysize
$bufysize
$ysize
Truth table0%0/3
A //= B
A= $bufysizeB= $ysize
| |||||||||||||||||||||
| 113 | 0 | $w = $bufxsize * $bytes_per_cell; | |||||||||||||||||||
| 114 | 0 | my $buf = ' ' x ($bufysize * $w); | |||||||||||||||||||
| 115 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 116 | 0 | Geo::GDAL::FFI::GDALRasterIO($$self, $Geo::GDAL::FFI::Read, $xoff, $yoff, $xsize, $ysize, $pointer, $bufxsize, $bufysize, $t, 0, 0); | |||||||||||||||||||
| 117 | 0 | my $offset = 0; | |||||||||||||||||||
| 118 | 0 | my @data; | |||||||||||||||||||
| 119 | 0 | for my $y (0..$bufysize-1) { | |||||||||||||||||||
| 120 | 0 | my @d = unpack($pc."[$bufxsize]", substr($buf, $offset, $w)); | |||||||||||||||||||
| 121 | 0 | push @data, \@d; | |||||||||||||||||||
| 122 | 0 | $offset += $w; | |||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | 0 | return \@data; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | sub ReadBlock { | ||||||||||||||||||||
| 128 | 0 | ▶ | my ($self, $xoff, $yoff, $xsize, $ysize, $t) = @_; | ||||||||||||||||||
|
Subroutine
ReadBlock: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 129 | 0 | ▶ | $xoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$xoff //= 0
MC/DC0%0/1
$xoff //= 0
$xoff
Truth table0%0/2
A
A= $xoff
| |||||||||||||||||||||
| 130 | 0 | ▶ | $yoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$yoff //= 0
MC/DC0%0/1
$yoff //= 0
$yoff
Truth table0%0/2
A
A= $yoff
| |||||||||||||||||||||
| 131 | 0 | ▶ | Geo::GDAL::FFI::GDALGetBlockSize($$self, \$xsize, \$ysize) unless defined $xsize; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 132 | 0 | ▶ | $t = Geo::GDAL::FFI::GDALGetRasterDataType($$self) unless defined $t; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 133 | 0 | my $buf; | |||||||||||||||||||
| 134 | 0 | my ($pc, $bytes_per_cell) = pack_char($t); | |||||||||||||||||||
| 135 | 0 | my $w = $xsize * $bytes_per_cell; | |||||||||||||||||||
| 136 | 0 | $buf = ' ' x ($ysize * $w); | |||||||||||||||||||
| 137 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 138 | 0 | Geo::GDAL::FFI::GDALReadBlock($$self, $xoff, $yoff, $pointer); | |||||||||||||||||||
| 139 | 0 | my $offset = 0; | |||||||||||||||||||
| 140 | 0 | my @data; | |||||||||||||||||||
| 141 | 0 | for my $y (0..$ysize-1) { | |||||||||||||||||||
| 142 | 0 | my @d = unpack($pc."[$xsize]", substr($buf, $offset, $w)); | |||||||||||||||||||
| 143 | 0 | push @data, \@d; | |||||||||||||||||||
| 144 | 0 | $offset += $w; | |||||||||||||||||||
| 145 | } | ||||||||||||||||||||
| 146 | 0 | return \@data; | |||||||||||||||||||
| 147 | } | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | sub Write { | ||||||||||||||||||||
| 150 | 0 | ▶ | my ($self, $data, $xoff, $yoff, $xsize, $ysize) = @_; | ||||||||||||||||||
|
Subroutine
Write: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||
| 151 | 0 | ▶ | $xoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$xoff //= 0
MC/DC0%0/1
$xoff //= 0
$xoff
Truth table0%0/2
A
A= $xoff
| |||||||||||||||||||||
| 152 | 0 | ▶ | $yoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$yoff //= 0
MC/DC0%0/1
$yoff //= 0
$yoff
Truth table0%0/2
A
A= $yoff
| |||||||||||||||||||||
| 153 | 0 | my $bufxsize = @{$data->[0]}; | |||||||||||||||||||
| 154 | 0 | my $bufysize = @$data; | |||||||||||||||||||
| 155 | 0 | ▶ | $xsize //= $bufxsize; | ||||||||||||||||||
|
Condition0%0/3
$xsize //= $bufxsize
MC/DC0%0/2
$xsize //= $bufxsize
$xsize
$bufxsize
Truth table0%0/3
A //= B
A= $xsizeB= $bufxsize
| |||||||||||||||||||||
| 156 | 0 | ▶ | $ysize //= $bufysize; | ||||||||||||||||||
|
Condition0%0/3
$ysize //= $bufysize
MC/DC0%0/2
$ysize //= $bufysize
$ysize
$bufysize
Truth table0%0/3
A //= B
A= $ysizeB= $bufysize
| |||||||||||||||||||||
| 157 | 0 | my $t = Geo::GDAL::FFI::GDALGetRasterDataType($$self); | |||||||||||||||||||
| 158 | 0 | my ($pc, $bytes_per_cell) = pack_char($t); | |||||||||||||||||||
| 159 | 0 | my $buf = ''; | |||||||||||||||||||
| 160 | 0 | for my $i (0..$bufysize-1) { | |||||||||||||||||||
| 161 | 0 | $buf .= pack($pc."[$bufxsize]", @{$data->[$i]}); | |||||||||||||||||||
| 162 | } | ||||||||||||||||||||
| 163 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 164 | 0 | Geo::GDAL::FFI::GDALRasterIO($$self, $Geo::GDAL::FFI::Write, $xoff, $yoff, $xsize, $ysize, $pointer, $bufxsize, $bufysize, $t, 0, 0); | |||||||||||||||||||
| 165 | } | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | sub WriteBlock { | ||||||||||||||||||||
| 168 | 0 | ▶ | my ($self, $data, $xoff, $yoff) = @_; | ||||||||||||||||||
|
Subroutine
WriteBlock: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 169 | 0 | my ($xsize, $ysize); | |||||||||||||||||||
| 170 | 0 | Geo::GDAL::FFI::GDALGetBlockSize($$self, \$xsize, \$ysize); | |||||||||||||||||||
| 171 | 0 | my $t = Geo::GDAL::FFI::GDALGetRasterDataType($$self); | |||||||||||||||||||
| 172 | 0 | my ($pc, $bytes_per_cell) = pack_char($t); | |||||||||||||||||||
| 173 | 0 | my $buf = ''; | |||||||||||||||||||
| 174 | 0 | for my $i (0..$ysize-1) { | |||||||||||||||||||
| 175 | 0 | $buf .= pack($pc."[$xsize]", @{$data->[$i]}); | |||||||||||||||||||
| 176 | } | ||||||||||||||||||||
| 177 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 178 | 0 | Geo::GDAL::FFI::GDALWriteBlock($$self, $xoff, $yoff, $pointer); | |||||||||||||||||||
| 179 | } | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | sub GetColorInterpretation { | ||||||||||||||||||||
| 182 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetColorInterpretation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 183 | return $Geo::GDAL::FFI::color_interpretations_reverse{ | ||||||||||||||||||||
| 184 | 0 | Geo::GDAL::FFI::GDALGetRasterColorInterpretation($$self) | |||||||||||||||||||
| 185 | }; | ||||||||||||||||||||
| 186 | } | ||||||||||||||||||||
| 187 | |||||||||||||||||||||
| 188 | sub SetColorInterpretation { | ||||||||||||||||||||
| 189 | 0 | ▶ | my ($self, $i) = @_; | ||||||||||||||||||
|
Subroutine
SetColorInterpretation: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 190 | 0 | my $tmp = $Geo::GDAL::FFI::color_interpretations{$i}; | |||||||||||||||||||
| 191 | 0 | ▶ | confess "Unknown color interpretation: $i." unless defined $tmp; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 192 | 0 | $i = $tmp; | |||||||||||||||||||
| 193 | 0 | Geo::GDAL::FFI::GDALSetRasterColorInterpretation($$self, $i); | |||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | sub GetColorTable { | ||||||||||||||||||||
| 197 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
GetColorTable: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 198 | 0 | my $ct = Geo::GDAL::FFI::GDALGetRasterColorTable($$self); | |||||||||||||||||||
| 199 | 0 | ▶ | return unless $ct; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 200 | # color table is a table of [c1...c4] | ||||||||||||||||||||
| 201 | # the interpretation of colors is from next method | ||||||||||||||||||||
| 202 | 0 | my @table; | |||||||||||||||||||
| 203 | 0 | for my $i (0..Geo::GDAL::FFI::GDALGetColorEntryCount($ct)-1) { | |||||||||||||||||||
| 204 | 0 | my $c = Geo::GDAL::FFI::GDALGetColorEntry($ct, $i); | |||||||||||||||||||
| 205 | 0 | push @table, $c; | |||||||||||||||||||
| 206 | } | ||||||||||||||||||||
| 207 | 0 | ▶ | return wantarray ? @table : \@table; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 208 | } | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | sub SetColorTable { | ||||||||||||||||||||
| 211 | 0 | ▶ | my ($self, $table) = @_; | ||||||||||||||||||
|
Subroutine
SetColorTable: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 212 | 0 | my $ct = Geo::GDAL::FFI::GDALCreateColorTable(); | |||||||||||||||||||
| 213 | 0 | for my $i (0..$#$table) { | |||||||||||||||||||
| 214 | 0 | Geo::GDAL::FFI::GDALSetColorEntry($ct, $i, $table->[$i]); | |||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | 0 | Geo::GDAL::FFI::GDALSetRasterColorTable($$self, $ct); | |||||||||||||||||||
| 217 | 0 | Geo::GDAL::FFI::GDALDestroyColorTable($ct); | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | sub GetPiddle { | ||||||||||||||||||||
| 221 | 0 | ▶ | require PDL::Lite; # minimal load | ||||||||||||||||||
|
Subroutine
GetPiddle: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||
| 222 | 0 | my ($self, $xoff, $yoff, $xsize, $ysize, $xdim, $ydim, $alg) = @_; | |||||||||||||||||||
| 223 | 0 | ▶ | $xoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$xoff //= 0
MC/DC0%0/1
$xoff //= 0
$xoff
Truth table0%0/2
A
A= $xoff
| |||||||||||||||||||||
| 224 | 0 | ▶ | $yoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$yoff //= 0
MC/DC0%0/1
$yoff //= 0
$yoff
Truth table0%0/2
A
A= $yoff
| |||||||||||||||||||||
| 225 | 0 | my ($w, $h) = $self->GetSize; | |||||||||||||||||||
| 226 | 0 | ▶ | $xsize //= $w - $xoff; | ||||||||||||||||||
|
Condition0%0/3
$xsize //= $w - $xoff
MC/DC0%0/2
$xsize //= $w - $xoff
$xsize
$w - $xoff
Truth table0%0/3
A //= B
A= $xsizeB= $w - $xoff
| |||||||||||||||||||||
| 227 | 0 | ▶ | $ysize //= $h - $yoff; | ||||||||||||||||||
|
Condition0%0/3
$ysize //= $h - $yoff
MC/DC0%0/2
$ysize //= $h - $yoff
$ysize
$h - $yoff
Truth table0%0/3
A //= B
A= $ysizeB= $h - $yoff
| |||||||||||||||||||||
| 228 | 0 | my $t = Geo::GDAL::FFI::GDALGetRasterDataType($$self); | |||||||||||||||||||
| 229 | 0 | my $pdl_t = $Geo::GDAL::FFI::data_type2pdl_data_type{$Geo::GDAL::FFI::data_types_reverse{$t}}; | |||||||||||||||||||
| 230 | 0 | ▶ | confess "The Piddle data_type is unsuitable." unless defined $pdl_t; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 231 | 0 | ▶ | $xdim //= $xsize; | ||||||||||||||||||
|
Condition0%0/3
$xdim //= $xsize
MC/DC0%0/2
$xdim //= $xsize
$xdim
$xsize
Truth table0%0/3
A //= B
A= $xdimB= $xsize
| |||||||||||||||||||||
| 232 | 0 | ▶ | $ydim //= $ysize; | ||||||||||||||||||
|
Condition0%0/3
$ydim //= $ysize
MC/DC0%0/2
$ydim //= $ysize
$ydim
$ysize
Truth table0%0/3
A //= B
A= $ydimB= $ysize
| |||||||||||||||||||||
| 233 | 0 | ▶ | $alg //= 'NearestNeighbour'; | ||||||||||||||||||
|
Condition0%0/2
$alg //= "NearestNeighbour"
MC/DC0%0/1
$alg //= "NearestNeighbour"
$alg
Truth table0%0/2
A
A= $alg
| |||||||||||||||||||||
| 234 | 0 | my $tmp = $Geo::GDAL::FFI::resampling{$alg}; | |||||||||||||||||||
| 235 | 0 | ▶ | confess "Unknown resampling scheme: $alg." unless defined $tmp; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 236 | 0 | $alg = $tmp; | |||||||||||||||||||
| 237 | 0 | my $bufxsize = $xsize; | |||||||||||||||||||
| 238 | 0 | my $bufysize = $ysize; | |||||||||||||||||||
| 239 | 0 | my ($pc, $bytes_per_cell) = pack_char($t); | |||||||||||||||||||
| 240 | 0 | my $buf = ' ' x ($bufysize * $bufxsize * $bytes_per_cell); | |||||||||||||||||||
| 241 | 0 | my ($pointer, $size) = scalar_to_buffer $buf; | |||||||||||||||||||
| 242 | 0 | Geo::GDAL::FFI::GDALRasterIO($$self, $Geo::GDAL::FFI::Read, $xoff, $yoff, $xsize, $ysize, $pointer, $bufxsize, $bufysize, $t, 0, 0); | |||||||||||||||||||
| 243 | 0 | my $pdl; | |||||||||||||||||||
| 244 | 0 | ▶ | if ($PDL::VERSION >= 2.091) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 245 | 0 | $pdl = PDL->new_around_datasv(0+\$buf); | |||||||||||||||||||
| 246 | 0 | $pdl->set_datatype($pdl_t); | |||||||||||||||||||
| 247 | 0 | $pdl->setdims([$xdim, $ydim]); | |||||||||||||||||||
| 248 | } | ||||||||||||||||||||
| 249 | else { | ||||||||||||||||||||
| 250 | 0 | $pdl = PDL->new; | |||||||||||||||||||
| 251 | 0 | $pdl->set_datatype($pdl_t); | |||||||||||||||||||
| 252 | 0 | $pdl->setdims([ $xdim, $ydim ]); | |||||||||||||||||||
| 253 | 0 | my $data = $pdl->get_dataref(); | |||||||||||||||||||
| 254 | # FIXME: see http://pdl.perl.org/PDLdocs/API.html how to wrap $buf into a piddle | ||||||||||||||||||||
| 255 | 0 | $$data = $buf; | |||||||||||||||||||
| 256 | 0 | $pdl->upd_data; | |||||||||||||||||||
| 257 | } | ||||||||||||||||||||
| 258 | # FIXME: we want approximate equality since no data value can be very large floating point value | ||||||||||||||||||||
| 259 | 0 | my $bad = GetNoDataValue($self); | |||||||||||||||||||
| 260 | 0 | ▶ | return $pdl->setbadif($pdl == $bad) if defined $bad; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 261 | 0 | return $pdl; | |||||||||||||||||||
| 262 | } | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | sub SetPiddle { | ||||||||||||||||||||
| 265 | 0 | ▶ | my ($self, $pdl, $xoff, $yoff, $xsize, $ysize) = @_; | ||||||||||||||||||
|
Subroutine
SetPiddle: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||
| 266 | 0 | ▶ | $xoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$xoff //= 0
MC/DC0%0/1
$xoff //= 0
$xoff
Truth table0%0/2
A
A= $xoff
| |||||||||||||||||||||
| 267 | 0 | ▶ | $yoff //= 0; | ||||||||||||||||||
|
Condition0%0/2
$yoff //= 0
MC/DC0%0/1
$yoff //= 0
$yoff
Truth table0%0/2
A
A= $yoff
| |||||||||||||||||||||
| 268 | 0 | my ($w, $h) = $self->GetSize; | |||||||||||||||||||
| 269 | 0 | my $t = $Geo::GDAL::FFI::pdl_data_type2data_type{$pdl->get_datatype}; | |||||||||||||||||||
| 270 | 0 | ▶ | confess "The Piddle data_type '".$pdl->get_datatype."' is unsuitable." unless defined $t; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 271 | 0 | $t = $Geo::GDAL::FFI::data_types{$t}; | |||||||||||||||||||
| 272 | 0 | my ($xdim, $ydim) = $pdl->dims(); | |||||||||||||||||||
| 273 | 0 | ▶ | $xsize //= $xdim; | ||||||||||||||||||
|
Condition0%0/3
$xsize //= $xdim
MC/DC0%0/2
$xsize //= $xdim
$xsize
$xdim
Truth table0%0/3
A //= B
A= $xsizeB= $xdim
| |||||||||||||||||||||
| 274 | 0 | ▶ | $ysize //= $ydim; | ||||||||||||||||||
|
Condition0%0/3
$ysize //= $ydim
MC/DC0%0/2
$ysize //= $ydim
$ysize
$ydim
Truth table0%0/3
A //= B
A= $ysizeB= $ydim
| |||||||||||||||||||||
| 275 | 0 | ▶ | if ($xdim > $w - $xoff) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 276 | 0 | warn "Piddle too wide ($xdim) for this raster band (width = $w, offset = $xoff)."; | |||||||||||||||||||
| 277 | 0 | $xdim = $w - $xoff; | |||||||||||||||||||
| 278 | } | ||||||||||||||||||||
| 279 | 0 | ▶ | if ($ydim > $h - $yoff) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 280 | 0 | $ydim = $h - $yoff; | |||||||||||||||||||
| 281 | 0 | warn "Piddle too tall ($ydim) for this raster band (height = $h, offset = $yoff)."; | |||||||||||||||||||
| 282 | } | ||||||||||||||||||||
| 283 | 0 | my $data = $pdl->get_dataref(); | |||||||||||||||||||
| 284 | 0 | my ($pointer, $size) = scalar_to_buffer $$data; | |||||||||||||||||||
| 285 | 0 | Geo::GDAL::FFI::GDALRasterIO($$self, $Geo::GDAL::FFI::Write, $xoff, $yoff, $xsize, $ysize, $pointer, $xdim, $ydim, $t, 0, 0); | |||||||||||||||||||
| 286 | } | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | 13 | 1; | |||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | =pod | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | =encoding UTF-8 | ||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | =head1 NAME | ||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | Geo::GDAL::FFI::Band - A GDAL raster band | ||||||||||||||||||||
| 297 | |||||||||||||||||||||
| 298 | =head1 SYNOPSIS | ||||||||||||||||||||
| 299 | |||||||||||||||||||||
| 300 | =head1 DESCRIPTION | ||||||||||||||||||||
| 301 | |||||||||||||||||||||
| 302 | A band (channel) in a raster dataset. Use the Band method of a dataset | ||||||||||||||||||||
| 303 | object to obtain a band object. | ||||||||||||||||||||
| 304 | |||||||||||||||||||||
| 305 | =head1 METHODS | ||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | =head2 GetDataType | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | my $datatype = $band->GetDataType; | ||||||||||||||||||||
| 310 | |||||||||||||||||||||
| 311 | =head2 GetSize | ||||||||||||||||||||
| 312 | |||||||||||||||||||||
| 313 | my @size = $band->GetSize; | ||||||||||||||||||||
| 314 | |||||||||||||||||||||
| 315 | =head2 GetBlockSize | ||||||||||||||||||||
| 316 | |||||||||||||||||||||
| 317 | my @size = $band->GetBlockSize; | ||||||||||||||||||||
| 318 | |||||||||||||||||||||
| 319 | =head2 GetNoDataValue | ||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | my $nodata = $band->GetNoDataValue; | ||||||||||||||||||||
| 322 | |||||||||||||||||||||
| 323 | =head2 SetNoDataValue | ||||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | $band->SetNoDataValue($value); | ||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | Calling the method without arguments deletes the nodata value. | ||||||||||||||||||||
| 328 | |||||||||||||||||||||
| 329 | $band->SetNoDataValue; | ||||||||||||||||||||
| 330 | |||||||||||||||||||||
| 331 | =head2 Read | ||||||||||||||||||||
| 332 | |||||||||||||||||||||
| 333 | my $data = $band->Read($xoff, $yoff, $xsize, $ysize, $bufxsize, $bufysize); | ||||||||||||||||||||
| 334 | |||||||||||||||||||||
| 335 | All arguments are optional. If no arguments are given, reads the whole | ||||||||||||||||||||
| 336 | raster band into a 2D Perl array. The returned array is an array of | ||||||||||||||||||||
| 337 | references to arrays of row values. | ||||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | =head2 ReadBlock | ||||||||||||||||||||
| 340 | |||||||||||||||||||||
| 341 | my $data = $band->ReadBlock($xoff, $yoff, @blocksize, $datatype); | ||||||||||||||||||||
| 342 | |||||||||||||||||||||
| 343 | Reads a block of data from the band and returns it as a Perl 2D | ||||||||||||||||||||
| 344 | array. C<@blocksize> and C<$datatype> (an integer) are optional and | ||||||||||||||||||||
| 345 | obtained from the GDAL raster object if not given. | ||||||||||||||||||||
| 346 | |||||||||||||||||||||
| 347 | =head2 Write | ||||||||||||||||||||
| 348 | |||||||||||||||||||||
| 349 | $band->Write($data, $xoff, $yoff, $xsize, $ysize); | ||||||||||||||||||||
| 350 | |||||||||||||||||||||
| 351 | =head2 WriteBlock | ||||||||||||||||||||
| 352 | |||||||||||||||||||||
| 353 | $band->WriteBlock($data, $xoff, $yoff); | ||||||||||||||||||||
| 354 | |||||||||||||||||||||
| 355 | =head2 SetPiddle | ||||||||||||||||||||
| 356 | |||||||||||||||||||||
| 357 | $band->SetPiddle($pdl, $xoff, $yoff, $xsize, $ysize); | ||||||||||||||||||||
| 358 | |||||||||||||||||||||
| 359 | Read data from a piddle into this Band. | ||||||||||||||||||||
| 360 | |||||||||||||||||||||
| 361 | =head2 GetPiddle | ||||||||||||||||||||
| 362 | |||||||||||||||||||||
| 363 | $band->GetPiddle($xoff, $yoff, $xsize, $ysize, $xdim, $ydim); | ||||||||||||||||||||
| 364 | |||||||||||||||||||||
| 365 | Read data from this Band into a piddle. | ||||||||||||||||||||
| 366 | |||||||||||||||||||||
| 367 | =head2 GetColorInterpretation | ||||||||||||||||||||
| 368 | |||||||||||||||||||||
| 369 | my $ci = $band->GetColorInterpretation; | ||||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | =head2 SetColorInterpretation | ||||||||||||||||||||
| 372 | |||||||||||||||||||||
| 373 | $band->SetColorInterpretation($ci); | ||||||||||||||||||||
| 374 | |||||||||||||||||||||
| 375 | =head2 GetColorTable | ||||||||||||||||||||
| 376 | |||||||||||||||||||||
| 377 | my $color_table = $band->GetColorTable; | ||||||||||||||||||||
| 378 | |||||||||||||||||||||
| 379 | Returns the color table as an array of arrays. The inner tables are | ||||||||||||||||||||
| 380 | colors [c1...c4]. | ||||||||||||||||||||
| 381 | |||||||||||||||||||||
| 382 | =head2 SetColorTable | ||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | $band->SetColorTable($color_table); | ||||||||||||||||||||
| 385 | |||||||||||||||||||||
| 386 | =head1 LICENSE | ||||||||||||||||||||
| 387 | |||||||||||||||||||||
| 388 | This software is released under the Artistic License. See | ||||||||||||||||||||
| 389 | L<perlartistic>. | ||||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | =head1 AUTHOR | ||||||||||||||||||||
| 392 | |||||||||||||||||||||
| 393 | Ari Jolma - Ari.Jolma at gmail.com | ||||||||||||||||||||
| 394 | |||||||||||||||||||||
| 395 | =head1 SEE ALSO | ||||||||||||||||||||
| 396 | |||||||||||||||||||||
| 397 | L<Geo::GDAL::FFI> | ||||||||||||||||||||
| 398 | |||||||||||||||||||||
| 399 | L<Alien::gdal>, L<FFI::Platypus>, L<http://www.gdal.org> | ||||||||||||||||||||
| 400 | |||||||||||||||||||||
| 401 | =cut | ||||||||||||||||||||
| 402 | |||||||||||||||||||||
| 403 | __END__; | ||||||||||||||||||||