56 |
uint32_t * cbp, |
uint32_t * cbp, |
57 |
const int block, |
const int block, |
58 |
const uint16_t * scan_table, |
const uint16_t * scan_table, |
59 |
|
const unsigned int lambda, |
60 |
const uint16_t * mpeg_quant_matrices) |
const uint16_t * mpeg_quant_matrices) |
61 |
{ |
{ |
62 |
int sum; |
int sum; |
93 |
} |
} |
94 |
|
|
95 |
|
|
96 |
return bits + (LAMBDA*distortion)/(quant*quant); |
return bits + (lambda*distortion)/(quant*quant); |
97 |
} |
} |
98 |
|
|
99 |
static __inline unsigned int |
static __inline unsigned int |
110 |
const int quant_type, |
const int quant_type, |
111 |
unsigned int bits[2], |
unsigned int bits[2], |
112 |
unsigned int cbp[2], |
unsigned int cbp[2], |
113 |
|
unsigned int lambda, |
114 |
const uint16_t * mpeg_quant_matrices) |
const uint16_t * mpeg_quant_matrices) |
115 |
{ |
{ |
116 |
int direction; |
int direction; |
171 |
|
|
172 |
distortion = sse8_16bit(coeff, dqcoeff, 8*sizeof(int16_t)); |
distortion = sse8_16bit(coeff, dqcoeff, 8*sizeof(int16_t)); |
173 |
|
|
174 |
return (LAMBDA*distortion)/(quant*quant); |
return (lambda*distortion)/(quant*quant); |
175 |
} |
} |
176 |
|
|
177 |
|
|
203 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
204 |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*data->iEdgedWidth); |
205 |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
206 |
rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table, data->mpeg_quant_matrices); |
rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, i, data->scan_table, data->lambda[i], data->mpeg_quant_matrices); |
207 |
} |
} |
208 |
|
|
209 |
rd += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
rd += t = BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
228 |
/* chroma U */ |
/* chroma U */ |
229 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[4], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
230 |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
231 |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->mpeg_quant_matrices); |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 4, data->scan_table, data->lambda[4], data->mpeg_quant_matrices); |
232 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
233 |
|
|
234 |
/* chroma V */ |
/* chroma V */ |
235 |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
ptr = interpolate8x8_switch2(data->RefQ, data->RefP[5], 0, 0, xc, yc, data->iEdgedWidth/2, data->rounding); |
236 |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
237 |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->mpeg_quant_matrices); |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->lambda[5], data->mpeg_quant_matrices); |
238 |
|
|
239 |
rd += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
rd += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
240 |
|
|
268 |
} |
} |
269 |
|
|
270 |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
271 |
rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->mpeg_quant_matrices); |
rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, &cbp, 5, data->scan_table, data->lambda[0], data->mpeg_quant_matrices); |
272 |
rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
rd += BITS_MULT*d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
273 |
|
|
274 |
if (rd < data->iMinSAD[0]) { |
if (rd < data->iMinSAD[0]) { |
315 |
xvid_me_SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidateRD16); |
xvid_me_SquareSearch(Data->currentMV->x, Data->currentMV->y, Data, 255, CheckCandidateRD16); |
316 |
|
|
317 |
if (MotionFlags&XVID_ME_HALFPELREFINE16_RD) |
if (MotionFlags&XVID_ME_HALFPELREFINE16_RD) |
318 |
xvid_me_SubpelRefine(Data, CheckCandidateRD16, 0); |
xvid_me_SubpelRefine(Data->currentMV[0], Data, CheckCandidateRD16, 0); |
319 |
|
|
320 |
if (Data->qpel) { |
if (Data->qpel) { |
321 |
if (MotionFlags&(XVID_ME_EXTSEARCH_RD | XVID_ME_HALFPELREFINE16_RD)) { /* there was halfpel-precision search */ |
if (MotionFlags&(XVID_ME_EXTSEARCH_RD | XVID_ME_HALFPELREFINE16_RD)) { /* there was halfpel-precision search */ |
333 |
if (MotionFlags & XVID_ME_FASTREFINE16) |
if (MotionFlags & XVID_ME_FASTREFINE16) |
334 |
FullRefine_Fast(Data, CheckCandidateRD16, 0); |
FullRefine_Fast(Data, CheckCandidateRD16, 0); |
335 |
else |
else |
336 |
xvid_me_SubpelRefine(Data, CheckCandidateRD16, 0); |
xvid_me_SubpelRefine(Data->currentQMV[0], Data, CheckCandidateRD16, 0); |
337 |
} |
} |
338 |
} |
} |
339 |
|
|
372 |
Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[1] = Data->RefP[1] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
373 |
Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[3] = Data->RefP[3] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
374 |
*Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; /* copy corresponding cbp bit */ |
*Data8->cbp = (Data->cbp[1] & (1<<(5-i))) ? 1:0; /* copy corresponding cbp bit */ |
375 |
|
Data8->lambda[0] = Data->lambda[i]; |
376 |
|
|
377 |
if(Data->qpel) { |
if(Data->qpel) { |
378 |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i); |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i); |
417 |
xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8); |
xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8); |
418 |
|
|
419 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
420 |
xvid_me_SubpelRefine(Data8, CheckCandidateRD8, 0); |
xvid_me_SubpelRefine(Data->currentMV[0], Data8, CheckCandidateRD8, 0); |
421 |
|
|
422 |
if(bsad > *Data8->iMinSAD) { /* we have found a better match */ |
if(bsad > *Data8->iMinSAD) { /* we have found a better match */ |
423 |
bx = Data8->currentQMV->x = 2*Data8->currentMV->x; |
bx = Data8->currentQMV->x = 2*Data8->currentMV->x; |
434 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD) { |
if (MotionFlags & XVID_ME_QUARTERPELREFINE8_RD) { |
435 |
if (MotionFlags & XVID_ME_FASTREFINE8) |
if (MotionFlags & XVID_ME_FASTREFINE8) |
436 |
FullRefine_Fast(Data8, CheckCandidateRD8, 0); |
FullRefine_Fast(Data8, CheckCandidateRD8, 0); |
437 |
else xvid_me_SubpelRefine(Data8, CheckCandidateRD8, 0); |
else xvid_me_SubpelRefine(Data->currentQMV[0], Data8, CheckCandidateRD8, 0); |
438 |
} |
} |
439 |
|
|
440 |
if (bsad <= Data->iMinSAD[0]) { |
if (bsad <= Data->iMinSAD[0]) { |
450 |
xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8); |
xvid_me_SquareSearch(Data8->currentMV->x, Data8->currentMV->x, Data8, 255, CheckCandidateRD8); |
451 |
|
|
452 |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
if (MotionFlags & XVID_ME_HALFPELREFINE8_RD) |
453 |
xvid_me_SubpelRefine(Data8, CheckCandidateRD8, 0); /* halfpel refinement */ |
xvid_me_SubpelRefine(Data->currentMV[0], Data8, CheckCandidateRD8, 0); /* halfpel refinement */ |
454 |
} |
} |
455 |
|
|
456 |
/* checking vector equal to predicion */ |
/* checking vector equal to predicion */ |
491 |
/* chroma U */ |
/* chroma U */ |
492 |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[4], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
493 |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
494 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices); |
495 |
|
|
496 |
if (bits >= *Data->iMinSAD) return bits; |
if (bits >= *Data->iMinSAD) return bits; |
497 |
|
|
498 |
/* chroma V */ |
/* chroma V */ |
499 |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
ptr = interpolate8x8_switch2(Data->RefQ + 64, Data->RefP[5], 0, 0, sumx, sumy, Data->iEdgedWidth/2, Data->rounding); |
500 |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
501 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices); |
502 |
|
|
503 |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len; |
504 |
|
|
524 |
|
|
525 |
|
|
526 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff, |
527 |
predictors[i], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices); |
predictors[i], iQuant, Data->quant_type, bits, cbp, Data->lambda[i], Data->mpeg_quant_matrices); |
528 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
529 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
530 |
|
|
538 |
/*chroma U */ |
/*chroma U */ |
539 |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
540 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff, |
541 |
predictors[4], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices); |
predictors[4], iQuant, Data->quant_type, bits, cbp, Data->lambda[4], Data->mpeg_quant_matrices); |
542 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
543 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
544 |
|
|
548 |
/* chroma V */ |
/* chroma V */ |
549 |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
550 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff, |
551 |
predictors[5], iQuant, Data->quant_type, bits, cbp, Data->mpeg_quant_matrices); |
predictors[5], iQuant, Data->quant_type, bits, cbp, Data->lambda[5], Data->mpeg_quant_matrices); |
552 |
|
|
553 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
554 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
572 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
573 |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
574 |
transfer_8to16subro(in, Data->Cur + s, vGMC->y + s + 16*(x+y*Data->iEdgedWidth), Data->iEdgedWidth); |
transfer_8to16subro(in, Data->Cur + s, vGMC->y + s + 16*(x+y*Data->iEdgedWidth), Data->iEdgedWidth); |
575 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, Data->scan_table, Data->mpeg_quant_matrices); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, Data->scan_table, Data->lambda[i], Data->mpeg_quant_matrices); |
576 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
577 |
} |
} |
578 |
|
|
580 |
|
|
581 |
/*chroma U */ |
/*chroma U */ |
582 |
transfer_8to16subro(in, Data->CurU, vGMC->u + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurU, vGMC->u + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2); |
583 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->mpeg_quant_matrices); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices); |
584 |
|
|
585 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
586 |
|
|
587 |
/* chroma V */ |
/* chroma V */ |
588 |
transfer_8to16subro(in, Data->CurV , vGMC->v + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurV , vGMC->v + 8*(x+y*(Data->iEdgedWidth/2)), Data->iEdgedWidth/2); |
589 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->mpeg_quant_matrices); |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices); |
590 |
|
|
591 |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
bits += BITS_MULT*mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len; |
592 |
|
|
628 |
backup[i] = v[i]; |
backup[i] = v[i]; |
629 |
} |
} |
630 |
|
|
631 |
|
for (i = 0; i < 6; i++) { |
632 |
|
/* HVS models, anyone ? */ |
633 |
|
Data->lambda[i] = LAMBDA; |
634 |
|
} |
635 |
|
|
636 |
min_rd = findRD_inter(Data, x, y, pParam, MotionFlags); |
min_rd = findRD_inter(Data, x, y, pParam, MotionFlags); |
637 |
cbp = *Data->cbp; |
cbp = *Data->cbp; |
638 |
|
|