20 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: estimation_rd_based.c,v 1.1.2.9 2003-11-13 23:11:24 edgomez Exp $ |
* $Id: estimation_rd_based.c,v 1.1.2.10 2003-11-19 12:24:25 syskin Exp $ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
172 |
|
|
173 |
|
|
174 |
static void |
static void |
175 |
CheckCandidateRD16(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidateRD16(const int x, const int y, SearchData * const data, const unsigned int Direction) |
176 |
{ |
{ |
177 |
|
|
178 |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
179 |
int32_t rd = 0; |
int32_t rd = 0; |
180 |
VECTOR * current; |
VECTOR * current; |
181 |
const uint8_t * ptr; |
const uint8_t * ptr; |
182 |
int i, cbp = 0, t, xc, yc; |
int i, t, xc, yc; |
183 |
|
unsigned cbp = 0; |
184 |
|
|
185 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
186 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
236 |
if (rd < data->iMinSAD[0]) { |
if (rd < data->iMinSAD[0]) { |
237 |
data->iMinSAD[0] = rd; |
data->iMinSAD[0] = rd; |
238 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
239 |
*data->dir = Direction; |
data->dir = Direction; |
240 |
*data->cbp = cbp; |
*data->cbp = cbp; |
241 |
} |
} |
242 |
} |
} |
243 |
|
|
244 |
static void |
static void |
245 |
CheckCandidateRD8(const int x, const int y, const SearchData * const data, const unsigned int Direction) |
CheckCandidateRD8(const int x, const int y, SearchData * const data, const unsigned int Direction) |
246 |
{ |
{ |
247 |
|
|
248 |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
int16_t *in = data->dctSpace, *coeff = data->dctSpace + 64; |
249 |
int32_t rd; |
int32_t rd; |
250 |
VECTOR * current; |
VECTOR * current; |
251 |
const uint8_t * ptr; |
const uint8_t * ptr; |
252 |
int cbp = 0; |
unsigned int cbp = 0; |
253 |
|
|
254 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
255 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
270 |
*data->cbp = cbp; |
*data->cbp = cbp; |
271 |
data->iMinSAD[0] = rd; |
data->iMinSAD[0] = rd; |
272 |
current[0].x = x; current[0].y = y; |
current[0].x = x; current[0].y = y; |
273 |
*data->dir = Direction; |
data->dir = Direction; |
274 |
} |
} |
275 |
} |
} |
276 |
|
|
337 |
} |
} |
338 |
|
|
339 |
static int |
static int |
340 |
findRD_inter4v(const SearchData * const Data, |
findRD_inter4v(SearchData * const Data, |
341 |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
MACROBLOCK * const pMB, const MACROBLOCK * const pMBs, |
342 |
const int x, const int y, |
const int x, const int y, |
343 |
const MBParam * const pParam, const uint32_t MotionFlags, |
const MBParam * const pParam, const uint32_t MotionFlags, |
344 |
const VECTOR * const backup) |
const VECTOR * const backup) |
345 |
{ |
{ |
346 |
|
|
347 |
int cbp = 0, bits = 0, t = 0, i; |
unsigned int cbp = 0, bits = 0, t = 0, i; |
348 |
SearchData Data2, *Data8 = &Data2; |
SearchData Data2, *Data8 = &Data2; |
349 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
350 |
int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64; |
int16_t *in = Data->dctSpace, *coeff = Data->dctSpace + 64; |
354 |
|
|
355 |
for (i = 0; i < 4; i++) { /* for all luma blocks */ |
for (i = 0; i < 4; i++) { /* for all luma blocks */ |
356 |
|
|
357 |
Data8->iMinSAD = Data->iMinSAD + i + 1; |
*Data8->iMinSAD = *(Data->iMinSAD + i + 1); |
358 |
Data8->currentMV = Data->currentMV + i + 1; |
*Data8->currentMV = *(Data->currentMV + i + 1); |
359 |
Data8->currentQMV = Data->currentQMV + i + 1; |
*Data8->currentQMV = *(Data->currentQMV + i + 1); |
360 |
Data8->Cur = Data->Cur + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->Cur = Data->Cur + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
361 |
Data8->RefP[0] = Data->RefP[0] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[0] = Data->RefP[0] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
362 |
Data8->RefP[2] = Data->RefP[2] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
Data8->RefP[2] = Data->RefP[2] + 8*((i&1) + (i>>1)*Data->iEdgedWidth); |
481 |
} |
} |
482 |
|
|
483 |
static int |
static int |
484 |
findRD_intra(const SearchData * const Data, MACROBLOCK * pMB, |
findRD_intra(SearchData * const Data, MACROBLOCK * pMB, |
485 |
const int x, const int y, const int mb_width) |
const int x, const int y, const int mb_width) |
486 |
{ |
{ |
487 |
int cbp[2] = {0, 0}, bits[2], i; |
unsigned int cbp[2] = {0, 0}, bits[2], i; |
488 |
int bits1 = BITS_MULT*1, bits2 = BITS_MULT*1; /* this one is ac/dc prediction flag bit */ |
unsigned int bits1 = BITS_MULT*1, bits2 = BITS_MULT*1; /* this one is ac/dc prediction flag bit */ |
489 |
int distortion = 0; |
unsigned int distortion = 0; |
490 |
|
|
491 |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64, * dqcoeff = Data->dctSpace + 128; |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64, * dqcoeff = Data->dctSpace + 128; |
492 |
const uint32_t iQuant = Data->iQuant; |
const uint32_t iQuant = Data->iQuant; |
537 |
|
|
538 |
|
|
539 |
static int |
static int |
540 |
findRD_gmc(const SearchData * const Data, const IMAGE * const vGMC, const int x, const int y) |
findRD_gmc(SearchData * const Data, const IMAGE * const vGMC, const int x, const int y) |
541 |
{ |
{ |
542 |
int bits = BITS_MULT*1; /* this one is mcsel */ |
int bits = BITS_MULT*1; /* this one is mcsel */ |
543 |
int cbp = 0, i; |
unsigned int cbp = 0, i; |
544 |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64; |
int16_t *in = Data->dctSpace, * coeff = Data->dctSpace + 64; |
545 |
|
|
546 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
588 |
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
589 |
const uint32_t iQuant = pMB->quant; |
const uint32_t iQuant = pMB->quant; |
590 |
|
|
591 |
int min_rd, intra_rd, i, cbp, c[2] = {0, 0}; |
int min_rd, intra_rd, i, cbp; |
592 |
VECTOR backup[5], *v; |
VECTOR backup[5], *v; |
593 |
Data->iQuant = iQuant; |
Data->iQuant = iQuant; |
|
Data->cbp = c; |
|
594 |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
Data->scan_table = VopFlags & XVID_VOP_ALTERNATESCAN ? |
595 |
scan_tables[2] : scan_tables[0]; |
scan_tables[2] : scan_tables[0]; |
596 |
|
|
694 |
const uint32_t iQuant = pMB->quant; |
const uint32_t iQuant = pMB->quant; |
695 |
const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0); |
const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0); |
696 |
int sad; |
int sad; |
697 |
int min_rd = -1, intra_rd, i, cbp = 63, c[2] = {0, 0}; |
int min_rd = -1, intra_rd, i, cbp = 63; |
698 |
VECTOR backup[5], *v; |
VECTOR backup[5], *v; |
699 |
int sad_backup[5]; |
int sad_backup[5]; |
700 |
int InterBias = MV16_INTER_BIAS; |
int InterBias = MV16_INTER_BIAS; |
748 |
} |
} |
749 |
} else { /* Rate-Distortion INTER<->INTER4V */ |
} else { /* Rate-Distortion INTER<->INTER4V */ |
750 |
Data->iQuant = iQuant; |
Data->iQuant = iQuant; |
|
Data->cbp = c; |
|
751 |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
752 |
|
|
753 |
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
848 |
} else { /* Rate-Distortion INTRA<->INTER */ |
} else { /* Rate-Distortion INTRA<->INTER */ |
849 |
if(min_rd < 0) { |
if(min_rd < 0) { |
850 |
Data->iQuant = iQuant; |
Data->iQuant = iQuant; |
|
Data->cbp = c; |
|
851 |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
852 |
|
|
853 |
for (i = 0; i < 5; i++) { |
for (i = 0; i < 5; i++) { |