Commit 03a32926 authored by Dake He's avatar Dake He

[level map] simplified context derivation

This CL simplifies context derivation for nz and base level flags in
level map.
1. Reduce SIG_COEF_CONTEXTS from 58 to 42.
2. NZ and base level flags share the same context offsets derived from a
template of size 5 (down from 7).

In limited runs, compression performance seems neutral if not better.
Encoding time for a key frame on a local linux machine is reduced by about 25% or more.

Change-Id: Ibd93b21c839154bc5ae26b993f9e66537cbf5942
parent 06b47089
......@@ -70,16 +70,27 @@ extern "C" {
#define EOB_COEF_CONTEXTS 22
#endif // CONFIG_CTX1D
#define USE_CAUSAL_BASE_CTX 0
#if CONFIG_EXT_TX
#define SIG_COEF_CONTEXTS_2D 26
#define SIG_COEF_CONTEXTS_1D 16
#if USE_CAUSAL_BASE_CTX
#define SIG_COEF_CONTEXTS (SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D)
#else // USE_CAUSAL_BASE_CTX
#define SIG_COEF_CONTEXTS \
(SIG_COEF_CONTEXTS_2D + SIG_COEF_CONTEXTS_1D + SIG_COEF_CONTEXTS_1D)
#else // CONFIG_EXT_TX
#endif // USE_CAUSAL_BASE_CTX
#else // CONFIG_EXT_TX
#define SIG_COEF_CONTEXTS_2D 16
#define SIG_COEF_CONTEXTS 16
#endif // CONFIG_EXT_TX
#if USE_CAUSAL_BASE_CTX
#define COEFF_BASE_CONTEXTS (SIG_COEF_CONTEXTS)
#else
#define COEFF_BASE_CONTEXTS 25
#endif
#define DC_SIGN_CONTEXTS 3
#define BR_TMP_OFFSET 12
......
......@@ -31,6 +31,104 @@ const aom_prob default_dc_sign[PLANE_TYPES][DC_SIGN_CONTEXTS] = {
{ 125, 102, 147 }, { 119, 101, 135 },
};
#if USE_CAUSAL_BASE_CTX
const aom_prob default_coeff_base
[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS][COEFF_BASE_CONTEXTS] = {
{ { { 139, 242, 199, 135, 87, 51, 245, 208, 138, 89, 60,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 240,
200, 108, 70, 56, 230, 199, 126, 66, 32, 242, 204,
128, 74, 45, 241, 203, 120, 62, 128, 128 },
{ 118, 230, 197, 147, 103, 60, 228, 202, 154, 110, 72,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 213,
196, 134, 94, 58, 199, 184, 130, 82, 40, 217, 186,
134, 86, 57, 204, 185, 127, 74, 128, 128 } },
{ { 203, 248, 223, 170, 105, 58, 252, 235, 195, 125, 72,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 253,
244, 209, 110, 85, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 170, 239, 210, 163, 112, 68, 239, 219, 175, 127, 84,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 246,
234, 184, 142, 154, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 } } },
{ { { 119, 240, 196, 136, 90, 50, 247, 214, 159, 109, 64,
241, 201, 137, 91, 53, 239, 199, 136, 89, 52, 251,
230, 176, 121, 76, 231, 202, 142, 84, 39, 246, 221,
169, 111, 61, 248, 221, 152, 97, 60, 128 },
{ 98, 209, 182, 140, 100, 56, 234, 207, 166, 122, 73,
215, 189, 142, 103, 59, 216, 188, 140, 99, 59, 235,
216, 179, 137, 88, 214, 189, 141, 96, 46, 224, 200,
159, 117, 68, 221, 199, 152, 108, 68, 128 } },
{ { 195, 245, 212, 159, 108, 64, 251, 231, 186, 131, 80,
250, 228, 175, 108, 58, 244, 213, 163, 120, 82, 254,
245, 216, 159, 91, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 150, 207, 199, 164, 121, 76, 239, 221, 185, 142, 89,
231, 208, 162, 113, 69, 228, 205, 169, 136, 95, 246,
235, 204, 157, 110, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 } } },
{ { { 93, 232, 185, 124, 81, 38, 244, 206, 147, 98, 53,
246, 210, 150, 100, 54, 244, 208, 146, 94, 44, 253,
236, 189, 135, 82, 228, 195, 130, 76, 35, 242, 220,
170, 114, 59, 253, 235, 184, 122, 68, 128 },
{ 80, 203, 169, 127, 86, 41, 228, 194, 151, 108, 58,
221, 195, 152, 110, 60, 220, 194, 149, 103, 48, 238,
221, 188, 147, 92, 205, 184, 130, 85, 41, 208, 195,
159, 120, 62, 233, 212, 173, 126, 76, 128 } },
{ { 187, 239, 199, 149, 109, 66, 250, 226, 179, 130, 82,
248, 218, 159, 100, 63, 251, 227, 184, 135, 91, 254,
241, 202, 150, 99, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 130, 202, 169, 146, 118, 73, 236, 217, 186, 146, 91,
215, 194, 154, 102, 77, 234, 216, 188, 145, 98, 245,
229, 201, 163, 110, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 } } },
{ { { 102, 225, 171, 113, 74, 33, 243, 201, 139, 92, 44,
244, 208, 146, 99, 53, 247, 214, 158, 107, 52, 253,
233, 183, 131, 73, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 80, 190, 152, 116, 79, 34, 222, 187, 142, 101, 47,
211, 187, 148, 106, 56, 221, 200, 163, 118, 56, 236,
215, 181, 140, 78, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 } },
{ { 166, 237, 184, 144, 106, 62, 245, 211, 167, 129, 93,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 254,
240, 205, 158, 112, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 91, 185, 133, 105, 95, 60, 213, 190, 164, 131, 107,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 242,
227, 203, 160, 127, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128 } } }
};
const aom_prob default_nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS] = {
{ { 59, 183, 130, 76, 48, 28, 202, 153, 84, 54, 34, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 200, 163, 84, 61, 34, 182, 131,
71, 31, 16, 210, 156, 78, 36, 26, 220, 170, 73, 32, 128, 128 },
{ 96, 209, 171, 109, 59, 28, 223, 187, 128, 71, 35, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 215, 192, 135, 63, 73, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } },
{ { 49, 190, 129, 74, 46, 25, 206, 150, 90, 55, 32, 205, 142, 79,
48, 27, 191, 137, 78, 47, 27, 223, 181, 109, 63, 37, 204, 136,
82, 42, 19, 226, 169, 106, 58, 30, 231, 180, 96, 49, 29, 128 },
{ 86, 210, 159, 90, 56, 34, 223, 181, 114, 69, 40, 229, 182, 113,
59, 28, 218, 162, 96, 64, 42, 237, 207, 146, 92, 50, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } },
{ { 41, 187, 119, 66, 40, 20, 212, 144, 80, 49, 26, 226, 151, 84,
49, 27, 214, 146, 82, 47, 22, 237, 190, 115, 68, 40, 206, 126,
71, 37, 17, 227, 168, 103, 61, 29, 237, 197, 119, 63, 32, 128 },
{ 70, 207, 146, 82, 54, 35, 226, 167, 99, 65, 40, 238, 176, 96,
57, 29, 229, 171, 108, 69, 47, 244, 201, 124, 78, 48, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } },
{ { 40, 176, 107, 57, 37, 16, 216, 136, 73, 44, 22, 235, 145, 79,
49, 26, 227, 149, 84, 52, 26, 247, 195, 107, 64, 35, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 },
{ 49, 210, 153, 95, 58, 31, 217, 151, 93, 64, 41, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 248, 197, 123, 79, 53, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } }
};
#else // USE_CAUSAL_BASE_CTX
const aom_prob default_coeff_base
[TX_SIZES][PLANE_TYPES][NUM_BASE_LEVELS][COEFF_BASE_CONTEXTS] = {
{ { {
......@@ -140,6 +238,7 @@ static const aom_prob default_nz_map[TX_SIZES][PLANE_TYPES][SIG_COEF_CONTEXTS] =
114, 36, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 128,
128, 128, 128, 128, 128, 128, 128, 128, 128, 128 } } };
#endif // USE_CAUSAL_BASE_CTX
#if CONFIG_CTX1D
const aom_prob default_eob_flag[TX_SIZES][PLANE_TYPES][EOB_COEF_CONTEXTS] = {
......
......@@ -324,17 +324,53 @@ static INLINE int get_br_ctx_coeff(const tran_low_t *const tcoeffs,
#define SIG_REF_OFFSET_NUM 7
static const int sig_ref_offset[SIG_REF_OFFSET_NUM][2] = {
{ 2, 1 }, { 2, 0 }, { 1, 2 }, { 1, 1 }, { 1, 0 }, { 0, 2 }, { 0, 1 },
{ 0, 1 }, { 1, 0 }, { 1, 1 }, { 0, 2 }, { 2, 0 }, { 1, 2 }, { 2, 1 },
};
static const int sig_ref_offset_vert[SIG_REF_OFFSET_NUM][2] = {
{ 2, 1 }, { 2, 0 }, { 3, 0 }, { 1, 1 }, { 1, 0 }, { 4, 0 }, { 0, 1 },
{ 1, 0 }, { 2, 0 }, { 0, 1 }, { 3, 0 }, { 4, 0 }, { 1, 1 }, { 2, 1 },
};
static const int sig_ref_offset_horiz[SIG_REF_OFFSET_NUM][2] = {
{ 0, 3 }, { 0, 4 }, { 1, 2 }, { 1, 1 }, { 1, 0 }, { 0, 2 }, { 0, 1 },
{ 0, 1 }, { 0, 2 }, { 1, 0 }, { 0, 3 }, { 0, 4 }, { 1, 1 }, { 1, 2 },
};
#if USE_CAUSAL_BASE_CTX
static INLINE int get_nz_count_mag(const tran_low_t *tcoeffs, int bwl,
int height, int row, int col,
TX_CLASS tx_class,
const int coeff_is_byte_flag, int *mag) {
int count = 0;
*mag = 0;
for (int idx = 0; idx < SIG_REF_OFFSET_NUM; ++idx) {
const int row_offset =
((tx_class == TX_CLASS_2D)
? sig_ref_offset[idx][0]
: ((tx_class == TX_CLASS_VERT) ? sig_ref_offset_vert[idx][0]
: sig_ref_offset_horiz[idx][0]));
const int col_offset =
((tx_class == TX_CLASS_2D)
? sig_ref_offset[idx][1]
: ((tx_class == TX_CLASS_VERT) ? sig_ref_offset_vert[idx][1]
: sig_ref_offset_horiz[idx][1]));
const int ref_row = row + row_offset;
const int ref_col = col + col_offset;
if (ref_row < 0 || ref_col < 0 || ref_row >= height ||
ref_col >= (1 << bwl))
continue;
const int nb_pos = (ref_row << bwl) + ref_col;
int level = abs(coeff_is_byte_flag ? ((const uint8_t *)tcoeffs)[nb_pos]
: ((const tran_low_t *)tcoeffs)[nb_pos]);
count += (level != 0);
#if 1
if (idx < 5) {
*mag += AOMMIN(level, 3);
}
#endif
}
return count;
}
#endif
static INLINE int get_nz_count(const tran_low_t *tcoeffs, int bwl, int height,
int row, int col, TX_CLASS tx_class,
const int coeff_is_byte_flag) {
......@@ -380,6 +416,9 @@ static INLINE TX_CLASS get_tx_class(TX_TYPE tx_type) {
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;
const int row = coeff_idx >> bwl;
......@@ -395,13 +434,21 @@ static INLINE int get_nz_map_ctx_from_count(int count,
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
#else
int offset = 0;
#endif
(void)height;
#if USE_CAUSAL_BASE_CTX
(void)count;
ctx = AOMMIN((mag + 1) >> 1, 4);
#else
ctx = (count + 1) >> 1;
#endif
if (tx_class == TX_CLASS_2D) {
{
......@@ -440,9 +487,16 @@ static INLINE int get_nz_map_ctx(const void *const tcoeffs, const int scan_idx,
const int col = coeff_idx - (row << bwl);
int tx_class = get_tx_class(tx_type);
#if USE_CAUSAL_BASE_CTX
int mag = 0;
int count = get_nz_count_mag(tcoeffs, bwl, height, row, col, tx_class,
coeff_is_byte_flag, &mag);
return get_nz_map_ctx_from_count(count, coeff_idx, bwl, height, mag, tx_type);
#else
int count = get_nz_count(tcoeffs, bwl, height, row, col, tx_class,
coeff_is_byte_flag);
return get_nz_map_ctx_from_count(count, coeff_idx, bwl, height, tx_type);
#endif
}
static INLINE int get_eob_ctx(const int coeff_idx, // raster order
......
......@@ -174,10 +174,37 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
levels[scan[c]] = is_nz;
if (counts) ++(*nz_map_count)[coeff_ctx][is_nz];
#if USE_CAUSAL_BASE_CTX
if (is_nz) {
int k;
for (k = 0; k < NUM_BASE_LEVELS; ++k) {
int ctx = coeff_ctx;
#if 0 // USE_CAUSAL_BASE_CTX read_coeffs
int is_k = av1_read_record_bit(counts, r, ACCT_STR);
#else
int is_k = av1_read_record_bin(
counts, r, ec_ctx->coeff_base_cdf[txs_ctx][plane_type][k][ctx], 2,
ACCT_STR);
if (counts) ++counts->coeff_base[txs_ctx][plane_type][k][ctx][is_k];
#endif
// is_k = 1 if level > (k+1)
if (is_k == 0) {
cul_level += k + 1;
break;
}
}
levels[scan[c]] = k + 1;
}
#endif
}
*max_scan_line = *eob;
#if USE_CAUSAL_BASE_CTX
update_eob = *eob - 1;
#else
int i;
for (i = 0; i < NUM_BASE_LEVELS; ++i) {
update_eob = 0;
......@@ -206,6 +233,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
update_eob = AOMMAX(update_eob, c);
}
}
#endif
// Loop to decode all signs in the transform block,
// starting with the sign of the DC (if applicable)
......
......@@ -312,7 +312,35 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
// printf("%d ", bit);
}
}
// printf("\n");
#if USE_CAUSAL_BASE_CTX
int coeff_ctx = 0;
for (int i = 0; i < eob; ++i) {
c = eob - 1 - i;
coeff_ctx = get_nz_map_ctx(tcoeff, c, scan, bwl, height, tx_type, 0);
if (c == eob - 1) assert(coeff_ctx == 0);
tran_low_t v = tcoeff[scan[c]];
int is_nz = (v != 0);
if (c < eob - 1) {
aom_write_bin(w, is_nz,
ec_ctx->nz_map_cdf[txs_ctx][plane_type][coeff_ctx], 2);
}
if (is_nz) {
const int level = abs(v);
int k;
for (k = 0; k < NUM_BASE_LEVELS; ++k) {
int is_k = (level > (k + 1));
int ctx = coeff_ctx;
aom_write_bin(w, is_k,
ec_ctx->coeff_base_cdf[txs_ctx][plane_type][k][ctx], 2);
if (is_k == 0) break;
}
}
}
update_eob = eob - 1;
#else
for (int i = 1; i < eob; ++i) {
c = eob - 1 - i;
int coeff_ctx = get_nz_map_ctx(tcoeff, c, scan, bwl, height, tx_type, 0);
......@@ -345,6 +373,7 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
update_eob = AOMMAX(update_eob, c);
}
}
#endif
// Loop to code all signs in the transform block,
// starting with the sign of DC (if applicable)
......@@ -549,18 +578,29 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int eob_cost = get_eob_cost(eob, seg_eob, coeff_costs, tx_type);
cost += eob_cost;
#if USE_CAUSAL_BASE_CTX
int coeff_ctx = 0;
#endif
for (c = eob - 1; c >= 0; --c) {
tran_low_t v = qcoeff[scan[c]];
int is_nz = (v != 0);
int level = abs(v);
#if USE_CAUSAL_BASE_CTX
coeff_ctx = get_nz_map_ctx(qcoeff, c, scan, bwl, height, tx_type, 0);
if (c == eob - 1) assert(coeff_ctx == 0);
#endif
if (c < eob - 1) {
#if !USE_CAUSAL_BASE_CTX
int coeff_ctx = get_nz_map_ctx(qcoeff, c, scan, bwl, height, tx_type, 0);
#endif
cost += coeff_costs->nz_map_cost[coeff_ctx][is_nz];
}
if (is_nz) {
#if !USE_CAUSAL_BASE_CTX
int ctx_ls[NUM_BASE_LEVELS] = { 0 };
#endif
int sign = (v < 0) ? 1 : 0;
// sign bit cost
......@@ -570,7 +610,16 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
} else {
cost += av1_cost_bit(128, sign);
}
#if USE_CAUSAL_BASE_CTX
int k;
for (k = 0; k < NUM_BASE_LEVELS; ++k) {
int is_k = (level > (k + 1));
int ctx = coeff_ctx;
// get_base_ctx_from_b(c, k, b0, b1, b2);
cost += coeff_costs->base_cost[k][ctx][is_k];
if (is_k == 0) break;
}
#else
get_base_ctx_set(qcoeff, scan[c], bwl, height, ctx_ls);
int i;
......@@ -583,6 +632,7 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
}
cost += coeff_costs->base_cost[i][ctx_ls[i]][0];
}
#endif
if (level > NUM_BASE_LEVELS) {
int ctx;
......@@ -671,8 +721,12 @@ void gen_txb_cache(TxbCache *txb_cache, TxbInfo *txb_info) {
qcoeff, bwl, height, row, col, get_tx_class(txb_info->tx_type), 0);
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_info->tx_type);
txb_cache->nz_ctx_arr[coeff_idx] =
get_nz_map_ctx_from_count(nz_count, coeff_idx, bwl, height,
#if USE_CAUSAL_BASE_CTX
0,
#endif
txb_info->tx_type);
// gen_base_count_mag_arr
if (!has_base(qcoeff[coeff_idx], 0)) continue;
......@@ -871,9 +925,12 @@ static int try_neighbor_level_down_nz(int coeff_idx, int nb_coeff_idx,
const int count = txb_cache->nz_count_arr[coeff_idx];
assert(count > 0);
txb_info->qcoeff[nb_coeff_idx] = get_lower_coeff(nb_coeff);
const int new_ctx =
get_nz_map_ctx_from_count(count - 1, coeff_idx, txb_info->bwl,
txb_info->height, txb_info->tx_type);
const int new_ctx = get_nz_map_ctx_from_count(
count - 1, coeff_idx, txb_info->bwl, txb_info->height,
#if USE_CAUSAL_BASE_CTX
0,
#endif
txb_info->tx_type);
txb_info->qcoeff[nb_coeff_idx] = nb_coeff;
const int ctx = txb_cache->nz_ctx_arr[coeff_idx];
const int is_nz = abs_qc > 0;
......@@ -1236,9 +1293,12 @@ void update_level_down(int coeff_idx, TxbCache *txb_cache, TxbInfo *txb_info) {
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_info->tx_type);
txb_cache->nz_ctx_arr[nb_coeff_idx] = get_nz_map_ctx_from_count(
count, nb_coeff_idx, txb_info->bwl, txb_info->height,
#if USE_CAUSAL_BASE_CTX
0,
#endif
txb_info->tx_type);
// int ref_ctx = get_nz_map_ctx(txb_info->qcoeff, nb_coeff_idx,
// txb_info->bwl, tx_type, 0);
// if (ref_ctx != txb_cache->nz_ctx_arr[nb_coeff_idx])
......@@ -1328,10 +1388,19 @@ int get_coeff_cost(tran_low_t qc, int scan_idx, TxbInfo *txb_info,
const tran_low_t abs_qc = abs(qc);
int cost = 0;
const int16_t *scan = txb_info->scan_order->scan;
#if USE_CAUSAL_BASE_CTX
int coeff_ctx =
get_nz_map_ctx(txb_info->qcoeff, scan_idx, scan, txb_info->bwl,
txb_info->height, txb_info->tx_type, 0);
#endif
if (scan_idx < txb_info->eob - 1) {
#if !USE_CAUSAL_BASE_CTX
int coeff_ctx =
get_nz_map_ctx(txb_info->qcoeff, scan_idx, scan, txb_info->bwl,
txb_info->height, txb_info->tx_type, 0);
#endif
cost += txb_costs->nz_map_cost[coeff_ctx][is_nz];
}
......@@ -1339,6 +1408,16 @@ int get_coeff_cost(tran_low_t qc, int scan_idx, TxbInfo *txb_info,
cost += get_sign_bit_cost(qc, scan_idx, txb_costs->dc_sign_cost,
txb_ctx->dc_sign_ctx);
#if USE_CAUSAL_BASE_CTX
int k;
for (k = 0; k < NUM_BASE_LEVELS; ++k) {
int ctx = coeff_ctx;
int is_k = (abs_qc > (k + 1));
cost += txb_costs->base_cost[k][ctx][is_k];
if (is_k == 0) break;
}
#else
int ctx_ls[NUM_BASE_LEVELS] = { 0 };
get_base_ctx_set(txb_info->qcoeff, scan[scan_idx], txb_info->bwl,
txb_info->height, ctx_ls);
......@@ -1348,6 +1427,7 @@ int get_coeff_cost(tran_low_t qc, int scan_idx, TxbInfo *txb_info,
cost += get_base_cost(abs_qc, ctx_ls[i],
txb_costs->base_cost[i][ctx_ls[i]], i);
}
#endif
if (abs_qc > NUM_BASE_LEVELS) {
int ctx = get_br_ctx_coeff(txb_info->qcoeff, scan[scan_idx],
......@@ -1537,6 +1617,7 @@ static int optimize_txb(TxbInfo *txb_info, const LV_MAP_COEFF_COST *txb_costs,
(void)fast_mode;
(void)txb_cache;
int update = 0;
// return update; //TODO: training only.
if (txb_info->eob == 0) return update;
const int max_eob = tx_size_2d[txb_info->tx_size];
......@@ -1927,17 +2008,46 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
&(td->counts->nz_map[txsize_ctx][plane_type]);
av1_update_eob_context(eob, seg_eob, tx_size, tx_type, plane_type, ec_ctx,
td->counts);
#if USE_CAUSAL_BASE_CTX
int coeff_ctx = 0;
update_eob = eob - 1;
#endif
for (c = eob - 1; c >= 0; --c) {
tran_low_t v = qcoeff[scan[c]];
int is_nz = (v != 0);
#if USE_CAUSAL_BASE_CTX
coeff_ctx = get_nz_map_ctx(tcoeff, c, scan, bwl, height, tx_type, 0);
if (c == eob - 1) assert(coeff_ctx == 0);
if (c < eob - 1) {
++(*nz_map_count)[coeff_ctx][is_nz];
update_cdf(ec_ctx->nz_map_cdf[txsize_ctx][plane_type][coeff_ctx], is_nz,
2);
}
if (is_nz) {
int k;
for (k = 0; k < NUM_BASE_LEVELS; ++k) {
int ctx = coeff_ctx;
int is_k = (abs(v) > (k + 1));
++td->counts->coeff_base[txsize_ctx][plane_type][k][ctx][is_k];
update_bin(ec_ctx->coeff_base_cdf[txsize_ctx][plane_type][k][ctx], is_k,
2);
if (is_k == 0) break;
}
}
#else
int coeff_ctx = get_nz_map_ctx(tcoeff, c, scan, bwl, height, tx_type, 0);
if (c == eob - 1) continue;
++(*nz_map_count)[coeff_ctx][is_nz];
update_cdf(ec_ctx->nz_map_cdf[txsize_ctx][plane_type][coeff_ctx], is_nz, 2);
#endif
}
#if !USE_CAUSAL_BASE_CTX
// Reverse process order to handle coefficient level and sign.
for (i = 0; i < NUM_BASE_LEVELS; ++i) {
update_eob = 0;
......@@ -1960,6 +2070,7 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
update_eob = AOMMAX(update_eob, c);
}
}
#endif
c = 0; // Update the context needed to code the DC sign (if applicable)
const int sign = signs[scan[c]];
......
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