[gdk-pixbuf: 6/7] gif: Simplify LZW clear code handling



commit a314f59344cb3fb2ca63264b44fa2f6cad8c86db
Author: Robert Ancell <robert ancell canonical com>
Date:   Wed Dec 5 11:56:34 2018 +1300

    gif: Simplify LZW clear code handling
    
    The existing code had a special state for handling codes after a clear code was
    received. This is more simply handled by using the 'lzw_oldcode' variable. This
    makes code that is less likely to introduce errors.

 gdk-pixbuf/io-gif.c | 21 +++------------------
 1 file changed, 3 insertions(+), 18 deletions(-)
---
diff --git a/gdk-pixbuf/io-gif.c b/gdk-pixbuf/io-gif.c
index f2207360e..be5bfc235 100644
--- a/gdk-pixbuf/io-gif.c
+++ b/gdk-pixbuf/io-gif.c
@@ -163,7 +163,6 @@ struct _GifContext
        int code_last_byte;
 
        /* lzw context */
-       gint lzw_fresh;
        gint lzw_code_size;
        guchar lzw_set_code_size;
        gint lzw_max_code;
@@ -567,23 +566,9 @@ static int
 lzw_read_byte (GifContext *context)
 {
        int code, incode;
-       gint retval;
        gint my_retval;
        register int i;
 
-       if (context->lzw_fresh) {
-               do {
-                       retval = get_code (context, context->lzw_code_size);
-                       if (retval < 0) {
-                               return retval;
-                       }
-
-                       context->lzw_firstcode = context->lzw_oldcode = retval;
-               } while (context->lzw_firstcode == context->lzw_clear_code);
-               context->lzw_fresh = FALSE;
-               return context->lzw_firstcode;
-       }
-
        if (context->lzw_sp > context->lzw_stack) {
                my_retval = *--(context->lzw_sp);
                return my_retval;
@@ -601,7 +586,7 @@ lzw_read_byte (GifContext *context)
                        context->lzw_max_code_size = 2 * context->lzw_clear_code;
                        context->lzw_max_code = context->lzw_clear_code + 2;
                        context->lzw_sp = context->lzw_stack;
-                       context->lzw_fresh = TRUE;
+                       context->lzw_oldcode = code;
                        return -3;
                } else if (code == context->lzw_end_code) {
                        int count;
@@ -659,7 +644,7 @@ lzw_read_byte (GifContext *context)
                 CHECK_LZW_SP ();
                *(context->lzw_sp)++ = context->lzw_firstcode = context->lzw_table[1][code];
 
-               if ((code = context->lzw_max_code) < (1 << MAX_LZW_BITS)) {
+               if (context->lzw_oldcode != context->lzw_clear_code && (code = context->lzw_max_code) < (1 << 
MAX_LZW_BITS)) {
                        context->lzw_table[0][code] = context->lzw_oldcode;
                        context->lzw_table[1][code] = context->lzw_firstcode;
                        ++context->lzw_max_code;
@@ -1128,7 +1113,7 @@ gif_prepare_lzw (GifContext *context)
        context->lzw_end_code = context->lzw_clear_code + 1;
        context->lzw_max_code_size = 2 * context->lzw_clear_code;
        context->lzw_max_code = context->lzw_clear_code + 2;
-       context->lzw_fresh = TRUE;
+       context->lzw_oldcode = context->lzw_clear_code;
        context->code_curbit = 0;
        context->code_lastbit = 0;
        /* During initialistion (in gif_lzw_fill_buffer) we substract 2 from


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]