Commit 899f0fc1 authored by Yaowu Xu's avatar Yaowu Xu

clean up tokenize_b() and stuff_b()

Change-Id: I0c1be01aae933243311ad321b6c456adaec1a0f5
parent ab480ced
......@@ -12,18 +12,19 @@
#include "vp9/common/vp9_blockd.h"
#include "vpx_mem/vpx_mem.h"
const unsigned char vp9_block2left[25] = {
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8
};
const unsigned char vp9_block2above[25] = {
0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8
const unsigned char vp9_block2left[TX_SIZE_MAX_SB][25] = {
{0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8},
{0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 6, 6, 6, 6, 8},
#if CONFIG_TX32X32 && CONFIG_SUPERBLOCKS
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 6, 6, 6, 6, 8}
#endif
};
const unsigned char vp9_block2left_8x8[25] = {
0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8
const unsigned char vp9_block2above[TX_SIZE_MAX_SB][25] = {
{0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 4, 5, 6, 7, 6, 7, 8},
{0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 6, 6, 6, 6, 8},
#if CONFIG_TX32X32 && CONFIG_SUPERBLOCKS
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 6, 6, 6, 6, 8}
#endif
};
const unsigned char vp9_block2above_8x8[25] = {
0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 2, 2, 2, 2, 4, 4, 4, 4, 6, 6, 6, 6, 8
};
......@@ -66,11 +66,6 @@ typedef struct {
ENTROPY_CONTEXT y2;
} ENTROPY_CONTEXT_PLANES;
extern const unsigned char vp9_block2left[25];
extern const unsigned char vp9_block2above[25];
extern const unsigned char vp9_block2left_8x8[25];
extern const unsigned char vp9_block2above_8x8[25];
#define VP9_COMBINEENTROPYCONTEXTS( Dest, A, B) \
Dest = ((A)!=0) + ((B)!=0);
......@@ -119,18 +114,17 @@ typedef enum {
SEG_LVL_EOB = 4, // EOB end stop marker.
SEG_LVL_TRANSFORM = 5, // Block transform size.
SEG_LVL_MAX = 6 // Number of MB level features supported
} SEG_LVL_FEATURES;
// Segment level features.
typedef enum {
TX_4X4, // 4x4 dct transform
TX_8X8, // 8x8 dct transform
TX_16X16, // 16x16 dct transform
TX_SIZE_MAX_MB, // Number of transforms available to MBs
TX_4X4 = 0, // 4x4 dct transform
TX_8X8 = 1, // 8x8 dct transform
TX_16X16 = 2, // 16x16 dct transform
TX_SIZE_MAX_MB = 3, // Number of different transforms available
#if CONFIG_TX32X32 && CONFIG_SUPERBLOCKS
TX_32X32 = TX_SIZE_MAX_MB, // 32x32 dct transform
TX_SIZE_MAX_SB, // Number of transforms available to SBs
TX_32X32 = TX_SIZE_MAX_MB, // 32x32 dct transform
TX_SIZE_MAX_SB, // Number of transforms available to SBs
#else
TX_SIZE_MAX_SB = TX_SIZE_MAX_MB,
#endif
......@@ -508,6 +502,9 @@ static TX_TYPE txfm_map(B_PREDICTION_MODE bmode) {
return tx_type;
}
extern const unsigned char vp9_block2left[TX_SIZE_MAX_SB][25];
extern const unsigned char vp9_block2above[TX_SIZE_MAX_SB][25];
#define USE_ADST_FOR_I16X16_8X8 0
#define USE_ADST_FOR_I16X16_4X4 0
#define USE_ADST_FOR_I8X8_4X4 1
......
......@@ -326,8 +326,8 @@ static int vp9_decode_mb_tokens_16x16(VP9D_COMP* const pbi,
// 8x8 chroma blocks
seg_eob = get_eob(xd, segment_id, 64);
for (i = 16; i < 24; i += 4) {
ENTROPY_CONTEXT* const a = A + vp9_block2above_8x8[i];
ENTROPY_CONTEXT* const l = L + vp9_block2left_8x8[i];
ENTROPY_CONTEXT* const a = A + vp9_block2above[TX_8X8][i];
ENTROPY_CONTEXT* const l = L + vp9_block2left[TX_8X8][i];
#if CONFIG_CNVCONTEXT
above_ec = (a[0] + a[1]) != 0;
left_ec = (l[0] + l[1]) != 0;
......@@ -363,8 +363,8 @@ static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
int has_2nd_order = get_2nd_order_usage(xd);
// 2nd order DC block
if (has_2nd_order) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[24];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[24];
ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][24];
ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][24];
eobs[24] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_Y2,
DCT_DCT, get_eob(xd, segment_id, 4),
......@@ -382,8 +382,8 @@ static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
// luma blocks
seg_eob = get_eob(xd, segment_id, 64);
for (i = 0; i < 16; i += 4) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[i];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[i];
ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][i];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
......@@ -408,8 +408,8 @@ static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
// use 4x4 transform for U, V components in I8X8/splitmv prediction mode
seg_eob = get_eob(xd, segment_id, 16);
for (i = 16; i < 24; i++) {
ENTROPY_CONTEXT *const a = A + vp9_block2above[i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[i];
ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_4X4][i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_4X4][i];
eobs[i] = c = decode_coefs(pbi, xd, bc, a, l, PLANE_TYPE_UV,
DCT_DCT, seg_eob, xd->block[i].qcoeff,
......@@ -418,8 +418,8 @@ static int vp9_decode_mb_tokens_8x8(VP9D_COMP* const pbi,
}
} else {
for (i = 16; i < 24; i += 4) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[i];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[i];
ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_8X8][i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_8X8][i];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
......@@ -448,8 +448,8 @@ static int decode_coefs_4x4(VP9D_COMP *dx, MACROBLOCKD *xd,
TX_TYPE tx_type, const int *scan) {
ENTROPY_CONTEXT *const A = (ENTROPY_CONTEXT *)xd->above_context;
ENTROPY_CONTEXT *const L = (ENTROPY_CONTEXT *)xd->left_context;
ENTROPY_CONTEXT *const a = A + vp9_block2above[i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[i];
ENTROPY_CONTEXT *const a = A + vp9_block2above[TX_4X4][i];
ENTROPY_CONTEXT *const l = L + vp9_block2left[TX_4X4][i];
unsigned short *const eobs = xd->eobs;
int c;
......
......@@ -671,15 +671,18 @@ void vp9_optimize_mby_4x4(MACROBLOCK *x) {
for (b = 0; b < 16; b++) {
optimize_b(x, b, type,
ta + vp9_block2above[b], tl + vp9_block2left[b], TX_4X4);
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b], TX_4X4);
}
if (has_2nd_order) {
b = 24;
optimize_b(x, b, PLANE_TYPE_Y2,
ta + vp9_block2above[b], tl + vp9_block2left[b], TX_4X4);
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b], TX_4X4);
check_reset_2nd_coeffs(&x->e_mbd,
ta + vp9_block2above[b], tl + vp9_block2left[b]);
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b]);
}
}
......@@ -700,7 +703,8 @@ void vp9_optimize_mbuv_4x4(MACROBLOCK *x) {
for (b = 16; b < 24; b++) {
optimize_b(x, b, PLANE_TYPE_UV,
ta + vp9_block2above[b], tl + vp9_block2left[b], TX_4X4);
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b], TX_4X4);
}
}
......@@ -727,8 +731,8 @@ void vp9_optimize_mby_8x8(MACROBLOCK *x) {
tl = (ENTROPY_CONTEXT *)&t_left;
type = has_2nd_order ? PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC;
for (b = 0; b < 16; b += 4) {
ENTROPY_CONTEXT *const a = ta + vp9_block2above_8x8[b];
ENTROPY_CONTEXT *const l = tl + vp9_block2left_8x8[b];
ENTROPY_CONTEXT *const a = ta + vp9_block2above[TX_8X8][b];
ENTROPY_CONTEXT *const l = tl + vp9_block2left[TX_8X8][b];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
......@@ -744,8 +748,8 @@ void vp9_optimize_mby_8x8(MACROBLOCK *x) {
// 8x8 always have 2nd order block
if (has_2nd_order) {
check_reset_8x8_2nd_coeffs(&x->e_mbd,
ta + vp9_block2above_8x8[24],
tl + vp9_block2left_8x8[24]);
ta + vp9_block2above[TX_8X8][24],
tl + vp9_block2left[TX_8X8][24]);
}
}
......@@ -758,8 +762,8 @@ void vp9_optimize_mbuv_8x8(MACROBLOCK *x) {
return;
for (b = 16; b < 24; b += 4) {
ENTROPY_CONTEXT *const a = ta + vp9_block2above_8x8[b];
ENTROPY_CONTEXT *const l = tl + vp9_block2left_8x8[b];
ENTROPY_CONTEXT *const a = ta + vp9_block2above[TX_8X8][b];
ENTROPY_CONTEXT *const l = tl + vp9_block2left[TX_8X8][b];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
......
......@@ -681,12 +681,14 @@ static int rdcost_mby_4x4(MACROBLOCK *mb, int has_2nd_order, int backup) {
cost += cost_coeffs(mb, xd->block + b,
(has_2nd_order ?
PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC),
ta + vp9_block2above[b], tl + vp9_block2left[b],
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b],
TX_4X4);
if (has_2nd_order)
cost += cost_coeffs(mb, xd->block + 24, PLANE_TYPE_Y2,
ta + vp9_block2above[24], tl + vp9_block2left[24],
ta + vp9_block2above[TX_4X4][24],
tl + vp9_block2left[TX_4X4][24],
TX_4X4);
return cost;
......@@ -739,12 +741,14 @@ static int rdcost_mby_8x8(MACROBLOCK *mb, int has_2nd_order, int backup) {
cost += cost_coeffs(mb, xd->block + b,
(has_2nd_order ?
PLANE_TYPE_Y_NO_DC : PLANE_TYPE_Y_WITH_DC),
ta + vp9_block2above_8x8[b], tl + vp9_block2left_8x8[b],
ta + vp9_block2above[TX_8X8][b],
tl + vp9_block2left[TX_8X8][b],
TX_8X8);
if (has_2nd_order)
cost += cost_coeffs_2x2(mb, xd->block + 24, PLANE_TYPE_Y2,
ta + vp9_block2above[24], tl + vp9_block2left[24]);
ta + vp9_block2above[TX_8X8][24],
tl + vp9_block2left[TX_8X8][24]);
return cost;
}
......@@ -1294,8 +1298,8 @@ static int64_t rd_pick_intra4x4mby_modes(VP9_COMP *cpi, MACROBLOCK *mb, int *Rat
#if CONFIG_COMP_INTRA_PRED
& best_second_mode, allow_comp,
#endif
bmode_costs, ta + vp9_block2above[i],
tl + vp9_block2left[i], &r, &ry, &d);
bmode_costs, ta + vp9_block2above[TX_4X4][i],
tl + vp9_block2left[TX_4X4][i], &r, &ry, &d);
cost += r;
distortion += d;
......@@ -1527,8 +1531,8 @@ static int64_t rd_pick_intra8x8block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
// compute quantization mse of 8x8 block
distortion = vp9_block_error_c((x->block + idx)->coeff,
(xd->block + idx)->dqcoeff, 64);
ta0 = a[vp9_block2above_8x8[idx]];
tl0 = l[vp9_block2left_8x8[idx]];
ta0 = a[vp9_block2above[TX_8X8][idx]];
tl0 = l[vp9_block2left[TX_8X8][idx]];
rate_t = cost_coeffs(x, xd->block + idx, PLANE_TYPE_Y_WITH_DC,
&ta0, &tl0, TX_8X8);
......@@ -1540,10 +1544,10 @@ static int64_t rd_pick_intra8x8block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
static const int iblock[4] = {0, 1, 4, 5};
TX_TYPE tx_type;
int i;
ta0 = a[vp9_block2above[ib]];
ta1 = a[vp9_block2above[ib + 1]];
tl0 = l[vp9_block2left[ib]];
tl1 = l[vp9_block2left[ib + 4]];
ta0 = a[vp9_block2above[TX_4X4][ib]];
ta1 = a[vp9_block2above[TX_4X4][ib + 1]];
tl0 = l[vp9_block2left[TX_4X4][ib]];
tl1 = l[vp9_block2left[TX_4X4][ib + 4]];
distortion = 0;
rate_t = 0;
for (i = 0; i < 4; ++i) {
......@@ -1596,15 +1600,15 @@ static int64_t rd_pick_intra8x8block(VP9_COMP *cpi, MACROBLOCK *x, int ib,
vp9_encode_intra8x8(x, ib);
if (xd->mode_info_context->mbmi.txfm_size == TX_8X8) {
a[vp9_block2above_8x8[idx]] = besta0;
a[vp9_block2above_8x8[idx] + 1] = besta1;
l[vp9_block2left_8x8[idx]] = bestl0;
l[vp9_block2left_8x8[idx] + 1] = bestl1;
a[vp9_block2above[TX_8X8][idx]] = besta0;
a[vp9_block2above[TX_8X8][idx] + 1] = besta1;
l[vp9_block2left[TX_8X8][idx]] = bestl0;
l[vp9_block2left[TX_8X8][idx] + 1] = bestl1;
} else {
a[vp9_block2above[ib]] = besta0;
a[vp9_block2above[ib + 1]] = besta1;
l[vp9_block2left[ib]] = bestl0;
l[vp9_block2left[ib + 4]] = bestl1;
a[vp9_block2above[TX_4X4][ib]] = besta0;
a[vp9_block2above[TX_4X4][ib + 1]] = besta1;
l[vp9_block2left[TX_4X4][ib]] = bestl0;
l[vp9_block2left[TX_4X4][ib + 4]] = bestl1;
}
return best_rd;
......@@ -1681,7 +1685,8 @@ static int rd_cost_mbuv_4x4(MACROBLOCK *mb, int backup) {
for (b = 16; b < 24; b++)
cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV,
ta + vp9_block2above[b], tl + vp9_block2left[b],
ta + vp9_block2above[TX_4X4][b],
tl + vp9_block2left[TX_4X4][b],
TX_4X4);
return cost;
......@@ -1721,8 +1726,8 @@ static int rd_cost_mbuv_8x8(MACROBLOCK *mb, int backup) {
for (b = 16; b < 24; b += 4)
cost += cost_coeffs(mb, xd->block + b, PLANE_TYPE_UV,
ta + vp9_block2above_8x8[b],
tl + vp9_block2left_8x8[b], TX_8X8);
ta + vp9_block2above[TX_8X8][b],
tl + vp9_block2left[TX_8X8][b], TX_8X8);
return cost;
}
......@@ -2244,8 +2249,8 @@ static int64_t encode_inter_mb_segment(MACROBLOCK *x,
thisdistortion = vp9_block_error(be->coeff, bd->dqcoeff, 16);
*distortion += thisdistortion;
*labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
ta + vp9_block2above[i],
tl + vp9_block2left[i], TX_4X4);
ta + vp9_block2above[TX_4X4][i],
tl + vp9_block2left[TX_4X4][i], TX_4X4);
}
}
*distortion >>= 2;
......@@ -2296,8 +2301,9 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64);
otherdist += thisdistortion;
othercost += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
tacp + vp9_block2above_8x8[idx],
tlcp + vp9_block2left_8x8[idx], TX_8X8);
tacp + vp9_block2above[TX_8X8][idx],
tlcp + vp9_block2left[TX_8X8][idx],
TX_8X8);
}
for (j = 0; j < 4; j += 2) {
bd = &xd->block[ib + iblock[j]];
......@@ -2307,13 +2313,13 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32);
*distortion += thisdistortion;
*labelyrate += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
ta + vp9_block2above[ib + iblock[j]],
tl + vp9_block2left[ib + iblock[j]],
TX_4X4);
ta + vp9_block2above[TX_4X4][ib + iblock[j]],
tl + vp9_block2left[TX_4X4][ib + iblock[j]],
TX_4X4);
*labelyrate += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
ta + vp9_block2above[ib + iblock[j] + 1],
tl + vp9_block2left[ib + iblock[j]],
TX_4X4);
ta + vp9_block2above[TX_4X4][ib + iblock[j] + 1],
tl + vp9_block2left[TX_4X4][ib + iblock[j]],
TX_4X4);
}
} else /* 8x8 */ {
if (otherrd) {
......@@ -2325,13 +2331,13 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
thisdistortion = vp9_block_error_c(be->coeff, bd->dqcoeff, 32);
otherdist += thisdistortion;
othercost += cost_coeffs(x, bd, PLANE_TYPE_Y_WITH_DC,
tacp + vp9_block2above[ib + iblock[j]],
tlcp + vp9_block2left[ib + iblock[j]],
TX_4X4);
tacp + vp9_block2above[TX_4X4][ib + iblock[j]],
tlcp + vp9_block2left[TX_4X4][ib + iblock[j]],
TX_4X4);
othercost += cost_coeffs(x, bd + 1, PLANE_TYPE_Y_WITH_DC,
tacp + vp9_block2above[ib + iblock[j] + 1],
tlcp + vp9_block2left[ib + iblock[j]],
TX_4X4);
tacp + vp9_block2above[TX_4X4][ib + iblock[j] + 1],
tlcp + vp9_block2left[TX_4X4][ib + iblock[j]],
TX_4X4);
}
}
x->vp9_short_fdct8x8(be->src_diff, be2->coeff, 32);
......@@ -2339,8 +2345,8 @@ static int64_t encode_inter_mb_segment_8x8(MACROBLOCK *x,
thisdistortion = vp9_block_error_c(be2->coeff, bd2->dqcoeff, 64);
*distortion += thisdistortion;
*labelyrate += cost_coeffs(x, bd2, PLANE_TYPE_Y_WITH_DC,
ta + vp9_block2above_8x8[idx],
tl + vp9_block2left_8x8[idx], TX_8X8);
ta + vp9_block2above[TX_8X8][idx],
tl + vp9_block2left[TX_8X8][idx], TX_8X8);
}
}
}
......
......@@ -103,30 +103,33 @@ static void fill_value_tokens() {
vp9_dct_value_tokens_ptr = dct_value_tokens + DCT_MAX_VALUE;
vp9_dct_value_cost_ptr = dct_value_cost + DCT_MAX_VALUE;
}
static void tokenize_b(VP9_COMP *cpi,
MACROBLOCKD *xd,
const BLOCKD * const b,
const int ib,
TOKENEXTRA **tp,
PLANE_TYPE type,
ENTROPY_CONTEXT *a,
ENTROPY_CONTEXT *l,
TX_SIZE tx_size,
int dry_run) {
int pt; /* near block/prev token context index */
int c = (type == PLANE_TYPE_Y_NO_DC) ? 1 : 0;
const BLOCKD * const b = xd->block + ib;
int eob = b->eob; /* one beyond last nonzero coeff */
TOKENEXTRA *t = *tp; /* store tokens starting here */
const short *qcoeff_ptr = b->qcoeff;
int seg_eob;
int segment_id = xd->mode_info_context->mbmi.segment_id;
const int segment_id = xd->mode_info_context->mbmi.segment_id;
const int *bands, *scan;
vp9_coeff_count *counts;
vp9_coeff_probs *probs;
const TX_TYPE tx_type = (type == PLANE_TYPE_Y_WITH_DC) ?
get_tx_type(xd, b) : DCT_DCT;
VP9_COMBINEENTROPYCONTEXTS(pt, *a, *l);
ENTROPY_CONTEXT *const a = (ENTROPY_CONTEXT *)xd->above_context +
vp9_block2above[tx_size][ib];
ENTROPY_CONTEXT *const l = (ENTROPY_CONTEXT *)xd->left_context +
vp9_block2left[tx_size][ib];
ENTROPY_CONTEXT a_ec = *a, l_ec = *l;
switch (tx_size) {
default:
case TX_4X4:
......@@ -152,6 +155,10 @@ static void tokenize_b(VP9_COMP *cpi,
bands = vp9_coef_bands;
scan = vp9_default_zig_zag1d;
} else {
#if CONFIG_CNVCONTEXT
a_ec = (a[0] + a[1]) != 0;
l_ec = (l[0] + l[1]) != 0;
#endif
seg_eob = 64;
bands = vp9_coef_bands_8x8;
scan = vp9_default_zig_zag1d_8x8;
......@@ -165,6 +172,10 @@ static void tokenize_b(VP9_COMP *cpi,
}
break;
case TX_16X16:
#if CONFIG_CNVCONTEXT
a_ec = (a[0] + a[1] + a[2] + a[3]) != 0;
l_ec = (l[0] + l[1] + l[2] + l[3]) != 0;
#endif
seg_eob = 256;
bands = vp9_coef_bands_16x16;
scan = vp9_default_zig_zag1d_16x16;
......@@ -194,6 +205,8 @@ static void tokenize_b(VP9_COMP *cpi,
#endif
}
VP9_COMBINEENTROPYCONTEXTS(pt, a_ec, l_ec);
if (vp9_segfeature_active(xd, segment_id, SEG_LVL_EOB))
seg_eob = vp9_get_segdata(xd, segment_id, SEG_LVL_EOB);
......@@ -204,7 +217,6 @@ static void tokenize_b(VP9_COMP *cpi,
if (c < eob) {
const int rc = scan[c];
const int v = qcoeff_ptr[rc];
assert(-DCT_MAX_VALUE <= v && v < DCT_MAX_VALUE);
t->Extra = vp9_dct_value_tokens_ptr[v].Extra;
......@@ -226,7 +238,17 @@ static void tokenize_b(VP9_COMP *cpi,
} while (c < eob && ++c < seg_eob);
*tp = t;
*a = *l = (c > !type); /* 0 <-> all coeff data is zero */
a_ec = l_ec = (c > !type); /* 0 <-> all coeff data is zero */
a[0] = a_ec;
l[0] = l_ec;
if (tx_size == TX_8X8 && type != PLANE_TYPE_Y2) {
a[1] = a_ec;
l[1] = l_ec;
} else if (tx_size == TX_16X16) {
a[1] = a[2] = a[3] = a_ec;
l[1] = l[2] = l[3] = l_ec;
}
}
int vp9_mby_is_skippable_4x4(MACROBLOCKD *xd, int has_2nd_order) {
......@@ -380,8 +402,6 @@ void vp9_tokenize_mb(VP9_COMP *cpi,
int tx_size = xd->mode_info_context->mbmi.txfm_size;
int mb_skip_context = vp9_get_pred_context(&cpi->common, xd, PRED_MBSKIP);
TOKENEXTRA *t_backup = *t;
ENTROPY_CONTEXT * A = (ENTROPY_CONTEXT *) xd->above_context;
ENTROPY_CONTEXT * L = (ENTROPY_CONTEXT *) xd->left_context;
// If the MB is going to be skipped because of a segment level flag
// exclude this from the skip count stats used to calculate the
......@@ -425,6 +445,7 @@ void vp9_tokenize_mb(VP9_COMP *cpi,
} else {
vp9_reset_mb_tokens_context(xd);
}
if (dry_run)
*t = t_backup;
return;
......@@ -434,9 +455,7 @@ void vp9_tokenize_mb(VP9_COMP *cpi,
cpi->skip_false_count[mb_skip_context] += skip_inc;
if (has_2nd_order) {
tokenize_b(cpi, xd, xd->block + 24, t, PLANE_TYPE_Y2,
A + vp9_block2above_8x8[24], L + vp9_block2left_8x8[24],
tx_size, dry_run);
tokenize_b(cpi, xd, 24, t, PLANE_TYPE_Y2, tx_size, dry_run);
plane_type = PLANE_TYPE_Y_NO_DC;
} else {
xd->above_context->y2 = 0;
......@@ -445,85 +464,29 @@ void vp9_tokenize_mb(VP9_COMP *cpi,
}
if (tx_size == TX_16X16) {
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (A[0] + A[1] + A[2] + A[3]) != 0;
ENTROPY_CONTEXT left_ec = (L[0] + L[1] + L[2] + L[3]) != 0;
#else
ENTROPY_CONTEXT above_ec = A[0];
ENTROPY_CONTEXT left_ec = L[0];
#endif
tokenize_b(cpi, xd, xd->block, t, PLANE_TYPE_Y_WITH_DC,
&above_ec, &left_ec, TX_16X16, dry_run);
A[1] = A[2] = A[3] = A[0] = above_ec;
L[1] = L[2] = L[3] = L[0] = left_ec;
tokenize_b(cpi, xd, 0, t, PLANE_TYPE_Y_WITH_DC, TX_16X16, dry_run);
for (b = 16; b < 24; b += 4) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[b];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[b];
#if CONFIG_CNVCONTEXT
above_ec = (a[0] + a[1]) != 0;
left_ec = (l[0] + l[1]) != 0;
#else
above_ec = a[0];
left_ec = l[0];
#endif
tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
&above_ec, &left_ec, TX_8X8, dry_run);
a[1] = a[0] = above_ec;
l[1] = l[0] = left_ec;
tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_8X8, dry_run);
}
A[8] = 0;
L[8] = 0;
} else if (tx_size == TX_8X8) {
for (b = 0; b < 16; b += 4) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[b];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[b];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
#else
ENTROPY_CONTEXT above_ec = a[0];
ENTROPY_CONTEXT left_ec = l[0];
#endif
tokenize_b(cpi, xd, xd->block + b, t, plane_type,
&above_ec, &left_ec, TX_8X8, dry_run);
a[1] = a[0] = above_ec;
l[1] = l[0] = left_ec;
tokenize_b(cpi, xd, b, t, plane_type, TX_8X8, dry_run);
}
if (xd->mode_info_context->mbmi.mode == I8X8_PRED ||
xd->mode_info_context->mbmi.mode == SPLITMV) {
for (b = 16; b < 24; b++) {
tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
A + vp9_block2above[b], L + vp9_block2left[b],
TX_4X4, dry_run);
tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_4X4, dry_run);
}
} else {
for (b = 16; b < 24; b += 4) {
ENTROPY_CONTEXT *const a = A + vp9_block2above_8x8[b];
ENTROPY_CONTEXT *const l = L + vp9_block2left_8x8[b];
#if CONFIG_CNVCONTEXT
ENTROPY_CONTEXT above_ec = (a[0] + a[1]) != 0;
ENTROPY_CONTEXT left_ec = (l[0] + l[1]) != 0;
#else
ENTROPY_CONTEXT above_ec = a[0];
ENTROPY_CONTEXT left_ec = l[0];
#endif
tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
&above_ec, &left_ec, TX_8X8, dry_run);
a[1] = a[0] = above_ec;
l[1] = l[0] = left_ec;
tokenize_b(cpi, xd, b, t, PLANE_TYPE_UV, TX_8X8, dry_run);
}
}
} else {
for (b = 0; b < 16; b++) {
tokenize_b(cpi, xd, xd->block + b, t, plane_type,
A + vp9_block2above[b], L + vp9_block2left[b],
TX_4X4, dry_run);
}
for (b = 16; b < 24; b++) {
tokenize_b(cpi, xd, xd->block + b, t, PLANE_TYPE_UV,
A + vp9_block2above[b], L + vp9_block2left[b],
TX_4X4, dry_run);
for (b = 0; b < 24; b++) {
if (b >= 16)
plane_type = PLANE_TYPE_UV;
tokenize_b(cpi, xd, b, t, plane_type, TX_4X4, dry_run);
}
}
if