changeset 4732:8583aa3c21bc libavcodec

simplify
author michael
date Sun, 25 Mar 2007 23:22:11 +0000
parents 93fca53ce2e2
children 507d08212e36
files lzw.c
diffstat 1 files changed, 6 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/lzw.c	Sun Mar 25 20:52:45 2007 +0000
+++ b/lzw.c	Sun Mar 25 23:22:11 2007 +0000
@@ -148,7 +148,7 @@
     s->clear_code = 1 << s->codesize;
     s->end_code = s->clear_code + 1;
     s->slot = s->newcodes = s->clear_code + 2;
-    s->oc = s->fc = 0;
+    s->oc = s->fc = -1;
     s->sp = s->stack;
 
     s->mode = mode;
@@ -203,18 +203,7 @@
             s->curmask = mask[s->cursize];
             s->slot = s->newcodes;
             s->top_slot = 1 << s->cursize;
-            while ((c = lzw_get_code(s)) == s->clear_code);
-            if (c == s->end_code) {
-                s->end_code = -1;
-                break;
-            }
-            /* test error */
-            if (c >= s->slot)
-                c = 0;
-            fc = oc = c;
-            *buf++ = c;
-            if ((--l) == 0)
-                break;
+            fc= oc= -1;
         } else {
             code = c;
             if (code >= s->slot) {
@@ -226,11 +215,12 @@
                 code = s->prefix[code];
             }
             *sp++ = code;
-            if (s->slot < s->top_slot) {
-                s->suffix[s->slot] = fc = code;
+            if (s->slot < s->top_slot && oc>=0) {
+                s->suffix[s->slot] = code;
                 s->prefix[s->slot++] = oc;
-                oc = c;
             }
+            fc = code;
+            oc = c;
             if (s->slot >= s->top_slot - s->extra_slot) {
                 if (s->cursize < LZW_MAXBITS) {
                     s->top_slot <<= 1;