- io->flags |= IMAGE_ALPHA | IMAGE_IO_HAS_BACKGROUND;
- GifColorType *background = color_map->Colors + gif->SBackGroundColor;
- color_make_rgb(&io->background_color, background->Red, background->Green, background->Blue);
+ ExtensionBlock *e = image->ExtensionBlocks + i;
+ if (e->Function == 0xF9)
+ {
+ DBG("Found graphics control extension");
+ if (unlikely(e->ByteCount != 4))
+ {
+ IMAGE_ERROR(io->context, IMAGE_ERROR_READ_FAILED, "Invalid graphics control extension.");
+ DGifCloseFile(gif);
+ return 0;
+ }
+ byte *b = e->Bytes;
+ /* transparent color present */
+ if (b[0] & 1)
+ {
+ rd->transparent_index = b[3];
+ io->flags |= IMAGE_ALPHA;
+ if (gif->SColorMap)
+ {
+ GifColorType *background = color_map->Colors + gif->SBackGroundColor;
+ color_make_rgb(&io->background_color, background->Red, background->Green, background->Blue);
+ }
+ }
+ /* We've got everything we need :-) */
+ break;
+ }
+ else
+ DBG("Found unknown extension: type=%d size=%d", e->Function, e->ByteCount);