Subject: | RAW reader does not properly process 4-channel data |
When reading a raw data string into a 32-bit (4-channel) Imager image,
the channels do not seem to end up being aligned properly. It looks
like an extra 0 is being injected each time as the alpha byte, and then
the next data byte (alpha) is pushed over to be read as the next red
byte, and so on, misaligning all data. I have attached a short script
showing this behavior.
Perl version: This is perl, v5.10.1 (*) built for
i486-linux-gnu-thread-multi
OS: Linux 2.6.32-25-generic-pae #45-Ubuntu SMP Sat Oct 16 21:01:33 UTC
2010 i686 GNU/Linux
Example output below -->
Imager Version: 0.87
Image Dimensions: 2x2, 4 channels.
Raw Data:
11 12 13 201
21 22 23 202
31 32 33 203
41 42 43 204
Imager Pixels:
11 12 13 0
201 21 22 0
23 202 31 0
32 33 203 0
Subject: | imagertest.pl |
#!/usr/bin/perl
use Imager;
## Set up raw data for a 2x2 4-channel image
my $w = 2;
my $h = 2;
my $numc = 4;
my @rawpixels = (
11,12,13,201,
21,22,23,202,
31,32,33,203,
41,42,43,204
);
my $rawdata = pack('C*', @rawpixels);
print "Imager Version: $Imager::VERSION\nImage Dimensions: ${w}x${h}, $numc channels.\n\n";
## Verify raw data string
print "Raw Data:\n";
foreach my $y (0..$h-1) {
foreach my $x (0..$w-1) {
foreach my $c (0..$numc-1) {
my $n = ($y*$h + $x)*$numc + $c;
print ord(substr($rawdata,$n,1))." ";
}
print "\n";
}
}
print "\n";
## Read raw data into Imager image
my $img = Imager->new();
$img->read(
type => 'raw',
data => $rawdata,
xsize => $w,
ysize => $h,
channels => 4,
storechannels => 4,
interleave => 0,
);
## Check Imager resulting pixels
print "Imager Pixels:\n";
foreach my $y (0..$h-1) {
foreach my $x (0..$w-1) {
my $color = $img->getpixel(x=>$x, y=>$y);
print join(' ', $color->rgba())."\n";
}
}
print "\n";
exit(0);