Commit 27a984fb authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Removing a lot of duplicated code.

Adding set_contexts contexts function and call it instead of
set_contexts_on_border. Calling txfrm_block_to_raster_xy to get aoff and
loff.

Change-Id: I41897e344afd2cae1f923f4fdbe63daccf6fe80e
parent ce28d0ca
......@@ -545,7 +545,7 @@ static void txfrm_block_to_raster_xy(BLOCK_SIZE_TYPE plane_bsize,
const int tx_cols = 1 << tx_cols_log2;
const int raster_mb = block >> (tx_size << 1);
*x = (raster_mb & (tx_cols - 1)) << tx_size;
*y = raster_mb >> tx_cols_log2 << tx_size;
*y = (raster_mb >> tx_cols_log2) << tx_size;
}
static void extend_for_intra(MACROBLOCKD* const xd, BLOCK_SIZE_TYPE plane_bsize,
......@@ -585,11 +585,12 @@ static void extend_for_intra(MACROBLOCKD* const xd, BLOCK_SIZE_TYPE plane_bsize,
*d = c;
}
}
static void set_contexts_on_border(MACROBLOCKD *xd, BLOCK_SIZE_TYPE plane_bsize,
int plane, int tx_size_in_blocks,
int eob, int aoff, int loff,
static void set_contexts_on_border(MACROBLOCKD *xd,
struct macroblockd_plane *pd,
BLOCK_SIZE_TYPE plane_bsize,
int tx_size_in_blocks, int has_eob,
int aoff, int loff,
ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) {
struct macroblockd_plane *pd = &xd->plane[plane];
int mi_blocks_wide = num_4x4_blocks_wide_lookup[plane_bsize];
int mi_blocks_high = num_4x4_blocks_high_lookup[plane_bsize];
int above_contexts = tx_size_in_blocks;
......@@ -613,14 +614,29 @@ static void set_contexts_on_border(MACROBLOCKD *xd, BLOCK_SIZE_TYPE plane_bsize,
left_contexts = mi_blocks_high - loff;
for (pt = 0; pt < above_contexts; pt++)
A[pt] = eob > 0;
A[pt] = has_eob;
for (pt = above_contexts; pt < tx_size_in_blocks; pt++)
A[pt] = 0;
for (pt = 0; pt < left_contexts; pt++)
L[pt] = eob > 0;
L[pt] = has_eob;
for (pt = left_contexts; pt < tx_size_in_blocks; pt++)
L[pt] = 0;
}
static void set_contexts(MACROBLOCKD *xd, struct macroblockd_plane *pd,
BLOCK_SIZE_TYPE plane_bsize, 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;
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, pd, plane_bsize, tx_size_in_blocks, has_eob,
aoff, loff, A, L);
} else {
vpx_memset(A, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
vpx_memset(L, has_eob, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
}
}
#endif // VP9_COMMON_VP9_BLOCKD_H_
......@@ -260,26 +260,17 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
const int segment_id = xd->mode_info_context->mbmi.segment_id;
const int ss_txfrm_size = tx_size << 1;
const int seg_eob = get_eob(seg, segment_id, 16 << ss_txfrm_size);
const int off = block >> ss_txfrm_size;
const int mod = b_width_log2(plane_bsize) - tx_size;
const int aoff = (off & ((1 << mod) - 1)) << tx_size;
const int loff = (off >> mod) << tx_size;
const int tx_size_in_blocks = 1 << tx_size;
ENTROPY_CONTEXT *A = pd->above_context + aoff;
ENTROPY_CONTEXT *L = pd->left_context + loff;
const int eob = decode_coefs(&arg->pbi->common, xd, arg->r, block,
pd->plane_type, seg_eob,
BLOCK_OFFSET(pd->qcoeff, block),
tx_size, pd->dequant, A, L);
int aoff, loff, eob;
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
eob = decode_coefs(&arg->pbi->common, xd, arg->r, block,
pd->plane_type, seg_eob, BLOCK_OFFSET(pd->qcoeff, block),
tx_size, pd->dequant,
pd->above_context + aoff, pd->left_context + loff);
set_contexts(xd, pd, plane_bsize, tx_size, eob > 0, aoff, loff);
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, plane_bsize, plane, tx_size_in_blocks, eob,
aoff, loff, A, L);
} else {
int pt;
for (pt = 0; pt < tx_size_in_blocks; pt++)
A[pt] = L[pt] = eob > 0;
}
pd->eobs[block] = eob;
*arg->eobtotal += eob;
}
......
......@@ -103,22 +103,9 @@ static void set_entropy_context_b(int plane, int block,
struct tokenize_b_args* const args = arg;
MACROBLOCKD *const xd = args->xd;
struct macroblockd_plane *pd = &xd->plane[plane];
const int off = block >> (2 * tx_size);
const int mod = b_width_log2(plane_bsize) - tx_size;
const int aoff = (off & ((1 << mod) - 1)) << tx_size;
const int loff = (off >> mod) << tx_size;
ENTROPY_CONTEXT *A = pd->above_context + aoff;
ENTROPY_CONTEXT *L = pd->left_context + loff;
const int eob = pd->eobs[block];
const int tx_size_in_blocks = 1 << tx_size;
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, plane_bsize, plane, tx_size_in_blocks, eob, aoff,
loff, A, L);
} else {
vpx_memset(A, eob > 0, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
vpx_memset(L, eob > 0, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
}
int aoff, loff;
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
set_contexts(xd, pd, plane_bsize, tx_size, pd->eobs[block] > 0, aoff, loff);
}
static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
......@@ -127,7 +114,6 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
VP9_COMP *cpi = args->cpi;
MACROBLOCKD *xd = args->xd;
TOKENEXTRA **tp = args->tp;
const int tx_size_in_blocks = 1 << tx_size;
struct macroblockd_plane *pd = &xd->plane[plane];
MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
int pt; /* near block/prev token context index */
......@@ -136,27 +122,25 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
const int eob = pd->eobs[block];
const PLANE_TYPE type = pd->plane_type;
const int16_t *qcoeff_ptr = BLOCK_OFFSET(pd->qcoeff, block);
const int off = block >> (2 * tx_size);
const int mod = b_width_log2(plane_bsize) - tx_size;
const int aoff = (off & ((1 << mod) - 1)) << tx_size;
const int loff = (off >> mod) << tx_size;
ENTROPY_CONTEXT *A = pd->above_context + aoff;
ENTROPY_CONTEXT *L = pd->left_context + loff;
int seg_eob;
const int segment_id = mbmi->segment_id;
const int16_t *scan, *nb;
vp9_coeff_count *counts;
vp9_coeff_probs_model *coef_probs;
vp9_coeff_count *const counts = cpi->coef_counts[tx_size];
vp9_coeff_probs_model *const coef_probs = cpi->common.fc.coef_probs[tx_size];
const int ref = is_inter_block(mbmi);
ENTROPY_CONTEXT above_ec, left_ec;
uint8_t token_cache[1024];
const uint8_t *band_translate;
ENTROPY_CONTEXT *A, *L;
int aoff, loff;
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &aoff, &loff);
A = pd->above_context + aoff;
L = pd->left_context + loff;
assert((!type && !plane) || (type && plane));
counts = cpi->coef_counts[tx_size];
coef_probs = cpi->common.fc.coef_probs[tx_size];
switch (tx_size) {
default:
case TX_4X4:
above_ec = A[0] != 0;
left_ec = L[0] != 0;
......@@ -185,6 +169,8 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
scan = vp9_default_scan_32x32;
band_translate = vp9_coefband_trans_8x8plus;
break;
default:
assert(!"Invalid transform size");
}
pt = combine_entropy_contexts(above_ec, left_ec);
......@@ -226,13 +212,8 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
} while (c < eob && ++c < seg_eob);
*tp = t;
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, plane_bsize, plane, tx_size_in_blocks, c,
aoff, loff, A, L);
} else {
vpx_memset(A, c > 0, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
vpx_memset(L, c > 0, sizeof(ENTROPY_CONTEXT) * tx_size_in_blocks);
}
set_contexts(xd, pd, plane_bsize, tx_size, c > 0, aoff, loff);
}
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