Commit aa5ae7e2 authored by Urvang Joshi's avatar Urvang Joshi
Browse files

detokenize: Refactor identical switch cases.

BUG=aomedia:442

Change-Id: If29250966a210495ca07c3959c1562447a00f90c
parent 359dc2b9
......@@ -66,6 +66,40 @@ static INLINE int read_coeff(const aom_prob *probs, int n, aom_reader *r) {
#endif
static int token_to_value(aom_reader *const r, int token, TX_SIZE tx_size,
int bit_depth) {
#if !CONFIG_HIGHBITDEPTH
assert(bit_depth == 8);
#endif // !CONFIG_HIGHBITDEPTH
switch (token) {
case ZERO_TOKEN:
case ONE_TOKEN:
case TWO_TOKEN:
case THREE_TOKEN:
case FOUR_TOKEN: return token;
case CATEGORY1_TOKEN:
return CAT1_MIN_VAL + READ_COEFF(av1_cat1_prob, av1_cat1_cdf, 1, r);
case CATEGORY2_TOKEN:
return CAT2_MIN_VAL + READ_COEFF(av1_cat2_prob, av1_cat2_cdf, 2, r);
case CATEGORY3_TOKEN:
return CAT3_MIN_VAL + READ_COEFF(av1_cat3_prob, av1_cat3_cdf, 3, r);
case CATEGORY4_TOKEN:
return CAT4_MIN_VAL + READ_COEFF(av1_cat4_prob, av1_cat4_cdf, 4, r);
case CATEGORY5_TOKEN:
return CAT5_MIN_VAL + READ_COEFF(av1_cat5_prob, av1_cat5_cdf, 5, r);
case CATEGORY6_TOKEN: {
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, bit_depth);
return CAT6_MIN_VAL + READ_COEFF(av1_cat6_prob + skip_bits, av1_cat6_cdf,
18 - skip_bits, r);
}
default:
assert(0); // Invalid token.
return -1;
}
}
static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
TX_SIZE tx_size, TX_TYPE tx_type, const int16_t *dq,
#if CONFIG_NEW_QUANT
......@@ -118,7 +152,6 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
int dq_shift;
int v, token;
int16_t dqv = dq[0];
int more_data = 1;
#if CONFIG_NEW_QUANT
const tran_low_t *dqv_val = &dq_val[0][0];
#endif // CONFIG_NEW_QUANT
......@@ -142,6 +175,7 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
#if CONFIG_NEW_TOKENSET
band = *band_translate++;
int more_data = 1;
while (more_data) {
int comb_token;
int last_pos = (c + 1 == max_eob);
......@@ -204,39 +238,12 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
*max_scan_line = AOMMAX(*max_scan_line, scan[c]);
token_cache[scan[c]] = av1_pt_energy_class[token];
switch (token) {
case ZERO_TOKEN:
case ONE_TOKEN:
case TWO_TOKEN:
case THREE_TOKEN:
case FOUR_TOKEN: val = token; break;
case CATEGORY1_TOKEN:
val = CAT1_MIN_VAL + READ_COEFF(av1_cat1_prob, av1_cat1_cdf, 1, r);
break;
case CATEGORY2_TOKEN:
val = CAT2_MIN_VAL + READ_COEFF(av1_cat2_prob, av1_cat2_cdf, 2, r);
break;
case CATEGORY3_TOKEN:
val = CAT3_MIN_VAL + READ_COEFF(av1_cat3_prob, av1_cat3_cdf, 3, r);
break;
case CATEGORY4_TOKEN:
val = CAT4_MIN_VAL + READ_COEFF(av1_cat4_prob, av1_cat4_cdf, 4, r);
break;
case CATEGORY5_TOKEN:
val = CAT5_MIN_VAL + READ_COEFF(av1_cat5_prob, av1_cat5_cdf, 5, r);
break;
case CATEGORY6_TOKEN: {
val = token_to_value(r, token, tx_size,
#if CONFIG_HIGHBITDEPTH
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, xd->bd);
xd->bd);
#else
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, 8);
#endif
val = CAT6_MIN_VAL + READ_COEFF(av1_cat6_prob + skip_bits, av1_cat6_cdf,
18 - skip_bits, r);
} break;
}
8);
#endif // CONFIG_HIGHBITDEPTH
#if CONFIG_NEW_QUANT
v = av1_dequant_abscoeff_nuq(val, dqv, dqv_val);
......@@ -303,39 +310,14 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
token = ONE_TOKEN +
aom_read_symbol(r, *cdf, CATEGORY6_TOKEN - ONE_TOKEN + 1, ACCT_STR);
INCREMENT_COUNT(ONE_TOKEN + (token > ONE_TOKEN));
switch (token) {
case ONE_TOKEN:
case TWO_TOKEN:
case THREE_TOKEN:
case FOUR_TOKEN: val = token; break;
case CATEGORY1_TOKEN:
val = CAT1_MIN_VAL + READ_COEFF(av1_cat1_prob, av1_cat1_cdf, 1, r);
break;
case CATEGORY2_TOKEN:
val = CAT2_MIN_VAL + READ_COEFF(av1_cat2_prob, av1_cat2_cdf, 2, r);
break;
case CATEGORY3_TOKEN:
val = CAT3_MIN_VAL + READ_COEFF(av1_cat3_prob, av1_cat3_cdf, 3, r);
break;
case CATEGORY4_TOKEN:
val = CAT4_MIN_VAL + READ_COEFF(av1_cat4_prob, av1_cat4_cdf, 4, r);
break;
case CATEGORY5_TOKEN:
val = CAT5_MIN_VAL + READ_COEFF(av1_cat5_prob, av1_cat5_cdf, 5, r);
break;
case CATEGORY6_TOKEN: {
assert(token != ZERO_TOKEN);
val = token_to_value(r, token, tx_size,
#if CONFIG_HIGHBITDEPTH
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, xd->bd);
xd->bd);
#else
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, 8);
#endif
val = CAT6_MIN_VAL + READ_COEFF(av1_cat6_prob + skip_bits, av1_cat6_cdf,
18 - skip_bits, r);
} break;
}
#else // CONFIG_EC_MULTISYMBOL
8);
#endif // CONFIG_HIGHBITDEPTH
#else // CONFIG_EC_MULTISYMBOL
if (!aom_read(r, prob[ONE_CONTEXT_NODE], ACCT_STR)) {
INCREMENT_COUNT(ONE_TOKEN);
token = ONE_TOKEN;
......@@ -344,38 +326,13 @@ static int decode_coefs(MACROBLOCKD *xd, PLANE_TYPE type, tran_low_t *dqcoeff,
INCREMENT_COUNT(TWO_TOKEN);
token = aom_read_tree(r, av1_coef_con_tree,
av1_pareto8_full[prob[PIVOT_NODE] - 1], ACCT_STR);
switch (token) {
case TWO_TOKEN:
case THREE_TOKEN:
case FOUR_TOKEN: val = token; break;
case CATEGORY1_TOKEN:
val = CAT1_MIN_VAL + read_coeff(av1_cat1_prob, 1, r);
break;
case CATEGORY2_TOKEN:
val = CAT2_MIN_VAL + read_coeff(av1_cat2_prob, 2, r);
break;
case CATEGORY3_TOKEN:
val = CAT3_MIN_VAL + read_coeff(av1_cat3_prob, 3, r);
break;
case CATEGORY4_TOKEN:
val = CAT4_MIN_VAL + read_coeff(av1_cat4_prob, 4, r);
break;
case CATEGORY5_TOKEN:
val = CAT5_MIN_VAL + read_coeff(av1_cat5_prob, 5, r);
break;
case CATEGORY6_TOKEN: {
assert(token != ZERO_TOKEN && token != ONE_TOKEN);
val = token_to_value(r, token, tx_size,
#if CONFIG_HIGHBITDEPTH
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, xd->bd);
xd->bd);
#else
const int skip_bits = (int)sizeof(av1_cat6_prob) -
av1_get_cat6_extrabits_size(tx_size, 8);
#endif
val = CAT6_MIN_VAL +
read_coeff(av1_cat6_prob + skip_bits, 18 - skip_bits, r);
break;
}
}
8);
#endif // CONFIG_HIGHBITDEPTH
}
#endif // CONFIG_EC_MULTISYMBOL
#if CONFIG_NEW_QUANT
......
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