4 |
* - Rate-Distortion Based Motion Estimation for P- and S- VOPs - |
* - Rate-Distortion Based Motion Estimation for P- and S- VOPs - |
5 |
* |
* |
6 |
* Copyright(C) 2003 Radoslaw Czyz <xvid@syskin.cjb.net> |
* Copyright(C) 2003 Radoslaw Czyz <xvid@syskin.cjb.net> |
7 |
* 2003 Michael Militzer <michael@xvid.org> |
* 2003-2010 Michael Militzer <michael@xvid.org> |
8 |
* |
* |
9 |
* This program is free software ; you can redistribute it and/or modify |
* This program is free software ; you can redistribute it and/or modify |
10 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
58 |
const uint16_t * scan_table, |
const uint16_t * scan_table, |
59 |
const unsigned int lambda, |
const unsigned int lambda, |
60 |
const uint16_t * mpeg_quant_matrices, |
const uint16_t * mpeg_quant_matrices, |
61 |
const unsigned int quant_sq) |
const unsigned int quant_sq, |
62 |
|
const unsigned int rel_var8, |
63 |
|
const unsigned int metric) |
64 |
{ |
{ |
65 |
int sum; |
int sum; |
66 |
int bits; |
int bits; |
78 |
if (quant_type) dequant_h263_inter(dqcoeff, coeff, quant, mpeg_quant_matrices); |
if (quant_type) dequant_h263_inter(dqcoeff, coeff, quant, mpeg_quant_matrices); |
79 |
else dequant_mpeg_inter(dqcoeff, coeff, quant, mpeg_quant_matrices); |
else dequant_mpeg_inter(dqcoeff, coeff, quant, mpeg_quant_matrices); |
80 |
|
|
81 |
distortion = sse8_16bit(data, dqcoeff, 8*sizeof(int16_t)); |
if (metric) distortion = masked_sseh8_16bit(data, dqcoeff, rel_var8); |
82 |
|
else distortion = sse8_16bit(data, dqcoeff, 8*sizeof(int16_t)); |
83 |
|
|
84 |
} else { |
} else { |
85 |
const static int16_t zero_block[64] = |
const static int16_t zero_block[64] = |
86 |
{ |
{ |
94 |
0, 0, 0, 0, 0, 0, 0, 0, |
0, 0, 0, 0, 0, 0, 0, 0, |
95 |
}; |
}; |
96 |
bits = 0; |
bits = 0; |
|
distortion = sse8_16bit(data, zero_block, 8*sizeof(int16_t)); |
|
|
} |
|
97 |
|
|
98 |
|
if (metric) distortion = masked_sseh8_16bit(data, (int16_t * const) zero_block, rel_var8); |
99 |
|
else distortion = sse8_16bit(data, (int16_t * const) zero_block, 8*sizeof(int16_t)); |
100 |
|
|
101 |
|
} |
102 |
|
|
103 |
return bits + (lambda*distortion)/quant_sq; |
return bits + (lambda*distortion)/quant_sq; |
104 |
} |
} |
119 |
unsigned int cbp[2], |
unsigned int cbp[2], |
120 |
unsigned int lambda, |
unsigned int lambda, |
121 |
const uint16_t * mpeg_quant_matrices, |
const uint16_t * mpeg_quant_matrices, |
122 |
const unsigned int quant_sq) |
const unsigned int quant_sq, |
123 |
|
const unsigned int metric, |
124 |
|
const int bound) |
125 |
{ |
{ |
126 |
int direction; |
int direction; |
127 |
int16_t *pCurrent; |
int16_t *pCurrent; |
140 |
} |
} |
141 |
|
|
142 |
predict_acdc(pMB-(x+mb_width*y), x, y, mb_width, block, qcoeff, |
predict_acdc(pMB-(x+mb_width*y), x, y, mb_width, block, qcoeff, |
143 |
quant, iDcScaler, predictors, 0); |
quant, iDcScaler, predictors, bound); |
144 |
|
|
145 |
direction = pMB->acpred_directions[block]; |
direction = pMB->acpred_directions[block]; |
146 |
pCurrent = (int16_t*)pMB->pred_values[block]; |
pCurrent = (int16_t*)pMB->pred_values[block]; |
179 |
bits[1] += coded = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]); |
bits[1] += coded = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]); |
180 |
if (coded > 0) cbp[1] |= 1 << (5 - block); |
if (coded > 0) cbp[1] |= 1 << (5 - block); |
181 |
|
|
182 |
distortion = sse8_16bit(coeff, dqcoeff, 8*sizeof(int16_t)); |
if (metric) distortion = masked_sseh8_16bit(coeff, dqcoeff, pMB->rel_var8[block]); |
183 |
|
else distortion = sse8_16bit(coeff, dqcoeff, 8*sizeof(int16_t)); |
184 |
|
|
185 |
return (lambda*distortion)/quant_sq; |
return (lambda*distortion)/quant_sq; |
186 |
} |
} |
217 |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur + s, ptr + s, data->iEdgedWidth); |
218 |
rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, |
rd += data->temp[i] = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, |
219 |
data->quant_type, &cbp, i, data->scan_table, data->lambda[i], |
data->quant_type, &cbp, i, data->scan_table, data->lambda[i], |
220 |
data->mpeg_quant_matrices, data->quant_sq); |
data->mpeg_quant_matrices, data->quant_sq, data->rel_var8[i], data->metric); |
221 |
} |
} |
222 |
|
|
223 |
rd += t = BITS_MULT * (d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision) - 2); |
rd += t = BITS_MULT * (d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision) - 2); |
244 |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurU, ptr, data->iEdgedWidth/2); |
245 |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
246 |
&cbp, 4, data->scan_table, data->lambda[4], |
&cbp, 4, data->scan_table, data->lambda[4], |
247 |
data->mpeg_quant_matrices, data->quant_sq); |
data->mpeg_quant_matrices, data->quant_sq, data->rel_var8[4], data->metric); |
248 |
if (rd >= data->iMinSAD[0]) return; |
if (rd >= data->iMinSAD[0]) return; |
249 |
|
|
250 |
/* chroma V */ |
/* chroma V */ |
252 |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
transfer_8to16subro(in, data->CurV, ptr, data->iEdgedWidth/2); |
253 |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
rd += Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
254 |
&cbp, 5, data->scan_table, data->lambda[5], |
&cbp, 5, data->scan_table, data->lambda[5], |
255 |
data->mpeg_quant_matrices, data->quant_sq); |
data->mpeg_quant_matrices, data->quant_sq, data->rel_var8[5], data->metric); |
256 |
|
|
257 |
rd += BITS_MULT * (mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len - 1); /* one was added before */ |
rd += BITS_MULT * (mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len - 1); /* one was added before */ |
258 |
|
|
288 |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
transfer_8to16subro(in, data->Cur, ptr, data->iEdgedWidth); |
289 |
rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
rd = Block_CalcBits(coeff, in, data->dctSpace + 128, data->iQuant, data->quant_type, |
290 |
&cbp, 5, data->scan_table, data->lambda[0], |
&cbp, 5, data->scan_table, data->lambda[0], |
291 |
data->mpeg_quant_matrices, data->quant_sq); |
data->mpeg_quant_matrices, data->quant_sq, data->rel_var8[0], data->metric); |
292 |
/* we took 2 bits into account before */ |
/* we took 2 bits into account before */ |
293 |
rd += BITS_MULT * (d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision) - 2); |
rd += BITS_MULT * (d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision) - 2); |
294 |
|
|
372 |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
373 |
const int x, const int y, |
const int x, const int y, |
374 |
const MBParam * const pParam, const uint32_t MotionFlags, |
const MBParam * const pParam, const uint32_t MotionFlags, |
375 |
const VECTOR * const backup) |
const VECTOR * const backup, const int bound) |
376 |
{ |
{ |
377 |
|
|
378 |
unsigned int cbp = 0, t = 0, i; |
unsigned int cbp = 0, t = 0, i; |
398 |
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); |
399 |
*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 */ |
400 |
Data8->lambda[0] = Data->lambda[i]; |
Data8->lambda[0] = Data->lambda[i]; |
401 |
|
Data8->rel_var8[0] = Data->rel_var8[i]; |
402 |
|
|
403 |
if(Data->qpel) { |
if(Data->qpel) { |
404 |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, i); |
Data8->predMV = get_qpmv2(pMBs, pParam->mb_width, bound, x, y, i); |
405 |
if (i != 0) t = d_mv_bits( Data8->currentQMV->x, Data8->currentQMV->y, |
if (i != 0) t = d_mv_bits( Data8->currentQMV->x, Data8->currentQMV->y, |
406 |
Data8->predMV, Data8->iFcode, 0) - 2; |
Data8->predMV, Data8->iFcode, 0) - 2; |
407 |
} else { |
} else { |
408 |
Data8->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, i); |
Data8->predMV = get_pmv2(pMBs, pParam->mb_width, bound, x, y, i); |
409 |
if (i != 0) t = d_mv_bits( Data8->currentMV->x, Data8->currentMV->y, |
if (i != 0) t = d_mv_bits( Data8->currentMV->x, Data8->currentMV->y, |
410 |
Data8->predMV, Data8->iFcode, 0) - 2; |
Data8->predMV, Data8->iFcode, 0) - 2; |
411 |
} |
} |
518 |
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); |
519 |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurU, ptr, Data->iEdgedWidth/2); |
520 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, |
521 |
Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices, Data->quant_sq, Data->rel_var8[4], Data->metric); |
522 |
|
|
523 |
if (bits >= *Data->iMinSAD) return bits; |
if (bits >= *Data->iMinSAD) return bits; |
524 |
|
|
526 |
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); |
527 |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
transfer_8to16subro(in, Data->CurV, ptr, Data->iEdgedWidth/2); |
528 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, |
529 |
Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices, Data->quant_sq, Data->rel_var8[5], Data->metric); |
530 |
|
|
531 |
bits += BITS_MULT*(mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len - 3); /* 3 were added before */ |
bits += BITS_MULT*(mcbpc_inter_tab[(MODE_INTER4V & 7) | ((cbp & 3) << 3)].len - 3); /* 3 were added before */ |
532 |
|
|
536 |
|
|
537 |
static int |
static int |
538 |
findRD_intra(SearchData * const Data, MACROBLOCK * pMB, |
findRD_intra(SearchData * const Data, MACROBLOCK * pMB, |
539 |
const int x, const int y, const int mb_width) |
const int x, const int y, const int mb_width, const int bound) |
540 |
{ |
{ |
541 |
unsigned int cbp[2] = {0, 0}, bits[2], i; |
unsigned int cbp[2] = {0, 0}, bits[2], i; |
542 |
/* minimum number of bits that WILL be coded in intra - mcbpc 5, cby 2 acdc flag - 1 and DC coeffs - 4*3+2*2 */ |
/* minimum number of bits that WILL be coded in intra - mcbpc 5, cby 2 acdc flag - 1 and DC coeffs - 4*3+2*2 */ |
554 |
|
|
555 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, i, in, coeff, dqcoeff, |
556 |
predictors[i], iQuant, Data->quant_type, bits, cbp, |
predictors[i], iQuant, Data->quant_type, bits, cbp, |
557 |
Data->lambda[i], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->lambda[i], Data->mpeg_quant_matrices, Data->quant_sq, |
558 |
|
Data->metric, bound); |
559 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
560 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
561 |
|
|
570 |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurU, Data->iEdgedWidth/2); |
571 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 4, in, coeff, dqcoeff, |
572 |
predictors[4], iQuant, Data->quant_type, bits, cbp, |
predictors[4], iQuant, Data->quant_type, bits, cbp, |
573 |
Data->lambda[4], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->lambda[4], Data->mpeg_quant_matrices, Data->quant_sq, |
574 |
|
Data->metric, bound); |
575 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
576 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
577 |
|
|
582 |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
transfer_8to16copy(in, Data->CurV, Data->iEdgedWidth/2); |
583 |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff, |
distortion = Block_CalcBitsIntra(pMB, x, y, mb_width, 5, in, coeff, dqcoeff, |
584 |
predictors[5], iQuant, Data->quant_type, bits, cbp, |
predictors[5], iQuant, Data->quant_type, bits, cbp, |
585 |
Data->lambda[5], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->lambda[5], Data->mpeg_quant_matrices, Data->quant_sq, |
586 |
|
Data->metric, bound); |
587 |
|
|
588 |
bits1 += distortion + BITS_MULT * bits[0]; |
bits1 += distortion + BITS_MULT * bits[0]; |
589 |
bits2 += distortion + BITS_MULT * bits[1]; |
bits2 += distortion + BITS_MULT * bits[1]; |
609 |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
int s = 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
610 |
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); |
611 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, i, |
612 |
Data->scan_table, Data->lambda[i], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->scan_table, Data->lambda[i], Data->mpeg_quant_matrices, |
613 |
|
Data->quant_sq, Data->rel_var8[i], Data->metric); |
614 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
615 |
} |
} |
616 |
|
|
619 |
/*chroma U */ |
/*chroma U */ |
620 |
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); |
621 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 4, |
622 |
Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->scan_table, Data->lambda[4], Data->mpeg_quant_matrices, |
623 |
|
Data->quant_sq, Data->rel_var8[4], Data->metric); |
624 |
|
|
625 |
if (bits >= Data->iMinSAD[0]) return bits; |
if (bits >= Data->iMinSAD[0]) return bits; |
626 |
|
|
627 |
/* chroma V */ |
/* chroma V */ |
628 |
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); |
629 |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, |
bits += Block_CalcBits(coeff, in, Data->dctSpace + 128, Data->iQuant, Data->quant_type, &cbp, 5, |
630 |
Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices, Data->quant_sq); |
Data->scan_table, Data->lambda[5], Data->mpeg_quant_matrices, |
631 |
|
Data->quant_sq, Data->rel_var8[5], Data->metric); |
632 |
|
|
633 |
bits += BITS_MULT * (mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len - 1); |
bits += BITS_MULT * (mcbpc_inter_tab[(MODE_INTER & 7) | ((cbp & 3) << 3)].len - 1); |
634 |
|
|
649 |
const IMAGE * const pCurrent, |
const IMAGE * const pCurrent, |
650 |
const IMAGE * const pRef, |
const IMAGE * const pRef, |
651 |
const IMAGE * const vGMC, |
const IMAGE * const vGMC, |
652 |
const int coding_type) |
const int coding_type, |
653 |
|
const int bound) |
654 |
{ |
{ |
655 |
int mode = MODE_INTER; |
int mode = MODE_INTER; |
656 |
int mcsel = 0; |
int mcsel = 0; |
662 |
Data->quant_sq = iQuant*iQuant; |
Data->quant_sq = iQuant*iQuant; |
663 |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
664 |
scan_tables[2] : scan_tables[0]; |
scan_tables[2] : scan_tables[0]; |
665 |
|
Data->metric = !!(VopFlags & XVID_VOP_RD_PSNRHVSM); |
666 |
|
|
667 |
pMB->mcsel = 0; |
pMB->mcsel = 0; |
668 |
|
|
674 |
|
|
675 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
676 |
Data->lambda[i] = (LAMBDA*pMB->lambda[i])>>LAMBDA_EXP; |
Data->lambda[i] = (LAMBDA*pMB->lambda[i])>>LAMBDA_EXP; |
677 |
|
Data->rel_var8[i] = pMB->rel_var8[i]; |
678 |
} |
} |
679 |
|
|
680 |
min_rd = findRD_inter(Data, x, y, pParam, MotionFlags); |
min_rd = findRD_inter(Data, x, y, pParam, MotionFlags); |
694 |
|
|
695 |
if (inter4v) { |
if (inter4v) { |
696 |
int v4_rd; |
int v4_rd; |
697 |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup, bound); |
698 |
if (v4_rd < min_rd) { |
if (v4_rd < min_rd) { |
699 |
Data->iMinSAD[0] = min_rd = v4_rd; |
Data->iMinSAD[0] = min_rd = v4_rd; |
700 |
mode = MODE_INTER4V; |
mode = MODE_INTER4V; |
704 |
|
|
705 |
/* there is no way for INTRA to take less than 24 bits - go to findRD_intra() for calculations */ |
/* there is no way for INTRA to take less than 24 bits - go to findRD_intra() for calculations */ |
706 |
if (min_rd > 24*BITS_MULT) { |
if (min_rd > 24*BITS_MULT) { |
707 |
intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width); |
intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width, bound); |
708 |
if (intra_rd < min_rd) { |
if (intra_rd < min_rd) { |
709 |
*Data->iMinSAD = min_rd = intra_rd; |
*Data->iMinSAD = min_rd = intra_rd; |
710 |
mode = MODE_INTRA; |
mode = MODE_INTRA; |
758 |
const IMAGE * const pCurrent, |
const IMAGE * const pCurrent, |
759 |
const IMAGE * const pRef, |
const IMAGE * const pRef, |
760 |
const IMAGE * const vGMC, |
const IMAGE * const vGMC, |
761 |
const int coding_type) |
const int coding_type, |
762 |
|
const int bound) |
763 |
{ |
{ |
764 |
int mode = MODE_INTER; |
int mode = MODE_INTER; |
765 |
int mcsel = 0; |
int mcsel = 0; |
775 |
int top = 0, top_right = 0, left = 0; |
int top = 0, top_right = 0, left = 0; |
776 |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
777 |
scan_tables[2] : scan_tables[0]; |
scan_tables[2] : scan_tables[0]; |
778 |
|
Data->metric = !!(VopFlags & XVID_VOP_RD_PSNRHVSM); |
779 |
|
|
780 |
pMB->mcsel = 0; |
pMB->mcsel = 0; |
781 |
Data->iQuant = iQuant; |
Data->iQuant = iQuant; |
783 |
|
|
784 |
for (i = 0; i < 6; i++) { |
for (i = 0; i < 6; i++) { |
785 |
Data->lambda[i] = (LAMBDA*pMB->lambda[i])>>LAMBDA_EXP; |
Data->lambda[i] = (LAMBDA*pMB->lambda[i])>>LAMBDA_EXP; |
786 |
|
Data->rel_var8[i] = pMB->rel_var8[i]; |
787 |
} |
} |
788 |
|
|
789 |
/* INTER <-> INTER4V decision */ |
/* INTER <-> INTER4V decision */ |
871 |
|
|
872 |
if (inter4v) { |
if (inter4v) { |
873 |
int v4_rd; |
int v4_rd; |
874 |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup, bound); |
875 |
if (v4_rd < min_rd) { |
if (v4_rd < min_rd) { |
876 |
Data->iMinSAD[0] = min_rd = v4_rd; |
Data->iMinSAD[0] = min_rd = v4_rd; |
877 |
mode = MODE_INTER4V; |
mode = MODE_INTER4V; |
947 |
|
|
948 |
if(mode == MODE_INTER4V) { |
if(mode == MODE_INTER4V) { |
949 |
int v4_rd; |
int v4_rd; |
950 |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
v4_rd = findRD_inter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup, bound); |
951 |
if (v4_rd < min_rd) { |
if (v4_rd < min_rd) { |
952 |
Data->iMinSAD[0] = min_rd = v4_rd; |
Data->iMinSAD[0] = min_rd = v4_rd; |
953 |
mode = MODE_INTER4V; |
mode = MODE_INTER4V; |
956 |
} |
} |
957 |
} |
} |
958 |
|
|
959 |
intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width); |
intra_rd = findRD_intra(Data, pMB, x, y, pParam->mb_width, bound); |
960 |
if (intra_rd < min_rd) { |
if (intra_rd < min_rd) { |
961 |
*Data->iMinSAD = min_rd = intra_rd; |
*Data->iMinSAD = min_rd = intra_rd; |
962 |
mode = MODE_INTRA; |
mode = MODE_INTRA; |