Commit 0c72b2fb authored by Linfeng Zhang's avatar Linfeng Zhang Committed by James Zern
Browse files

Clean txb code

Make a couple of functions inlined, and other small changes.

Change-Id: Icd11b20f0fa2ddb14621df401f95cf0ce2f6be28
parent 4d51bedc
......@@ -253,51 +253,6 @@ const int16_t k_eob_group_start[12] = { 0, 1, 2, 3, 5, 9,
17, 33, 65, 129, 257, 513 };
const int16_t k_eob_offset_bits[12] = { 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int av1_get_eob_pos_ctx(TX_TYPE tx_type, int eob_token) {
int offset = 0;
int tx_class = get_tx_class(tx_type);
if (tx_class != TX_CLASS_2D) offset = 11;
return eob_token - 1 + offset;
}
int16_t get_eob_pos_token(int eob, int16_t *extra) {
int16_t t;
if (eob < 3) {
t = eob;
} else {
t = 3;
if (eob > 4) {
t++;
}
if (eob > 8) {
t++;
}
if (eob > 16) {
t++;
}
if (eob > 32) {
t++;
}
if (eob > 64) {
t++;
}
if (eob > 128) {
t++;
}
if (eob > 256) {
t++;
}
if (eob > 512) {
t++;
}
}
*extra = eob - k_eob_group_start[t];
return t;
}
// Note: because of the SSE2 optimization, levels[] must be in the range [0,
// 127], inclusive.
void av1_get_base_level_counts(const uint8_t *const levels,
......
......@@ -14,8 +14,6 @@
extern const int16_t k_eob_group_start[12];
extern const int16_t k_eob_offset_bits[12];
int16_t get_eob_pos_token(int eob, int16_t *extra);
int av1_get_eob_pos_ctx(TX_TYPE tx_type, int eob_token);
extern const int8_t av1_coeff_band_4x4[16];
......@@ -54,16 +52,61 @@ static const int mag_ref_offset[CONTEXT_MAG_POSITION_NUM][2] = {
{ 0, 1 }, { 1, 0 }, { 1, 1 }
};
static INLINE TX_CLASS get_tx_class(TX_TYPE tx_type) {
switch (tx_type) {
case V_DCT:
case V_ADST:
case V_FLIPADST: return TX_CLASS_VERT;
case H_DCT:
case H_ADST:
case H_FLIPADST: return TX_CLASS_HORIZ;
default: return TX_CLASS_2D;
static const TX_CLASS tx_type_to_class[TX_TYPES] = {
TX_CLASS_2D, // DCT_DCT
TX_CLASS_2D, // ADST_DCT
TX_CLASS_2D, // DCT_ADST
TX_CLASS_2D, // ADST_ADST
TX_CLASS_2D, // FLIPADST_DCT
TX_CLASS_2D, // DCT_FLIPADST
TX_CLASS_2D, // FLIPADST_FLIPADST
TX_CLASS_2D, // ADST_FLIPADST
TX_CLASS_2D, // FLIPADST_ADST
TX_CLASS_2D, // IDTX
TX_CLASS_VERT, // V_DCT
TX_CLASS_HORIZ, // H_DCT
TX_CLASS_VERT, // V_ADST
TX_CLASS_HORIZ, // H_ADST
TX_CLASS_VERT, // V_FLIPADST
TX_CLASS_HORIZ, // H_FLIPADST
};
static const int8_t eob_to_pos_small[33] = {
0, 1, 2, // 0-2
3, 3, // 3-4
4, 4, 4, 4, // 5-8
5, 5, 5, 5, 5, 5, 5, 5, // 9-16
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6 // 17-32
};
static const int8_t eob_to_pos_large[17] = {
6, // place holder
7, // 33-64
8, 8, // 65-128
9, 9, 9, 9, // 129-256
10, 10, 10, 10, 10, 10, 10, 10, // 257-512
11 // 513-
};
static INLINE int get_eob_pos_token(const int eob, int *const extra) {
int t;
if (eob < 33) {
t = eob_to_pos_small[eob];
} else {
const int e = AOMMIN((eob - 1) >> 5, 16);
t = eob_to_pos_large[e];
}
*extra = eob - k_eob_group_start[t];
return t;
}
static INLINE int av1_get_eob_pos_ctx(const TX_TYPE tx_type,
const int eob_token) {
const int offset = (tx_type_to_class[tx_type] == TX_CLASS_2D) ? 0 : 11;
return eob_token - 1 + offset;
}
static INLINE int get_txb_bwl(TX_SIZE tx_size) {
......@@ -337,7 +380,7 @@ static INLINE int get_br_ctx(const uint8_t *const levels,
int nb_mag[3] = { 0 };
#if CONFIG_LV_MAP_MULTI && USE_CAUSAL_BR_CTX
(void)count;
const TX_CLASS tx_class = get_tx_class(tx_type);
const TX_CLASS tx_class = tx_type_to_class[tx_type];
get_level_mag_with_txclass(levels, stride, row, col, nb_mag, tx_class);
mag = AOMMIN(nb_mag[0], COEFF_BASE_RANGE + NUM_BASE_LEVELS + 1) +
......@@ -496,7 +539,7 @@ 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 TX_CLASS tx_class = tx_type_to_class[tx_type];
const int stats =
#if USE_CAUSAL_BASE_CTX
get_nz_mag(levels, bwl, row, col, tx_class);
......
......@@ -46,7 +46,7 @@ static int read_golomb(MACROBLOCKD *xd, aom_reader *r, FRAME_COUNTS *counts) {
return x - 1;
}
static INLINE int rec_eob_pos(int16_t eob_token, int16_t extra) {
static INLINE int rec_eob_pos(const int eob_token, const int extra) {
int eob = k_eob_group_start[eob_token];
if (eob > 2) {
eob += extra;
......@@ -115,17 +115,14 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
av1_get_tx_type(plane_type, xd, blk_row, blk_col, block, tx_size);
const SCAN_ORDER *const scan_order = get_scan(cm, tx_size, tx_type, mbmi);
const int16_t *const scan = scan_order->scan;
int16_t dummy;
const int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int16_t eob_extra = 0;
int16_t eob_pt = 0;
int is_equal = 0;
for (int i = 1; i < max_eob_pt; i++) {
const int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, i);
is_equal = av1_read_record_bin(
int dummy;
const int max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int eob_extra = 0;
int eob_pt = 1;
for (eob_pt = 1; eob_pt < max_eob_pt; eob_pt++) {
const int eob_pos_ctx = av1_get_eob_pos_ctx(tx_type, eob_pt);
const int is_equal = av1_read_record_bin(
counts, r, ec_ctx->eob_flag_cdf[txs_ctx][plane_type][eob_pos_ctx], 2,
ACCT_STR);
// printf("eob_flag_cdf: %d %d %2d\n", txs_ctx, plane_type, eob_pos_ctx);
......@@ -135,13 +132,9 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *const xd,
if (counts) ++counts->eob_flag[txs_ctx][plane_type][eob_pos_ctx][is_equal];
if (is_equal) {
eob_pt = i;
break;
}
}
if (is_equal == 0) {
eob_pt = max_eob_pt;
}
// printf("Dec: ");
if (k_eob_offset_bits[eob_pt] > 0) {
......
......@@ -143,10 +143,9 @@ void av1_update_eob_context(int eob, int seg_eob, TX_SIZE tx_size,
TX_TYPE tx_type, PLANE_TYPE plane,
FRAME_CONTEXT *ec_ctx, FRAME_COUNTS *counts,
uint8_t allow_update_cdf) {
int16_t eob_extra;
int16_t eob_pt = get_eob_pos_token(eob, &eob_extra);
int16_t dummy;
int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int eob_extra, dummy;
const int eob_pt = get_eob_pos_token(eob, &eob_extra);
const int max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
TX_SIZE txs_ctx = get_txsize_entropy_ctx(tx_size);
for (int i = 1; i < max_eob_pt; i++) {
......@@ -171,10 +170,9 @@ void av1_update_eob_context(int eob, int seg_eob, TX_SIZE tx_size,
static int get_eob_cost(int eob, int seg_eob,
const LV_MAP_COEFF_COST *txb_costs, TX_TYPE tx_type) {
int16_t eob_extra;
int16_t eob_pt = get_eob_pos_token(eob, &eob_extra);
int16_t dummy;
int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int eob_extra, dummy;
const int eob_pt = get_eob_pos_token(eob, &eob_extra);
const int max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int eob_cost = 0;
// printf("Enc: [%d, %d], (%d, %d) ", seg_eob, eob, eob_pt, eob_extra);
......@@ -351,10 +349,9 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
get_min_tx_size(tx_size), w);
#endif
int16_t eob_extra;
int16_t eob_pt = get_eob_pos_token(eob, &eob_extra);
int16_t dummy;
int16_t max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
int eob_extra, dummy;
const int eob_pt = get_eob_pos_token(eob, &eob_extra);
const int max_eob_pt = get_eob_pos_token(seg_eob, &dummy);
// printf("Enc: [%d, %d], (%d, %d) ", seg_eob, eob, eob_pt, eob_extra);
for (int i = 1; i < max_eob_pt; i++) {
......@@ -865,8 +862,8 @@ void gen_txb_cache(TxbCache *txb_cache, TxbInfo *txb_info) {
const int row = coeff_idx >> bwl;
const int col = coeff_idx - (row << bwl);
txb_cache->nz_count_arr[coeff_idx] =
get_nz_count(levels, bwl, row, col, get_tx_class(txb_info->tx_type));
txb_cache->nz_count_arr[coeff_idx] = get_nz_count(
levels, bwl, row, col, tx_type_to_class[txb_info->tx_type]);
txb_cache->nz_ctx_arr[coeff_idx] = get_nz_map_ctx_from_stats(
#if USE_CAUSAL_BASE_CTX
......
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