84 |
int *acpred_direction = &pMBs[index].acpred_directions[block]; |
int *acpred_direction = &pMBs[index].acpred_directions[block]; |
85 |
uint32_t i; |
uint32_t i; |
86 |
|
|
87 |
left = top = diag = current = 0; |
left = top = diag = current = NULL; |
88 |
|
|
89 |
/* grab left,top and diag macroblocks */ |
/* grab left,top and diag macroblocks */ |
90 |
|
|
94 |
(pMBs[index - 1].mode == MODE_INTRA || |
(pMBs[index - 1].mode == MODE_INTRA || |
95 |
pMBs[index - 1].mode == MODE_INTRA_Q)) { |
pMBs[index - 1].mode == MODE_INTRA_Q)) { |
96 |
|
|
97 |
left = pMBs[index - 1].pred_values[0]; |
left = (int16_t*)pMBs[index - 1].pred_values[0]; |
98 |
left_quant = pMBs[index - 1].quant; |
left_quant = pMBs[index - 1].quant; |
99 |
} |
} |
100 |
/* top macroblock */ |
/* top macroblock */ |
103 |
(pMBs[index - mb_width].mode == MODE_INTRA || |
(pMBs[index - mb_width].mode == MODE_INTRA || |
104 |
pMBs[index - mb_width].mode == MODE_INTRA_Q)) { |
pMBs[index - mb_width].mode == MODE_INTRA_Q)) { |
105 |
|
|
106 |
top = pMBs[index - mb_width].pred_values[0]; |
top = (int16_t*)pMBs[index - mb_width].pred_values[0]; |
107 |
top_quant = pMBs[index - mb_width].quant; |
top_quant = pMBs[index - mb_width].quant; |
108 |
} |
} |
109 |
/* diag macroblock */ |
/* diag macroblock */ |
112 |
(pMBs[index - 1 - mb_width].mode == MODE_INTRA || |
(pMBs[index - 1 - mb_width].mode == MODE_INTRA || |
113 |
pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) { |
pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) { |
114 |
|
|
115 |
diag = pMBs[index - 1 - mb_width].pred_values[0]; |
diag = (int16_t*)pMBs[index - 1 - mb_width].pred_values[0]; |
116 |
} |
} |
117 |
|
|
118 |
current = pMBs[index].pred_values[0]; |
current = (int16_t*)pMBs[index].pred_values[0]; |
119 |
|
|
120 |
/* now grab pLeft, pTop, pDiag _blocks_ */ |
/* now grab pLeft, pTop, pDiag _blocks_ */ |
121 |
|
|
219 |
const int bsversion) |
const int bsversion) |
220 |
{ |
{ |
221 |
uint8_t acpred_direction = pMB->acpred_directions[block]; |
uint8_t acpred_direction = pMB->acpred_directions[block]; |
222 |
int16_t *pCurrent = pMB->pred_values[block]; |
int16_t *pCurrent = (int16_t*)pMB->pred_values[block]; |
223 |
uint32_t i; |
uint32_t i; |
224 |
|
|
225 |
DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]); |
DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]); |
226 |
|
|
227 |
dct_codes[0] += predictors[0]; /* dc prediction */ |
dct_codes[0] += predictors[0]; /* dc prediction */ |
228 |
pCurrent[0] = dct_codes[0]*iDcScaler; |
pCurrent[0] = dct_codes[0]*iDcScaler; |
229 |
if (!bsversion || bsversion > BS_VERSION_BUGGY_DC_CLIPPING) { |
if (bsversion > BS_VERSION_BUGGY_DC_CLIPPING) { |
230 |
pCurrent[0] = CLIP(pCurrent[0], -2048, 2047); |
pCurrent[0] = CLIP(pCurrent[0], -2048, 2047); |
231 |
} |
} |
232 |
|
|
270 |
S2 = sum of all qcoeff |
S2 = sum of all qcoeff |
271 |
*/ |
*/ |
272 |
|
|
273 |
int |
static int |
274 |
calc_acdc_coeff(MACROBLOCK * pMB, |
calc_acdc_coeff(MACROBLOCK * pMB, |
275 |
uint32_t block, |
uint32_t block, |
276 |
int16_t qcoeff[64], |
int16_t qcoeff[64], |
277 |
uint32_t iDcScaler, |
uint32_t iDcScaler, |
278 |
int16_t predictors[8]) |
int16_t predictors[8]) |
279 |
{ |
{ |
280 |
int16_t *pCurrent = pMB->pred_values[block]; |
int16_t *pCurrent = (int16_t*)pMB->pred_values[block]; |
281 |
uint32_t i; |
uint32_t i; |
282 |
int S1 = 0, S2 = 0; |
int S1 = 0, S2 = 0; |
283 |
|
|
327 |
|
|
328 |
/* returns the bits *saved* if prediction is enabled */ |
/* returns the bits *saved* if prediction is enabled */ |
329 |
|
|
330 |
int |
static int |
331 |
calc_acdc_bits(MACROBLOCK * pMB, |
calc_acdc_bits(MACROBLOCK * pMB, |
332 |
uint32_t block, |
uint32_t block, |
333 |
int16_t qcoeff[64], |
int16_t qcoeff[64], |
335 |
int16_t predictors[8]) |
int16_t predictors[8]) |
336 |
{ |
{ |
337 |
const int direction = pMB->acpred_directions[block]; |
const int direction = pMB->acpred_directions[block]; |
338 |
int16_t *pCurrent = pMB->pred_values[block]; |
int16_t *pCurrent = (int16_t*)pMB->pred_values[block]; |
339 |
int16_t tmp[8]; |
int16_t tmp[8]; |
340 |
unsigned int i; |
unsigned int i; |
341 |
int Z1, Z2; |
int Z1, Z2; |
386 |
|
|
387 |
/* apply predictors[] to qcoeff */ |
/* apply predictors[] to qcoeff */ |
388 |
|
|
389 |
void |
static void |
390 |
apply_acdc(MACROBLOCK * pMB, |
apply_acdc(MACROBLOCK * pMB, |
391 |
uint32_t block, |
uint32_t block, |
392 |
int16_t qcoeff[64], |
int16_t qcoeff[64], |
409 |
uint32_t x, |
uint32_t x, |
410 |
uint32_t y, |
uint32_t y, |
411 |
uint32_t mb_width, |
uint32_t mb_width, |
412 |
int16_t qcoeff[6 * 64]) |
int16_t qcoeff[6 * 64], |
413 |
|
const int bound) |
414 |
{ |
{ |
415 |
|
|
416 |
int32_t j; |
int32_t j; |
427 |
iDcScaler = get_dc_scaler(iQuant, j<4); |
iDcScaler = get_dc_scaler(iQuant, j<4); |
428 |
|
|
429 |
predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64], |
predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64], |
430 |
iQuant, iDcScaler, predictors[j], 0); |
iQuant, iDcScaler, predictors[j], bound); |
431 |
|
|
432 |
if ((frame->vop_flags & XVID_VOP_HQACPRED)) |
if ((frame->vop_flags & XVID_VOP_HQACPRED)) |
433 |
S += calc_acdc_bits(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]); |
S += calc_acdc_bits(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]); |
525 |
return pmv[last_cand]; /* no point calculating median mv */ |
return pmv[last_cand]; /* no point calculating median mv */ |
526 |
} |
} |
527 |
|
|
528 |
|
VECTOR get_pmv2_interlaced(const MACROBLOCK * const mbs, |
529 |
|
const int mb_width, |
530 |
|
const int bound, |
531 |
|
const int x, |
532 |
|
const int y, |
533 |
|
const int block) |
534 |
|
{ |
535 |
|
int lx, ly, lz; /* left */ |
536 |
|
int tx, ty, tz; /* top */ |
537 |
|
int rx, ry, rz; /* top-right */ |
538 |
|
int lpos, tpos, rpos; |
539 |
|
int num_cand = 0, last_cand = 1; |
540 |
|
|
541 |
|
VECTOR pmv[4]; /* left neighbour, top neighbour, top-right neighbour */ |
542 |
|
|
543 |
|
lx=x-1; ly=y; lz=1; |
544 |
|
tx=x; ty=y-1; tz=2; |
545 |
|
rx=x+1; ry=y-1; rz=2; |
546 |
|
|
547 |
|
lpos=lx+ly*mb_width; |
548 |
|
rpos=rx+ry*mb_width; |
549 |
|
tpos=tx+ty*mb_width; |
550 |
|
|
551 |
|
if(lx>=0 && lpos>=bound) |
552 |
|
{ |
553 |
|
num_cand++; |
554 |
|
if(mbs[lpos].field_pred) |
555 |
|
pmv[1] = mbs[lpos].mvs_avg; |
556 |
|
else |
557 |
|
pmv[1] = mbs[lpos].mvs[lz]; |
558 |
|
} |
559 |
|
else |
560 |
|
{ |
561 |
|
pmv[1] = zeroMV; |
562 |
|
} |
563 |
|
|
564 |
|
if(tpos>=bound) |
565 |
|
{ |
566 |
|
num_cand++; |
567 |
|
last_cand=2; |
568 |
|
if(mbs[tpos].field_pred) |
569 |
|
pmv[2] = mbs[tpos].mvs_avg; |
570 |
|
else |
571 |
|
pmv[2] = mbs[tpos].mvs[tz]; |
572 |
|
} |
573 |
|
else |
574 |
|
{ |
575 |
|
pmv[2] = zeroMV; |
576 |
|
} |
577 |
|
|
578 |
|
if(rx<mb_width && rpos>=bound) |
579 |
|
{ |
580 |
|
num_cand++; |
581 |
|
last_cand = 3; |
582 |
|
if(mbs[rpos].field_pred) |
583 |
|
pmv[3] = mbs[rpos].mvs_avg; |
584 |
|
else |
585 |
|
pmv[3] = mbs[rpos].mvs[rz]; |
586 |
|
} |
587 |
|
else |
588 |
|
{ |
589 |
|
pmv[3] = zeroMV; |
590 |
|
} |
591 |
|
|
592 |
|
/* If there're more than one candidate, we return the median vector */ |
593 |
|
if(num_cand>1) |
594 |
|
{ |
595 |
|
/* set median */ |
596 |
|
pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), |
597 |
|
MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x))); |
598 |
|
pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), |
599 |
|
MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y))); |
600 |
|
|
601 |
|
return pmv[0]; |
602 |
|
} |
603 |
|
|
604 |
|
return pmv[last_cand]; /* no point calculating median mv */ |
605 |
|
} |
606 |
|
|
607 |
VECTOR |
VECTOR |
608 |
get_qpmv2(const MACROBLOCK * const mbs, |
get_qpmv2(const MACROBLOCK * const mbs, |
609 |
const int mb_width, |
const int mb_width, |