summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuilhem Moulin <guilhem@fripost.org>2017-01-14 00:33:43 +0100
committerGuilhem Moulin <guilhem@fripost.org>2017-01-14 00:33:43 +0100
commit57a244f0776a94ef8c789376340a2fa02e838935 (patch)
tree0db7de625694a5ca2f6902260e44916fa5c6dd5b
parent300a8f205f8ce1c0c616863633b8ead9b5cb6b20 (diff)
Inline::C: Don't assume we can modify inplace and return the input buffer back to Perl.HEADmaster
-rwxr-xr-xmkindex.pl16
1 files changed, 9 insertions, 7 deletions
diff --git a/mkindex.pl b/mkindex.pl
index 97fdf93..ed75907 100755
--- a/mkindex.pl
+++ b/mkindex.pl
@@ -498,7 +498,6 @@ sub expand_rgba {
my $src_data = $src_band->ReadRaster(0, $y, $xSize, 1);
for (my $b = 0; $b < $dst_nb; $b++) {
- local $_ = $src_data;
# We use an inlined C function to speed up things a bit.
# Essentially what we're doing is a splice through the
# lookup table.
@@ -507,8 +506,8 @@ sub expand_rgba {
# than our C code, can be obtained using transliteration:
# my $src_str = join '', map chr, (0 .. $src_nc-1);
# eval "tr/\Q$src_str\E/\Q$lookup->[$b]\E/";
- &subst ( $_, $lookup->[$b], $xSize );
- $dst_ds->Band(1+$b)->WriteRaster(0, $y, $xSize, 1, $_);
+ my $dst_data = &subst( $src_data, $lookup->[$b], $xSize );
+ $dst_ds->Band(1+$b)->WriteRaster(0, $y, $xSize, 1, $dst_data);
}
&{$config{progress}}( (1+$y) / $ySize ) if $config{progress};
@@ -687,8 +686,11 @@ __END__
__C__
-void subst (unsigned char *data, unsigned char *lookup, int length) {
- int i;
- for (i = 0; i < length; i++)
- data[i] = lookup[ data[i] ];
+SV *subst(unsigned char *data, unsigned char *lookup, int length) {
+ char *out = malloc(length * sizeof(unsigned char));
+ for (int i = 0; i < length; i++)
+ out[i] = lookup[ data[i] ];
+ SV* ret = newSVpvn(out, length);
+ free(out);
+ return(ret);
}