I'm using GIFLIB to load in a gif file and I want to extract the RGB data from each frame.
I've used DGifSlurp to load in the file but I cant work out exactly how to get the RGB data from the SavedImage structure. Two tests seem to work, though I've guessed how to do it, but a third crashes with a memory exception. Is there a function in the library I should be using, or is there simple code ?
void TestGIF()
{
int error=0;
GifFileType * gif=DGifOpenFileName("d:/exampleGIF3.gif",&error);
error=DGifSlurp(gif);
unsigned int h=gif->SHeight;
unsigned int w=gif->SWidth;
int i,j;
unsigned char * d=malloc(w*h*4);
unsigned char * save=d;
for(i=0;i<gif->ImageCount;i++)
{
d=save;
SavedImage * p=&gif->SavedImages[i];
for(j=0;j<w*h;j++)
{
int c=p->RasterBits[j];
if(c==gif->SBackGroundColor)
{
d+=4; //use last frame colour
}
else
{
GifColorType rgb=gif->SColorMap->Colors[c];
*d++=rgb.Blue;
*d++=rgb.Green;
*d++=rgb.Red;
*d++=0xff;
}
}
char outname[512];
sprintf(outname,"d:/image%02d.tga",i);
SAVETGA(outname,save,w,h,4);
}
free(save);
error=DGifCloseFile(gif, &error);
}
It crashes with a memory exception while reading the third frame of 13 in this example gif
What code should I be using to get the RGB data from the SavedImage structure please ?
Thanks
Shaun