diff --git a/libavcodec/common.h b/libavcodec/common.h index d398b397fb..02a491a58a 100644 --- a/libavcodec/common.h +++ b/libavcodec/common.h @@ -129,6 +129,14 @@ typedef unsigned int uint_fast16_t; typedef unsigned int uint_fast32_t; #endif +#ifndef INT_BIT +# if INT_MAX == INT64_MAX +# define INT_BIT 64 +# else +# define INT_BIT 32 +# endif +#endif + #if defined(CONFIG_OS2) || defined(CONFIG_SUNOS) static inline float floorf(float f) { return floor(f); diff --git a/libavcodec/h263.c b/libavcodec/h263.c index b89119004d..8c26634de4 100644 --- a/libavcodec/h263.c +++ b/libavcodec/h263.c @@ -1630,30 +1630,12 @@ void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) bit_size = f_code - 1; range = 1 << bit_size; /* modulo encoding */ - l = range * 32; -#if 1 - val+= l; - val&= 2*l-1; - val-= l; + l= INT_BIT - 6 - bit_size; + val = (val<>l; sign = val>>31; val= (val^sign)-sign; sign&=1; -#else - if (val < -l) { - val += 2*l; - } else if (val >= l) { - val -= 2*l; - } - assert(val>=-l && val= 0) { - sign = 0; - } else { - val = -val; - sign = 1; - } -#endif val--; code = (val >> bit_size) + 1; bits = val & (range - 1); @@ -4375,8 +4357,8 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) /* modulo decoding */ if (!s->h263_long_vectors) { - l = 1 << (f_code + 4); - val = ((val + l)&(l*2-1)) - l; + l = INT_BIT - 5 - f_code; + val = (val<>l; } else { /* horrible h263 long vector mode */ if (pred < -31 && val < -63) diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 15c51096d3..f235a199b0 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -696,7 +696,7 @@ void mpeg1_encode_mb(MpegEncContext *s, // RAL: Parameter added: f_or_b_code static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) { - int code, bit_size, l, m, bits, range, sign; + int code, bit_size, l, bits, range, sign; if (val == 0) { /* zero vector */ @@ -708,13 +708,8 @@ static void mpeg1_encode_motion(MpegEncContext *s, int val, int f_or_b_code) bit_size = f_or_b_code - 1; range = 1 << bit_size; /* modulo encoding */ - l = 16 * range; - m = 2 * l; - if (val < -l) { - val += m; - } else if (val >= l) { - val -= m; - } + l= INT_BIT - 5 - bit_size; + val= (val<>l; if (val >= 0) { val--; @@ -1411,8 +1406,8 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) val += pred; /* modulo decoding */ - l = 1 << (shift+4); - val = ((val + l)&(l*2-1)) - l; + l= INT_BIT - 5 - shift; + val = (val<>l; return val; }