Reputation: 4302
I have read the giflib usage explanation and wrote the following code:
GifFileType *gifFile = DGifOpenFileName("D:\\my.gif00.gif");
DGifSlurp(gifFile);
int h = gifFile->SHeight;
int w = gifFile->SWidth;
int count = gifFile->ImageCount;
GifPixelType *myPixels = new GifPixelType[w];
int errcode = DGifGetLine(gifFile, myPixels, 1);
if (errcode == GIF_OK) {
} else {
PrintGifError();
}
As you see there, any file I set into the DGifOpenFileName function as argument results in an error, the PrintGifError() prints out the following message:
GIF-LIB error: #Pixels bigger than Width * Height.
I can't understand what is wrong in my code. what I want is to read the gif file's pixels, Edit them then set back to the gif file. Could you help with this issue?
Upvotes: 0
Views: 1470
Reputation: 5039
As far as I can tell, this seems to indicate that you gif file is corrupt.
The problem is that you shouldn't be using DGifGetLine()
. The function DGifSlurp()
reads the entire GIF file into the gifFile structure. Internally, it calls DGifGetLine()
(and a fair few other things), and by the time it returns, the entire file has been processed. Trying to call DGifGetLine()
after that doesn't make sense.
This is what dgif_lib.c says about DGifSlurp()
:
/******************************************************************************
This routine reads an entire GIF into core, hanging all its state info off
the GifFileType pointer. Call DGifOpenFileName() or DGifOpenFileHandle()
first to initialize I/O. Its inverse is EGifSpew().
*******************************************************************************/
Upvotes: 5