From 480304fbb190cd0dbfea23b1a84fe8d85e414579 Mon Sep 17 00:00:00 2001 From: Sean Fox Date: Tue, 12 Aug 2008 22:44:53 +0000 Subject: Pixels are now properly initialised as transparent instead of to the image's background color svn path=/trunk/libnsgif/; revision=5079 --- libnsgif.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libnsgif.c') diff --git a/libnsgif.c b/libnsgif.c index 70a37b4..ae89f99 100644 --- a/libnsgif.c +++ b/libnsgif.c @@ -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 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) { * 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 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) { /* 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; -- cgit v1.2.3