Commit f72e1382 authored by Linfeng Zhang's avatar Linfeng Zhang Committed by James Zern

Add av1_get_base_level_counts()

which calculates base level counts in block.

Change-Id: Ia975faad4afbfc0c587bdcd403de3d4dc3f5f411
parent 8c841f7d
......@@ -282,3 +282,17 @@ int16_t get_eob_pos_token(int eob, int16_t *extra) {
return t;
}
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) {
const int stride = width + TX_PAD_HOR;
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,
base_ref_offset, BASE_CONTEXT_POSITION_NUM);
}
}
}
......@@ -179,14 +179,14 @@ static INLINE int get_base_ctx_from_count_mag(int row, int col, int count,
static INLINE int get_base_ctx(const uint8_t *const levels,
const int c, // raster order
const int bwl, const int level_minus_1) {
const int bwl, const int level_minus_1,
const int count) {
const int row = c >> bwl;
const int col = c - (row << bwl);
const int stride = (1 << bwl) + TX_PAD_HOR;
int mag_count = 0;
int nb_mag[3] = { 0 };
const int count = get_level_count(levels, stride, row, col, level_minus_1,
base_ref_offset, BASE_CONTEXT_POSITION_NUM);
get_level_mag(levels, stride, row, col, nb_mag);
for (int idx = 0; idx < 3; ++idx)
......@@ -567,4 +567,8 @@ void av1_init_txb_probs(FRAME_CONTEXT *fc);
void av1_init_lv_map(AV1_COMMON *cm);
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);
#endif // AV1_COMMON_TXB_COMMON_H_
......@@ -205,15 +205,17 @@ 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);
for (c = *eob - 1; c >= 0; --c) {
uint8_t *const level = &levels[get_paded_idx(scan[c], bwl)];
int ctx;
if (*level <= i) continue;
ctx = get_base_ctx(levels, scan[c], bwl, i);
ctx = get_base_ctx(levels, scan[c], bwl, i, level_counts[scan[c]]);
if (av1_read_record_bin(
counts, r, ec_ctx->coeff_base_cdf[txs_ctx][plane_type][i][ctx], 2,
......
......@@ -371,6 +371,7 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
}
update_eob = eob - 1;
#else
uint8_t level_counts[MAX_TX_SQUARE];
for (int i = 1; i < eob; ++i) {
c = eob - 1 - i;
int coeff_ctx = get_nz_map_ctx(levels, c, scan, bwl, height, tx_type);
......@@ -383,13 +384,14 @@ void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
}
for (int i = 0; i < NUM_BASE_LEVELS; ++i) {
av1_get_base_level_counts(levels, i, width, height, level_counts);
for (c = eob - 1; c >= 0; --c) {
const tran_low_t level = abs(tcoeff[scan[c]]);
int ctx;
if (level <= i) continue;
ctx = get_base_ctx(levels, scan[c], bwl, i);
ctx = get_base_ctx(levels, scan[c], bwl, i, level_counts[scan[c]]);
if (level == i + 1) {
aom_write_bin(w, 1, ec_ctx->coeff_base_cdf[txs_ctx][plane_type][i][ctx],
......@@ -2096,14 +2098,16 @@ void av1_update_and_record_txb_context(int plane, int block, int blk_row,
#if !USE_CAUSAL_BASE_CTX
// Reverse process order to handle coefficient level and sign.
uint8_t level_counts[MAX_TX_SQUARE];
for (int i = 0; i < NUM_BASE_LEVELS; ++i) {
av1_get_base_level_counts(levels, i, width, height, level_counts);
for (c = eob - 1; c >= 0; --c) {
const tran_low_t level = abs(tcoeff[scan[c]]);
int ctx;
if (level <= i) continue;
ctx = get_base_ctx(levels, scan[c], bwl, i);
ctx = get_base_ctx(levels, scan[c], bwl, i, level_counts[scan[c]]);
if (level == i + 1) {
++td->counts->coeff_base[txsize_ctx][plane_type][i][ctx][1];
......
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