changeset 1280:8623c2e29555 libavcodec

optimize
author michaelni
date Fri, 23 May 2003 16:04:24 +0000
parents 77aafc141a39
children 37176fafe11e
files mjpeg.c
diffstat 1 files changed, 11 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/mjpeg.c	Fri May 23 12:58:46 2003 +0000
+++ b/mjpeg.c	Fri May 23 16:04:24 2003 +0000
@@ -557,12 +557,7 @@
             mant--;
         }
         
-        /* compute the log (XXX: optimize) */
-        nbits = 0;
-        while (val != 0) {
-            val = val >> 1;
-            nbits++;
-        }
+        nbits= av_log2(val) + 1;
             
         put_bits(&s->pb, huff_size[nbits], huff_code[nbits]);
         
@@ -613,12 +608,7 @@
                 mant--;
             }
             
-            /* compute the log (XXX: optimize) */
-            nbits = 0;
-            while (val != 0) {
-                val = val >> 1;
-                nbits++;
-            }
+            nbits= av_log2(val) + 1;
             code = (run << 4) | nbits;
 
             put_bits(&s->pb, huff_size_ac[code], huff_code_ac[code]);
@@ -902,7 +892,7 @@
 
 static inline int mjpeg_decode_dc(MJpegDecodeContext *s, int dc_index)
 {
-    int code, diff;
+    int code;
     code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2);
     if (code < 0)
     {
@@ -910,20 +900,18 @@
                 &s->vlcs[0][dc_index]);
         return 0xffff;
     }
-    if (code == 0) {
-        diff = 0;
-    } else {
-        diff = get_xbits(&s->gb, code);
-    }
-    return diff;
+
+    if(code)
+        return get_xbits(&s->gb, code);
+    else
+        return 0;
 }
 
 /* decode block and dequantize */
 static int decode_block(MJpegDecodeContext *s, DCTELEM *block, 
                         int component, int dc_index, int ac_index, int quant_index)
 {
-    int nbits, code, i, j, level;
-    int run, val;
+    int code, i, j, level, val;
     VLC *ac_vlc;
     int16_t *quant_matrix;
 
@@ -953,10 +941,8 @@
         if (code == 0xf0) {
             i += 16;
         } else {
-            run = code >> 4;
-            nbits = code & 0xf;
-            level = get_xbits(&s->gb, nbits);
-            i += run;
+            level = get_xbits(&s->gb, code & 0xf);
+            i += code >> 4;
             if (i >= 64) {
                 dprintf("error count: %d\n", i);
                 return -1;