Commit 47e4b369 authored by Angie Chiang's avatar Angie Chiang

Compute lv_map's coeff cost in av1_cost_coeffs()

1) move the original implementation in av1_cost_coeffs() to
cost_coeffs() and let av1_cost_coeffs become a switch for
choosing original coeff cost or lv_map's coeff cost

2) change get_txb_ctx's naming. Use plane_bsize instead of
bsize to make the intention clear.

3) remove txb context computing in get_txb_ctx
Change-Id: I17e3d39d796e051d1c90f0a0c5d7d0888b9ca292
parent 47748b56
......@@ -242,14 +242,14 @@ static INLINE int get_dc_sign_ctx(int dc_sign) {
return dc_sign_ctx;
}
static INLINE void get_txb_ctx(BLOCK_SIZE bsize, TX_SIZE tx_size, int plane,
const ENTROPY_CONTEXT *a,
static INLINE void get_txb_ctx(BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
int plane, const ENTROPY_CONTEXT *a,
const ENTROPY_CONTEXT *l, TXB_CTX *txb_ctx) {
const int tx_size_in_blocks = 1 << tx_size;
int ctx_offset = (plane == 0) ? 0 : 7;
int k;
if (bsize > txsize_to_bsize[tx_size]) ctx_offset += 3;
if (plane_bsize > txsize_to_bsize[tx_size]) ctx_offset += 3;
int dc_sign = 0;
for (k = 0; k < tx_size_in_blocks; ++k) {
......@@ -281,7 +281,7 @@ static INLINE void get_txb_ctx(BLOCK_SIZE bsize, TX_SIZE tx_size, int plane,
top = AOMMIN(top, 255);
left = AOMMIN(left, 255);
if (bsize == txsize_to_bsize[tx_size])
if (plane_bsize == txsize_to_bsize[tx_size])
txb_ctx->txb_skip_ctx = 0;
else if (top == 0 && left == 0)
txb_ctx->txb_skip_ctx = 1;
......
......@@ -245,7 +245,7 @@ static INLINE void get_base_ctx_set(const tran_low_t *tcoeffs,
}
int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int block, TXB_CTX *txb_ctx, int *cul_level) {
int block, TXB_CTX *txb_ctx) {
MACROBLOCKD *const xd = &x->e_mbd;
const TX_SIZE tx_size = get_tx_size(plane, xd);
const PLANE_TYPE plane_type = get_plane_type(plane);
......@@ -260,7 +260,6 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
aom_prob *nz_map = xd->fc->nz_map[tx_size][plane_type];
const int bwl = b_width_log2_lookup[txsize_to_bsize[tx_size]] + 2;
*cul_level = 0;
// txb_mask is only initialized for once here. After that, it will be set when
// coding zero map and then reset when coding level 1 info.
uint8_t txb_mask[32 * 32] = { 0 };
......@@ -311,7 +310,6 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
if (level == i + 1) {
cost += av1_cost_bit(coeff_base[i][ctx_ls[i]], 1);
*cul_level += level;
continue;
}
cost += av1_cost_bit(coeff_base[i][ctx_ls[i]], 0);
......@@ -320,7 +318,6 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
if (level > NUM_BASE_LEVELS) {
int idx;
int ctx;
*cul_level += level;
ctx = get_level_ctx(qcoeff, scan[c], bwl);
......@@ -361,10 +358,6 @@ int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
txb_mask[scan[c]] = 1;
}
*cul_level = AOMMIN(63, *cul_level);
// DC value
set_dc_sign(cul_level, qcoeff[0]);
return cost;
}
......
......@@ -24,6 +24,8 @@ extern "C" {
#endif
void av1_alloc_txb_buf(AV1_COMP *cpi);
void av1_free_txb_buf(AV1_COMP *cpi);
int av1_cost_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int block, TXB_CTX *txb_ctx);
void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCKD *xd,
aom_writer *w, int block, int plane,
const tran_low_t *tcoeff, uint16_t eob,
......
......@@ -33,6 +33,9 @@
#include "av1/common/reconintra.h"
#include "av1/common/scan.h"
#include "av1/common/seg_common.h"
#if CONFIG_LV_MAP
#include "av1/common/txb_common.h"
#endif
#if CONFIG_WARPED_MOTION
#include "av1/common/warped_motion.h"
#endif // CONFIG_WARPED_MOTION
......@@ -43,6 +46,9 @@
#include "av1/encoder/encodemb.h"
#include "av1/encoder/encodemv.h"
#include "av1/encoder/encoder.h"
#if CONFIG_LV_MAP
#include "av1/encoder/encodetxb.h"
#endif
#include "av1/encoder/hybrid_fwd_txfm.h"
#include "av1/encoder/mcomp.h"
#if CONFIG_PALETTE
......@@ -1118,10 +1124,11 @@ static int64_t av1_block_error2_c(const tran_low_t *coeff,
* can skip this if the last coefficient in this transform block, e.g. the
* 16th coefficient in a 4x4 block or the 64th coefficient in a 8x8 block,
* were non-zero). */
int av1_cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int block, TX_SIZE tx_size, const SCAN_ORDER *scan_order,
const ENTROPY_CONTEXT *a, const ENTROPY_CONTEXT *l,
int use_fast_coef_costing) {
#if !CONFIG_LV_MAP
static int cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int block, TX_SIZE tx_size, const SCAN_ORDER *scan_order,
const ENTROPY_CONTEXT *a, const ENTROPY_CONTEXT *l,
int use_fast_coef_costing) {
MACROBLOCKD *const xd = &x->e_mbd;
MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
const struct macroblock_plane *p = &x->plane[plane];
......@@ -1259,6 +1266,39 @@ int av1_cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
return cost;
}
#endif // !CONFIG_LV_MAP
int av1_cost_coeffs(const AV1_COMMON *const cm, MACROBLOCK *x, int plane,
int block, TX_SIZE tx_size, const SCAN_ORDER *scan_order,
const ENTROPY_CONTEXT *a, const ENTROPY_CONTEXT *l,
int use_fast_coef_costing) {
#if !CONFIG_LV_MAP
return cost_coeffs(cm, x, plane, block, tx_size, scan_order, a, l,
use_fast_coef_costing);
#else // !CONFIG_LV_MAP
(void)scan_order;
(void)use_fast_coef_costing;
const MACROBLOCKD *xd = &x->e_mbd;
const MB_MODE_INFO *mbmi = &xd->mi[0]->mbmi;
const struct macroblockd_plane *pd = &xd->plane[plane];
const BLOCK_SIZE bsize = mbmi->sb_type;
#if CONFIG_CB4X4
#if CONFIG_CHROMA_2X2
const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, pd);
#else
const BLOCK_SIZE plane_bsize =
AOMMAX(BLOCK_4X4, get_plane_block_size(bsize, pd));
#endif // CONFIG_CHROMA_2X2
#else // CONFIG_CB4X4
const BLOCK_SIZE plane_bsize =
get_plane_block_size(AOMMAX(BLOCK_8X8, bsize), pd);
#endif // CONFIG_CB4X4
TXB_CTX txb_ctx;
get_txb_ctx(plane_bsize, tx_size, plane, a, l, &txb_ctx);
return av1_cost_coeffs_txb(cm, x, plane, block, &txb_ctx);
#endif // !CONFIG_LV_MAP
}
#endif // !CONFIG_PVQ || CONFIG_VAR_TX
static void dist_block(const AV1_COMP *cpi, MACROBLOCK *x, int plane, int block,
......
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