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" |
62 |
#include "image/postprocessing.h" |
#include "image/postprocessing.h" |
63 |
#include "utils/mem_align.h" |
#include "utils/mem_align.h" |
64 |
|
|
65 |
|
#ifdef ARCH_IS_IA32 |
66 |
|
#define interpolate16x16_quarterpel new_interpolate16x16_quarterpel |
67 |
|
#define interpolate8x8_quarterpel new_interpolate8x8_quarterpel |
68 |
|
#endif |
69 |
|
|
70 |
static int |
static int |
71 |
decoder_resize(DECODER * dec) |
decoder_resize(DECODER * dec) |
72 |
{ |
{ |
345 |
stop_coding_timer(); |
stop_coding_timer(); |
346 |
|
|
347 |
start_timer(); |
start_timer(); |
348 |
add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors); |
add_acdc(pMB, i, &block[i * 64], iDcScaler, predictors, dec->bs_version); |
349 |
stop_prediction_timer(); |
stop_prediction_timer(); |
350 |
|
|
351 |
start_timer(); |
start_timer(); |
396 |
uint8_t * pY_Cur, |
uint8_t * pY_Cur, |
397 |
uint8_t * pU_Cur, |
uint8_t * pU_Cur, |
398 |
uint8_t * pV_Cur, |
uint8_t * pV_Cur, |
399 |
const int reduced_resolution, |
int reduced_resolution, |
400 |
const MACROBLOCK * pMB) |
const MACROBLOCK * pMB) |
401 |
{ |
{ |
402 |
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); |
|
403 |
|
|
404 |
int stride = dec->edged_width; |
int stride = dec->edged_width; |
405 |
int next_block = stride * (reduced_resolution ? 16 : 8); |
int next_block = stride * (reduced_resolution ? 16 : 8); |
|
const int stride2 = stride/2; |
|
406 |
int i; |
int i; |
407 |
const uint32_t iQuant = pMB->quant; |
const uint32_t iQuant = pMB->quant; |
408 |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
const int direction = dec->alternate_vertical_scan ? 2 : 0; |
409 |
const quant_interFuncPtr dequant = dec->quant_type == 0 ? dequant_h263_inter : dequant_mpeg_inter; |
typedef void (*get_inter_block_function_t)( |
410 |
|
Bitstream * bs, |
411 |
|
int16_t * block, |
412 |
|
int direction, |
413 |
|
const int quant, |
414 |
|
const uint16_t *matrix); |
415 |
|
typedef void (*add_residual_function_t)( |
416 |
|
uint8_t *predicted_block, |
417 |
|
const int16_t *residual, |
418 |
|
int stride); |
419 |
|
|
420 |
|
const get_inter_block_function_t get_inter_block = (dec->quant_type == 0) |
421 |
|
? (get_inter_block_function_t)get_inter_block_h263 |
422 |
|
: (get_inter_block_function_t)get_inter_block_mpeg; |
423 |
|
|
424 |
|
const add_residual_function_t add_residual = (reduced_resolution) |
425 |
|
? (add_residual_function_t)add_upsampled_8x8_16to8 |
426 |
|
: (add_residual_function_t)transfer_16to8add; |
427 |
|
|
428 |
for (i = 0; i < 6; i++) { |
uint8_t *dst[6]; |
429 |
|
int strides[6]; |
430 |
|
|
|
if (cbp & (1 << (5 - i))) { /* coded */ |
|
431 |
|
|
432 |
memset(block, 0, 64 * sizeof(int16_t)); /* clear */ |
if (dec->interlacing && pMB->field_dct) { |
433 |
|
next_block = stride; |
434 |
|
stride *= 2; |
435 |
|
} |
436 |
|
|
437 |
start_timer(); |
reduced_resolution = !!reduced_resolution; |
438 |
get_inter_block(bs, block, direction); |
dst[0] = pY_Cur; |
439 |
stop_coding_timer(); |
dst[2] = pY_Cur + next_block; |
440 |
|
dst[1] = dst[0] + (8<<reduced_resolution); |
441 |
|
dst[3] = dst[2] + (8<<reduced_resolution); |
442 |
|
dst[4] = pU_Cur; |
443 |
|
dst[5] = pV_Cur; |
444 |
|
strides[0] = strides[1] = strides[2] = strides[3] = stride; |
445 |
|
strides[4] = stride/2; |
446 |
|
strides[5] = stride/2; |
447 |
|
|
448 |
|
for (i = 0; i < 6; i++) { |
449 |
|
/* Process only coded blocks */ |
450 |
|
if (cbp & (1 << (5 - i))) { |
451 |
|
|
452 |
|
/* Clear the block */ |
453 |
|
memset(&data[0], 0, 64*sizeof(int16_t)); |
454 |
|
|
455 |
|
/* Decode coeffs and dequantize on the fly */ |
456 |
start_timer(); |
start_timer(); |
457 |
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)); |
458 |
stop_iquant_timer(); |
stop_coding_timer(); |
459 |
|
|
460 |
|
/* iDCT */ |
461 |
start_timer(); |
start_timer(); |
462 |
idct(&data[i * 64]); |
idct(&data[0]); |
463 |
stop_idct_timer(); |
stop_idct_timer(); |
|
} |
|
|
} |
|
|
|
|
|
if (dec->interlacing && pMB->field_dct) { |
|
|
next_block = stride; |
|
|
stride *= 2; |
|
|
} |
|
464 |
|
|
465 |
|
/* Add this residual to the predicted block */ |
466 |
start_timer(); |
start_timer(); |
467 |
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); |
|
|
} |
|
468 |
stop_transfer_timer(); |
stop_transfer_timer(); |
469 |
} |
} |
470 |
|
} |
471 |
|
} |
472 |
|
|
473 |
/* decode an inter macroblock */ |
/* decode an inter macroblock */ |
474 |
static void |
static void |
825 |
mb_height = (dec->height + 31) / 32; |
mb_height = (dec->height + 31) / 32; |
826 |
} |
} |
827 |
|
|
828 |
|
if (!dec->is_edged[0]) { |
829 |
start_timer(); |
start_timer(); |
830 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
831 |
dec->width, dec->height, dec->bs_version); |
dec->width, dec->height, dec->bs_version); |
832 |
|
dec->is_edged[0] = 1; |
833 |
stop_edges_timer(); |
stop_edges_timer(); |
834 |
|
} |
835 |
|
|
836 |
if (gmc_warp) { |
if (gmc_warp) { |
837 |
/* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ |
/* accuracy: 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ |
1042 |
if (!direct) { |
if (!direct) { |
1043 |
uv_dx = pMB->mvs[0].x; |
uv_dx = pMB->mvs[0].x; |
1044 |
uv_dy = pMB->mvs[0].y; |
uv_dy = pMB->mvs[0].y; |
|
|
|
1045 |
b_uv_dx = pMB->b_mvs[0].x; |
b_uv_dx = pMB->b_mvs[0].x; |
1046 |
b_uv_dy = pMB->b_mvs[0].y; |
b_uv_dy = pMB->b_mvs[0].y; |
1047 |
|
|
1054 |
|
|
1055 |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
uv_dx = (uv_dx >> 1) + roundtab_79[uv_dx & 0x3]; |
1056 |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
uv_dy = (uv_dy >> 1) + roundtab_79[uv_dy & 0x3]; |
|
|
|
1057 |
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]; |
1058 |
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]; |
1059 |
|
|
1060 |
} 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 { |
|
1061 |
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; |
1062 |
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; |
1063 |
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; |
1064 |
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; |
1065 |
|
|
1066 |
|
if (dec->quarterpel) { |
1067 |
|
uv_dx /= 2; |
1068 |
|
uv_dy /= 2; |
1069 |
|
b_uv_dx /= 2; |
1070 |
|
b_uv_dy /= 2; |
1071 |
} |
} |
1072 |
|
|
1073 |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
uv_dx = (uv_dx >> 3) + roundtab_76[uv_dx & 0xf]; |
1151 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1152 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos, |
1153 |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos, |
1154 |
stride, 1, 8); |
stride, 0, 8); |
1155 |
|
|
1156 |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1157 |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->cur.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1158 |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
dec->tmp.y + (16 * y_pos * stride) + 16 * x_pos + 8, |
1159 |
stride, 1, 8); |
stride, 0, 8); |
1160 |
|
|
1161 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1162 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1163 |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos, |
1164 |
stride, 1, 8); |
stride, 0, 8); |
1165 |
|
|
1166 |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
interpolate8x8_avg2(dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1167 |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->cur.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1168 |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
dec->tmp.y + ((16 * y_pos + 8) * stride) + 16 * x_pos + 8, |
1169 |
stride, 1, 8); |
stride, 0, 8); |
1170 |
|
|
1171 |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1172 |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.u + (8 * y_pos * stride2) + 8 * x_pos, |
1173 |
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.u + (8 * y_pos * stride2) + 8 * x_pos, |
1174 |
stride2, 1, 8); |
stride2, 0, 8); |
1175 |
|
|
1176 |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
interpolate8x8_avg2(dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1177 |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->cur.v + (8 * y_pos * stride2) + 8 * x_pos, |
1178 |
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
dec->tmp.v + (8 * y_pos * stride2) + 8 * x_pos, |
1179 |
stride2, 1, 8); |
stride2, 0, 8); |
1180 |
|
|
1181 |
stop_comp_timer(); |
stop_comp_timer(); |
1182 |
|
|
1226 |
uint32_t x, y; |
uint32_t x, y; |
1227 |
VECTOR mv; |
VECTOR mv; |
1228 |
const VECTOR zeromv = {0,0}; |
const VECTOR zeromv = {0,0}; |
|
const int64_t TRB = dec->time_pp - dec->time_bp, TRD = dec->time_pp; |
|
1229 |
int i; |
int i; |
1230 |
|
|
1231 |
|
if (!dec->is_edged[0]) { |
1232 |
start_timer(); |
start_timer(); |
1233 |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[0], dec->edged_width, dec->edged_height, |
1234 |
dec->width, dec->height, dec->bs_version); |
dec->width, dec->height, dec->bs_version); |
1235 |
|
dec->is_edged[0] = 1; |
1236 |
|
stop_edges_timer(); |
1237 |
|
} |
1238 |
|
|
1239 |
|
if (!dec->is_edged[1]) { |
1240 |
|
start_timer(); |
1241 |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
image_setedges(&dec->refn[1], dec->edged_width, dec->edged_height, |
1242 |
dec->width, dec->height, dec->bs_version); |
dec->width, dec->height, dec->bs_version); |
1243 |
|
dec->is_edged[1] = 1; |
1244 |
stop_edges_timer(); |
stop_edges_timer(); |
1245 |
|
} |
1246 |
|
|
1247 |
for (y = 0; y < dec->mb_height; y++) { |
for (y = 0; y < dec->mb_height; y++) { |
1248 |
/* Initialize Pred Motion Vector */ |
/* Initialize Pred Motion Vector */ |
1329 |
|
|
1330 |
case MODE_DIRECT_NONE_MV: |
case MODE_DIRECT_NONE_MV: |
1331 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
1332 |
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; |
1333 |
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; |
1334 |
? ((TRB - TRD) * last_mb->mvs[i].x) / TRD |
|
1335 |
: mb->mvs[i].x - last_mb->mvs[i].x); |
mb->b_mvs[i].x = (mv.x) |
1336 |
mb->mvs[i].y = (int32_t) ((TRB * last_mb->mvs[i].y) / TRD + mv.y); |
? mb->mvs[i].x - last_mb->mvs[i].x |
1337 |
mb->b_mvs[i].y = (int32_t) ((mv.y == 0) |
: last_mb->mvs[i].x*(dec->time_bp - dec->time_pp)/dec->time_pp; |
1338 |
? ((TRB - TRD) * last_mb->mvs[i].y) / TRD |
mb->b_mvs[i].y = (mv.y) |
1339 |
: mb->mvs[i].y - last_mb->mvs[i].y); |
? mb->mvs[i].y - last_mb->mvs[i].y |
1340 |
|
: last_mb->mvs[i].y*(dec->time_bp - dec->time_pp)/dec->time_pp; |
1341 |
} |
} |
1342 |
|
|
1343 |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
decoder_bf_interpolate_mbinter(dec, dec->refn[1], dec->refn[0], |
1567 |
} |
} |
1568 |
|
|
1569 |
image_swap(&dec->refn[0], &dec->refn[1]); |
image_swap(&dec->refn[0], &dec->refn[1]); |
1570 |
|
dec->is_edged[1] = dec->is_edged[0]; |
1571 |
image_swap(&dec->cur, &dec->refn[0]); |
image_swap(&dec->cur, &dec->refn[0]); |
1572 |
|
dec->is_edged[0] = 0; |
1573 |
SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); |
SWAP(MACROBLOCK *, dec->mbs, dec->last_mbs); |
1574 |
dec->last_reduced_resolution = reduced_resolution; |
dec->last_reduced_resolution = reduced_resolution; |
1575 |
dec->last_coding_type = coding_type; |
dec->last_coding_type = coding_type; |
1581 |
|
|
1582 |
if (dec->low_delay) { |
if (dec->low_delay) { |
1583 |
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"); |
1584 |
dec->low_delay = 1; |
dec->low_delay = 0; |
1585 |
} |
} |
1586 |
|
|
1587 |
if (dec->frames < 2) { |
if (dec->frames < 2) { |