Matt - 2013-05-27

Hi !

I try to extract images from a gif file using the v5.0,4 of the giflib, in order bind them in Opencv. I don't understand why my code actually segfaults.
I am probably doing something wrong.

t_gif   initGif(const char *filename){
    t_gif gif;
    int *error;
    GifFileType *GifFile = DGifOpenFileName(filename, error);
    assert(error != NULL);

    int ret = DGifSlurp(GifFile);
    assert(ret == GIF_OK);

    gif.h = (int)GifFile->SHeight;
    gif.w = GifFile->SWidth;
    gif.nbFrames = GifFile->ImageCount;
    gif.colorSize = GifFile->SColorResolution;

    GifImageDesc Image = GifFile->Image;
    SavedImage *img = &GifFile->SavedImages[0];

    cout << "width: " << gif.w << endl;
    cout << "height: " << gif.h << endl;
    cout << "Image Count: " << gif.nbFrames << endl;
    cout << "SColor Resolution: " << gif.colorSize << endl;
    Mat color = Mat(Size(gif.w, gif.h), CV_8UC1, img->RasterBits);
    imwrite("./test.png", color);
    return gif;
}

Could you tell me what am I doing wrong ? I thought that I could use DGifSlurp in order to populate the GifFileType struct.
Thanks

 

Last edit: Matt 2013-05-27