From 64ac6655f3839474849662a53a836d36275ee78d Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 9 Aug 2009 22:24:14 +0000 Subject: Fix palette entry population some more. Hopefully, it's completely endian agnostic now and still builds with GCC 4.4 svn path=/trunk/libnsgif/; revision=9138 --- src/libnsgif.c | 46 +++++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/libnsgif.c b/src/libnsgif.c index 4847647..98e650e 100644 --- a/src/libnsgif.c +++ b/src/libnsgif.c @@ -320,12 +320,19 @@ gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data) } for (index = 0; index < gif->colour_table_size; index++) { /* Gif colour map contents are r,g,b. - * Our table entries are ABGR */ - - gif->global_colour_table[index] = (0xff << 24) | - (gif_data[2] << 16) | - (gif_data[1] << 8) | - gif_data[0]; + * + * We want to pack them bytewise into the + * colour table, such that the red component + * is in byte 0 and the alpha component is in + * byte 3. + */ + unsigned char *entry = (unsigned char *) &gif-> + global_colour_table[index]; + + entry[0] = gif_data[0]; /* r */ + entry[1] = gif_data[1]; /* g */ + entry[2] = gif_data[2]; /* b */ + entry[3] = 0xff; /* a */ gif_data += 3; } @@ -333,8 +340,13 @@ gif_result gif_initialise(gif_animation *gif, size_t size, unsigned char *data) } else { /* Create a default colour table with the first two colours as black and white */ - gif->global_colour_table[0] = 0xff000000; - gif->global_colour_table[1] = 0xffffffff; + unsigned int *entry = gif->global_colour_table; + + entry[0] = 0x00000000; + /* Force Alpha channel to opaque */ + ((unsigned char *) entry)[3] = 0xff; + + entry[1] = 0xffffffff; } } @@ -848,12 +860,20 @@ gif_result gif_decode_frame(gif_animation *gif, unsigned int frame) { if (!clear_image) { for (index = 0; index < colour_table_size; index++) { /* Gif colour map contents are r,g,b. - * Our table entries are ABGR */ + * + * We want to pack them bytewise into the + * colour table, such that the red component + * is in byte 0 and the alpha component is in + * byte 3. + */ + unsigned char *entry = + (unsigned char *) &colour_table[index]; + + entry[0] = gif_data[0]; /* r */ + entry[1] = gif_data[1]; /* g */ + entry[2] = gif_data[2]; /* b */ + entry[3] = 0xff; /* a */ - colour_table[index] = (0xff << 24) | - (gif_data[2] << 16) | - (gif_data[1] << 8) | - gif_data[0]; gif_data += 3; } } else { -- cgit v1.2.3