Commit 1f80a568 authored by John Koleszar's avatar John Koleszar

Make vp9_optimize_sb* common

Unify the various vp9_optimize_sb functions into one that handles all
transform sizes.

Change-Id: I48b642fbfb3e72cc2e0bcf1d0317a80a80547882
parent d068d869
...@@ -1014,6 +1014,74 @@ static uint8_t* raster_block_offset_uint8(MACROBLOCKD *xd, ...@@ -1014,6 +1014,74 @@ static uint8_t* raster_block_offset_uint8(MACROBLOCKD *xd,
return base + raster_block_offset(xd, bsize, plane, block, stride); return base + raster_block_offset(xd, bsize, plane, block, stride);
} }
static int txfrm_block_to_raster_block(MACROBLOCKD *xd,
BLOCK_SIZE_TYPE bsize,
int plane, int block,
int ss_txfrm_size) {
const int bwl = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
const int txwl = ss_txfrm_size / 2;
const int tx_cols_lg2 = bwl - txwl;
const int tx_cols = 1 << tx_cols_lg2;
const int raster_mb = block >> ss_txfrm_size;
const int x = (raster_mb & (tx_cols - 1)) << (txwl);
const int y = raster_mb >> tx_cols_lg2 << (txwl);
return x + (y << bwl);
}
static void txfrm_block_to_raster_xy(MACROBLOCKD *xd,
BLOCK_SIZE_TYPE bsize,
int plane, int block,
int ss_txfrm_size,
int *x, int *y) {
const int bwl = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
const int txwl = ss_txfrm_size / 2;
const int tx_cols_lg2 = bwl - txwl;
const int tx_cols = 1 << tx_cols_lg2;
const int raster_mb = block >> ss_txfrm_size;
*x = (raster_mb & (tx_cols - 1)) << (txwl);
*y = raster_mb >> tx_cols_lg2 << (txwl);
}
static TX_SIZE tx_size_for_plane(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
int plane) {
// TODO(jkoleszar): This duplicates a ton of code, but we're going to be
// moving this to a per-plane lookup shortly, and this will go away then.
if (!plane) {
return xd->mode_info_context->mbmi.txfm_size;
} else {
const int bw = b_width_log2(bsize), bh = b_height_log2(bsize);
#if !CONFIG_SB8X8
const MB_PREDICTION_MODE mode = xd->mode_info_context->mbmi.mode;
const int is_split =
xd->mode_info_context->mbmi.txfm_size == TX_8X8 &&
(mode == I8X8_PRED || mode == SPLITMV);
#endif
// block and transform sizes, in number of 4x4 blocks log 2 ("*_b")
// 4x4=0, 8x8=2, 16x16=4, 32x32=6, 64x64=8
const TX_SIZE tx_size = xd->mode_info_context->mbmi.txfm_size;
const int block_size_b = bw + bh;
const int txfrm_size_b = tx_size * 2;
// subsampled size of the block
const int ss_sum = xd->plane[plane].subsampling_x +
xd->plane[plane].subsampling_y;
const int ss_block_size = block_size_b - ss_sum;
// size of the transform to use. scale the transform down if it's larger
// than the size of the subsampled data, or forced externally by the mb mode
const int ss_max = MAX(xd->plane[plane].subsampling_x,
xd->plane[plane].subsampling_y);
const int ss_txfrm_size = txfrm_size_b > ss_block_size
#if !CONFIG_SB8X8
|| is_split
#endif // !CONFIG_SB8X8
? txfrm_size_b - ss_max * 2
: txfrm_size_b;
return (TX_SIZE)(ss_txfrm_size / 2);
}
}
#if CONFIG_CODE_ZEROGROUP #if CONFIG_CODE_ZEROGROUP
static int get_zpc_used(TX_SIZE tx_size) { static int get_zpc_used(TX_SIZE tx_size) {
return (tx_size >= TX_16X16); return (tx_size >= TX_16X16);
......
...@@ -358,21 +358,6 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd, vp9_reader *r) { ...@@ -358,21 +358,6 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd, vp9_reader *r) {
} }
#endif #endif
static int txfrm_block_to_raster_block(MACROBLOCKD *xd,
BLOCK_SIZE_TYPE bsize,
int plane, int block,
int ss_txfrm_size) {
const int bwl = b_width_log2(bsize) - xd->plane[plane].subsampling_x;
const int txwl = ss_txfrm_size / 2;
const int tx_cols_lg2 = bwl - txwl;
const int tx_cols = 1 << tx_cols_lg2;
const int raster_mb = block >> ss_txfrm_size;
const int x = (raster_mb & (tx_cols - 1)) << (txwl);
const int y = raster_mb >> tx_cols_lg2 << (txwl);
return x + (y << bwl);
}
static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize, static void decode_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
int ss_txfrm_size, void *arg) { int ss_txfrm_size, void *arg) {
MACROBLOCKD* const xd = arg; MACROBLOCKD* const xd = arg;
......
...@@ -2443,7 +2443,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, ...@@ -2443,7 +2443,7 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
vp9_subtract_sbuv(x, bsize); vp9_subtract_sbuv(x, bsize);
vp9_transform_sbuv_4x4(x, bsize); vp9_transform_sbuv_4x4(x, bsize);
vp9_quantize_sbuv_4x4(x, bsize); vp9_quantize_sbuv_4x4(x, bsize);
vp9_optimize_sbuv_4x4(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
vp9_inverse_transform_sbuv_4x4(xd, bsize); vp9_inverse_transform_sbuv_4x4(xd, bsize);
vp9_recon_sbuv(xd, bsize); vp9_recon_sbuv(xd, bsize);
...@@ -2507,11 +2507,11 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, ...@@ -2507,11 +2507,11 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
vp9_quantize_sbuv_16x16(x, bsize); vp9_quantize_sbuv_16x16(x, bsize);
} }
if (x->optimize) { if (x->optimize) {
vp9_optimize_sby_32x32(cm, x, bsize); vp9_optimize_sby(cm, x, bsize);
if (bsize == BLOCK_SIZE_SB64X64) if (bsize == BLOCK_SIZE_SB64X64)
vp9_optimize_sbuv_32x32(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
else else
vp9_optimize_sbuv_16x16(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
} }
vp9_inverse_transform_sby_32x32(xd, bsize); vp9_inverse_transform_sby_32x32(xd, bsize);
if (bsize == BLOCK_SIZE_SB64X64) if (bsize == BLOCK_SIZE_SB64X64)
...@@ -2530,11 +2530,11 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, ...@@ -2530,11 +2530,11 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
vp9_quantize_sbuv_8x8(x, bsize); vp9_quantize_sbuv_8x8(x, bsize);
} }
if (x->optimize) { if (x->optimize) {
vp9_optimize_sby_16x16(cm, x, bsize); vp9_optimize_sby(cm, x, bsize);
if (bsize >= BLOCK_SIZE_SB32X32) if (bsize >= BLOCK_SIZE_SB32X32)
vp9_optimize_sbuv_16x16(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
else else
vp9_optimize_sbuv_8x8(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
} }
vp9_inverse_transform_sby_16x16(xd, bsize); vp9_inverse_transform_sby_16x16(xd, bsize);
if (bsize >= BLOCK_SIZE_SB32X32) if (bsize >= BLOCK_SIZE_SB32X32)
...@@ -2546,19 +2546,19 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, ...@@ -2546,19 +2546,19 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
vp9_transform_sby_8x8(x, bsize); vp9_transform_sby_8x8(x, bsize);
vp9_quantize_sby_8x8(x, bsize); vp9_quantize_sby_8x8(x, bsize);
if (x->optimize) if (x->optimize)
vp9_optimize_sby_8x8(cm, x, bsize); vp9_optimize_sby(cm, x, bsize);
vp9_inverse_transform_sby_8x8(xd, bsize); vp9_inverse_transform_sby_8x8(xd, bsize);
if (bsize >= BLOCK_SIZE_MB16X16) { if (bsize >= BLOCK_SIZE_MB16X16) {
vp9_transform_sbuv_8x8(x, bsize); vp9_transform_sbuv_8x8(x, bsize);
vp9_quantize_sbuv_8x8(x, bsize); vp9_quantize_sbuv_8x8(x, bsize);
if (x->optimize) if (x->optimize)
vp9_optimize_sbuv_8x8(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
vp9_inverse_transform_sbuv_8x8(xd, bsize); vp9_inverse_transform_sbuv_8x8(xd, bsize);
} else { } else {
vp9_transform_sbuv_4x4(x, bsize); vp9_transform_sbuv_4x4(x, bsize);
vp9_quantize_sbuv_4x4(x, bsize); vp9_quantize_sbuv_4x4(x, bsize);
if (x->optimize) if (x->optimize)
vp9_optimize_sbuv_4x4(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
vp9_inverse_transform_sbuv_4x4(xd, bsize); vp9_inverse_transform_sbuv_4x4(xd, bsize);
} }
break; break;
...@@ -2568,8 +2568,8 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, ...@@ -2568,8 +2568,8 @@ static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t,
vp9_quantize_sby_4x4(x, bsize); vp9_quantize_sby_4x4(x, bsize);
vp9_quantize_sbuv_4x4(x, bsize); vp9_quantize_sbuv_4x4(x, bsize);
if (x->optimize) { if (x->optimize) {
vp9_optimize_sby_4x4(cm, x, bsize); vp9_optimize_sby(cm, x, bsize);
vp9_optimize_sbuv_4x4(cm, x, bsize); vp9_optimize_sbuv(cm, x, bsize);
} }
vp9_inverse_transform_sby_4x4(xd, bsize); vp9_inverse_transform_sby_4x4(xd, bsize);
vp9_inverse_transform_sbuv_4x4(xd, bsize); vp9_inverse_transform_sbuv_4x4(xd, bsize);
......
...@@ -114,21 +114,21 @@ void vp9_encode_intra16x16mby(VP9_COMMON *const cm, MACROBLOCK *x) { ...@@ -114,21 +114,21 @@ void vp9_encode_intra16x16mby(VP9_COMMON *const cm, MACROBLOCK *x) {
vp9_transform_sby_16x16(x, BLOCK_SIZE_MB16X16); vp9_transform_sby_16x16(x, BLOCK_SIZE_MB16X16);
vp9_quantize_sby_16x16(x, BLOCK_SIZE_MB16X16); vp9_quantize_sby_16x16(x, BLOCK_SIZE_MB16X16);
if (x->optimize) if (x->optimize)
vp9_optimize_sby_16x16(cm, x, BLOCK_SIZE_MB16X16); vp9_optimize_sby(cm, x, BLOCK_SIZE_MB16X16);
vp9_inverse_transform_sby_16x16(xd, BLOCK_SIZE_MB16X16); vp9_inverse_transform_sby_16x16(xd, BLOCK_SIZE_MB16X16);
break; break;
case TX_8X8: case TX_8X8:
vp9_transform_sby_8x8(x, BLOCK_SIZE_MB16X16); vp9_transform_sby_8x8(x, BLOCK_SIZE_MB16X16);
vp9_quantize_sby_8x8(x, BLOCK_SIZE_MB16X16); vp9_quantize_sby_8x8(x, BLOCK_SIZE_MB16X16);
if (x->optimize) if (x->optimize)
vp9_optimize_sby_8x8(cm, x, BLOCK_SIZE_MB16X16); vp9_optimize_sby(cm, x, BLOCK_SIZE_MB16X16);
vp9_inverse_transform_sby_8x8(xd, BLOCK_SIZE_MB16X16); vp9_inverse_transform_sby_8x8(xd, BLOCK_SIZE_MB16X16);
break; break;
default: default:
vp9_transform_sby_4x4(x, BLOCK_SIZE_MB16X16); vp9_transform_sby_4x4(x, BLOCK_SIZE_MB16X16);
vp9_quantize_sby_4x4(x, BLOCK_SIZE_MB16X16); vp9_quantize_sby_4x4(x, BLOCK_SIZE_MB16X16);
if (x->optimize) if (x->optimize)
vp9_optimize_sby_4x4(cm, x, BLOCK_SIZE_MB16X16); vp9_optimize_sby(cm, x, BLOCK_SIZE_MB16X16);
vp9_inverse_transform_sby_4x4(xd, BLOCK_SIZE_MB16X16); vp9_inverse_transform_sby_4x4(xd, BLOCK_SIZE_MB16X16);
break; break;
} }
...@@ -148,14 +148,14 @@ void vp9_encode_intra16x16mbuv(VP9_COMMON *const cm, MACROBLOCK *x) { ...@@ -148,14 +148,14 @@ void vp9_encode_intra16x16mbuv(VP9_COMMON *const cm, MACROBLOCK *x) {
vp9_transform_sbuv_4x4(x, BLOCK_SIZE_MB16X16); vp9_transform_sbuv_4x4(x, BLOCK_SIZE_MB16X16);
vp9_quantize_sbuv_4x4(x, BLOCK_SIZE_MB16X16); vp9_quantize_sbuv_4x4(x, BLOCK_SIZE_MB16X16);
if (x->optimize) if (x->optimize)
vp9_optimize_sbuv_4x4(cm, x, BLOCK_SIZE_MB16X16); vp9_optimize_sbuv(cm, x, BLOCK_SIZE_MB16X16);
vp9_inverse_transform_sbuv_4x4(xd, BLOCK_SIZE_MB16X16); vp9_inverse_transform_sbuv_4x4(xd, BLOCK_SIZE_MB16X16);
break; break;
default: // 16x16 or 8x8 default: // 16x16 or 8x8
vp9_transform_sbuv_8x8(x, BLOCK_SIZE_MB16X16); vp9_transform_sbuv_8x8(x, BLOCK_SIZE_MB16X16);
vp9_quantize_sbuv_8x8(x, BLOCK_SIZE_MB16X16); vp9_quantize_sbuv_8x8(x, BLOCK_SIZE_MB16X16);
if (x->optimize) if (x->optimize)
vp9_optimize_sbuv_8x8(cm, x, BLOCK_SIZE_MB16X16); vp9_optimize_sbuv(cm, x, BLOCK_SIZE_MB16X16);
vp9_inverse_transform_sbuv_8x8(xd, BLOCK_SIZE_MB16X16); vp9_inverse_transform_sbuv_8x8(xd, BLOCK_SIZE_MB16X16);
break; break;
} }
......
...@@ -249,57 +249,53 @@ static int trellis_get_coeff_context(const int *scan, ...@@ -249,57 +249,53 @@ static int trellis_get_coeff_context(const int *scan,
return pt; return pt;
} }
static void optimize_b(VP9_COMMON *const cm, static void optimize_b(VP9_COMMON *const cm, MACROBLOCK *mb,
MACROBLOCK *mb, int ib, PLANE_TYPE type, int plane, int block, BLOCK_SIZE_TYPE bsize,
const int16_t *dequant_ptr,
ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l, ENTROPY_CONTEXT *a, ENTROPY_CONTEXT *l,
int tx_size, int y_blocks) { TX_SIZE tx_size) {
const int ref = mb->e_mbd.mode_info_context->mbmi.ref_frame != INTRA_FRAME; const int ref = mb->e_mbd.mode_info_context->mbmi.ref_frame != INTRA_FRAME;
MACROBLOCKD *const xd = &mb->e_mbd; MACROBLOCKD *const xd = &mb->e_mbd;
vp9_token_state tokens[1025][2]; vp9_token_state tokens[1025][2];
unsigned best_index[1025][2]; unsigned best_index[1025][2];
const struct plane_block_idx pb_idx = plane_block_idx(y_blocks, ib); const int16_t *coeff_ptr = BLOCK_OFFSET(mb->plane[plane].coeff,
const int16_t *coeff_ptr = BLOCK_OFFSET(mb->plane[pb_idx.plane].coeff, block, 16);
pb_idx.block, 16);
int16_t *qcoeff_ptr; int16_t *qcoeff_ptr;
int16_t *dqcoeff_ptr; int16_t *dqcoeff_ptr;
int eob = xd->plane[pb_idx.plane].eobs[pb_idx.block], final_eob, sz = 0; int eob = xd->plane[plane].eobs[block], final_eob, sz = 0;
const int i0 = 0; const int i0 = 0;
int rc, x, next, i; int rc, x, next, i;
int64_t rdmult, rddiv, rd_cost0, rd_cost1; int64_t rdmult, rddiv, rd_cost0, rd_cost1;
int rate0, rate1, error0, error1, t0, t1; int rate0, rate1, error0, error1, t0, t1;
int best, band, pt; int best, band, pt;
PLANE_TYPE type = xd->plane[plane].plane_type;
int err_mult = plane_rd_mult[type]; int err_mult = plane_rd_mult[type];
int default_eob, pad; int default_eob, pad;
int const *scan, *nb; int const *scan, *nb;
const int mul = 1 + (tx_size == TX_32X32); const int mul = 1 + (tx_size == TX_32X32);
uint8_t token_cache[1024]; uint8_t token_cache[1024];
const int ib = txfrm_block_to_raster_block(xd, bsize, plane,
block, 2 * tx_size);
const int16_t *dequant_ptr = xd->plane[plane].dequant;
assert((!type && !pb_idx.plane) || (type && pb_idx.plane)); assert((!type && !plane) || (type && plane));
dqcoeff_ptr = BLOCK_OFFSET(xd->plane[pb_idx.plane].dqcoeff, pb_idx.block, 16); dqcoeff_ptr = BLOCK_OFFSET(xd->plane[plane].dqcoeff, block, 16);
qcoeff_ptr = BLOCK_OFFSET(xd->plane[pb_idx.plane].qcoeff, pb_idx.block, 16); qcoeff_ptr = BLOCK_OFFSET(xd->plane[plane].qcoeff, block, 16);
switch (tx_size) { switch (tx_size) {
default: default:
case TX_4X4: { case TX_4X4: {
const TX_TYPE tx_type = get_tx_type_4x4(xd, ib); const TX_TYPE tx_type = plane == 0 ? get_tx_type_4x4(xd, ib) : DCT_DCT;
default_eob = 16; default_eob = 16;
scan = get_scan_4x4(tx_type); scan = get_scan_4x4(tx_type);
break; break;
} }
case TX_8X8: { case TX_8X8: {
const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; const TX_TYPE tx_type = plane == 0 ? get_tx_type_8x8(xd, ib) : DCT_DCT;
const int sz = 1 + b_width_log2(sb_type);
const int x = ib & ((1 << sz) - 1), y = ib - x;
const TX_TYPE tx_type = get_tx_type_8x8(xd, y + (x >> 1));
scan = get_scan_8x8(tx_type); scan = get_scan_8x8(tx_type);
default_eob = 64; default_eob = 64;
break; break;
} }
case TX_16X16: { case TX_16X16: {
const BLOCK_SIZE_TYPE sb_type = xd->mode_info_context->mbmi.sb_type; const TX_TYPE tx_type = plane == 0 ? get_tx_type_16x16(xd, ib) : DCT_DCT;
const int sz = 2 + b_width_log2(sb_type);
const int x = ib & ((1 << sz) - 1), y = ib - x;
const TX_TYPE tx_type = get_tx_type_16x16(xd, y + (x >> 2));
scan = get_scan_16x16(tx_type); scan = get_scan_16x16(tx_type);
default_eob = 256; default_eob = 256;
break; break;
...@@ -480,201 +476,81 @@ static void optimize_b(VP9_COMMON *const cm, ...@@ -480,201 +476,81 @@ static void optimize_b(VP9_COMMON *const cm,
} }
final_eob++; final_eob++;
xd->plane[pb_idx.plane].eobs[pb_idx.block] = final_eob; xd->plane[plane].eobs[block] = final_eob;
*a = *l = (final_eob > 0); *a = *l = (final_eob > 0);
} }
void vp9_optimize_sby_32x32(VP9_COMMON *const cm, MACROBLOCK *x, struct optimize_ctx {
BLOCK_SIZE_TYPE bsize) { ENTROPY_CONTEXT ta[MAX_MB_PLANE][16];
MACROBLOCKD *const xd = &x->e_mbd; ENTROPY_CONTEXT tl[MAX_MB_PLANE][16];
ENTROPY_CONTEXT *a = xd->plane[0].above_context; };
ENTROPY_CONTEXT *l = xd->plane[0].left_context;
const int bwl = b_width_log2(bsize) - 3, bw = 1 << bwl;
const int bh = 1 << (b_height_log2(bsize) - 3);
ENTROPY_CONTEXT ta[2], tl[2];
int n;
for (n = 0; n < bw; n++, a += 8)
ta[n] = (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7]) != 0;
for (n = 0; n < bh; n++, l += 8)
tl[n] = (l[0] + l[1] + l[2] + l[3] + l[4] + l[5] + l[6] + l[7]) != 0;
for (n = 0; n < bw * bh; n++) {
const int x_idx = n & (bw - 1), y_idx = n >> bwl;
optimize_b(cm, x, n * 64, PLANE_TYPE_Y_WITH_DC, x->e_mbd.plane[0].dequant,
ta + x_idx, tl + y_idx, TX_32X32, 64 * bw * bh);
}
}
void vp9_optimize_sby_16x16(VP9_COMMON *const cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
ENTROPY_CONTEXT *a = xd->plane[0].above_context;
ENTROPY_CONTEXT *l = xd->plane[0].left_context;
const int bwl = b_width_log2(bsize) - 2, bw = 1 << bwl;
const int bh = 1 << (b_height_log2(bsize) - 2);
ENTROPY_CONTEXT ta[4], tl[4];
int n;
for (n = 0; n < bw; n++, a += 4)
ta[n] = (a[0] + a[1] + a[2] + a[3]) != 0;
for (n = 0; n < bh; n++, l += 4)
tl[n] = (l[0] + l[1] + l[2] + l[3]) != 0;
for (n = 0; n < bw * bh; n++) {
const int x_idx = n & (bw - 1), y_idx = n >> bwl;
optimize_b(cm, x, n * 16, PLANE_TYPE_Y_WITH_DC, x->e_mbd.plane[0].dequant,
ta + x_idx, tl + y_idx, TX_16X16, 16 * bw * bh);
}
}
void vp9_optimize_sby_8x8(VP9_COMMON *const cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
ENTROPY_CONTEXT *a = xd->plane[0].above_context;
ENTROPY_CONTEXT *l = xd->plane[0].left_context;
const int bwl = b_width_log2(bsize) - 1, bw = 1 << bwl;
const int bh = 1 << (b_height_log2(bsize) - 1);
ENTROPY_CONTEXT ta[8], tl[8];
int n;
for (n = 0; n < bw; n++, a += 2)
ta[n] = (a[0] + a[1]) != 0;
for (n = 0; n < bh; n++, l += 2)
tl[n] = (l[0] + l[1]) != 0;
for (n = 0; n < bw * bh; n++) {
const int x_idx = n & (bw - 1), y_idx = n >> bwl;
optimize_b(cm, x, n * 4, PLANE_TYPE_Y_WITH_DC, x->e_mbd.plane[0].dequant,
ta + x_idx, tl + y_idx, TX_8X8, 4 * bw * bh);
}
}
void vp9_optimize_sby_4x4(VP9_COMMON *const cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd;
int bwl = b_width_log2(bsize), bw = 1 << bwl;
int bh = 1 << b_height_log2(bsize);
ENTROPY_CONTEXT ta[16], tl[16];
int n;
vpx_memcpy(ta, xd->plane[0].above_context, sizeof(ENTROPY_CONTEXT) * bw);
vpx_memcpy(tl, xd->plane[0].left_context, sizeof(ENTROPY_CONTEXT) * bh);
for (n = 0; n < bw * bh; n++) { struct optimize_block_args {
const int x_idx = n & (bw - 1), y_idx = n >> bwl; VP9_COMMON *cm;
MACROBLOCK *x;
struct optimize_ctx *ctx;
};
optimize_b(cm, x, n, PLANE_TYPE_Y_WITH_DC, x->e_mbd.plane[0].dequant, static void optimize_block(int plane, int block, BLOCK_SIZE_TYPE bsize,
ta + x_idx, tl + y_idx, TX_4X4, bh * bw); int ss_txfrm_size, void *arg) {
} const struct optimize_block_args* const args = arg;
} MACROBLOCKD* const xd = &args->x->e_mbd;
int x, y;
void vp9_optimize_sbuv_32x32(VP9_COMMON *const cm, MACROBLOCK *x, // find current entropy context
BLOCK_SIZE_TYPE bsize) { txfrm_block_to_raster_xy(xd, bsize, plane, block, ss_txfrm_size, &x, &y);
MACROBLOCKD *const xd = &x->e_mbd;
int b;
assert(bsize == BLOCK_SIZE_SB64X64); optimize_b(args->cm, args->x, plane, block, bsize,
for (b = 256; b < 384; b += 64) { &args->ctx->ta[plane][x], &args->ctx->tl[plane][y],
const int plane = 1 + (b >= 320); ss_txfrm_size / 2);
ENTROPY_CONTEXT *a = xd->plane[plane].above_context;
ENTROPY_CONTEXT *l = xd->plane[plane].left_context;
ENTROPY_CONTEXT a_ec, l_ec;
a_ec = (a[0] + a[1] + a[2] + a[3] + a[4] + a[5] + a[6] + a[7]) != 0;
l_ec = (l[0] + l[1] + l[2] + l[3] + l[4] + l[5] + l[6] + l[7]) != 0;
optimize_b(cm, x, b, PLANE_TYPE_UV, x->e_mbd.plane[plane].dequant,
&a_ec, &l_ec, TX_32X32, 256);
}
} }
void vp9_optimize_sbuv_16x16(VP9_COMMON *const cm, MACROBLOCK *x, void vp9_optimize_init(MACROBLOCKD *xd, BLOCK_SIZE_TYPE bsize,
BLOCK_SIZE_TYPE bsize) { struct optimize_ctx *ctx) {
MACROBLOCKD *const xd = &x->e_mbd; int p;
const int bwl = b_width_log2(bsize) - 2, bhl = b_height_log2(bsize) - 2;
const int bw = 1 << (bwl - 1); for (p = 0; p < MAX_MB_PLANE; p++) {
const int bh = 1 << (bhl - 1); const struct macroblockd_plane* const plane = &xd->plane[p];
int uvoff = 16 << (bwl + bhl); const int bwl = b_width_log2(bsize) - plane->subsampling_x;
int plane, n; const int bhl = b_height_log2(bsize) - plane->subsampling_y;
const TX_SIZE tx_size = tx_size_for_plane(xd, bsize, p);
for (plane = 1; plane < MAX_MB_PLANE; plane++) { int i, j;
ENTROPY_CONTEXT ta[2], *a = xd->plane[plane].above_context;
ENTROPY_CONTEXT tl[2], *l = xd->plane[plane].left_context; for (i = 0; i < 1 << bwl; i += 1 << tx_size) {
int c = 0;
for (n = 0; n < bw; n++, a += 4) ctx->ta[p][i] = 0;
ta[n] = (a[0] + a[1] + a[2] + a[3]) != 0; for (j = 0; j < 1 << tx_size && !c; j++) {
for (n = 0; n < bh; n++, l += 4) c = ctx->ta[p][i] |= plane->above_context[i + j];
tl[n] = (l[0] + l[1] + l[2] + l[3]) != 0; }
}
for (n = 0; n < bw * bh; n++) { for (i = 0; i < 1 << bhl; i += 1 << tx_size) {
const int x_idx = n & (bw - 1), y_idx = n >> (bwl - 1); int c = 0;
optimize_b(cm, x, uvoff + n * 16, PLANE_TYPE_UV, ctx->tl[p][i] = 0;
x->e_mbd.plane[plane].dequant, for (j = 0; j < 1 << tx_size && !c; j++) {
&ta[x_idx], &tl[y_idx], c = ctx->tl[p][i] |= plane->left_context[i + j];
TX_16X16, bh * bw * 64); }
} }
uvoff = (uvoff * 5) >> 2; // switch u -> v
} }
} }
void vp9_optimize_sbuv_8x8(VP9_COMMON *const cm, MACROBLOCK *x, void vp9_optimize_sby(VP9_COMMON *const cm, MACROBLOCK *x,
BLOCK_SIZE_TYPE bsize) { BLOCK_SIZE_TYPE bsize) {
MACROBLOCKD *const xd = &x->e_mbd; struct optimize_ctx ctx;
const int bwl = b_width_log2(bsize) - 1, bhl = b_height_log2(bsize) - 1; struct optimize_block_args arg = {cm, x, &ctx};
const int bw = 1 << (bwl - 1); vp9_optimize_init(&x->e_mbd, bsize, &ctx);
const int bh = 1 << (bhl - 1); foreach_transformed_block_in_plane(&x->e_mbd, bsize, 0,
int uvoff = 4 << (bwl + bhl); #if !CONFIG_SB8X8
int plane, n; 0,
#endif
for (plane = 1; plane < MAX_MB_PLANE; plane++) { optimize_block, &arg);
ENTROPY_CONTEXT ta[4], *a = xd->plane[plane].above_context;