48 |
#include "image/interpolate8x8.h" |
#include "image/interpolate8x8.h" |
49 |
#include "image/reduced.h" |
#include "image/reduced.h" |
50 |
#include "image/font.h" |
#include "image/font.h" |
51 |
|
#include "image/qpel.h" |
52 |
|
|
53 |
#include "bitstream/mbcoding.h" |
#include "bitstream/mbcoding.h" |
54 |
#include "prediction/mbprediction.h" |
#include "prediction/mbprediction.h" |
304 |
|
|
305 |
start_timer(); |
start_timer(); |
306 |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], |
predict_acdc(dec->mbs, x_pos, y_pos, dec->mb_width, i, &block[i * 64], |
307 |
iQuant, iDcScaler, predictors, bound, dec->bs_version); |
iQuant, iDcScaler, predictors, bound); |
308 |
if (!acpred_flag) { |
if (!acpred_flag) { |
309 |
pMB->acpred_directions[i] = 0; |
pMB->acpred_directions[i] = 0; |
310 |
} |
} |
340 |
stop_coding_timer(); |
stop_coding_timer(); |
341 |
|
|
342 |
start_timer(); |
start_timer(); |
343 |
add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors); |
add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version); |
344 |
stop_prediction_timer(); |
stop_prediction_timer(); |
345 |
|
|
346 |
start_timer(); |
start_timer(); |
391 |
uint8_t * pY_Cur, |
uint8_t * pY_Cur, |
392 |
uint8_t * pU_Cur, |
uint8_t * pU_Cur, |
393 |
uint8_t * pV_Cur, |
uint8_t * pV_Cur, |
394 |
const int reduced_resolution, |
int reduced_resolution, |
395 |
const MACROBLOCK * pMB) |
const MACROBLOCK * pMB) |
396 |
{ |
{ |
397 |
DECLARE_ALIGNED_MATRIX(block, 1, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(data, 1, 64, int16_t, CACHE_LINE); |
|
DECLARE_ALIGNED_MATRIX(data, 6, 64, int16_t, CACHE_LINE); |
|
398 |
|
|
399 |
int stride = dec->edged_width; |
int stride = dec->edged_width; |
400 |
int next_block = stride * (reduced_resolution ? 16 : 8); |
int next_block = stride * (reduced_resolution ? 16 : 8); |
|
const int stride2 = stride/2; |
|
401 |
int i; |
int i; |
402 |
const uint32_t iQuant = pMB->quant; |
const uint32_t iQuant = pMB->quant; |
403 |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
404 |
const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter; |
typedef void (*get_inter_block_function_t)( |
405 |
|
Bitstream * bs, |
406 |
|
int16_t * block, |
407 |
|
int direction, |
408 |
|
const int quant, |
409 |
|
const uint16_t *matrix); |
410 |
|
typedef void (*add_residual_function_t)( |
411 |
|
uint8_t *predicted_block, |
412 |
|
const int16_t *residual, |
413 |
|
int stride); |
414 |
|
|
415 |
|
const get_inter_block_function_t get_inter_block = (dec->quant_type == 0) |
416 |
|
? (get_inter_block_function_t)get_inter_block_h263 |
417 |
|
: (get_inter_block_function_t)get_inter_block_mpeg; |
418 |
|
|
419 |
|
const add_residual_function_t add_residual = (reduced_resolution) |
420 |
|
? (add_residual_function_t)add_upsampled_8x8_16to8 |
421 |
|
: (add_residual_function_t)transfer_16to8add; |
422 |
|
|
423 |
for (i = 0; i < 6; i++) { |
uint8_t *dst[6]; |
424 |
|
int strides[6]; |
425 |
|
|
|
if (cbp & (1 << (5 - i))) { /* coded */ |
|
426 |
|
|
427 |
memset(block, 0, 64 * sizeof(int16_t)); /* clear */ |
if (dec->interlacing && pMB->field_dct) { |
428 |
|
next_block = stride; |
429 |
|
stride *= 2; |
430 |
|
} |
431 |
|
|
432 |
start_timer(); |
reduced_resolution = !!reduced_resolution; |
433 |
get_inter_block(bs, block, direction); |
dst[0] = pY_Cur; |
434 |
stop_coding_timer(); |
dst[2] = pY_Cur + next_block; |
435 |
|
dst[1] = dst[0] + (8<<reduced_resolution); |
436 |
|
dst[3] = dst[2] + (8<<reduced_resolution); |
437 |
|
dst[4] = pU_Cur; |
438 |
|
dst[5] = pV_Cur; |
439 |
|
strides[0] = strides[1] = strides[2] = strides[3] = stride; |
440 |
|
strides[4] = stride/2; |
441 |
|
strides[5] = stride/2; |
442 |
|
|
443 |
|
for (i = 0; i < 6; i++) { |
444 |
|
/* Process only coded blocks */ |
445 |
|
if (cbp & (1 << (5 - i))) { |
446 |
|
|
447 |
|
/* Clear the block */ |
448 |
|
memset(&data[0], 0, 64*sizeof(int16_t)); |
449 |
|
|
450 |
|
/* Decode coeffs and dequantize on the fly */ |
451 |
start_timer(); |
start_timer(); |
452 |
dequant(&data[i * 64], block, iQuant, dec->mpeg_quant_matrices); |
get_inter_block(bs, &data[0], direction, iQuant, get_inter_matrix(dec->mpeg_quant_matrices)); |
453 |
stop_iquant_timer(); |
stop_coding_timer(); |
454 |
|
|
455 |
|
/* iDCT */ |
456 |
start_timer(); |
start_timer(); |
457 |
idct(&data[i * 64]); |
idct(&data[0]); |
458 |
stop_idct_timer(); |
stop_idct_timer(); |
|
} |
|
|
} |
|
|
|
|
|
if (dec->interlacing && pMB->field_dct) { |
|
|
next_block = stride; |
|
|
stride *= 2; |
|
|
} |
|
459 |
|
|
460 |
|
/* Add this residual to the predicted block */ |
461 |
start_timer(); |
start_timer(); |
462 |
if (reduced_resolution) { |
add_residual(dst[i], &data[0], strides[i]); |
|
if (cbp & 32) |
|
|
add_upsampled_8x8_16to8(pY_Cur, &data[0 * 64], stride); |
|
|
if (cbp & 16) |
|
|
add_upsampled_8x8_16to8(pY_Cur + 16, &data[1 * 64], stride); |
|
|
if (cbp & 8) |
|
|
add_upsampled_8x8_16to8(pY_Cur + next_block, &data[2 * 64], stride); |
|
|
if (cbp & 4) |
|
|
add_upsampled_8x8_16to8(pY_Cur + 16 + next_block, &data[3 * 64], stride); |
|
|
if (cbp & 2) |
|
|
add_upsampled_8x8_16to8(pU_Cur, &data[4 * 64], stride2); |
|
|
if (cbp & 1) |
|
|
add_upsampled_8x8_16to8(pV_Cur, &data[5 * 64], stride2); |
|
|
} else { |
|
|
if (cbp & 32) |
|
|
transfer_16to8add(pY_Cur, &data[0 * 64], stride); |
|
|
if (cbp & 16) |
|
|
transfer_16to8add(pY_Cur + 8, &data[1 * 64], stride); |
|
|
if (cbp & 8) |
|
|
transfer_16to8add(pY_Cur + next_block, &data[2 * 64], stride); |
|
|
if (cbp & 4) |
|
|
transfer_16to8add(pY_Cur + 8 + next_block, &data[3 * 64], stride); |
|
|
if (cbp & 2) |
|
|
transfer_16to8add(pU_Cur, &data[4 * 64], stride2); |
|
|
if (cbp & 1) |
|
|
transfer_16to8add(pV_Cur, &data[5 * 64], stride2); |
|
|
} |
|
463 |
stop_transfer_timer(); |
stop_transfer_timer(); |
464 |
} |
} |
465 |
|
} |
466 |
|
} |
467 |
|
|
468 |
/* decode an inter macroblock */ |
/* decode an inter macroblock */ |
469 |
static void |
static void |
1037 |
if (!direct) { |
if (!direct) { |
1038 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1039 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
|
|
|
1040 |
b_uv_dx = pMB->b_mvs[0].x; |
b_uv_dx = pMB->b_mvs[0].x; |
1041 |
b_uv_dy = pMB->b_mvs[0].y; |
b_uv_dy = pMB->b_mvs[0].y; |
1042 |
|
|
1049 |
|
|
1050 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1051 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
|
|
|
1052 |
b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3]; |
b_uv_dx = (b_uv_dx >> 1) + roundtab_79[b_uv_dx & 0x3]; |
1053 |
b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; |
b_uv_dy = (b_uv_dy >> 1) + roundtab_79[b_uv_dy & 0x3]; |
1054 |
|
|
1055 |
} else { |
} else { |
|
if(dec->quarterpel) { |
|
|
uv_dx = (pMB->mvs[0].x / 2) + (pMB->mvs[1].x / 2) + (pMB->mvs[2].x / 2) + (pMB->mvs[3].x / 2); |
|
|
uv_dy = (pMB->mvs[0].y / 2) + (pMB->mvs[1].y / 2) + (pMB->mvs[2].y / 2) + (pMB->mvs[3].y / 2); |
|
|
b_uv_dx = (pMB->b_mvs[0].x / 2) + (pMB->b_mvs[1].x / 2) + (pMB->b_mvs[2].x / 2) + (pMB->b_mvs[3].x / 2); |
|
|
b_uv_dy = (pMB->b_mvs[0].y / 2) + (pMB->b_mvs[1].y / 2) + (pMB->b_mvs[2].y / 2) + (pMB->b_mvs[3].y / 2); |
|
|
} else { |
|
1056 |
uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
uv_dx = pMB->mvs[0].x + pMB->mvs[1].x + pMB->mvs[2].x + pMB->mvs[3].x; |
1057 |
uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
uv_dy = pMB->mvs[0].y + pMB->mvs[1].y + pMB->mvs[2].y + pMB->mvs[3].y; |
1058 |
b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; |
b_uv_dx = pMB->b_mvs[0].x + pMB->b_mvs[1].x + pMB->b_mvs[2].x + pMB->b_mvs[3].x; |
1059 |
b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; |
b_uv_dy = pMB->b_mvs[0].y + pMB->b_mvs[1].y + pMB->b_mvs[2].y + pMB->b_mvs[3].y; |
1060 |
|
|
1061 |
|
if (dec->quarterpel) { |
1062 |
|
uv_dx /= 2; |
1063 |
|
uv_dy /= 2; |
1064 |
|
b_uv_dx /= 2; |
1065 |
|
b_uv_dy /= 2; |
1066 |
} |
} |
1067 |
|
|
1068 |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
1110 |
|
|
1111 |
if(dec->quarterpel) { |
if(dec->quarterpel) { |
1112 |
if(!direct) { |
if(!direct) { |
1113 |
interpolate16x16_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate16x16_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1114 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1115 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1116 |
} else { |
} else { |
1117 |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1118 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos, |
1119 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1120 |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1121 |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos, |
1122 |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1123 |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1124 |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos, 16*y_pos + 8, |
1125 |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1126 |
interpolate8x8_quarterpel(dec->tmp.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
interpolate8x8_add_quarterpel(dec->cur.y, backward.y, dec->qtmp.y, dec->qtmp.y + 64, |
1127 |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
dec->qtmp.y + 128, 16*x_pos + 8, 16*y_pos + 8, |
1128 |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1129 |
} |
} |
1130 |
} else { |
} else { |
1131 |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, 16 * y_pos, |
interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos, 16 * y_pos, |
1132 |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
pMB->b_mvs[0].x, pMB->b_mvs[0].y, stride, 0); |
1133 |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos + 8, |
1134 |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
16 * y_pos, pMB->b_mvs[1].x, pMB->b_mvs[1].y, stride, 0); |
1135 |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos, |
interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos, |
1136 |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
16 * y_pos + 8, pMB->b_mvs[2].x, pMB->b_mvs[2].y, stride, 0); |
1137 |
interpolate8x8_switch(dec->tmp.y, backward.y, 16 * x_pos + 8, |
interpolate8x8_add_switch(dec->cur.y, backward.y, 16 * x_pos + 8, |
1138 |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
16 * y_pos + 8, pMB->b_mvs[3].x, pMB->b_mvs[3].y, stride, 0); |
1139 |
} |
} |
1140 |
|
|
1141 |
interpolate8x8_switch(dec->tmp.u, backward.u, 8 * x_pos, 8 * y_pos, |
interpolate8x8_add_switch(dec->cur.u, backward.u, 8 * x_pos, 8 * y_pos, |
1142 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1143 |
interpolate8x8_switch(dec->tmp.v, backward.v, 8 * x_pos, 8 * y_pos, |
interpolate8x8_add_switch(dec->cur.v, backward.v, 8 * x_pos, 8 * y_pos, |
1144 |
b_uv_dx, b_uv_dy, stride2, 0); |
b_uv_dx, b_uv_dy, stride2, 0); |
1145 |
|
|
|
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
|
|
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
|
|
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
|
|
stride, 1, 8); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
|
|
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
|
|
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
|
|
stride, 1, 8); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
|
|
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
|
|
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
|
|
stride, 1, 8); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
|
|
stride, 1, 8); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
stride2, 1, 8); |
|
|
|
|
|
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
|
|
stride2, 1, 8); |
|
|
|
|
1146 |
stop_comp_timer(); |
stop_comp_timer(); |
1147 |
|
|
1148 |
if (cbp) |
if (cbp) |
1191 |
uint32_t x, y; |
uint32_t x, y; |
1192 |
VECTOR mv; |
VECTOR mv; |
1193 |
const VECTOR zeromv = {0,0}; |
const VECTOR zeromv = {0,0}; |
|
const int32_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
|
1194 |
int i; |
int i; |
1195 |
|
|
1196 |
if (!dec->is_edged[0]) { |
if (!dec->is_edged[0]) { |
1294 |
|
|
1295 |
case MODE_DIRECT_NONE_MV: |
case MODE_DIRECT_NONE_MV: |
1296 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
1297 |
mb->mvs[i].x = (int32_t) ((TRB * last_mb->mvs[i].x) / TRD + mv.x); |
mb->mvs[i].x = last_mb->mvs[i].x*dec->time_bp/dec->time_pp + mv.x; |
1298 |
mb->b_mvs[i].x = (int32_t) ((mv.x == 0) |
mb->mvs[i].y = last_mb->mvs[i].y*dec->time_bp/dec->time_pp + mv.y; |
1299 |
? ((TRB - TRD) * last_mb->mvs[i].x) / TRD |
|
1300 |
: mb->mvs[i].x - last_mb->mvs[i].x); |
mb->b_mvs[i].x = (mv.x) |
1301 |
mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y); |
? mb->mvs[i].x - last_mb->mvs[i].x |
1302 |
mb->b_mvs[i].y = (int32_t) ((mv.y == 0) |
: last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp; |
1303 |
? ((TRB - TRD) * last_mb->mvs[i].y) / TRD |
mb->b_mvs[i].y = (mv.y) |
1304 |
: mb->mvs[i].y - last_mb->mvs[i].y); |
? mb->mvs[i].y - last_mb->mvs[i].y |
1305 |
|
: last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp; |
1306 |
} |
} |
1307 |
|
|
1308 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1546 |
|
|
1547 |
if (dec->low_delay) { |
if (dec->low_delay) { |
1548 |
DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
DPRINTF(XVID_DEBUG_ERROR, "warning: bvop found in low_delay==1 stream\n"); |
1549 |
dec->low_delay = 1; |
dec->low_delay = 0; |
1550 |
} |
} |
1551 |
|
|
1552 |
if (dec->frames < 2) { |
if (dec->frames < 2) { |