From 05858889b2261fc3a98c19e25219b435ea0f6154 Mon Sep 17 00:00:00 2001 From: BERO Date: Wed, 14 May 2003 01:08:02 +0000 Subject: [PATCH] decode motion & modulo optimize patch by (BERO ) Originally committed as revision 1872 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/h263.c | 14 ++++++-------- libavcodec/mpeg12.c | 17 +++++++---------- libavcodec/msmpeg4.c | 8 +++++--- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/libavcodec/h263.c b/libavcodec/h263.c index 6cc2dc47c0..259ca8431f 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -3437,10 +3437,12 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) 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 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) /* 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) diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 32d3057831..2186b5799e 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -1176,7 +1176,7 @@ static int mpeg_decode_mb(MpegEncContext *s, /* 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 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) 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; } diff --git a/libavcodec/msmpeg4.c b/libavcodec/msmpeg4.c index df39315854..e4daec4e8f 100644 --- a/libavcodec/msmpeg4.c +++ b/libavcodec/msmpeg4.c @@ -1481,10 +1481,12 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) 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;