Commit b11a1875 authored by zhaoxiu.zeng's avatar zhaoxiu.zeng Committed by Michael Niedermayer

avcodec/golomb: simplify sign conversion

Signed-off-by: 's avatarZeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Signed-off-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parent 0073c8e3
......@@ -195,7 +195,7 @@ static inline int get_se_golomb(GetBitContext *gb)
return ff_se_golomb_vlc_code[buf];
} else {
int log = av_log2(buf);
int log = av_log2(buf), sign;
LAST_SKIP_BITS(re, gb, 31 - log);
UPDATE_CACHE(re, gb);
buf = GET_CACHE(re, gb);
......@@ -205,10 +205,8 @@ static inline int get_se_golomb(GetBitContext *gb)
LAST_SKIP_BITS(re, gb, 32 - log);
CLOSE_READER(re, gb);
if (buf & 1)
buf = -(buf >> 1);
else
buf = (buf >> 1);
sign = -(buf & 1);
buf = ((buf >> 1) ^ sign) - sign;
return buf;
}
......@@ -217,13 +215,10 @@ static inline int get_se_golomb(GetBitContext *gb)
static inline int get_se_golomb_long(GetBitContext *gb)
{
unsigned int buf = get_ue_golomb_long(gb);
int sign;
if (buf & 1)
buf = (buf + 1) >> 1;
else
buf = -(buf >> 1);
return buf;
sign = (buf & 1) - 1;
return ((buf >> 1) ^ sign) + 1;
}
static inline int svq3_get_se_golomb(GetBitContext *gb)
......@@ -264,13 +259,9 @@ static inline int dirac_get_se_golomb(GetBitContext *gb)
uint32_t ret = svq3_get_ue_golomb(gb);
if (ret) {
uint32_t buf;
OPEN_READER(re, gb);
UPDATE_CACHE(re, gb);
buf = SHOW_SBITS(re, gb, 1);
LAST_SKIP_BITS(re, gb, 1);
ret = (ret ^ buf) - buf;
CLOSE_READER(re, gb);
int sign;
sign = -get_bits1(gb);
ret = (ret ^ sign) - sign;
}
return ret;
......@@ -372,14 +363,11 @@ static inline int get_sr_golomb(GetBitContext *gb, int k, int limit,
int esc_len)
{
int v = get_ur_golomb(gb, k, limit, esc_len);
int sign;
v++;
if (v & 1)
return v >> 1;
else
return -(v >> 1);
// return (v>>1) ^ -(v&1);
sign = (v & 1) - 1;
return ((v >> 1) ^ sign) - sign;
}
/**
......@@ -406,10 +394,7 @@ static inline unsigned int get_ur_golomb_shorten(GetBitContext *gb, int k)
static inline int get_sr_golomb_shorten(GetBitContext *gb, int k)
{
int uvar = get_ur_golomb_jpegls(gb, k + 1, INT_MAX, 0);
if (uvar & 1)
return ~(uvar >> 1);
else
return uvar >> 1;
return (uvar >> 1) ^ -(uvar & 1);
}
#ifdef TRACE
......
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