fixed bug in jpeg2000 decoding
[swftools.git] / lib / q.c
diff --git a/lib/q.c b/lib/q.c
index 8971616..9f7ce2c 100644 (file)
--- a/lib/q.c
+++ b/lib/q.c
@@ -688,6 +688,18 @@ unsigned int crc32_add_string(unsigned int checksum, const char*s)
     }
     return checksum;
 }
+unsigned int crc32_add_bytes(unsigned int checksum, const void*_s, int len)
+{
+    unsigned char*s = (unsigned char*)_s;
+    crc32_init();
+    if(!s || !len)
+        return checksum;
+    do {
+        checksum = checksum>>8 ^ crc32[(*s^checksum)&0xff];
+        s++;
+    } while(--len);
+    return checksum;
+}
 
 unsigned int string_hash(const string_t*str)
 {
@@ -1340,10 +1352,12 @@ void mtf_increase(mtf_t*m, const void*key)
     while(item) {
        if(m->type->equals(item->key, key)) {
            item->num++;
-           if(last) last->next = item->next;
-           else m->first = item->next;
-            item->next = m->first;
-            m->first = item;
+           if(item->num>m->first->num) {
+               if(last) last->next = item->next;
+               else m->first = item->next;
+               item->next = m->first;
+               m->first = item;
+           }
             return;
        }
        last = item;