• Create Account

## Error decompressing gif images using giflib

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1Plerion  Members

Posted 15 April 2014 - 06:05 PM

Hello all

I am using giflib to parse gif files and retreive the infos I need. In genereal this works pretty nice, though there are some gifs (usually ones showing people) that have an invalid behavior. See the following video:

After further investigation i have realized, that those invalid parts are actually using the transparent color index that is given in the extension block. Right now i get the color information from the gif like that:

		mImageNumber = (mImageNumber + 1) % (mGifFile->ImageCount);
auto& img = mGifFile->SavedImages[mImageNumber];

auto colorMap = img.ImageDesc.ColorMap ? img.ImageDesc.ColorMap : mGifFile->SColorMap;
memset(&mGcb, 0, sizeof(mGcb));

int ret = DGifSavedExtensionToGCB(mGifFile, mImageNumber, &mGcb);
int32 transparent = -1;
if (ret == GIF_OK) {
mHasGcb = true;
mLastFrame = sTime->getGameTime();
transparent = mGcb.TransparentColor;
} else {
mHasGcb = false;
}

for (uint32 i = 0; i < img.ImageDesc.Height; ++i) {
for (uint32 j = 0; j < img.ImageDesc.Width; ++j) {
auto clrIndex = img.RasterBits[i * img.ImageDesc.Width + j];
auto& clrObj = colorMap->Colors[clrIndex];
auto r = clrObj.Red;
auto g = clrObj.Green;
auto b = clrObj.Blue;
auto alpha = clrIndex == transparent ? 0x00 : 0xFF;
mColorData[(i + img.ImageDesc.Top) * mGifFile->SWidth + (j + img.ImageDesc.Left)] = (alpha << 24) | (b << 16) | (g << 8) | r;
}
}

mTexture->fromMemory(mGifFile->SWidth, mGifFile->SHeight, mColorData);


All those wrong pixels are having the transparent color. I also tried ignoring alpha, but the color value of the transparent color is white, so it does not look any better.

		mGifFile = DGifOpen(this, onRead, &mError);
if (mError) {
throw System::InvalidOperation(GifErrorString(mError));
}

mError = DGifSlurp(mGifFile);
if (mError == 0) {
throw System::InvalidOperation(GifErrorString(mGifFile->Error));
}


Could this be an issue of giflib? The gif im using is:

Is there another library available besides giflib that is able to handle gif files?