Passing plane_bsize to foreach_transformed_block_visitor.

Updating all foreach_transformed_block_visitor functions to work with
plane block size instead of general block. Removing a lot of duplicated
code.

Change-Id: I6a9069e27528c611f5a648e1da0c5a5fd17f1bb4
This commit is contained in:
Dmitry Kovalev 2013-08-19 15:47:24 -07:00
parent 2e3478a593
commit 82d4d9a008
8 changed files with 53 additions and 128 deletions

View File

@ -407,7 +407,7 @@ static INLINE int plane_block_height(BLOCK_SIZE_TYPE bsize,
}
typedef void (*foreach_transformed_block_visitor)(int plane, int block,
BLOCK_SIZE_TYPE bsize,
BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size,
void *arg);
@ -422,10 +422,10 @@ static INLINE void foreach_transformed_block_in_plane(
const MB_MODE_INFO* mbmi = &xd->mode_info_context->mbmi;
const TX_SIZE tx_size = plane ? get_uv_tx_size(mbmi)
: mbmi->txfm_size;
const int bw = b_width_log2(bsize) - pd->subsampling_x;
const int bh = b_height_log2(bsize) - pd->subsampling_y;
const int txfrm_size_b = tx_size * 2;
const int step = 1 << txfrm_size_b;
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
const int bw = b_width_log2(plane_bsize);
const int bh = b_height_log2(plane_bsize);
const int step = 1 << (tx_size << 1);
int i;
// If mb_to_right_edge is < 0 we are in a situation in which
@ -452,15 +452,13 @@ static INLINE void foreach_transformed_block_in_plane(
for (r = 0; r < (1 << bh); r += (1 << tx_size)) {
for (c = 0; c < (1 << bw); c += (1 << tx_size)) {
if (r < max_blocks_high && c < max_blocks_wide)
visit(plane, i, bsize, tx_size, arg);
visit(plane, i, plane_bsize, tx_size, arg);
i += step;
}
}
} else {
const int ss_block_size = bw + bh;
assert(txfrm_size_b <= ss_block_size);
for (i = 0; i < (1 << ss_block_size); i += step)
visit(plane, i, bsize, tx_size, arg);
for (i = 0; i < (1 << (bw + bh)); i += step)
visit(plane, i, plane_bsize, tx_size, arg);
}
}
@ -610,14 +608,13 @@ 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 bsize,
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,
ENTROPY_CONTEXT *A, ENTROPY_CONTEXT *L) {
struct macroblockd_plane *pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE bs = get_plane_block_size(bsize, pd);
int mi_blocks_wide = num_4x4_blocks_wide_lookup[bs];
int mi_blocks_high = num_4x4_blocks_high_lookup[bs];
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;
int left_contexts = tx_size_in_blocks;
int pt;

View File

@ -87,11 +87,10 @@ static void init_dequantizer(VP9_COMMON *cm, MACROBLOCKD *xd) {
xd->plane[i].dequant = cm->uv_dequant[xd->q_index];
}
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
MACROBLOCKD* const xd = arg;
struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
int16_t* const qcoeff = BLOCK_OFFSET(pd->qcoeff, block);
const int stride = pd->dst.stride;
const int eob = pd->eobs[block];
@ -124,11 +123,11 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
}
}
static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void decode_block_intra(int plane, int block,
BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
MACROBLOCKD* const xd = arg;
struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
MODE_INFO *const mi = xd->mode_info_context;
const int raster_block = txfrm_block_to_raster_block(plane_bsize, tx_size,
block);
@ -139,7 +138,7 @@ static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
const int mode = (plane == 0) ? mi->mbmi.mode : mi->mbmi.uv_mode;
if (plane == 0 && mi->mbmi.sb_type < BLOCK_8X8) {
assert(bsize == BLOCK_8X8);
assert(plane_bsize == BLOCK_8X8);
b_mode = mi->bmi[raster_block].as_mode;
} else {
b_mode = mode;
@ -156,7 +155,7 @@ static void decode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
if (mi->mbmi.skip_coeff)
return;
decode_block(plane, block, bsize, tx_size, arg);
decode_block(plane, block, plane_bsize, tx_size, arg);
}
static int decode_tokens(VP9D_COMP *pbi, BLOCK_SIZE_TYPE bsize, vp9_reader *r) {

View File

@ -249,10 +249,9 @@ struct decode_block_args {
int *eobtotal;
};
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *argv) {
const struct decode_block_args* const arg = argv;
const int bw = b_width_log2(bsize);
// find the maximum eob for this transform size, adjusted by segment
MACROBLOCKD *xd = &arg->pbi->mb;
@ -262,7 +261,7 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
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 = bw - tx_size - pd->subsampling_x;
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;
@ -274,8 +273,8 @@ static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
tx_size, pd->dequant, A, L);
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, bsize, plane, tx_size_in_blocks, eob, aoff, loff,
A, L);
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++)

View File

@ -14,7 +14,7 @@
#include "vp9/encoder/vp9_onyx_int.h"
int vp9_encode_intra(MACROBLOCK *x, int use_16x16_pred);
void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg);
#endif // VP9_ENCODER_VP9_ENCODEINTRA_H_

View File

@ -142,12 +142,11 @@ static int trellis_get_coeff_context(const int16_t *scan,
}
static void optimize_b(MACROBLOCK *mb,
int plane, int block, BLOCK_SIZE_TYPE bsize,
int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
TX_SIZE tx_size) {
MACROBLOCKD *const xd = &mb->e_mbd;
struct macroblockd_plane *pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
const int ref = is_inter_block(&xd->mode_info_context->mbmi);
vp9_token_state tokens[1025][2];
unsigned best_index[1025][2];
@ -371,24 +370,12 @@ static void optimize_b(MACROBLOCK *mb,
*a = *l = (final_eob > 0);
}
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, MACROBLOCK *mb, struct optimize_ctx *ctx) {
MACROBLOCKD *const xd = &mb->e_mbd;
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize,
&xd->plane[plane]);
int x, y;
// find current entropy context
txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y);
optimize_b(mb, plane, block, bsize, &ctx->ta[plane][x], &ctx->tl[plane][y],
tx_size);
}
static void optimize_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
TX_SIZE tx_size, void *arg) {
const struct encode_b_args* const args = arg;
vp9_optimize_b(plane, block, bsize, tx_size, args->x, args->ctx);
optimize_b(mb, plane, block, plane_bsize,
&ctx->ta[plane][x], &ctx->tl[plane][y], tx_size);
}
void optimize_init_b(int plane, BLOCK_SIZE_TYPE bsize, void *arg) {
@ -432,23 +419,6 @@ void optimize_init_b(int plane, BLOCK_SIZE_TYPE bsize, void *arg) {
}
}
void vp9_optimize_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
struct optimize_ctx ctx;
struct encode_b_args arg = {x, &ctx};
optimize_init_b(0, bsize, &arg);
foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0, optimize_block, &arg);
}
void vp9_optimize_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
struct optimize_ctx ctx;
struct encode_b_args arg = {x, &ctx};
int i;
for (i = 1; i < MAX_MB_PLANE; ++i)
optimize_init_b(i, bsize, &arg);
foreach_transformed_block_uv(&x->e_mbd, bsize, optimize_block, &arg);
}
void vp9_xform_quant(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct encode_b_args* const args = arg;
@ -522,13 +492,12 @@ void vp9_xform_quant(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
}
}
static void encode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void encode_block(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct encode_b_args *const args = arg;
MACROBLOCK *const x = args->x;
MACROBLOCKD *const xd = &x->e_mbd;
struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
const int raster_block = txfrm_block_to_raster_block(plane_bsize, tx_size,
block);
@ -538,7 +507,7 @@ static void encode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
vp9_xform_quant(plane, block, plane_bsize, tx_size, arg);
if (x->optimize)
vp9_optimize_b(plane, block, bsize, tx_size, x, args->ctx);
vp9_optimize_b(plane, block, plane_bsize, tx_size, x, args->ctx);
if (x->skip_encode || pd->eobs[block] == 0)
return;
@ -567,20 +536,6 @@ static void encode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
}
}
void vp9_xform_quant_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct encode_b_args arg = {x, NULL};
foreach_transformed_block_in_plane(xd, bsize, 0, vp9_xform_quant, &arg);
}
void vp9_xform_quant_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD* const xd = &x->e_mbd;
struct encode_b_args arg = {x, NULL};
foreach_transformed_block_uv(xd, bsize, vp9_xform_quant, &arg);
}
void vp9_encode_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
@ -593,21 +548,6 @@ void vp9_encode_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
foreach_transformed_block_in_plane(xd, bsize, 0, encode_block, &arg);
}
void vp9_encode_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
struct encode_b_args arg = {x, &ctx};
vp9_subtract_sbuv(x, bsize);
if (x->optimize) {
int i;
for (i = 1; i < MAX_MB_PLANE; ++i)
optimize_init_b(i, bsize, &arg);
}
foreach_transformed_block_uv(xd, bsize, encode_block, &arg);
}
void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
struct optimize_ctx ctx;
@ -624,7 +564,7 @@ void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize) {
foreach_transformed_block(xd, bsize, encode_block, &arg);
}
void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct encode_b_args* const args = arg;
MACROBLOCK *const x = args->x;
@ -632,7 +572,6 @@ void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
MB_MODE_INFO *mbmi = &xd->mode_info_context->mbmi;
struct macroblock_plane *const p = &x->plane[plane];
struct macroblockd_plane *const pd = &xd->plane[plane];
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize, pd);
int16_t *coeff = BLOCK_OFFSET(p->coeff, block);
int16_t *qcoeff = BLOCK_OFFSET(pd->qcoeff, block);
int16_t *dqcoeff = BLOCK_OFFSET(pd->dqcoeff, block);
@ -646,12 +585,11 @@ void vp9_encode_block_intra(int plane, int block, BLOCK_SIZE_TYPE bsize,
int16_t *src_diff;
uint16_t *eob = &pd->eobs[block];
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0)
extend_for_intra(xd, plane_bsize, plane, block, tx_size);
}
// if (x->optimize)
// vp9_optimize_b(plane, block, bsize, tx_size, x, args->ctx);
// vp9_optimize_b(plane, block, plane_bsize, tx_size, x, args->ctx);
switch (tx_size) {
case TX_32X32:

View File

@ -32,19 +32,11 @@ struct encode_b_args {
struct optimize_ctx *ctx;
};
void vp9_optimize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
TX_SIZE tx_size, MACROBLOCK *x, struct optimize_ctx *ctx);
void vp9_optimize_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_optimize_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_encode_sb(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_encode_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_encode_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_xform_quant(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg);
void vp9_xform_quant_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_xform_quant_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_subtract_sby(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);
void vp9_subtract_sbuv(MACROBLOCK *x, BLOCK_SIZE_TYPE bsize);

View File

@ -610,14 +610,12 @@ static void rate_block(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
args->scan, args->nb);
}
static void block_yrd_txfm(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void block_yrd_txfm(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct rdcost_block_args *args = arg;
MACROBLOCK *const x = args->x;
MACROBLOCKD *const xd = &x->e_mbd;
struct encode_b_args encode_args = {x, NULL};
const BLOCK_SIZE_TYPE plane_bsize = get_plane_block_size(bsize,
&xd->plane[plane]);
int64_t rd1, rd2, rd;
if (args->skip)
@ -634,7 +632,7 @@ static void block_yrd_txfm(int plane, int block, BLOCK_SIZE_TYPE bsize,
}
if (!is_inter_block(&xd->mode_info_context->mbmi))
vp9_encode_block_intra(plane, block, bsize, tx_size, &encode_args);
vp9_encode_block_intra(plane, block, plane_bsize, tx_size, &encode_args);
else
vp9_xform_quant(plane, block, plane_bsize, tx_size, &encode_args);

View File

@ -97,50 +97,51 @@ struct tokenize_b_args {
TX_SIZE tx_size;
};
static void set_entropy_context_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void set_entropy_context_b(int plane, int block,
BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct tokenize_b_args* const args = arg;
MACROBLOCKD *const xd = args->xd;
const int bwl = b_width_log2(bsize);
struct macroblockd_plane *pd = &xd->plane[plane];
const int off = block >> (2 * tx_size);
const int mod = bwl - tx_size - xd->plane[plane].subsampling_x;
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 = xd->plane[plane].above_context + aoff;
ENTROPY_CONTEXT *L = xd->plane[plane].left_context + loff;
const int eob = xd->plane[plane].eobs[block];
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, bsize, plane, tx_size_in_blocks, eob, aoff, loff,
A, L);
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);
}
}
static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE plane_bsize,
TX_SIZE tx_size, void *arg) {
struct tokenize_b_args* const args = arg;
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 */
int c = 0, rc = 0;
TOKENEXTRA *t = *tp; /* store tokens starting here */
const int eob = xd->plane[plane].eobs[block];
const PLANE_TYPE type = xd->plane[plane].plane_type;
const int16_t *qcoeff_ptr = BLOCK_OFFSET(xd->plane[plane].qcoeff, block);
const int bwl = b_width_log2(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 = bwl - tx_size - xd->plane[plane].subsampling_x;
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 = xd->plane[plane].above_context + aoff;
ENTROPY_CONTEXT *L = xd->plane[plane].left_context + loff;
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;
@ -226,8 +227,8 @@ static void tokenize_b(int plane, int block, BLOCK_SIZE_TYPE bsize,
*tp = t;
if (xd->mb_to_right_edge < 0 || xd->mb_to_bottom_edge < 0) {
set_contexts_on_border(xd, bsize, plane, tx_size_in_blocks, c, aoff, loff,
A, L);
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);
@ -240,7 +241,8 @@ struct is_skippable_args {
};
static void is_skippable(int plane, int block,
BLOCK_SIZE_TYPE bsize, TX_SIZE tx_size, void *argv) {
BLOCK_SIZE_TYPE plane_bsize, TX_SIZE tx_size,
void *argv) {
struct is_skippable_args *args = argv;
args->skippable[0] &= (!args->xd->plane[plane].eobs[block]);
}