changeset 1255:625ccacd1113 libavcodec

decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)
author michaelni
date Wed, 14 May 2003 01:08:02 +0000
parents 604661d34c68
children b8e1c17b8d7d
files h263.c mpeg12.c msmpeg4.c
diffstat 3 files changed, 18 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/h263.c	Wed May 14 00:32:22 2003 +0000
+++ b/h263.c	Wed May 14 01:08:02 2003 +0000
@@ -3437,10 +3437,12 @@
 
     sign = get_bits1(&s->gb);
     shift = f_code - 1;
-    val = (code - 1) << shift;
-    if (shift > 0)
+    val = code;
+    if (shift) {
+        val = (val - 1) << shift;
         val |= get_bits(&s->gb, shift);
-    val++;
+        val++;
+    }
     if (sign)
         val = -val;
     val += pred;
@@ -3448,11 +3450,7 @@
     /* modulo decoding */
     if (!s->h263_long_vectors) {
         l = 1 << (f_code + 4);
-        if (val < -l) {
-            val += l<<1;
-        } else if (val >= l) {
-            val -= l<<1;
-        }
+        val = ((val + l)&(l*2-1)) - l;
     } else {
         /* horrible h263 long vector mode */
         if (pred < -31 && val < -63)
--- a/mpeg12.c	Wed May 14 00:32:22 2003 +0000
+++ b/mpeg12.c	Wed May 14 01:08:02 2003 +0000
@@ -1176,7 +1176,7 @@
 /* as h263, but only 17 codes */
 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
 {
-    int code, sign, val, m, l, shift;
+    int code, sign, val, l, shift;
 
     code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
     if (code == 0) {
@@ -1188,22 +1188,19 @@
 
     sign = get_bits1(&s->gb);
     shift = fcode - 1;
-    val = (code - 1) << shift;
-    if (shift > 0)
+    val = code;
+    if (shift) {
+        val = (val - 1) << shift;
         val |= get_bits(&s->gb, shift);
-    val++;
+        val++;
+    }
     if (sign)
         val = -val;
     val += pred;
     
     /* modulo decoding */
     l = 1 << (shift+4);
-    m = 2 * l;
-    if (val < -l) {
-        val += m;
-    } else if (val >= l) {
-        val -= m;
-    }
+    val = ((val + l)&(l*2-1)) - l;
     return val;
 }
 
--- a/msmpeg4.c	Wed May 14 00:32:22 2003 +0000
+++ b/msmpeg4.c	Wed May 14 01:08:02 2003 +0000
@@ -1481,10 +1481,12 @@
         return pred;
     sign = get_bits1(&s->gb);
     shift = f_code - 1;
-    val = (code - 1) << shift;
-    if (shift > 0)
+    val = code;
+    if (shift) {
+        val = (val - 1) << shift;
         val |= get_bits(&s->gb, shift);
-    val++;
+        val++;
+    }
     if (sign)
         val = -val;