Commit 2891d70b authored by Dmitry Kovalev's avatar Dmitry Kovalev
Browse files

Code cleanup.

Removing redundant code, introducing new functions for better
decomposition, adding 'clamp' function to vp9_common.h.

Change-Id: Ic3b8ca13bbc38f60f0c9c43910b5802005e31aaf
parent 9b4095c5
...@@ -51,4 +51,8 @@ static INLINE uint8_t clip_pixel(int val) { ...@@ -51,4 +51,8 @@ static INLINE uint8_t clip_pixel(int val) {
return (val > 255) ? 255u : (val < 0) ? 0u : val; return (val > 255) ? 255u : (val < 0) ? 0u : val;
} }
static INLINE int clamp(int value, int low, int high) {
return value < low ? low : (value > high ? high : value);
}
#endif // VP9_COMMON_VP9_COMMON_H_ #endif // VP9_COMMON_VP9_COMMON_H_
...@@ -95,50 +95,46 @@ void vp9_init_de_quantizer(VP9D_COMP *pbi) { ...@@ -95,50 +95,46 @@ void vp9_init_de_quantizer(VP9D_COMP *pbi) {
} }
} }
static void mb_init_dequantizer(VP9D_COMP *pbi, MACROBLOCKD *xd) { static int get_qindex(MACROBLOCKD *mb, int segment_id, int base_qindex) {
// Set the Q baseline allowing for any segment level adjustment
if (vp9_segfeature_active(mb, segment_id, SEG_LVL_ALT_Q)) {
if (mb->mb_segment_abs_delta == SEGMENT_ABSDATA)
return vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q); // Abs Value
else
return clamp(base_qindex + vp9_get_segdata(mb, segment_id, SEG_LVL_ALT_Q),
0, MAXQ); // Delta Value
} else {
return base_qindex;
}
}
static void mb_init_dequantizer(VP9D_COMP *pbi, MACROBLOCKD *mb) {
int i; int i;
int qindex;
VP9_COMMON *const pc = &pbi->common;
int segment_id = xd->mode_info_context->mbmi.segment_id;
// Set the Q baseline allowing for any segment level adjustment VP9_COMMON *const pc = &pbi->common;
if (vp9_segfeature_active(xd, segment_id, SEG_LVL_ALT_Q)) { int segment_id = mb->mode_info_context->mbmi.segment_id;
if (xd->mb_segment_abs_delta == SEGMENT_ABSDATA) int qindex = get_qindex(mb, segment_id, pc->base_qindex);
/* Abs Value */ mb->q_index = qindex;
qindex = vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q);
else {
/* Delta Value */
qindex = pc->base_qindex +
vp9_get_segdata(xd, segment_id, SEG_LVL_ALT_Q);
/* Clamp to valid range */
qindex = (qindex >= 0) ? ((qindex <= MAXQ) ? qindex : MAXQ) : 0;
}
} else
qindex = pc->base_qindex;
xd->q_index = qindex; for (i = 0; i < 16; i++)
mb->block[i].dequant = pc->Y1dequant[qindex];
/* Set up the block level dequant pointers */ for (i = 16; i < 24; i++)
for (i = 0; i < 16; i++) { mb->block[i].dequant = pc->UVdequant[qindex];
xd->block[i].dequant = pc->Y1dequant[qindex];
}
xd->inv_txm4x4_1 = vp9_short_idct4x4llm_1; if (mb->lossless) {
xd->inv_txm4x4 = vp9_short_idct4x4llm;
xd->itxm_add = vp9_dequant_idct_add;
xd->itxm_add_y_block = vp9_dequant_idct_add_y_block;
xd->itxm_add_uv_block = vp9_dequant_idct_add_uv_block;
if (xd->lossless) {
assert(qindex == 0); assert(qindex == 0);
xd->inv_txm4x4_1 = vp9_short_inv_walsh4x4_1_x8; mb->inv_txm4x4_1 = vp9_short_inv_walsh4x4_1_x8;
xd->inv_txm4x4 = vp9_short_inv_walsh4x4_x8; mb->inv_txm4x4 = vp9_short_inv_walsh4x4_x8;
xd->itxm_add = vp9_dequant_idct_add_lossless_c; mb->itxm_add = vp9_dequant_idct_add_lossless_c;
xd->itxm_add_y_block = vp9_dequant_idct_add_y_block_lossless_c; mb->itxm_add_y_block = vp9_dequant_idct_add_y_block_lossless_c;
xd->itxm_add_uv_block = vp9_dequant_idct_add_uv_block_lossless_c; mb->itxm_add_uv_block = vp9_dequant_idct_add_uv_block_lossless_c;
} } else {
mb->inv_txm4x4_1 = vp9_short_idct4x4llm_1;
for (i = 16; i < 24; i++) { mb->inv_txm4x4 = vp9_short_idct4x4llm;
xd->block[i].dequant = pc->UVdequant[qindex]; mb->itxm_add = vp9_dequant_idct_add;
mb->itxm_add_y_block = vp9_dequant_idct_add_y_block;
mb->itxm_add_uv_block = vp9_dequant_idct_add_uv_block;
} }
} }
...@@ -333,10 +329,8 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -333,10 +329,8 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
int ib = vp9_i8x8_block[i]; int ib = vp9_i8x8_block[i];
const int iblock[4] = {0, 1, 4, 5}; const int iblock[4] = {0, 1, 4, 5};
int j; int j;
int i8x8mode; BLOCKD *b = &xd->block[ib];
BLOCKD *b; int i8x8mode = b->bmi.as_mode.first;
b = &xd->block[ib];
i8x8mode = b->bmi.as_mode.first;
vp9_intra8x8_predict(xd, b, i8x8mode, b->predictor); vp9_intra8x8_predict(xd, b, i8x8mode, b->predictor);
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
b = &xd->block[ib + iblock[j]]; b = &xd->block[ib + iblock[j]];
...@@ -363,9 +357,8 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -363,9 +357,8 @@ static void decode_4x4(VP9D_COMP *pbi, MACROBLOCKD *xd,
} }
} else if (mode == B_PRED) { } else if (mode == B_PRED) {
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
int b_mode;
BLOCKD *b = &xd->block[i]; BLOCKD *b = &xd->block[i];
b_mode = xd->mode_info_context->bmi[i].as_mode.first; int b_mode = xd->mode_info_context->bmi[i].as_mode.first;
#if CONFIG_NEWBINTRAMODES #if CONFIG_NEWBINTRAMODES
xd->mode_info_context->bmi[i].as_mode.context = b->bmi.as_mode.context = xd->mode_info_context->bmi[i].as_mode.context = b->bmi.as_mode.context =
vp9_find_bpred_context(b); vp9_find_bpred_context(b);
...@@ -503,10 +496,11 @@ static void decode_superblock64(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -503,10 +496,11 @@ static void decode_superblock64(VP9D_COMP *pbi, MACROBLOCKD *xd,
case TX_32X32: case TX_32X32:
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
const int x_idx = n & 1, y_idx = n >> 1; const int x_idx = n & 1, y_idx = n >> 1;
const int y_offset = x_idx * 32 + y_idx * xd->dst.y_stride * 32;
vp9_dequant_idct_add_32x32(xd->qcoeff + n * 1024, vp9_dequant_idct_add_32x32(xd->qcoeff + n * 1024,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + x_idx * 32 + y_idx * xd->dst.y_stride * 32, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + x_idx * 32 + y_idx * xd->dst.y_stride * 32, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 64]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 64]);
} }
vp9_dequant_idct_add_32x32(xd->qcoeff + 4096, vp9_dequant_idct_add_32x32(xd->qcoeff + 4096,
...@@ -519,96 +513,103 @@ static void decode_superblock64(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -519,96 +513,103 @@ static void decode_superblock64(VP9D_COMP *pbi, MACROBLOCKD *xd,
case TX_16X16: case TX_16X16:
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
const int x_idx = n & 3, y_idx = n >> 2; const int x_idx = n & 3, y_idx = n >> 2;
const int y_offset = y_idx * 16 * xd->dst.y_stride + x_idx * 16;
const TX_TYPE tx_type = get_tx_type_16x16(xd, const TX_TYPE tx_type = get_tx_type_16x16(xd,
(y_idx * 16 + x_idx) * 4); (y_idx * 16 + x_idx) * 4);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
vp9_dequant_idct_add_16x16(xd->qcoeff + n * 256, vp9_dequant_idct_add_16x16(xd->qcoeff + n * 256,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]);
} else { } else {
vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->qcoeff + n * 256, vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->qcoeff + n * 256,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]);
} }
} }
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
const int x_idx = n & 1, y_idx = n >> 1; const int x_idx = n & 1, y_idx = n >> 1;
const int uv_offset = y_idx * 16 * xd->dst.uv_stride + x_idx * 16;
vp9_dequant_idct_add_16x16(xd->qcoeff + 4096 + n * 256, vp9_dequant_idct_add_16x16(xd->qcoeff + 4096 + n * 256,
xd->block[16].dequant, xd->block[16].dequant,
xd->dst.u_buffer + y_idx * 16 * xd->dst.uv_stride + x_idx * 16, xd->dst.u_buffer + uv_offset,
xd->dst.u_buffer + y_idx * 16 * xd->dst.uv_stride + x_idx * 16, xd->dst.u_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n * 16]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n * 16]);
vp9_dequant_idct_add_16x16(xd->qcoeff + 4096 + 1024 + n * 256, vp9_dequant_idct_add_16x16(xd->qcoeff + 4096 + 1024 + n * 256,
xd->block[20].dequant, xd->block[20].dequant,
xd->dst.v_buffer + y_idx * 16 * xd->dst.uv_stride + x_idx * 16, xd->dst.v_buffer + uv_offset,
xd->dst.v_buffer + y_idx * 16 * xd->dst.uv_stride + x_idx * 16, xd->dst.v_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n * 16]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n * 16]);
} }
break; break;
case TX_8X8: case TX_8X8:
for (n = 0; n < 64; n++) { for (n = 0; n < 64; n++) {
const int x_idx = n & 7, y_idx = n >> 3; const int x_idx = n & 7, y_idx = n >> 3;
const int y_offset = y_idx * 8 * xd->dst.y_stride + x_idx * 8;
const TX_TYPE tx_type = get_tx_type_8x8(xd, (y_idx * 16 + x_idx) * 2); const TX_TYPE tx_type = get_tx_type_8x8(xd, (y_idx * 16 + x_idx) * 2);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]);
} else { } else {
vp9_ht_dequant_idct_add_8x8_c(tx_type, xd->qcoeff + n * 64, vp9_ht_dequant_idct_add_8x8_c(tx_type, xd->qcoeff + n * 64,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]);
} }
} }
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
const int x_idx = n & 3, y_idx = n >> 2; const int x_idx = n & 3, y_idx = n >> 2;
const int uv_offset = y_idx * 8 * xd->dst.uv_stride + x_idx * 8;
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 4096, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 4096,
xd->block[16].dequant, xd->block[16].dequant,
xd->dst.u_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.u_buffer + uv_offset,
xd->dst.u_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.u_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n * 4]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n * 4]);
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 4096 + 1024, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 4096 + 1024,
xd->block[20].dequant, xd->block[20].dequant,
xd->dst.v_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.v_buffer + uv_offset,
xd->dst.v_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.v_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n * 4]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n * 4]);
} }
break; break;
case TX_4X4: case TX_4X4:
for (n = 0; n < 256; n++) { for (n = 0; n < 256; n++) {
const int x_idx = n & 15, y_idx = n >> 4; const int x_idx = n & 15, y_idx = n >> 4;
const int y_offset = y_idx * 4 * xd->dst.y_stride + x_idx * 4;
const TX_TYPE tx_type = get_tx_type_4x4(xd, y_idx * 16 + x_idx); const TX_TYPE tx_type = get_tx_type_4x4(xd, y_idx * 16 + x_idx);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
xd->itxm_add(xd->qcoeff + n * 16, xd->block[0].dequant, xd->itxm_add(xd->qcoeff + n * 16, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]);
} else { } else {
vp9_ht_dequant_idct_add_c(tx_type, xd->qcoeff + n * 16, vp9_ht_dequant_idct_add_c(tx_type, xd->qcoeff + n * 16,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]);
} }
} }
for (n = 0; n < 64; n++) { for (n = 0; n < 64; n++) {
const int x_idx = n & 7, y_idx = n >> 3; const int x_idx = n & 7, y_idx = n >> 3;
const int uv_offset = y_idx * 4 * xd->dst.uv_stride + x_idx * 4;
xd->itxm_add(xd->qcoeff + 4096 + n * 16, xd->itxm_add(xd->qcoeff + 4096 + n * 16,
xd->block[16].dequant, xd->block[16].dequant,
xd->dst.u_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.u_buffer + uv_offset,
xd->dst.u_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.u_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[256 + n]);
xd->itxm_add(xd->qcoeff + 4096 + 1024 + n * 16, xd->itxm_add(xd->qcoeff + 4096 + 1024 + n * 16,
xd->block[20].dequant, xd->block[20].dequant,
xd->dst.v_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.v_buffer + uv_offset,
xd->dst.v_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.v_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[320 + n]);
} }
break; break;
...@@ -681,19 +682,20 @@ static void decode_superblock32(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -681,19 +682,20 @@ static void decode_superblock32(VP9D_COMP *pbi, MACROBLOCKD *xd,
case TX_16X16: case TX_16X16:
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
const int x_idx = n & 1, y_idx = n >> 1; const int x_idx = n & 1, y_idx = n >> 1;
const int y_offset = y_idx * 16 * xd->dst.y_stride + x_idx * 16;
const TX_TYPE tx_type = get_tx_type_16x16(xd, const TX_TYPE tx_type = get_tx_type_16x16(xd,
(y_idx * 8 + x_idx) * 4); (y_idx * 8 + x_idx) * 4);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
vp9_dequant_idct_add_16x16( vp9_dequant_idct_add_16x16(
xd->qcoeff + n * 256, xd->block[0].dequant, xd->qcoeff + n * 256, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]);
} else { } else {
vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->qcoeff + n * 256, vp9_ht_dequant_idct_add_16x16_c(tx_type, xd->qcoeff + n * 256,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 16 * xd->dst.y_stride + x_idx * 16, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 16]);
} }
} }
...@@ -706,63 +708,69 @@ static void decode_superblock32(VP9D_COMP *pbi, MACROBLOCKD *xd, ...@@ -706,63 +708,69 @@ static void decode_superblock32(VP9D_COMP *pbi, MACROBLOCKD *xd,
case TX_8X8: case TX_8X8:
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
const int x_idx = n & 3, y_idx = n >> 2; const int x_idx = n & 3, y_idx = n >> 2;
const int y_offset = y_idx * 8 * xd->dst.y_stride + x_idx * 8;
const TX_TYPE tx_type = get_tx_type_8x8(xd, (y_idx * 8 + x_idx) * 2); const TX_TYPE tx_type = get_tx_type_8x8(xd, (y_idx * 8 + x_idx) * 2);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]);
} else { } else {
vp9_ht_dequant_idct_add_8x8_c(tx_type, xd->qcoeff + n * 64, vp9_ht_dequant_idct_add_8x8_c(tx_type, xd->qcoeff + n * 64,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 8 * xd->dst.y_stride + x_idx * 8, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n * 4]);
} }
} }
for (n = 0; n < 4; n++) { for (n = 0; n < 4; n++) {
const int x_idx = n & 1, y_idx = n >> 1; const int x_idx = n & 1, y_idx = n >> 1;
const int uv_offset = y_idx * 8 * xd->dst.uv_stride + x_idx * 8;
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 1024, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 1024,
xd->block[16].dequant, xd->block[16].dequant,
xd->dst.u_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.u_buffer + uv_offset,
xd->dst.u_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.u_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[64 + n * 4]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[64 + n * 4]);
vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 1280, vp9_dequant_idct_add_8x8_c(xd->qcoeff + n * 64 + 1280,
xd->block[20].dequant, xd->block[20].dequant,
xd->dst.v_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.v_buffer + uv_offset,
xd->dst.v_buffer + y_idx * 8 * xd->dst.uv_stride + x_idx * 8, xd->dst.v_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[80 + n * 4]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[80 + n * 4]);
} }
break; break;
case TX_4X4: case TX_4X4:
for (n = 0; n < 64; n++) { for (n = 0; n < 64; n++) {
const int x_idx = n & 7, y_idx = n >> 3; const int x_idx = n & 7, y_idx = n >> 3;
const int y_offset = y_idx * 4 * xd->dst.y_stride + x_idx * 4;
const TX_TYPE tx_type = get_tx_type_4x4(xd, y_idx * 8 + x_idx); const TX_TYPE tx_type = get_tx_type_4x4(xd, y_idx * 8 + x_idx);
if (tx_type == DCT_DCT) { if (tx_type == DCT_DCT) {
xd->itxm_add(xd->qcoeff + n * 16, xd->block[0].dequant, xd->itxm_add(xd->qcoeff + n * 16, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]);
} else { } else {
vp9_ht_dequant_idct_add_c(tx_type, xd->qcoeff + n * 16, vp9_ht_dequant_idct_add_c(tx_type, xd->qcoeff + n * 16,
xd->block[0].dequant, xd->block[0].dequant,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_buffer + y_idx * 4 * xd->dst.y_stride + x_idx * 4, xd->dst.y_buffer + y_offset,
xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]); xd->dst.y_stride, xd->dst.y_stride, xd->eobs[n]);
} }
} }
for (n = 0; n < 16; n++) { for (n = 0; n < 16; n++) {
const int x_idx = n & 3, y_idx = n >> 2; const int x_idx = n & 3, y_idx = n >> 2;
const int uv_offset = y_idx * 4 * xd->dst.uv_stride + x_idx * 4;
xd->itxm_add(xd->qcoeff + 1024 + n * 16, xd->itxm_add(xd->qcoeff + 1024 + n * 16,
xd->block[16].dequant, xd->block[16].dequant,
xd->dst.u_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.u_buffer + uv_offset,
xd->dst.u_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.u_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[64 + n]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[64 + n]);
xd->itxm_add(xd->qcoeff + 1280 + n * 16, xd->itxm_add(xd->qcoeff + 1280 + n * 16,
xd->block[20].dequant, xd->block[20].dequant,
xd->dst.v_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.v_buffer + uv_offset,
xd->dst.v_buffer + y_idx * 4 * xd->dst.uv_stride + x_idx * 4, xd->dst.v_buffer + uv_offset,
xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[80 + n]); xd->dst.uv_stride, xd->dst.uv_stride, xd->eobs[80 + n]);
} }
break; break;
...@@ -1047,13 +1055,10 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc, ...@@ -1047,13 +1055,10 @@ static void decode_sb_row(VP9D_COMP *pbi, VP9_COMMON *pc,
} }
static unsigned int read_partition_size(const unsigned char *cx_size) { static unsigned int read_partition_size(const unsigned char *cx_size) {
const unsigned int size = return cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16);
cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16);
return size;
} }
static int read_is_valid(const unsigned char *start, static int read_is_valid(const unsigned char *start, size_t len,
size_t len,
const unsigned char *end) { const unsigned char *end) {
return start + len > start && start + len <= end; return start + len > start && start + len <= end;
} }
...@@ -1062,22 +1067,15 @@ static int read_is_valid(const unsigned char *start, ...@@ -1062,22 +1067,15 @@ static int read_is_valid(const unsigned char *start,
static void setup_token_decoder(VP9D_COMP *pbi, static void setup_token_decoder(VP9D_COMP *pbi,
const unsigned char *cx_data, const unsigned char *cx_data,
BOOL_DECODER* const bool_decoder) { BOOL_DECODER* const bool_decoder) {
VP9_COMMON *pc = &pbi->common; VP9_COMMON *pc = &pbi->common;
const unsigned char *user_data_end = pbi->Source + pbi->source_sz; const unsigned char *user_data_end = pbi->Source + pbi->source_sz;
const unsigned char *partition; const unsigned char *partition = cx_data;
ptrdiff_t bytes_left = user_data_end - partition;
ptrdiff_t partition_size; ptrdiff_t partition_size = bytes_left;
ptrdiff_t bytes_left;
// Set up pointers to token partition // Validate the calculated partition length. If the buffer
partition = cx_data;