> From: Neil Watkiss [mailto:[EMAIL PROTECTED]]
> If you could send the same snippet inside a script that
> demonstrates the
> problem, someone might notice something. Right now, I have no
> idea looking
> at your code what could be wrong.
Ooops...excessive brevity. Sorry.
Here is a more complete picture. The very strange thing is that if you
create a raster that is 100x100 (30,000 datapoints in all--3 per pixel), it
works (see the two commented out lines below). But my much smaller 30 x 30
raster below (2700 datapoints), generates errors. I don't get it.
#!perl;
#
# error.pl
#
# A little script which is meant to convert an array of
# pixel intensities (3 values per pixel) to the raw
# Tk::Canvas data format (#hhhhhh, where hh is some hex
# value, 0-255).
#
# Unfortunately, it generates errors under windows.
#
use Inline C => DATA;
#for ($x=0; $x<30000; $x++) # this works (with the other change below)
for ($x=0; $x<2700; $x++)
{
# load the raster, three values per pixel
# (Just arbitrary value of 255 for every sample/pixel
# for this demonstration)
push @$imageData, 255;
}
for ($i = 1; $i < 1000; $i++)
{
# Now try to convert the raster (it will work a couple of times)
print "Attempts TIFFToCanvas call, iteration # $i\n";
# $canvasData = TIFFToCanvas($imageData, 100, 100); # this works.
$canvasData = TIFFToCanvas($imageData, 30, 30);
}
exit;
__END__
__C__
SV* TIFFToCanvas(SV* svImage, int w, int h)
{
AV *avImage, *avCanvas;
int x, y; // loop indices, and the image area
SV *r, *g, *b, *s;
char *pixel = NULL; // a single pixel in #hhhhhh (Canvas) format
char *pixels = NULL; // the entire row of pixels in Canvas format
avCanvas = newAV(); // an array to hold transformed data
r = sv_newmortal(); // the red channel
g = sv_newmortal(); // the green channel
b = sv_newmortal(); // the blue channel
//Extract and dereference image array to AV*
avImage = (AV*)SvRV(svImage);
// allocate some memory
pixel = (char*)malloc(8 * sizeof(char));
pixels = (char*)malloc(8 * w * sizeof(char));
if (pixel == NULL)
handle_error(1, 1);
if (pixels == NULL)
handle_error(1, 2);
//iterate through rows and columns of image data,
//and covert to #hhhhhh format
//w is the width of the image
//Everything is multiplied by 3 because there are 3
//samples for every pixel.
for(y = 0; y < h; y++)
{
strcpy(pixels, "");
for (x = 0; x < w; x++)
{
r = *av_fetch(avImage, ((y * w) + x) * 3, 0);
g = *av_fetch(avImage, ((y * w) + x) * 3 + 1, 0);
b = *av_fetch(avImage, ((y * w) + x) * 3 + 2, 0);
sprintf(pixel, "#%02X%02X%02X ", SvIV(r), SvIV(g), SvIV(b));
strcat(pixels, pixel);
}
s = newSVpv(pixels, 0);
av_push(avCanvas, s);
}
free(pixel);
free(pixels);
return newRV_noinc((SV*)(avCanvas));
}
int handle_error (int iErrNo, int iTrap)
{
printf("Error %d at trap %d\n\n", iErrNo, iTrap);
exit(0);
return 0;
}