From b11a187575f6262c0941fdbb1cd3fd7ffd819500 Mon Sep 17 00:00:00 2001 From: "zhaoxiu.zeng" Date: Sat, 14 Feb 2015 00:58:58 +0800 Subject: [PATCH] avcodec/golomb: simplify sign conversion Signed-off-by: Zeng Zhaoxiu Signed-off-by: Michael Niedermayer --- libavcodec/golomb.h | 41 +++++++++++++---------------------------- 1 file 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