diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-08-09 22:24:14 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-08-09 22:24:14 +0000 |
commit | 64ac6655f3839474849662a53a836d36275ee78d (patch) | |
tree | d4179274f7ed6f8b8242f7d236860ee6e2f59128 /src | |
parent | 24a8a84b5d77b00460e3970621f4639b0c72919b (diff) | |
download | libnsgif-64ac6655f3839474849662a53a836d36275ee78d.tar.gz libnsgif-64ac6655f3839474849662a53a836d36275ee78d.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/libnsgif.c | 46 |
1 files changed, 33 insertions, 13 deletions
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 { |