diff options
author | zhaoxiu.zeng <zhaoxiu.zeng@gmail.com> | 2015-02-14 00:58:58 +0800 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2015-02-14 00:41:45 +0100 |
commit | b11a187575f6262c0941fdbb1cd3fd7ffd819500 (patch) | |
tree | 626c2cfc7d2bbfe7533629005248151da89226a0 /libavcodec | |
parent | 0073c8e34500141cf3ac5e538a1bef85f90ab16f (diff) | |
download | ffmpeg-b11a187575f6262c0941fdbb1cd3fd7ffd819500.tar.gz |
avcodec/golomb: simplify sign conversion
Signed-off-by: Zeng Zhaoxiu <zhaoxiu.zeng@gmail.com>
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/golomb.h | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h index c4b1354265..1632ee37cc 100644 --- a/libavcodec/golomb.h +++ b/libavcodec/golomb.h @@ -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 |