Commit 8ac4557b authored by Linfeng Zhang's avatar Linfeng Zhang

Update get_nz_map_ctx()

Change-Id: I8c739c9b1911b983a14772d79e0c7c28373fdca2
parent 0fff534b
......@@ -315,7 +315,7 @@ static INLINE int get_br_ctx_from_count_mag(const int row, const int col,
// Left column: 5 - 7
// others: 8 - 11
static const int offset_pos[2][2] = { { 8, 5 }, { 2, 0 } };
const int mag_clamp = (mag < 6) ? mag : 6;
const int mag_clamp = AOMMIN(mag, 6);
const int offset = mag_clamp >> 1;
const int ctx =
br_level_map[count] + offset * BR_TMP_OFFSET + offset_pos[!row][!col];
......@@ -384,11 +384,10 @@ static const int sig_ref_offset_horiz[SIG_REF_OFFSET_NUM][2] = {
};
#if USE_CAUSAL_BASE_CTX
static INLINE int get_nz_count_mag(const uint8_t *const levels, const int bwl,
const int row, const int col,
const TX_CLASS tx_class, int *const mag) {
int count = 0;
*mag = 0;
static INLINE int get_nz_mag(const uint8_t *const levels, const int bwl,
const int row, const int col,
const TX_CLASS tx_class) {
int mag = 0;
for (int idx = 0; idx < SIG_REF_OFFSET_NUM; ++idx) {
const int row_offset =
((tx_class == TX_CLASS_2D)
......@@ -405,12 +404,12 @@ static INLINE int get_nz_count_mag(const uint8_t *const levels, const int bwl,
const int nb_pos =
(ref_row << bwl) + (ref_row << TX_PAD_HOR_LOG2) + ref_col;
const int level = levels[nb_pos];
count += (level != 0);
*mag += AOMMIN(level, 3);
mag += AOMMIN(level, 3);
}
return count;
return mag;
}
#endif
static INLINE int get_nz_count(const uint8_t *const levels, const int bwl,
const int row, const int col,
const TX_CLASS tx_class) {
......@@ -433,66 +432,49 @@ static INLINE int get_nz_count(const uint8_t *const levels, const int bwl,
return count;
}
// TODO(angiebird): optimize this function by generate a table that maps from
// count to ctx
static INLINE int get_nz_map_ctx_from_count(int count,
int coeff_idx, // raster order
int bwl, int height,
#if USE_CAUSAL_BASE_CTX
const int mag,
#endif
TX_TYPE tx_type) {
(void)tx_type;
static INLINE int get_nz_map_ctx_from_stats(
const int stats,
const int coeff_idx, // raster order
const int bwl, const int height, const TX_CLASS tx_class) {
const int row = coeff_idx >> bwl;
const int col = coeff_idx - (row << bwl);
const int width = 1 << bwl;
int ctx = 0;
const TX_CLASS tx_class = get_tx_class(tx_type);
int offset;
if (tx_class == TX_CLASS_2D)
offset = 0;
else if (tx_class == TX_CLASS_VERT)
offset = SIG_COEF_CONTEXTS_2D;
else
#if USE_CAUSAL_BASE_CTX
offset = SIG_COEF_CONTEXTS_2D;
#else
offset = SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D;
#endif
int ctx = (stats + 1) >> 1;
#if USE_CAUSAL_BASE_CTX
(void)count;
ctx = AOMMIN((mag + 1) >> 1, 4);
#else
ctx = (count + 1) >> 1;
ctx = AOMMIN(ctx, 4);
#endif
if (tx_class == TX_CLASS_2D) {
{
if (row == 0 && col == 0) return offset + 0;
const int width = 1 << bwl;
if (width < height)
if (row < 2) return offset + 11 + ctx;
if (row == 0 && col == 0) return 0;
if (width > height)
if (col < 2) return offset + 16 + ctx;
if (width < height) {
if (row < 2) return 11 + ctx;
} else if (width > height) {
if (col < 2) return 16 + ctx;
}
if (row + col < 2) return offset + ctx + 1;
if (row + col < 4) return offset + 5 + ctx + 1;
if (row + col < 2) return ctx + 1;
if (row + col < 4) return 5 + ctx + 1;
return offset + 21 + AOMMIN(ctx, 4);
}
return 21 + AOMMIN(ctx, 4);
} else {
if (tx_class == TX_CLASS_VERT) {
if (row == 0) return offset + ctx;
if (row < 2) return offset + 5 + ctx;
return offset + 10 + ctx;
} else {
if (col == 0) return offset + ctx;
if (col < 2) return offset + 5 + ctx;
return offset + 10 + ctx;
static const int pos_to_offset[3] = {
SIG_COEF_CONTEXTS_2D, SIG_COEF_CONTEXTS_2D + 5, SIG_COEF_CONTEXTS_2D + 10
};
const int idx = (tx_class == TX_CLASS_VERT) ? row : col;
const int *map = pos_to_offset;
#if !USE_CAUSAL_BASE_CTX
static const int col_to_offset[3] = {
SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D,
SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + 5,
SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + 10
};
if (tx_class == TX_CLASS_HORIZ) {
map = col_to_offset;
}
#endif
return ctx + map[AOMMIN(idx, 2)];
}
}
......@@ -500,10 +482,9 @@ static INLINE int get_nz_map_ctx(const uint8_t *const levels,
const int scan_idx, const int16_t *const scan,
const int bwl, const int height,
#if CONFIG_LV_MAP_MULTI
const TX_TYPE tx_type, const int is_eob) {
#else
const TX_TYPE tx_type) {
const int is_eob,
#endif
const TX_TYPE tx_type) {
#if CONFIG_LV_MAP_MULTI
if (is_eob) {
if (scan_idx == 0) return SIG_COEF_CONTEXTS - 4;
......@@ -515,16 +496,14 @@ static INLINE int get_nz_map_ctx(const uint8_t *const levels,
const int coeff_idx = scan[scan_idx];
const int row = coeff_idx >> bwl;
const int col = coeff_idx - (row << bwl);
const TX_CLASS tx_class = get_tx_class(tx_type);
const int stats =
#if USE_CAUSAL_BASE_CTX
int mag = 0;
int count = get_nz_count_mag(levels, bwl, row, col, tx_class, &mag);
return get_nz_map_ctx_from_count(count, coeff_idx, bwl, height, mag, tx_type);
get_nz_mag(levels, bwl, row, col, tx_class);
#else
int count = get_nz_count(levels, bwl, row, col, tx_class);
return get_nz_map_ctx_from_count(count, coeff_idx, bwl, height, tx_type);
get_nz_count(levels, bwl, row, col, tx_class);
#endif
return get_nz_map_ctx_from_stats(stats, coeff_idx, bwl, height, tx_class);
}
static INLINE int get_eob_ctx(const int coeff_idx, // raster order
......
......@@ -171,7 +171,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
const int pos = scan[c];
#if CONFIG_LV_MAP_MULTI
const int coeff_ctx =
get_nz_map_ctx(levels, c, scan, bwl, height, tx_type, c == *eob - 1);
get_nz_map_ctx(levels, c, scan, bwl, height, c == *eob - 1, tx_type);
#if USE_BASE_EOB_ALPHABET
aom_cdf_prob *cdf;
int nsymbs;
......
......@@ -389,7 +389,7 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
#if CONFIG_LV_MAP_MULTI
coeff_ctx =
get_nz_map_ctx(levels, c, scan, bwl, height, tx_type, c == eob - 1);
get_nz_map_ctx(levels, c, scan, bwl, height, c == eob - 1, tx_type);
tran_low_t v = tcoeff[scan[c]];
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
......@@ -714,7 +714,7 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int level = abs(v);
#if CONFIG_LV_MAP_MULTI
coeff_ctx =
get_nz_map_ctx(levels, c, scan, bwl, height, tx_type, c == eob - 1);
get_nz_map_ctx(levels, c, scan, bwl, height, c == eob - 1, tx_type);
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
cost += coeff_costs
......@@ -868,13 +868,13 @@ void gen_txb_cache(TxbCache *txb_cache, TxbInfo *txb_info) {
txb_cache->nz_count_arr[coeff_idx] =
get_nz_count(levels, bwl, row, col, get_tx_class(txb_info->tx_type));
const int nz_count = txb_cache->nz_count_arr[coeff_idx];
txb_cache->nz_ctx_arr[coeff_idx] =
get_nz_map_ctx_from_count(nz_count, coeff_idx, bwl, height,
txb_cache->nz_ctx_arr[coeff_idx] = get_nz_map_ctx_from_stats(
#if USE_CAUSAL_BASE_CTX
0,
0,
#else
txb_cache->nz_count_arr[coeff_idx],
#endif
txb_info->tx_type);
coeff_idx, bwl, height, txb_info->tx_type);
// gen_base_count_mag_arr
if (!has_base(qcoeff[coeff_idx], 0)) continue;
......@@ -1087,14 +1087,16 @@ static int try_neighbor_level_down_nz(int coeff_idx, int nb_coeff_idx,
const int nb_scan_idx = iscan[nb_coeff_idx];
if (nb_scan_idx < scan_idx) {
const int count = txb_cache->nz_count_arr[coeff_idx];
(void)count;
assert(count > 0);
update_qcoeff(nb_coeff_idx, get_lower_coeff(nb_coeff), txb_info);
const int new_ctx = get_nz_map_ctx_from_count(
count - 1, coeff_idx, txb_info->bwl, txb_info->height,
const int new_ctx = get_nz_map_ctx_from_stats(
#if USE_CAUSAL_BASE_CTX
0,
#else
count - 1,
#endif
txb_info->tx_type);
coeff_idx, txb_info->bwl, txb_info->height, txb_info->tx_type);
update_qcoeff(nb_coeff_idx, nb_coeff, txb_info);
const int ctx = txb_cache->nz_ctx_arr[coeff_idx];
#if CONFIG_LV_MAP_MULTI
......@@ -1468,13 +1470,13 @@ void update_level_down(const int coeff_idx, TxbCache *const txb_cache,
txb_cache->nz_count_arr[nb_coeff_idx] -= 1;
assert(txb_cache->nz_count_arr[nb_coeff_idx] >= 0);
}
const int count = txb_cache->nz_count_arr[nb_coeff_idx];
txb_cache->nz_ctx_arr[nb_coeff_idx] = get_nz_map_ctx_from_count(
count, nb_coeff_idx, txb_info->bwl, txb_info->height,
txb_cache->nz_ctx_arr[nb_coeff_idx] = get_nz_map_ctx_from_stats(
#if USE_CAUSAL_BASE_CTX
0,
#else
txb_cache->nz_count_arr[nb_coeff_idx],
#endif
txb_info->tx_type);
nb_coeff_idx, txb_info->bwl, txb_info->height, txb_info->tx_type);
// int ref_ctx = get_nz_map_ctx(txb_info->levels, nb_coeff_idx,
// txb_info->bwl, tx_type);
// if (ref_ctx != txb_cache->nz_ctx_arr[nb_coeff_idx])
......@@ -1572,7 +1574,7 @@ static int get_coeff_cost(const tran_low_t qc, const int scan_idx,
#if CONFIG_LV_MAP_MULTI
int coeff_ctx =
get_nz_map_ctx(txb_info->levels, scan_idx, scan, txb_info->bwl,
txb_info->height, txb_info->tx_type, is_eob);
txb_info->height, is_eob, txb_info->tx_type);
#if USE_BASE_EOB_ALPHABET
if (is_eob) {
cost +=
......@@ -2271,7 +2273,7 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
(void)is_nz;
(void)nz_map_count;
coeff_ctx =
get_nz_map_ctx(levels, c, scan, bwl, height, tx_type, c == eob - 1);
get_nz_map_ctx(levels, c, scan, bwl, height, c == eob - 1, tx_type);
#if USE_BASE_EOB_ALPHABET
if (c == eob - 1) {
update_cdf(ec_ctx->coeff_base_eob_cdf[txsize_ctx][plane_type]
......
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