You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-04 22:03:09 +02:00
avcodec/ituh263enc: Simplify encoding umotion vectors
There is no need to use two loops. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
@ -573,38 +573,20 @@ static void h263_encode_block(MPVEncContext *const s, int16_t block[], int n)
|
|||||||
/* Encode MV differences on H.263+ with Unrestricted MV mode */
|
/* Encode MV differences on H.263+ with Unrestricted MV mode */
|
||||||
static void h263p_encode_umotion(PutBitContext *pb, int val)
|
static void h263p_encode_umotion(PutBitContext *pb, int val)
|
||||||
{
|
{
|
||||||
short sval = 0;
|
|
||||||
short i = 0;
|
|
||||||
short n_bits = 0;
|
|
||||||
short temp_val;
|
|
||||||
int code = 0;
|
|
||||||
int tcode;
|
|
||||||
|
|
||||||
if ( val == 0)
|
if ( val == 0)
|
||||||
put_bits(pb, 1, 1);
|
put_bits(pb, 1, 1);
|
||||||
else if (val == 1)
|
|
||||||
put_bits(pb, 3, 0);
|
|
||||||
else if (val == -1)
|
|
||||||
put_bits(pb, 3, 2);
|
|
||||||
else {
|
else {
|
||||||
|
unsigned code = (val < 0) << 1;
|
||||||
|
unsigned aval = val < 0 ? -val : val;
|
||||||
|
unsigned n_bits = 2;
|
||||||
|
|
||||||
sval = ((val < 0) ? (short)(-val):(short)val);
|
while (aval != 1) { // The leading digit is implicitly coded via length
|
||||||
temp_val = sval;
|
unsigned tmp = (aval & 1) << 1 | 1;
|
||||||
|
aval >>= 1;
|
||||||
while (temp_val != 0) {
|
code |= tmp << n_bits;
|
||||||
temp_val = temp_val >> 1;
|
n_bits += 2;
|
||||||
n_bits++;
|
|
||||||
}
|
}
|
||||||
|
put_bits(pb, n_bits + 1, code);
|
||||||
i = n_bits - 1;
|
|
||||||
while (i > 0) {
|
|
||||||
tcode = (sval & (1 << (i-1))) >> (i-1);
|
|
||||||
tcode = (tcode << 1) | 1;
|
|
||||||
code = (code << 2) | tcode;
|
|
||||||
i--;
|
|
||||||
}
|
|
||||||
code = ((code << 1) | (val < 0)) << 1;
|
|
||||||
put_bits(pb, (2*n_bits)+1, code);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user