[FFmpeg-cvslog] mpeg124: use sign_extend() function

Mans Rullgard git at videolan.org
Mon Oct 10 03:59:52 CEST 2011


ffmpeg | branch: master | Mans Rullgard <mans at mansr.com> | Sun Oct  9 23:16:07 2011 +0100| [aa498fef0dbd6eebd1b4dd90c36d3117cd9a17b2] | committer: Mans Rullgard

mpeg124: use sign_extend() function

Signed-off-by: Mans Rullgard <mans at mansr.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=aa498fef0dbd6eebd1b4dd90c36d3117cd9a17b2
---

 libavcodec/ituh263dec.c |    5 ++---
 libavcodec/ituh263enc.c |    5 ++---
 libavcodec/mpeg12.c     |    6 ++----
 3 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/libavcodec/ituh263dec.c b/libavcodec/ituh263dec.c
index a54d7c1..a234c2a 100644
--- a/libavcodec/ituh263dec.c
+++ b/libavcodec/ituh263dec.c
@@ -271,7 +271,7 @@ int ff_h263_resync(MpegEncContext *s){
 
 int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
 {
-    int code, val, sign, shift, l;
+    int code, val, sign, shift;
     code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
 
     if (code == 0)
@@ -293,8 +293,7 @@ int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
 
     /* modulo decoding */
     if (!s->h263_long_vectors) {
-        l = INT_BIT - 5 - f_code;
-        val = (val<<l)>>l;
+        val = sign_extend(val, 5 + f_code);
     } else {
         /* horrible h263 long vector mode */
         if (pred < -31 && val < -63)
diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
index 383a81b..783a04f 100644
--- a/libavcodec/ituh263enc.c
+++ b/libavcodec/ituh263enc.c
@@ -657,7 +657,7 @@ void h263_encode_mb(MpegEncContext * s,
 
 void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
 {
-    int range, l, bit_size, sign, code, bits;
+    int range, bit_size, sign, code, bits;
 
     if (val == 0) {
         /* zero vector */
@@ -667,8 +667,7 @@ void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code)
         bit_size = f_code - 1;
         range = 1 << bit_size;
         /* modulo encoding */
-        l= INT_BIT - 6 - bit_size;
-        val = (val<<l)>>l;
+        val = sign_extend(val, 6 + bit_size);
         sign = val>>31;
         val= (val^sign)-sign;
         sign&=1;
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 6a12344..5734ab8 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -54,7 +54,7 @@ static VLC mv_vlc;
 /* as H.263, but only 17 codes */
 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
 {
-    int code, sign, val, l, shift;
+    int code, sign, val, shift;
 
     code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
     if (code == 0) {
@@ -77,9 +77,7 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
     val += pred;
 
     /* modulo decoding */
-    l   = INT_BIT - 5 - shift;
-    val = (val << l) >> l;
-    return val;
+    return sign_extend(val, 5 + shift);
 }
 
 static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n)



More information about the ffmpeg-cvslog mailing list