I was informed this morning that GIFs on http://www.drobe.co.uk were
decoding incorrectly.  I narrowed this down to an error in the way GIF
frames were initialised: the pixels were all set to the background
color initially, rather than being transparent.  It could be that this
is a problem in the way transparency is handled in libnsgif--though
I'm hopeful that it's not; the GIF's transparency index is stored and
used, but this code was written by Richard Wilson and I haven't
thoroughly examined it.  The patch should correct the problem, but let
me know if any more quirks come up.

Quick how to:
After applying the patch, run a "make; make install" in the libnsgif
directory to get the library re-compiled and installed.  Then 'make
clean; make' in NetSurf's directory to be sure it's linked with the
new libnsgif.  Test and report bugs back to me.


Sean
--- libnsgif.c	2008-08-12 14:27:46.000000000 -0500
+++ ../libnsgif.c	2008-08-12 14:24:44.000000000 -0500
@@ -91,6 +91,10 @@
 */
 #define GIF_MAX_LZW 12
 
+/* Transparent colour
+*/
+#define GIF_TRANSPARENT_COLOUR 0x00
+
 /*	GIF Flags
 */
 #define GIF_FRAME_COMBINE 1
@@ -876,7 +880,10 @@
 		 *	colour or this is the first frame, clear the frame data
 		*/
 		if ((frame == 0) || (gif->decoded_frame == GIF_INVALID_FRAME)) {
-			memset((char*)frame_data, colour_table[gif->background_index], gif->width * gif->height * sizeof(int));
+			memset((char*)frame_data, GIF_TRANSPARENT_COLOUR, gif->width * gif->height * sizeof(int));
+			/* The line below would fill the image with its background color, but because GIFs support
+			 * transparency we likely wouldn't want to do that. */
+			/* memset((char*)frame_data, colour_table[gif->background_index], gif->width * gif->height * sizeof(int)); */
 		} else if ((frame != 0) && (gif->frames[frame - 1].disposal_method == GIF_FRAME_CLEAR)) {
 			clear_image = true;
 			if ((return_value = gif_decode_frame(gif, (frame - 1))) != GIF_OK)
@@ -890,7 +897,8 @@
 				/*	If we don't find one, clear the frame data
 				*/
 				if (last_undisposed_frame == -1) {
-					memset((char*)frame_data, colour_table[gif->background_index], gif->width * gif->height * sizeof(int));
+					/* see notes above on transparency vs. background color */
+					memset((char*)frame_data, GIF_TRANSPARENT_COLOUR, gif->width * gif->height * sizeof(int));
 				} else {
 					if ((return_value = gif_decode_frame(gif, last_undisposed_frame)) != GIF_OK)
 						goto gif_decode_frame_exit;

Reply via email to