GIF input plugin fixes and improvements.

Hello,

I have fixed the gif input plugin so now it can properly read a broader range of gifs and generate images that better resembles those generated by modern browsers.

As a side result, I think the code is a little bit easier to read and understand.

I've tested these changes with giflib 4.1.4, 4.2.0, 5.0.4, and 5.0.5.

Mariusz