Commit ea8183b0 authored by Angie Chiang's avatar Angie Chiang

Add get_br_count_mag()

This will speed up lv_map encoder time by 1.5%

Change-Id: Ia9f7634bae221d2fb8fb7dc6f3202c6bacdd5b32
parent cfea5c30
......@@ -179,6 +179,33 @@ static int br_level_map[9] = {
#define BR_MAG_OFFSET 1
// TODO(angiebird): optimize this function by using a table to map from
// count/mag to ctx
static INLINE int get_br_count_mag(int *mag, const tran_low_t *tcoeffs, int bwl,
int height, int row, int col, int level) {
mag[0] = 0;
mag[1] = 0;
int count = 0;
for (int idx = 0; idx < BR_CONTEXT_POSITION_NUM; ++idx) {
const int ref_row = row + br_ref_offset[idx][0];
const int ref_col = col + br_ref_offset[idx][1];
if (ref_row < 0 || ref_col < 0 || ref_row >= height ||
ref_col >= (1 << bwl))
continue;
const int pos = (ref_row << bwl) + ref_col;
tran_low_t abs_coeff = abs(tcoeffs[pos]);
count += abs_coeff > level;
if (br_ref_offset[idx][0] >= 0 && br_ref_offset[idx][1] >= 0) {
if (abs_coeff > mag[0]) {
mag[0] = abs_coeff;
mag[1] = 1;
} else if (abs_coeff == mag[0]) {
++mag[1];
}
}
}
return count;
}
static INLINE int get_br_ctx_from_count_mag(int row, int col, int count,
int mag) {
int offset = 0;
......
......@@ -476,10 +476,8 @@ void gen_txb_cache(TxbCache *txb_cache, TxbInfo *txb_info) {
if (!has_br(qcoeff[coeff_idx])) continue;
int *br_count = txb_cache->br_count_arr + coeff_idx;
int *br_mag = txb_cache->br_mag_arr[coeff_idx];
*br_count = get_level_count(qcoeff, bwl, height, row, col, NUM_BASE_LEVELS,
br_ref_offset, BR_CONTEXT_POSITION_NUM);
get_mag(br_mag, qcoeff, bwl, height, row, col, br_ref_offset,
BR_CONTEXT_POSITION_NUM);
*br_count = get_br_count_mag(br_mag, qcoeff, bwl, height, row, col,
NUM_BASE_LEVELS);
txb_cache->br_ctx_arr[coeff_idx] =
get_br_ctx_from_count_mag(row, col, *br_count, br_mag[0]);
}
......
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