minor optimization of h263_encode_motion()

Originally committed as revision 976 to svn://svn.ffmpeg.org/ffmpeg/trunk
pull/126/head
Michael Niedermayer 23 years ago
parent 202ef8b819
commit a9c6830605
  1. 17
      libavcodec/h263.c

@ -1079,7 +1079,7 @@ INT16 *h263_pred_motion(MpegEncContext * s, int block,
static void h263_encode_motion(MpegEncContext * s, int val, int f_code) static void h263_encode_motion(MpegEncContext * s, int val, int f_code)
{ {
int range, l, m, bit_size, sign, code, bits; int range, l, bit_size, sign, code, bits;
if (val == 0) { if (val == 0) {
/* zero vector */ /* zero vector */
@ -1090,12 +1090,20 @@ static void h263_encode_motion(MpegEncContext * s, int val, int f_code)
range = 1 << bit_size; range = 1 << bit_size;
/* modulo encoding */ /* modulo encoding */
l = range * 32; l = range * 32;
m = 2 * l; #if 1
val+= l;
val&= 2*l-1;
val-= l;
sign = val>>31;
val= (val^sign)-sign;
sign&=1;
#else
if (val < -l) { if (val < -l) {
val += m; val += 2*l;
} else if (val >= l) { } else if (val >= l) {
val -= m; val -= 2*l;
} }
assert(val>=-l && val<l); assert(val>=-l && val<l);
if (val >= 0) { if (val >= 0) {
@ -1104,6 +1112,7 @@ static void h263_encode_motion(MpegEncContext * s, int val, int f_code)
val = -val; val = -val;
sign = 1; sign = 1;
} }
#endif
val--; val--;
code = (val >> bit_size) + 1; code = (val >> bit_size) + 1;
bits = val & (range - 1); bits = val & (range - 1);

Loading…
Cancel
Save