0 LR for LF and 1 LR for default
diff --git a/av1/common/entropy.h b/av1/common/entropy.h index 6cd87d8..5e7cb61 100644 --- a/av1/common/entropy.h +++ b/av1/common/entropy.h
@@ -66,7 +66,8 @@ // Number of symbols for base range coding in low-frequency region #define LF_BASE_SYMBOLS 6 #define LF_NUM_BASE_LEVELS (LF_BASE_SYMBOLS - 2) -#define LF_MAX_BASE_BR_RANGE (COEFF_BASE_RANGE + LF_NUM_BASE_LEVELS + 1) +#define LF_COEFF_BASE_RANGE (0 * (BR_CDF_SIZE - 1)) +#define LF_MAX_BASE_BR_RANGE (LF_COEFF_BASE_RANGE + LF_NUM_BASE_LEVELS + 1) // Limits to determine the low-frequency region for coefficient coding. #define LF_2D_LIM 4 // row + column limit @@ -83,8 +84,7 @@ #define NUM_BASE_LEVELS 2 #define BR_CDF_SIZE (4) -#define COEFF_BASE_RANGE (0 * (BR_CDF_SIZE - 1)) - +#define COEFF_BASE_RANGE (1 * (BR_CDF_SIZE - 1)) #define COEFF_CONTEXT_BITS 3 #define COEFF_CONTEXT_MASK ((1 << COEFF_CONTEXT_BITS) - 1) #define MAX_BASE_BR_RANGE (COEFF_BASE_RANGE + NUM_BASE_LEVELS + 1)
diff --git a/av1/common/txb_common.h b/av1/common/txb_common.h index 5651a9d..46ee5b1 100644 --- a/av1/common/txb_common.h +++ b/av1/common/txb_common.h
@@ -131,9 +131,9 @@ const int col = c - (row << bwl); const int stride = (1 << bwl) + TX_PAD_HOR; const int pos = row * stride + col; - int mag = AOMMIN(levels[pos + 1], MAX_BASE_BR_RANGE) + - AOMMIN(levels[pos + stride], MAX_BASE_BR_RANGE) + - AOMMIN(levels[pos + 1 + stride], MAX_BASE_BR_RANGE); + int mag = AOMMIN(levels[pos + 1], LF_MAX_BASE_BR_RANGE) + + AOMMIN(levels[pos + stride], LF_MAX_BASE_BR_RANGE) + + AOMMIN(levels[pos + 1 + stride], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, 6); return mag + 7; } @@ -149,22 +149,22 @@ const int col = c - (row << bwl); const int stride = (1 << bwl) + TX_PAD_HOR; const int pos = row * stride + col; - int mag = AOMMIN(levels[pos + 1], MAX_BASE_BR_RANGE); - mag += AOMMIN(levels[pos + stride], MAX_BASE_BR_RANGE); + int mag = AOMMIN(levels[pos + 1], LF_MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + stride], LF_MAX_BASE_BR_RANGE); switch (tx_class) { case TX_CLASS_2D: - mag += AOMMIN(levels[pos + stride + 1], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + stride + 1], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, 6); if (c == 0) return mag; if ((row < 2) && (col < 2)) return mag + 7; break; case TX_CLASS_HORIZ: - mag += AOMMIN(levels[pos + 2], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + 2], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, 6); if (col == 0) return mag + 7; break; case TX_CLASS_VERT: - mag += AOMMIN(levels[pos + (stride << 1)], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + (stride << 1)], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, 6); if (row == 0) return mag + 7; break; @@ -269,12 +269,13 @@ const TX_CLASS tx_class) { int mag; // Note: AOMMIN(level, 5) is useless for decoder since level < 5. - mag = clip_max3[levels[1]]; // { 0, 1 } - mag += clip_max3[levels[(1 << bwl) + TX_PAD_HOR]]; // { 1, 0 } + + mag = clip_max5[levels[1]]; // { 0, 1 } + mag += clip_max5[levels[(1 << bwl) + TX_PAD_HOR]]; // { 1, 0 } if (tx_class == TX_CLASS_2D) { - mag += clip_max3[levels[(1 << bwl) + TX_PAD_HOR + 1]]; // { 1, 1 } - mag += clip_max3[levels[2]]; // { 0, 2 } - mag += clip_max3[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]]; // { 2, 0 } + mag += clip_max5[levels[(1 << bwl) + TX_PAD_HOR + 1]]; // { 1, 1 } + mag += clip_max5[levels[2]]; // { 0, 2 } + mag += clip_max5[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]]; // { 2, 0 } } else if (tx_class == TX_CLASS_VERT) { mag += clip_max3[levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)]]; // { 2, 0 } mag += clip_max3[levels[(3 << bwl) + (3 << TX_PAD_HOR_LOG2)]]; // { 3, 0 } @@ -447,19 +448,19 @@ const int col = c - (row << bwl); const int stride = (1 << bwl) + TX_PAD_HOR; const int pos = row * stride + col; - int mag = AOMMIN(levels[pos + 1], MAX_BASE_BR_RANGE); - mag += AOMMIN(levels[pos + stride], MAX_BASE_BR_RANGE); + int mag = AOMMIN(levels[pos + 1], LF_MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + stride], LF_MAX_BASE_BR_RANGE); switch (tx_class) { case TX_CLASS_2D: - mag += AOMMIN(levels[pos + stride + 1], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + stride + 1], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, (COEFF_BR_PH_CONTEXTS - 1)); break; case TX_CLASS_HORIZ: - mag += AOMMIN(levels[pos + 2], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + 2], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, (COEFF_BR_PH_CONTEXTS - 1)); break; case TX_CLASS_VERT: - mag += AOMMIN(levels[pos + (stride << 1)], MAX_BASE_BR_RANGE); + mag += AOMMIN(levels[pos + (stride << 1)], LF_MAX_BASE_BR_RANGE); mag = AOMMIN((mag + 1) >> 1, (COEFF_BR_PH_CONTEXTS - 1)); break; default: break; @@ -502,11 +503,11 @@ int mag; // Note: AOMMIN(level, 3) is useless for decoder since level < 5. levels = levels + get_padded_idx(coeff_idx, bwl); - mag = AOMMIN(levels[1], 3); // { 0, 1 } - mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR], 3); // { 1, 0 } - mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR + 1], 3); // { 1, 1 } - mag += AOMMIN(levels[2], 3); // { 0, 2 } - mag += AOMMIN(levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)], 3); // { 2, 0 } + mag = AOMMIN(levels[1], 5); // { 0, 1 } + mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR], 5); // { 1, 0 } + mag += AOMMIN(levels[(1 << bwl) + TX_PAD_HOR + 1], 5); // { 1, 1 } + mag += AOMMIN(levels[2], 5); // { 0, 2 } + mag += AOMMIN(levels[(2 << bwl) + (2 << TX_PAD_HOR_LOG2)], 5); // { 2, 0 } int ctx = (mag + 1) >> 1; const int row = coeff_idx >> bwl; const int col = coeff_idx - (row << bwl);
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c index a32820d..5cfc9d7 100644 --- a/av1/decoder/decodetxb.c +++ b/av1/decoder/decodetxb.c
@@ -86,7 +86,7 @@ if (level > LF_NUM_BASE_LEVELS) { const int br_ctx = get_br_lf_ctx_2d(levels, pos, bwl); aom_cdf_prob *cdf = br_lf_cdf[br_ctx]; - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = aom_read_symbol(r, cdf, BR_CDF_SIZE, ACCT_INFO("k", "br_lf_cdf")); level += k; @@ -134,7 +134,7 @@ if (level > LF_NUM_BASE_LEVELS) { const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class); aom_cdf_prob *cdf = br_lf_cdf[br_ctx]; - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = aom_read_symbol(r, cdf, BR_CDF_SIZE, ACCT_INFO("k", "br_lf_cdf")); level += k; @@ -630,7 +630,7 @@ if (level > LF_NUM_BASE_LEVELS) { const int br_ctx = get_br_ctx_lf_eob(pos, tx_class); cdf = ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx]; - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = aom_read_symbol(r, cdf, BR_CDF_SIZE, ACCT_INFO("k", "coeff_br_lf_cdf")); level += k; @@ -675,7 +675,7 @@ for (int si = *eob - 1; si > 0; --si) { int pos = scan[si]; int level = - AOMMIN(levels[get_padded_idx(pos, bwl)], MAX_BASE_BR_RANGE); + AOMMIN(levels[get_padded_idx(pos, bwl)], LF_MAX_BASE_BR_RANGE); if (level) { ++num_nz; sum_abs1 += level; @@ -697,7 +697,7 @@ for (int si = *eob - 1; si > 0; --si) { int pos = scan[si]; int level = - AOMMIN(levels[get_padded_idx(pos, bwl)], MAX_BASE_BR_RANGE); + AOMMIN(levels[get_padded_idx(pos, bwl)], LF_MAX_BASE_BR_RANGE); if (level) { ++num_nz; sum_abs1 += level;
diff --git a/av1/encoder/block.h b/av1/encoder/block.h index baf8306..dff2c94 100644 --- a/av1/encoder/block.h +++ b/av1/encoder/block.h
@@ -166,7 +166,7 @@ int base_lf_cost[LF_SIG_COEF_CONTEXTS][LF_BASE_SYMBOLS * 2]; //! Cost for encoding an increment to the low-frequency coefficient int lps_lf_cost[LF_LEVEL_CONTEXTS] - [COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1]; + [LF_COEFF_BASE_RANGE + 1 + LF_COEFF_BASE_RANGE + 1]; //! Cost for encoding the base level of a parity-hidden coefficient int base_ph_cost[COEFF_BASE_PH_CONTEXTS][4]; //! Cost for encoding an increment to the parity-hidden coefficient
diff --git a/av1/encoder/encodemb.c b/av1/encoder/encodemb.c index cfbacc4..3dfc385 100644 --- a/av1/encoder/encodemb.c +++ b/av1/encoder/encodemb.c
@@ -138,7 +138,7 @@ for (int si = eob - 1; si > 0; si--) { const int pos = scan[si]; nz += !!(qcoeff[pos]); - sum_abs1 += AOMMIN(abs(qcoeff[pos]), MAX_BASE_BR_RANGE); + sum_abs1 += AOMMIN(abs(qcoeff[pos]), LF_MAX_BASE_BR_RANGE); } if (nz >= PHTHRESH && ((qcoeff[0] & 1) != (sum_abs1 & 1))) { int tune_pos = scan[0]; @@ -160,8 +160,8 @@ absdqcoeff = abs(dqcoeff[pos]); absqcoeff = abs(qcoeff[pos]); bool tunable = - (absqcoeff < MAX_BASE_BR_RANGE) || - ((absqcoeff == MAX_BASE_BR_RANGE) && (abstcoeff < absdqcoeff)); + (absqcoeff < LF_MAX_BASE_BR_RANGE) || + ((absqcoeff == LF_MAX_BASE_BR_RANGE) && (abstcoeff < absdqcoeff)); absqcoeff += ((abstcoeff < absdqcoeff) ? -1 : 1); absdqcoeff = (tran_low_t)(ROUND_POWER_OF_TWO_64( (tran_high_t)absqcoeff *
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c index 828b9ac..dc5047a 100644 --- a/av1/encoder/encodetxb.c +++ b/av1/encoder/encodetxb.c
@@ -52,8 +52,8 @@ } coef_info[scan_idx].tunable = - (abs(coef_info[scan_idx].qc) < MAX_BASE_BR_RANGE) || - ((abs(qc_up) == MAX_BASE_BR_RANGE) && upround); + (abs(coef_info[scan_idx].qc) < LF_MAX_BASE_BR_RANGE) || + ((abs(qc_up) == LF_MAX_BASE_BR_RANGE) && upround); if (coef_info[scan_idx].tunable) { if (upround) { coef_info[scan_idx].delta_cost = (cost_low - cost_up); @@ -321,8 +321,8 @@ // Golomb cost of coding bypass coded level values in the // low-frequency region. static INLINE int get_golomb_cost_lf(int abs_qc) { - if (abs_qc >= 1 + LF_NUM_BASE_LEVELS + COEFF_BASE_RANGE) { - const int r = abs_qc - COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS; + if (abs_qc >= 1 + LF_NUM_BASE_LEVELS + LF_COEFF_BASE_RANGE) { + const int r = abs_qc - LF_COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS; const int length = get_msb(r) + 1; return av1_cost_literal(2 * length - 1); } @@ -333,7 +333,7 @@ // low-frequency region, includes the bypass cost. static INLINE int get_br_lf_cost(tran_low_t level, const int *coeff_lps) { const int base_range = - AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, COEFF_BASE_RANGE); + AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, LF_COEFF_BASE_RANGE); return coeff_lps[base_range] + get_golomb_cost_lf(level); } @@ -342,12 +342,12 @@ static INLINE int get_br_lf_cost_with_diff(tran_low_t level, const int *coeff_lps, int *diff) { const int base_range = - AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, COEFF_BASE_RANGE); + AOMMIN(level - 1 - LF_NUM_BASE_LEVELS, LF_COEFF_BASE_RANGE); int golomb_bits = 0; - if (level <= COEFF_BASE_RANGE + 1 + LF_NUM_BASE_LEVELS) - *diff += coeff_lps[base_range + COEFF_BASE_RANGE + 1]; - if (level >= COEFF_BASE_RANGE + 1 + LF_NUM_BASE_LEVELS) { - int r = level - COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS; + if (level <= LF_COEFF_BASE_RANGE + 1 + LF_NUM_BASE_LEVELS) + *diff += coeff_lps[base_range + LF_COEFF_BASE_RANGE + 1]; + if (level >= LF_COEFF_BASE_RANGE + 1 + LF_NUM_BASE_LEVELS) { + int r = level - LF_COEFF_BASE_RANGE - LF_NUM_BASE_LEVELS; if (r < 32) { golomb_bits = golomb_bits_cost[r]; *diff += golomb_cost_diff[r]; @@ -892,7 +892,7 @@ level - 1 - LF_NUM_BASE_LEVELS; // level is above 1. const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class); aom_cdf_prob *cdf = ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx]; - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1); aom_write_symbol(w, k, cdf, BR_CDF_SIZE); if (k < BR_CDF_SIZE - 1) break; @@ -925,6 +925,7 @@ const int pos = scan[0]; const tran_low_t v = tcoeff[pos]; const tran_low_t level = abs(v); + write_coeff_hidden(w, tx_class, scan, bwl, levels, level, ec_ctx->coeff_base_ph_cdf, ec_ctx->coeff_br_ph_cdf); } else { @@ -973,7 +974,7 @@ level - 1 - LF_NUM_BASE_LEVELS; // level is above 1. const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class); aom_cdf_prob *cdf = ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx]; - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1); aom_write_symbol(w, k, cdf, BR_CDF_SIZE); if (k < BR_CDF_SIZE - 1) break; @@ -1047,8 +1048,8 @@ const int col = pos - (row << bwl); int limits = get_lf_limits(row, col, tx_class, plane); if (limits) { - if (level > COEFF_BASE_RANGE + LF_NUM_BASE_LEVELS) - write_golomb(w, level - COEFF_BASE_RANGE - 1 - LF_NUM_BASE_LEVELS); + if (level > LF_COEFF_BASE_RANGE + LF_NUM_BASE_LEVELS) + write_golomb(w, level - LF_COEFF_BASE_RANGE - 1 - LF_NUM_BASE_LEVELS); } else { if (level > COEFF_BASE_RANGE + NUM_BASE_LEVELS) write_golomb(w, level - COEFF_BASE_RANGE - 1 - NUM_BASE_LEVELS); @@ -1438,7 +1439,7 @@ const int(*lps_cost)[COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1] = coeff_costs->lps_cost; - const int(*lps_lf_cost)[COEFF_BASE_RANGE + 1 + COEFF_BASE_RANGE + 1] = + const int(*lps_lf_cost)[LF_COEFF_BASE_RANGE + 1 + LF_COEFF_BASE_RANGE + 1] = coeff_costs->lps_lf_cost; int c = eob - 1; { @@ -2710,7 +2711,7 @@ const int blkpos = scan[scan_idx]; if (qcoeff[blkpos]) { ++nzsbb; - sum_abs1 += AOMMIN(abs(qcoeff[blkpos]), MAX_BASE_BR_RANGE); + sum_abs1 += AOMMIN(abs(qcoeff[blkpos]), LF_MAX_BASE_BR_RANGE); } } int hidepos = scan[0], rate_cur = 0; @@ -3621,7 +3622,7 @@ if (level > LF_NUM_BASE_LEVELS) { const int base_range = level - 1 - LF_NUM_BASE_LEVELS; const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class); - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1); if (allow_update_cdf) { update_cdf(ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx], k, @@ -3757,7 +3758,7 @@ if (level > LF_NUM_BASE_LEVELS) { const int base_range = level - 1 - LF_NUM_BASE_LEVELS; const int br_ctx = get_br_lf_ctx(levels, pos, bwl, tx_class); - for (int idx = 0; idx < COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { + for (int idx = 0; idx < LF_COEFF_BASE_RANGE; idx += BR_CDF_SIZE - 1) { const int k = AOMMIN(base_range - idx, BR_CDF_SIZE - 1); if (allow_update_cdf) { update_cdf(ec_ctx->coeff_br_lf_cdf[plane_type][br_ctx], k,
diff --git a/av1/encoder/rd.c b/av1/encoder/rd.c index 218b323..2d2c4f7 100644 --- a/av1/encoder/rd.c +++ b/av1/encoder/rd.c
@@ -1107,7 +1107,7 @@ int i, j; av1_cost_tokens_from_cdf(br_lf_rate, fc->coeff_br_lf_cdf[plane][ctx], NULL); - for (i = 0; i < COEFF_BASE_RANGE; i += BR_CDF_SIZE - 1) { + for (i = 0; i < LF_COEFF_BASE_RANGE; i += BR_CDF_SIZE - 1) { for (j = 0; j < BR_CDF_SIZE - 1; j++) { pcost->lps_lf_cost[ctx][i + j] = prev_cost_lf + br_lf_rate[j]; } @@ -1116,10 +1116,10 @@ pcost->lps_lf_cost[ctx][i] = prev_cost_lf; } for (int ctx = 0; ctx < LF_LEVEL_CONTEXTS; ++ctx) { - pcost->lps_lf_cost[ctx][0 + COEFF_BASE_RANGE + 1] = + pcost->lps_lf_cost[ctx][0 + LF_COEFF_BASE_RANGE + 1] = pcost->lps_lf_cost[ctx][0]; - for (int i = 1; i <= COEFF_BASE_RANGE; ++i) { - pcost->lps_lf_cost[ctx][i + COEFF_BASE_RANGE + 1] = + for (int i = 1; i <= LF_COEFF_BASE_RANGE; ++i) { + pcost->lps_lf_cost[ctx][i + LF_COEFF_BASE_RANGE + 1] = pcost->lps_lf_cost[ctx][i] - pcost->lps_lf_cost[ctx][i - 1]; } }