Commit 05858889 authored by BERO's avatar BERO Committed by Michael Niedermayer

decode motion & modulo optimize patch by (BERO <bero at geocities dot co dot jp>)

Originally committed as revision 1872 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent d8e00c09
...@@ -3437,10 +3437,12 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) ...@@ -3437,10 +3437,12 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
sign = get_bits1(&s->gb); sign = get_bits1(&s->gb);
shift = f_code - 1; shift = f_code - 1;
val = (code - 1) << shift; val = code;
if (shift > 0) if (shift) {
val = (val - 1) << shift;
val |= get_bits(&s->gb, shift); val |= get_bits(&s->gb, shift);
val++; val++;
}
if (sign) if (sign)
val = -val; val = -val;
val += pred; val += pred;
...@@ -3448,11 +3450,7 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) ...@@ -3448,11 +3450,7 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code)
/* modulo decoding */ /* modulo decoding */
if (!s->h263_long_vectors) { if (!s->h263_long_vectors) {
l = 1 << (f_code + 4); l = 1 << (f_code + 4);
if (val < -l) { val = ((val + l)&(l*2-1)) - l;
val += l<<1;
} else if (val >= l) {
val -= l<<1;
}
} else { } else {
/* horrible h263 long vector mode */ /* horrible h263 long vector mode */
if (pred < -31 && val < -63) if (pred < -31 && val < -63)
......
...@@ -1176,7 +1176,7 @@ static int mpeg_decode_mb(MpegEncContext *s, ...@@ -1176,7 +1176,7 @@ static int mpeg_decode_mb(MpegEncContext *s,
/* as h263, but only 17 codes */ /* as h263, but only 17 codes */
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) 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); code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2);
if (code == 0) { if (code == 0) {
...@@ -1188,22 +1188,19 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) ...@@ -1188,22 +1188,19 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
sign = get_bits1(&s->gb); sign = get_bits1(&s->gb);
shift = fcode - 1; shift = fcode - 1;
val = (code - 1) << shift; val = code;
if (shift > 0) if (shift) {
val = (val - 1) << shift;
val |= get_bits(&s->gb, shift); val |= get_bits(&s->gb, shift);
val++; val++;
}
if (sign) if (sign)
val = -val; val = -val;
val += pred; val += pred;
/* modulo decoding */ /* modulo decoding */
l = 1 << (shift+4); l = 1 << (shift+4);
m = 2 * l; val = ((val + l)&(l*2-1)) - l;
if (val < -l) {
val += m;
} else if (val >= l) {
val -= m;
}
return val; return val;
} }
......
...@@ -1481,10 +1481,12 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) ...@@ -1481,10 +1481,12 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
return pred; return pred;
sign = get_bits1(&s->gb); sign = get_bits1(&s->gb);
shift = f_code - 1; shift = f_code - 1;
val = (code - 1) << shift; val = code;
if (shift > 0) if (shift) {
val = (val - 1) << shift;
val |= get_bits(&s->gb, shift); val |= get_bits(&s->gb, shift);
val++; val++;
}
if (sign) if (sign)
val = -val; val = -val;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment