Commit 97fc474c authored by Linfeng Zhang's avatar Linfeng Zhang Committed by James Zern

Add av1_get_br_level_counts()

which calculates br level counts in block.

Change-Id: Iec5c9a8a0ce7e57bf5fb29db552f6a9065c5de88
parent f72e1382
......@@ -296,3 +296,17 @@ void av1_get_base_level_counts(const uint8_t *const levels,
}
}
}
void av1_get_br_level_counts(const uint8_t *const levels, const int width,
const int height, uint8_t *const level_counts) {
const int stride = width + TX_PAD_HOR;
const int level_minus_1 = NUM_BASE_LEVELS;
for (int row = 0; row < height; ++row) {
for (int col = 0; col < width; ++col) {
level_counts[row * width + col] =
get_level_count(levels, stride, row, col, level_minus_1,
br_ref_offset, BR_CONTEXT_POSITION_NUM);
}
}
}
......@@ -281,15 +281,12 @@ static INLINE int get_br_ctx_from_count_mag(int row, int col, int count,
static INLINE int get_br_ctx(const uint8_t *const levels,
const int c, // raster order
const int bwl) {
const int bwl, const int count) {
const int row = c >> bwl;
const int col = c - (row << bwl);
const int stride = (1 << bwl) + TX_PAD_HOR;
const int level_minus_1 = NUM_BASE_LEVELS;
int mag = 0;
int nb_mag[3] = { 0 };
const int count = get_level_count(levels, stride, row, col, level_minus_1,
br_ref_offset, BR_CONTEXT_POSITION_NUM);
get_level_mag(levels, stride, row, col, nb_mag);
for (int idx = 0; idx < 3; ++idx) mag = AOMMAX(mag, nb_mag[idx]);
const int ctx = get_br_ctx_from_count_mag(row, col, count, mag);
......@@ -571,4 +568,7 @@ void av1_get_base_level_counts(const uint8_t *const levels,
const int level_minus_1, const int width,
const int height, uint8_t *const level_counts);
void av1_get_br_level_counts(const uint8_t *const levels, const int width,
const int height, uint8_t *const level_counts);
#endif // AV1_COMMON_TXB_COMMON_H_
......@@ -74,6 +74,7 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
int cul_level = 0;
uint8_t levels_buf[TX_PAD_2D];
uint8_t *const levels = set_levels(levels_buf, width);
uint8_t level_counts[MAX_TX_SQUARE];
int8_t signs[MAX_TX_SQUARE];
memset(tcoeffs, 0, sizeof(*tcoeffs) * seg_eob);
......@@ -205,7 +206,6 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
#if USE_CAUSAL_BASE_CTX
update_eob = *eob - 1;
#else
uint8_t level_counts[MAX_TX_SQUARE];
int i;
for (i = 0; i < NUM_BASE_LEVELS; ++i) {
av1_get_base_level_counts(levels, i, width, height, level_counts);
......@@ -255,52 +255,55 @@ uint8_t av1_read_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
}
}
for (c = update_eob; c >= 0; --c) {
uint8_t *const level = &levels[get_paded_idx(scan[c], bwl)];
int idx;
int ctx;
if (*level <= NUM_BASE_LEVELS) continue;
ctx = get_br_ctx(levels, scan[c], bwl);
if (update_eob >= 0) {
av1_get_br_level_counts(levels, width, height, level_counts);
for (c = update_eob; c >= 0; --c) {
uint8_t *const level = &levels[get_paded_idx(scan[c], bwl)];
int idx;
int ctx;
for (idx = 0; idx < BASE_RANGE_SETS; ++idx) {
if (av1_read_record_bin(
counts, r, ec_ctx->coeff_br_cdf[txs_ctx][plane_type][idx][ctx], 2,
ACCT_STR)) {
int extra_bits = (1 << br_extra_bits[idx]) - 1;
// int br_offset = aom_read_literal(r, extra_bits, ACCT_STR);
int br_offset = 0;
int tok;
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][1];
for (tok = 0; tok < extra_bits; ++tok) {
if (av1_read_record_bin(
counts, r, ec_ctx->coeff_lps_cdf[txs_ctx][plane_type][ctx], 2,
ACCT_STR)) {
br_offset = tok;
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][1];
break;
if (*level <= NUM_BASE_LEVELS) continue;
ctx = get_br_ctx(levels, scan[c], bwl, level_counts[scan[c]]);
for (idx = 0; idx < BASE_RANGE_SETS; ++idx) {
if (av1_read_record_bin(
counts, r, ec_ctx->coeff_br_cdf[txs_ctx][plane_type][idx][ctx],
2, ACCT_STR)) {
int extra_bits = (1 << br_extra_bits[idx]) - 1;
// int br_offset = aom_read_literal(r, extra_bits, ACCT_STR);
int br_offset = 0;
int tok;
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][1];
for (tok = 0; tok < extra_bits; ++tok) {
if (av1_read_record_bin(
counts, r, ec_ctx->coeff_lps_cdf[txs_ctx][plane_type][ctx],
2, ACCT_STR)) {
br_offset = tok;
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][1];
break;
}
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][0];
}
if (counts) ++counts->coeff_lps[txs_ctx][plane_type][ctx][0];
}
if (tok == extra_bits) br_offset = extra_bits;
if (tok == extra_bits) br_offset = extra_bits;
int br_base = br_index_to_coeff[idx];
int br_base = br_index_to_coeff[idx];
*level = NUM_BASE_LEVELS + 1 + br_base + br_offset;
cul_level += *level;
break;
*level = NUM_BASE_LEVELS + 1 + br_base + br_offset;
cul_level += *level;
break;
}
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][0];
}
if (counts) ++counts->coeff_br[txs_ctx][plane_type][idx][ctx][0];
}
if (idx < BASE_RANGE_SETS) continue;
if (idx < BASE_RANGE_SETS) continue;
// decode 0-th order Golomb code
*level = COEFF_BASE_RANGE + 1 + NUM_BASE_LEVELS;
// Save golomb in tcoeffs because adding it to level may incur overflow
tcoeffs[scan[c]] = read_golomb(xd, r, counts);
cul_level += *level + tcoeffs[scan[c]];
// decode 0-th order Golomb code
*level = COEFF_BASE_RANGE + 1 + NUM_BASE_LEVELS;
// Save golomb in tcoeffs because adding it to level may incur overflow
tcoeffs[scan[c]] = read_golomb(xd, r, counts);
cul_level += *level + tcoeffs[scan[c]];
}
}
for (c = 0; c < *eob; ++c) {
......
This diff is collapsed.
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