Commit b92bd690 authored by Jingning Han's avatar Jingning Han

Unify set_contexts() function for encoder and decoder

Remove the separate implementations of set_contexts() in encoder
and decoder.

Change-Id: I9f6e9b075532faae0f74f885d9443589254258a7
parent 1195a396
......@@ -85,8 +85,7 @@ void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
}
void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
int aoff, int loff) {
TX_SIZE tx_size, int has_eob, int aoff, int loff) {
ENTROPY_CONTEXT *const a = pd->above_context + aoff;
ENTROPY_CONTEXT *const l = pd->left_context + loff;
const int tx_size_in_blocks = 1 << tx_size;
......@@ -94,8 +93,8 @@ void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
// above
if (has_eob && xd->mb_to_right_edge < 0) {
int i;
const int blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize] +
(xd->mb_to_right_edge >> (5 + pd->subsampling_x));
const int blocks_wide =
pd->n4_w + (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
int above_contexts = tx_size_in_blocks;
if (above_contexts + aoff > blocks_wide)
above_contexts = blocks_wide - aoff;
......@@ -109,8 +108,8 @@ void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
// left
if (has_eob && xd->mb_to_bottom_edge < 0) {
int i;
const int blocks_high = num_4x4_blocks_high_lookup[plane_bsize] +
(xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
const int blocks_high =
pd->n4_h + (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
int left_contexts = tx_size_in_blocks;
if (left_contexts + loff > blocks_high) left_contexts = blocks_high - loff;
......
......@@ -365,8 +365,7 @@ void av1_foreach_transformed_block(const MACROBLOCKD *const xd,
void *arg);
void av1_set_contexts(const MACROBLOCKD *xd, struct macroblockd_plane *pd,
BLOCK_SIZE plane_bsize, TX_SIZE tx_size, int has_eob,
int aoff, int loff);
TX_SIZE tx_size, int has_eob, int aoff, int loff);
#ifdef __cplusplus
} // extern "C"
......
......@@ -447,6 +447,17 @@ static INLINE int calc_mi_size(int len) {
return len + MI_BLOCK_SIZE;
}
static void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh, int bwl,
int bhl) {
int i;
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].n4_w = (bw << 1) >> xd->plane[i].subsampling_x;
xd->plane[i].n4_h = (bh << 1) >> xd->plane[i].subsampling_y;
xd->plane[i].n4_wl = bwl - xd->plane[i].subsampling_x;
xd->plane[i].n4_hl = bhl - xd->plane[i].subsampling_y;
}
}
static INLINE void set_mi_row_col(MACROBLOCKD *xd, const TileInfo *const tile,
int mi_row, int bh, int mi_col, int bw,
int mi_rows, int mi_cols) {
......
......@@ -431,17 +431,6 @@ static INLINE void dec_reset_skip_context(MACROBLOCKD *xd) {
}
}
static void set_plane_n4(MACROBLOCKD *const xd, int bw, int bh, int bwl,
int bhl) {
int i;
for (i = 0; i < MAX_MB_PLANE; i++) {
xd->plane[i].n4_w = (bw << 1) >> xd->plane[i].subsampling_x;
xd->plane[i].n4_h = (bh << 1) >> xd->plane[i].subsampling_y;
xd->plane[i].n4_wl = bwl - xd->plane[i].subsampling_x;
xd->plane[i].n4_hl = bhl - xd->plane[i].subsampling_y;
}
}
static MB_MODE_INFO *set_offsets(AV1_COMMON *const cm, MACROBLOCKD *const xd,
BLOCK_SIZE bsize, int mi_row, int mi_col,
int bw, int bh, int x_mis, int y_mis, int bwl,
......
......@@ -218,46 +218,6 @@ static int decode_coefs(const MACROBLOCKD *xd, PLANE_TYPE type,
return c;
}
// TODO(slavarnway): Decode version of av1_set_context. Modify
// av1_set_context
// after testing is complete, then delete this version.
static void dec_set_contexts(const MACROBLOCKD *xd,
struct macroblockd_plane *pd, TX_SIZE tx_size,
int has_eob, int aoff, int loff) {
ENTROPY_CONTEXT *const a = pd->above_context + aoff;
ENTROPY_CONTEXT *const l = pd->left_context + loff;
const int tx_size_in_blocks = 1 << tx_size;
// above
if (has_eob && xd->mb_to_right_edge < 0) {
int i;
const int blocks_wide =
pd->n4_w + (xd->mb_to_right_edge >> (5 + pd->subsampling_x));
int above_contexts = tx_size_in_blocks;
if (above_contexts + aoff > blocks_wide)
above_contexts = blocks_wide - aoff;
for (i = 0; i < above_contexts; ++i) a[i] = has_eob;
for (i = above_contexts; i < tx_size_in_blocks; ++i) a[i] = 0;
} else {
memset(a, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
}
// left
if (has_eob && xd->mb_to_bottom_edge < 0) {
int i;
const int blocks_high =
pd->n4_h + (xd->mb_to_bottom_edge >> (5 + pd->subsampling_y));
int left_contexts = tx_size_in_blocks;
if (left_contexts + loff > blocks_high) left_contexts = blocks_high - loff;
for (i = 0; i < left_contexts; ++i) l[i] = has_eob;
for (i = left_contexts; i < tx_size_in_blocks; ++i) l[i] = 0;
} else {
memset(l, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
}
}
int av1_decode_block_tokens(MACROBLOCKD *xd, int plane, const scan_order *sc,
int x, int y, TX_SIZE tx_size, aom_reader *r,
int seg_id) {
......@@ -273,6 +233,6 @@ int av1_decode_block_tokens(MACROBLOCKD *xd, int plane, const scan_order *sc,
const int eob = decode_coefs(xd, pd->plane_type, pd->dqcoeff, tx_size,
dequant, ctx, sc->scan, sc->neighbors, r);
#endif
dec_set_contexts(xd, pd, tx_size, eob > 0, x, y);
av1_set_contexts(xd, pd, tx_size, eob > 0, x, y);
return eob;
}
......@@ -184,6 +184,8 @@ static void set_offsets(const AV1_COMP *const cpi, const TileInfo *const tile,
MB_MODE_INFO *mbmi;
const int mi_width = num_8x8_blocks_wide_lookup[bsize];
const int mi_height = num_8x8_blocks_high_lookup[bsize];
const int bwl = b_width_log2_lookup[AOMMAX(bsize, BLOCK_8X8)];
const int bhl = b_height_log2_lookup[AOMMAX(bsize, BLOCK_8X8)];
const struct segmentation *const seg = &cm->seg;
set_skip_context(xd, mi_row, mi_col);
......@@ -202,6 +204,8 @@ static void set_offsets(const AV1_COMP *const cpi, const TileInfo *const tile,
x->mv_row_max = (cm->mi_rows - mi_row) * MI_SIZE + AOM_INTERP_EXTEND;
x->mv_col_max = (cm->mi_cols - mi_col) * MI_SIZE + AOM_INTERP_EXTEND;
set_plane_n4(xd, mi_width, mi_height, bwl, bhl);
// Set up distance of MB to edge of frame in 1/8th pel units.
assert(!(mi_col & (mi_width - 1)) && !(mi_row & (mi_height - 1)));
set_mi_row_col(xd, tile, mi_row, mi_height, mi_col, mi_width, cm->mi_rows,
......
......@@ -343,8 +343,8 @@ static void set_entropy_context_b(int plane, int block, int blk_row,
MACROBLOCKD *const xd = &x->e_mbd;
struct macroblock_plane *p = &x->plane[plane];
struct macroblockd_plane *pd = &xd->plane[plane];
av1_set_contexts(xd, pd, plane_bsize, tx_size, p->eobs[block] > 0, blk_col,
blk_row);
(void)plane_bsize;
av1_set_contexts(xd, pd, tx_size, p->eobs[block] > 0, blk_col, blk_row);
}
static INLINE void add_token(TOKENEXTRA **t, const aom_prob *context_tree,
......@@ -408,6 +408,7 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
const int seg_eob = get_tx_eob(&cpi->common.seg, segment_id, tx_size);
int16_t token;
EXTRABIT extra;
(void)plane_bsize;
pt = get_entropy_context(tx_size, pd->above_context + blk_col,
pd->left_context + blk_row);
scan = so->scan;
......@@ -449,7 +450,7 @@ static void tokenize_b(int plane, int block, int blk_row, int blk_col,
*tp = t;
av1_set_contexts(xd, pd, plane_bsize, tx_size, c > 0, blk_col, blk_row);
av1_set_contexts(xd, pd, tx_size, c > 0, blk_col, blk_row);
}
struct is_skippable_args {
......
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