995 |
uint32_t mb_width = pParam->mb_width; |
uint32_t mb_width = pParam->mb_width; |
996 |
uint32_t mb_height = pParam->mb_height; |
uint32_t mb_height = pParam->mb_height; |
997 |
const uint32_t iEdgedWidth = pParam->edged_width; |
const uint32_t iEdgedWidth = pParam->edged_width; |
998 |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->global_flags); |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
999 |
|
|
1000 |
uint32_t x, y; |
uint32_t x, y; |
1001 |
uint32_t iIntra = 0; |
uint32_t iIntra = 0; |
1002 |
int32_t quant = current->quant, sad00; |
int32_t sad00; |
1003 |
|
|
1004 |
// some pre-initialized thingies for SearchP |
// some pre-initialized thingies for SearchP |
1005 |
int32_t temp[8]; |
int32_t temp[8]; |
1015 |
Data.temp = temp; |
Data.temp = temp; |
1016 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
1017 |
Data.rounding = pParam->m_rounding_type; |
Data.rounding = pParam->m_rounding_type; |
1018 |
Data.qpel = pParam->m_quarterpel; |
Data.qpel = current->vol_flags & XVID_QUARTERPEL; |
1019 |
Data.chroma = MotionFlags & PMV_CHROMA16; |
Data.chroma = MotionFlags & PMV_CHROMA16; |
1020 |
Data.rrv = current->global_flags & XVID_REDUCED; |
Data.rrv = current->vop_flags & XVID_REDUCED; |
1021 |
|
|
1022 |
if ((current->global_flags & XVID_REDUCED)) { |
if ((current->vop_flags & XVID_REDUCED)) { |
1023 |
mb_width = (pParam->width + 31) / 32; |
mb_width = (pParam->width + 31) / 32; |
1024 |
mb_height = (pParam->height + 31) / 32; |
mb_height = (pParam->height + 31) / 32; |
1025 |
Data.qpel = 0; |
Data.qpel = 0; |
1052 |
|
|
1053 |
sad00 = pMB->sad16; |
sad00 = pMB->sad16; |
1054 |
|
|
|
if (!(current->global_flags & XVID_LUMIMASKING)) { |
|
|
pMB->dquant = NO_CHANGE; |
|
|
} else { |
|
|
if (pMB->dquant != NO_CHANGE) { |
|
|
quant += DQtab[pMB->dquant]; |
|
|
if (quant > 31) quant = 31; |
|
|
else if (quant < 1) quant = 1; |
|
|
} |
|
|
} |
|
|
pMB->quant = current->quant; |
|
|
|
|
1055 |
//initial skip decision |
//initial skip decision |
1056 |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
/* no early skip for GMC (global vector = skip vector is unknown!) */ |
1057 |
if (!(current->global_flags & XVID_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
if (!(current->vol_flags & XVID_GMC)) { /* no fast SKIP for S(GMC)-VOPs */ |
1058 |
if (pMB->dquant == NO_CHANGE && sad00 < pMB->quant * INITIAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
if (pMB->dquant == 0 && sad00 < pMB->quant * INITIAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
1059 |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) { |
1060 |
SkipMacroblockP(pMB, sad00); |
SkipMacroblockP(pMB, sad00); |
1061 |
continue; |
continue; |
1063 |
} |
} |
1064 |
|
|
1065 |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x, |
1066 |
y, MotionFlags, current->global_flags, pMB->quant, |
y, MotionFlags, current->vol_flags, pMB->quant, |
1067 |
&Data, pParam, pMBs, reference->mbs, |
&Data, pParam, pMBs, reference->mbs, |
1068 |
current->global_flags & XVID_INTER4V, pMB); |
current->vop_flags & XVID_INTER4V, pMB); |
1069 |
|
|
1070 |
/* 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?" */ |
1071 |
if (!(current->global_flags & XVID_GMC)) { |
if (!(current->vol_flags & XVID_GMC)) { |
1072 |
if ( pMB->dquant == NO_CHANGE && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) { |
if ( pMB->dquant == 0 && sad00 < pMB->quant * MAX_SAD00_FOR_SKIP) { |
1073 |
if (!(current->global_flags & XVID_MODEDECISION_BITS)) { |
if (!(current->vop_flags & XVID_MODEDECISION_BITS)) { |
1074 |
if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
if ( (100*pMB->sad16)/(sad00+1) > FINAL_SKIP_THRESH * (Data.rrv ? 4:1) ) |
1075 |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) |
if (Data.chroma || SkipDecisionP(pCurrent, pRef, x, y, iEdgedWidth/2, pMB->quant, Data.rrv)) |
1076 |
SkipMacroblockP(pMB, sad00); |
SkipMacroblockP(pMB, sad00); |
1086 |
} |
} |
1087 |
} |
} |
1088 |
|
|
1089 |
if (current->global_flags & XVID_GMC ) /* GMC only for S(GMC)-VOPs */ |
if (current->vol_flags & XVID_GMC ) /* GMC only for S(GMC)-VOPs */ |
1090 |
{ |
{ |
1091 |
current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV); |
current->warp = GlobalMotionEst( pMBs, pParam, current, reference, pRefH, pRefV, pRefHV); |
1092 |
} |
} |
1161 |
const int x, const int y, |
const int x, const int y, |
1162 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1163 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1164 |
const uint32_t GlobalFlags) |
const uint32_t VopFlags) |
1165 |
{ |
{ |
1166 |
|
|
1167 |
int mode = MODE_INTER; |
int mode = MODE_INTER; |
1168 |
|
|
1169 |
if (!(GlobalFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision |
if (!(VopFlags & XVID_MODEDECISION_BITS)) { //normal, fast, SAD-based mode decision |
1170 |
// int intra = 0; |
// int intra = 0; |
1171 |
int sad; |
int sad; |
1172 |
int InterBias = MV16_INTER_BIAS; |
int InterBias = MV16_INTER_BIAS; |
1209 |
int bits, intra, i; |
int bits, intra, i; |
1210 |
VECTOR backup[5], *v; |
VECTOR backup[5], *v; |
1211 |
Data->lambda16 = iQuant; |
Data->lambda16 = iQuant; |
1212 |
Data->lambda8 = pParam->m_quant_type; |
Data->lambda8 = (pParam->vol_flags & XVID_MPEGQUANT)?1:0; |
1213 |
|
|
1214 |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1215 |
for (i = 0; i < 5; i++) { |
for (i = 0; i < 5; i++) { |
1243 |
const int x, |
const int x, |
1244 |
const int y, |
const int y, |
1245 |
const uint32_t MotionFlags, |
const uint32_t MotionFlags, |
1246 |
const uint32_t GlobalFlags, |
const uint32_t VopFlags, |
1247 |
const uint32_t iQuant, |
const uint32_t iQuant, |
1248 |
SearchData * const Data, |
SearchData * const Data, |
1249 |
const MBParam * const pParam, |
const MBParam * const pParam, |
1278 |
Data->lambda8 = lambda_vec8[iQuant]; |
Data->lambda8 = lambda_vec8[iQuant]; |
1279 |
Data->qpel_precision = 0; |
Data->qpel_precision = 0; |
1280 |
|
|
1281 |
if (pMB->dquant != NO_CHANGE) inter4v = 0; |
if (pMB->dquant != 0) inter4v = 0; |
1282 |
|
|
1283 |
for(i = 0; i < 5; i++) |
for(i = 0; i < 5; i++) |
1284 |
Data->currentMV[i].x = Data->currentMV[i].y = 0; |
Data->currentMV[i].x = Data->currentMV[i].y = 0; |
1293 |
Data->iMinSAD[3] = pMB->sad8[2]; |
Data->iMinSAD[3] = pMB->sad8[2]; |
1294 |
Data->iMinSAD[4] = pMB->sad8[3]; |
Data->iMinSAD[4] = pMB->sad8[3]; |
1295 |
|
|
1296 |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) || (x | y)) { |
if ((!(VopFlags & XVID_MODEDECISION_BITS)) || (x | y)) { |
1297 |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
threshA = Data->temp[0]; // that's where we keep this SAD atm |
1298 |
if (threshA < 512) threshA = 512; |
if (threshA < 512) threshA = 512; |
1299 |
else if (threshA > 1024) threshA = 1024; |
else if (threshA > 1024) threshA = 1024; |
1319 |
if ((Data->iMinSAD[0] <= threshA) || |
if ((Data->iMinSAD[0] <= threshA) || |
1320 |
(MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) && |
(MVequal(Data->currentMV[0], (prevMBs+x+y*pParam->mb_width)->mvs[0]) && |
1321 |
(Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) { |
(Data->iMinSAD[0] < (prevMBs+x+y*pParam->mb_width)->sad16))) { |
1322 |
if (!(GlobalFlags & XVID_MODEDECISION_BITS)) inter4v = 0; } |
if (!(VopFlags & XVID_MODEDECISION_BITS)) inter4v = 0; } |
1323 |
else { |
else { |
1324 |
|
|
1325 |
MainSearchFunc * MainSearchPtr; |
MainSearchFunc * MainSearchPtr; |
1382 |
SubpelRefine(Data); |
SubpelRefine(Data); |
1383 |
} |
} |
1384 |
|
|
1385 |
if ((!(GlobalFlags & XVID_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0; |
if ((!(VopFlags & XVID_MODEDECISION_BITS)) && (Data->iMinSAD[0] < (int32_t)iQuant * 30)) inter4v = 0; |
1386 |
|
|
1387 |
if (inter4v && (!(GlobalFlags & XVID_MODEDECISION_BITS) || |
if (inter4v && (!(VopFlags & XVID_MODEDECISION_BITS) || |
1388 |
(!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) || |
(!(MotionFlags & QUARTERPELREFINE8_BITS)) || (!(MotionFlags & HALFPELREFINE8_BITS)) || |
1389 |
((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_EXTSEARCH8)) ))) { |
((!(MotionFlags & EXTSEARCH_BITS)) && (!(MotionFlags&PMV_EXTSEARCH8)) ))) { |
1390 |
// if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop |
// if decision is BITS-based and all refinement steps will be done in BITS domain, there is no reason to call this loop |
1397 |
Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8); |
Search8(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8); |
1398 |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
Search8(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8); |
1399 |
|
|
1400 |
if ((Data->chroma) && (!(GlobalFlags & XVID_MODEDECISION_BITS))) { |
if ((Data->chroma) && (!(VopFlags & XVID_MODEDECISION_BITS))) { |
1401 |
// chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it |
// chroma is only used for comparsion to INTER. if the comparsion will be done in BITS domain, there is no reason to compute it |
1402 |
int sumx = 0, sumy = 0; |
int sumx = 0, sumy = 0; |
1403 |
const int div = 1 + Data->qpel; |
const int div = 1 + Data->qpel; |
1413 |
} |
} |
1414 |
} |
} |
1415 |
|
|
1416 |
inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, GlobalFlags); |
inter4v = ModeDecision(iQuant, Data, inter4v, pMB, pMBs, x, y, pParam, MotionFlags, VopFlags); |
1417 |
|
|
1418 |
if (Data->rrv) { |
if (Data->rrv) { |
1419 |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
2027 |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
2028 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = &iMinSAD; |
2029 |
Data.lambda16 = lambda_vec16[frame->quant]; |
Data.lambda16 = lambda_vec16[frame->quant]; |
2030 |
Data.qpel = pParam->m_quarterpel; |
Data.qpel = pParam->vol_flags & XVID_QUARTERPEL; |
2031 |
Data.rounding = 0; |
Data.rounding = 0; |
2032 |
Data.chroma = frame->motion_flags & PMV_CHROMA8; |
Data.chroma = frame->motion_flags & PMV_CHROMA8; |
2033 |
Data.temp = temp; |
Data.temp = temp; |
2052 |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
2053 |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
2054 |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurV = frame->image.v + (j * Data.iEdgedWidth/2 + i) * 8; |
|
pMB->quant = frame->quant; |
|
2055 |
|
|
2056 |
/* direct search comes first, because it (1) checks for SKIP-mode |
/* direct search comes first, because it (1) checks for SKIP-mode |
2057 |
and (2) sets very good predictions for forward and backward search */ |
and (2) sets very good predictions for forward and backward search */ |
2151 |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
else Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0); //else median |
2152 |
|
|
2153 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16, |
2154 |
pParam->width, pParam->height, Data->iFcode - pParam->m_quarterpel, 0, Data->rrv); |
pParam->width, pParam->height, Data->iFcode - (pParam->vol_flags&XVID_QUARTERPEL?1:0), 0, Data->rrv); |
2155 |
|
|
2156 |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
2157 |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
Data->Ref = pRef + (x + y * pParam->edged_width) * 16; |
2208 |
Data.currentMV = currentMV; |
Data.currentMV = currentMV; |
2209 |
Data.iMinSAD = iMinSAD; |
Data.iMinSAD = iMinSAD; |
2210 |
Data.iFcode = Current->fcode; |
Data.iFcode = Current->fcode; |
2211 |
Data.rrv = Current->global_flags & XVID_REDUCED; |
Data.rrv = Current->vop_flags & XVID_REDUCED; |
2212 |
Data.temp = temp; |
Data.temp = temp; |
2213 |
CheckCandidate = CheckCandidate32I; |
CheckCandidate = CheckCandidate32I; |
2214 |
|
|