21 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
22 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
23 |
* |
* |
24 |
* $Id: motion_est.c,v 1.58.2.30 2003-08-28 11:14:04 syskin Exp $ |
* $Id: motion_est.c,v 1.58.2.35 2003-09-06 11:24:50 Isibaar Exp $ |
25 |
* |
* |
26 |
****************************************************************************/ |
****************************************************************************/ |
27 |
|
|
347 |
} |
} |
348 |
|
|
349 |
static void |
static void |
350 |
|
CheckCandidate16_subpel(const int x, const int y, const SearchData * const data, const int Direction) |
351 |
|
{ |
352 |
|
int xc, yc; |
353 |
|
const uint8_t *Reference; |
354 |
|
VECTOR *current, *current2; |
355 |
|
int32_t sad; uint32_t t; |
356 |
|
|
357 |
|
if ( (x > data->max_dx) || (x < data->min_dx) |
358 |
|
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
359 |
|
|
360 |
|
if (!data->qpel_precision) { |
361 |
|
Reference = GetReference(x, y, data); |
362 |
|
current = data->currentMV; |
363 |
|
current2 = data->currentMV2; |
364 |
|
xc = x; yc = y; |
365 |
|
} else { /* x and y are in 1/4 precision */ |
366 |
|
Reference = Interpolate16x16qpel(x, y, 0, data); |
367 |
|
xc = x/2; yc = y/2; /* for chroma sad */ |
368 |
|
current = data->currentQMV; |
369 |
|
current2 = data->currentQMV2; |
370 |
|
} |
371 |
|
|
372 |
|
sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); |
373 |
|
t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision, 0); |
374 |
|
|
375 |
|
sad += (data->lambda16 * t * sad)>>10; |
376 |
|
data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; |
377 |
|
|
378 |
|
if (data->chroma && sad < data->iMinSAD[0]) |
379 |
|
sad += ChromaSAD((xc >> 1) + roundtab_79[xc & 0x3], |
380 |
|
(yc >> 1) + roundtab_79[yc & 0x3], data); |
381 |
|
|
382 |
|
if (data->temp[0] < data->iMinSAD[1]) { |
383 |
|
data->iMinSAD[1] = data->temp[0]; current[1].x = x; current[1].y = y; } |
384 |
|
if (data->temp[1] < data->iMinSAD[2]) { |
385 |
|
data->iMinSAD[2] = data->temp[1]; current[2].x = x; current[2].y = y; } |
386 |
|
if (data->temp[2] < data->iMinSAD[3]) { |
387 |
|
data->iMinSAD[3] = data->temp[2]; current[3].x = x; current[3].y = y; } |
388 |
|
if (data->temp[3] < data->iMinSAD[4]) { |
389 |
|
data->iMinSAD[4] = data->temp[3]; current[4].x = x; current[4].y = y; } |
390 |
|
|
391 |
|
if (sad < data->iMinSAD[0]) { |
392 |
|
*(data->iMinSAD2) = *(data->iMinSAD); |
393 |
|
current2->x = current->x; current2->y = current->y; |
394 |
|
|
395 |
|
data->iMinSAD[0] = sad; |
396 |
|
current[0].x = x; current[0].y = y; |
397 |
|
*data->dir = Direction; |
398 |
|
return; |
399 |
|
} |
400 |
|
|
401 |
|
if (sad < *(data->iMinSAD2)) { |
402 |
|
*(data->iMinSAD2) = sad; |
403 |
|
current2->x = x; current2->y = y; |
404 |
|
*data->dir = Direction; |
405 |
|
} |
406 |
|
} |
407 |
|
|
408 |
|
static void |
409 |
CheckCandidate8(const int x, const int y, const SearchData * const data, const int Direction) |
CheckCandidate8(const int x, const int y, const SearchData * const data, const int Direction) |
410 |
{ |
{ |
411 |
int32_t sad; uint32_t t; |
int32_t sad; uint32_t t; |
546 |
if ( (x > data->max_dx) || (x < data->min_dx) |
if ( (x > data->max_dx) || (x < data->min_dx) |
547 |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
|| (y > data->max_dy) || (y < data->min_dy) ) return; |
548 |
|
|
549 |
sad = sad32v_c(data->Cur, data->RefP[0] + (x>>1) + (y>>1)*((int)data->iEdgedWidth), |
sad = sad32v_c(data->Cur, data->RefP[0] + x + y*((int)data->iEdgedWidth), |
550 |
data->iEdgedWidth, data->temp); |
data->iEdgedWidth, data->temp); |
551 |
|
|
552 |
if (sad < *(data->iMinSAD)) { |
if (sad < *(data->iMinSAD)) { |
977 |
/* MAINSEARCH FUNCTIONS END */ |
/* MAINSEARCH FUNCTIONS END */ |
978 |
|
|
979 |
static void |
static void |
980 |
|
SubpelRefine_Fast(SearchData * data, CheckFunc * CheckCandidate) |
981 |
|
{ |
982 |
|
/* Do a half-pel or q-pel refinement */ |
983 |
|
VECTOR centerMV; |
984 |
|
VECTOR second_best; |
985 |
|
int best_sad = *data->iMinSAD; |
986 |
|
int xo, yo, xo2, yo2; |
987 |
|
int size = 2; |
988 |
|
CheckFunc *backupFunc = CheckCandidate; |
989 |
|
|
990 |
|
if(data->qpel_precision) |
991 |
|
size = 1; |
992 |
|
|
993 |
|
centerMV = *data->currentMV; |
994 |
|
*data->iMinSAD = 256 * 4096; |
995 |
|
|
996 |
|
CHECK_CANDIDATE(centerMV.x, centerMV.y - size, 0); |
997 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y - size, 0); |
998 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y, 0); |
999 |
|
CHECK_CANDIDATE(centerMV.x + size, centerMV.y + size, 0); |
1000 |
|
|
1001 |
|
CHECK_CANDIDATE(centerMV.x, centerMV.y + size, 0); |
1002 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y + size, 0); |
1003 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y, 0); |
1004 |
|
CHECK_CANDIDATE(centerMV.x - size, centerMV.y - size, 0); |
1005 |
|
|
1006 |
|
second_best = *data->currentMV; |
1007 |
|
|
1008 |
|
if(data->qpel_precision) { |
1009 |
|
second_best.x *= 2; second_best.y *= 2; |
1010 |
|
} |
1011 |
|
|
1012 |
|
data->currentMV[0] = centerMV; |
1013 |
|
*data->iMinSAD = best_sad; |
1014 |
|
|
1015 |
|
centerMV = data->qpel_precision ? *data->currentQMV : *data->currentMV; |
1016 |
|
|
1017 |
|
xo = centerMV.x; |
1018 |
|
yo = centerMV.y; |
1019 |
|
xo2 = second_best.x; |
1020 |
|
yo2 = second_best.y; |
1021 |
|
|
1022 |
|
CheckCandidate = CheckCandidate16_subpel; |
1023 |
|
*data->iMinSAD2 = 256 * 4096; |
1024 |
|
|
1025 |
|
if (yo == yo2) |
1026 |
|
{ |
1027 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
1028 |
|
CHECK_CANDIDATE(xo, yo-1, 0); |
1029 |
|
CHECK_CANDIDATE(xo, yo+1, 0); |
1030 |
|
|
1031 |
|
if(best_sad <= *data->iMinSAD2) |
1032 |
|
goto ende; |
1033 |
|
|
1034 |
|
if(data->currentQMV[0].x == data->currentQMV2[0].x) { |
1035 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo-1, 0); |
1036 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo+1, 0); |
1037 |
|
goto ende; |
1038 |
|
} |
1039 |
|
else { |
1040 |
|
CHECK_CANDIDATE((xo+xo2)>>1, |
1041 |
|
(data->currentQMV[0].x == xo) ? data->currentQMV[0].y : data->currentQMV2[0].y, |
1042 |
|
0); |
1043 |
|
goto ende; |
1044 |
|
} |
1045 |
|
} |
1046 |
|
|
1047 |
|
if (xo == xo2) |
1048 |
|
{ |
1049 |
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
1050 |
|
CHECK_CANDIDATE(xo-1, yo, 0); |
1051 |
|
CHECK_CANDIDATE(xo+1, yo, 0); |
1052 |
|
|
1053 |
|
if(best_sad < *data->iMinSAD2) |
1054 |
|
goto ende; |
1055 |
|
|
1056 |
|
if(data->currentQMV[0].y == data->currentQMV2[0].y) { |
1057 |
|
CHECK_CANDIDATE(xo-1, (yo+yo2)>>1, 0); |
1058 |
|
CHECK_CANDIDATE(xo+1, (yo+yo2)>>1, 0); |
1059 |
|
goto ende; |
1060 |
|
} |
1061 |
|
else { |
1062 |
|
CHECK_CANDIDATE((data->currentQMV[0].y == yo) ? data->currentQMV[0].x : data->currentQMV2[0].x, (yo+yo2)>>1, 0); |
1063 |
|
goto ende; |
1064 |
|
} |
1065 |
|
} |
1066 |
|
|
1067 |
|
CHECK_CANDIDATE(xo, (yo+yo2)>>1, 0); |
1068 |
|
CHECK_CANDIDATE((xo+xo2)>>1, yo, 0); |
1069 |
|
|
1070 |
|
if(best_sad <= *data->iMinSAD2) |
1071 |
|
goto ende; |
1072 |
|
|
1073 |
|
CHECK_CANDIDATE((xo+xo2)>>1, (yo+yo2)>>1, 0); |
1074 |
|
|
1075 |
|
ende: |
1076 |
|
CheckCandidate = backupFunc; |
1077 |
|
} |
1078 |
|
|
1079 |
|
static void |
1080 |
SubpelRefine(const SearchData * const data, CheckFunc * const CheckCandidate) |
SubpelRefine(const SearchData * const data, CheckFunc * const CheckCandidate) |
1081 |
{ |
{ |
1082 |
/* Do a half-pel or q-pel refinement */ |
/* Do a half-pel or q-pel refinement */ |
1129 |
} |
} |
1130 |
|
|
1131 |
static __inline void |
static __inline void |
1132 |
|
ModeDecision_Fast(SearchData * const Data, |
1133 |
|
MACROBLOCK * const pMB, |
1134 |
|
const MACROBLOCK * const pMBs, |
1135 |
|
const int x, const int y, |
1136 |
|
const MBParam * const pParam, |
1137 |
|
const uint32_t MotionFlags, |
1138 |
|
const uint32_t VopFlags, |
1139 |
|
const uint32_t VolFlags, |
1140 |
|
const IMAGE * const pCurrent, |
1141 |
|
const IMAGE * const pRef, |
1142 |
|
const IMAGE * const vGMC, |
1143 |
|
const int coding_type) |
1144 |
|
{ |
1145 |
|
int mode = MODE_INTER; |
1146 |
|
int mcsel = 0; |
1147 |
|
int inter4v = (VopFlags & XVID_VOP_INTER4V) && (pMB->dquant == 0); |
1148 |
|
const uint32_t iQuant = pMB->quant; |
1149 |
|
const int skip_possible = (coding_type == P_VOP) && (pMB->dquant == 0); |
1150 |
|
int sad; |
1151 |
|
int min_rd = -1, intra_rd, i, cbp, c[2] = {0, 0}; |
1152 |
|
VECTOR backup[5], *v; |
1153 |
|
int sad_backup[5]; |
1154 |
|
int InterBias = MV16_INTER_BIAS; |
1155 |
|
int thresh = 0; |
1156 |
|
int count = 0; |
1157 |
|
int top = 0, top_right = 0, left = 0; |
1158 |
|
|
1159 |
|
pMB->mcsel = 0; |
1160 |
|
|
1161 |
|
/* INTER <-> INTER4V decision */ |
1162 |
|
if ((Data->iMinSAD[0] + 75 < Data->iMinSAD[1] + |
1163 |
|
Data->iMinSAD[2] + Data->iMinSAD[3] + Data->iMinSAD[4])) { /* normal, fast, SAD-based mode decision */ |
1164 |
|
if (inter4v == 0 || Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + |
1165 |
|
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant) { |
1166 |
|
mode = MODE_INTER; |
1167 |
|
sad = Data->iMinSAD[0]; |
1168 |
|
} else { |
1169 |
|
mode = MODE_INTER4V; |
1170 |
|
sad = Data->iMinSAD[1] + Data->iMinSAD[2] + |
1171 |
|
Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * (int32_t)iQuant; |
1172 |
|
Data->iMinSAD[0] = sad; |
1173 |
|
} |
1174 |
|
|
1175 |
|
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
1176 |
|
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
1177 |
|
if ( (100*sad)/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
1178 |
|
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
1179 |
|
mode = MODE_NOT_CODED; |
1180 |
|
goto early_out; |
1181 |
|
} |
1182 |
|
|
1183 |
|
/* mcsel */ |
1184 |
|
if (coding_type == S_VOP) { |
1185 |
|
|
1186 |
|
int32_t iSAD = sad16(Data->Cur, |
1187 |
|
vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536); |
1188 |
|
|
1189 |
|
if (Data->chroma) { |
1190 |
|
iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1191 |
|
iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1192 |
|
} |
1193 |
|
|
1194 |
|
if (iSAD <= sad) { /* mode decision GMC */ |
1195 |
|
mode = MODE_INTER; |
1196 |
|
mcsel = 1; |
1197 |
|
sad = iSAD; |
1198 |
|
} |
1199 |
|
|
1200 |
|
} |
1201 |
|
} else { /* Rate-Distortion INTER<->INTER4V */ |
1202 |
|
Data->iQuant = iQuant; |
1203 |
|
Data->cbp = c; |
1204 |
|
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1205 |
|
|
1206 |
|
/* final skip decision, a.k.a. "the vector you found, really that good?" */ |
1207 |
|
if (skip_possible && (pMB->sad16 < (int)iQuant * MAX_SAD00_FOR_SKIP)) |
1208 |
|
if ( (100*Data->iMinSAD[0])/(pMB->sad16+1) > FINAL_SKIP_THRESH) |
1209 |
|
if (Data->chroma || SkipDecisionP(pCurrent, pRef, x, y, Data->iEdgedWidth/2, iQuant, Data->rrv)) { |
1210 |
|
mode = MODE_NOT_CODED; |
1211 |
|
goto early_out; |
1212 |
|
} |
1213 |
|
|
1214 |
|
for (i = 0; i < 5; i++) { |
1215 |
|
sad_backup[i] = Data->iMinSAD[i]; |
1216 |
|
Data->iMinSAD[i] = 256*4096; |
1217 |
|
backup[i] = v[i]; |
1218 |
|
} |
1219 |
|
|
1220 |
|
min_rd = findRDinter(Data, pMBs, x, y, pParam, MotionFlags); |
1221 |
|
cbp = *Data->cbp; |
1222 |
|
sad = sad_backup[0]; |
1223 |
|
|
1224 |
|
if (coding_type == S_VOP) { |
1225 |
|
int gmc_rd; |
1226 |
|
int32_t iSAD = sad16(Data->Cur, |
1227 |
|
vGMC->y + 16*y*Data->iEdgedWidth + 16*x, Data->iEdgedWidth, 65536); |
1228 |
|
|
1229 |
|
if (Data->chroma) { |
1230 |
|
iSAD += sad8(Data->CurU, vGMC->u + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1231 |
|
iSAD += sad8(Data->CurV, vGMC->v + 8*y*(Data->iEdgedWidth/2) + 8*x, Data->iEdgedWidth/2); |
1232 |
|
} |
1233 |
|
|
1234 |
|
*Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */ |
1235 |
|
gmc_rd = findRDgmc(Data, vGMC, x, y); |
1236 |
|
if (gmc_rd < min_rd) { |
1237 |
|
mcsel = 1; |
1238 |
|
*Data->iMinSAD = min_rd = gmc_rd; |
1239 |
|
mode = MODE_INTER; |
1240 |
|
cbp = *Data->cbp; |
1241 |
|
sad = iSAD; |
1242 |
|
} |
1243 |
|
} |
1244 |
|
|
1245 |
|
if (inter4v) { |
1246 |
|
int v4_rd; |
1247 |
|
v4_rd = findRDinter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1248 |
|
if (v4_rd < min_rd) { |
1249 |
|
Data->iMinSAD[0] = min_rd = v4_rd; |
1250 |
|
mode = MODE_INTER4V; |
1251 |
|
cbp = *Data->cbp; |
1252 |
|
sad = sad_backup[1] + sad_backup[2] + |
1253 |
|
sad_backup[3] + sad_backup[4] + IMV16X16 * (int32_t)iQuant; |
1254 |
|
} |
1255 |
|
} |
1256 |
|
} |
1257 |
|
|
1258 |
|
left = top = top_right = -1; |
1259 |
|
thresh = 0; |
1260 |
|
|
1261 |
|
if((x > 0) && (y > 0) && (x < (int32_t) pParam->mb_width)) { |
1262 |
|
left = (&pMBs[(x-1) + y * pParam->mb_width])->sad16; // left |
1263 |
|
top = (&pMBs[x + (y-1) * pParam->mb_width])->sad16; // top |
1264 |
|
top_right = (&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16; // top right |
1265 |
|
|
1266 |
|
if(((&pMBs[(x-1) + y * pParam->mb_width])->mode != MODE_INTRA) && |
1267 |
|
((&pMBs[x + (y-1) * pParam->mb_width])->mode != MODE_INTRA) && |
1268 |
|
((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mode != MODE_INTRA)) { |
1269 |
|
thresh = MAX(MAX(top, left), top_right); |
1270 |
|
} |
1271 |
|
else |
1272 |
|
thresh = MIN(MIN(top, left), top_right); |
1273 |
|
} |
1274 |
|
|
1275 |
|
/* INTRA <-> INTER decision */ |
1276 |
|
if (sad < thresh) { /* normal, fast, SAD-based mode decision */ |
1277 |
|
/* intra decision */ |
1278 |
|
|
1279 |
|
if (iQuant > 8) InterBias += 100 * (iQuant - 8); /* to make high quants work */ |
1280 |
|
if (y != 0) |
1281 |
|
if ((pMB - pParam->mb_width)->mode == MODE_INTRA ) InterBias -= 80; |
1282 |
|
if (x != 0) |
1283 |
|
if ((pMB - 1)->mode == MODE_INTRA ) InterBias -= 80; |
1284 |
|
|
1285 |
|
if (Data->chroma) InterBias += 50; /* dev8(chroma) ??? <-- yes, we need dev8 (no big difference though) */ |
1286 |
|
if (Data->rrv) InterBias *= 4; |
1287 |
|
|
1288 |
|
if (InterBias < sad) { |
1289 |
|
int32_t deviation; |
1290 |
|
if (!Data->rrv) |
1291 |
|
deviation = dev16(Data->Cur, Data->iEdgedWidth); |
1292 |
|
else |
1293 |
|
deviation = dev16(Data->Cur, Data->iEdgedWidth) + /* dev32() */ |
1294 |
|
dev16(Data->Cur+16, Data->iEdgedWidth) + |
1295 |
|
dev16(Data->Cur + 16*Data->iEdgedWidth, Data->iEdgedWidth) + |
1296 |
|
dev16(Data->Cur+16+16*Data->iEdgedWidth, Data->iEdgedWidth); |
1297 |
|
|
1298 |
|
if (deviation < (sad - InterBias)) mode = MODE_INTRA; |
1299 |
|
} |
1300 |
|
|
1301 |
|
pMB->cbp = 63; |
1302 |
|
} else { /* Rate-Distortion INTRA<->INTER */ |
1303 |
|
if(min_rd < 0) { |
1304 |
|
Data->iQuant = iQuant; |
1305 |
|
Data->cbp = c; |
1306 |
|
v = Data->qpel ? Data->currentQMV : Data->currentMV; |
1307 |
|
|
1308 |
|
for (i = 0; i < 5; i++) { |
1309 |
|
Data->iMinSAD[i] = 256*4096; |
1310 |
|
backup[i] = v[i]; |
1311 |
|
} |
1312 |
|
|
1313 |
|
if(mode == MODE_INTER) { |
1314 |
|
min_rd = findRDinter(Data, pMBs, x, y, pParam, MotionFlags); |
1315 |
|
cbp = *Data->cbp; |
1316 |
|
|
1317 |
|
if (coding_type == S_VOP) { |
1318 |
|
int gmc_rd; |
1319 |
|
|
1320 |
|
*Data->iMinSAD = min_rd += BITS_MULT*1; /* mcsel */ |
1321 |
|
gmc_rd = findRDgmc(Data, vGMC, x, y); |
1322 |
|
if (gmc_rd < min_rd) { |
1323 |
|
mcsel = 1; |
1324 |
|
*Data->iMinSAD = min_rd = gmc_rd; |
1325 |
|
mode = MODE_INTER; |
1326 |
|
cbp = *Data->cbp; |
1327 |
|
} |
1328 |
|
} |
1329 |
|
} |
1330 |
|
|
1331 |
|
if(mode == MODE_INTER4V) { |
1332 |
|
int v4_rd; |
1333 |
|
v4_rd = findRDinter4v(Data, pMB, pMBs, x, y, pParam, MotionFlags, backup); |
1334 |
|
if (v4_rd < min_rd) { |
1335 |
|
Data->iMinSAD[0] = min_rd = v4_rd; |
1336 |
|
mode = MODE_INTER4V; |
1337 |
|
cbp = *Data->cbp; |
1338 |
|
} |
1339 |
|
} |
1340 |
|
} |
1341 |
|
|
1342 |
|
intra_rd = findRDintra(Data); |
1343 |
|
if (intra_rd < min_rd) { |
1344 |
|
*Data->iMinSAD = min_rd = intra_rd; |
1345 |
|
mode = MODE_INTRA; |
1346 |
|
} |
1347 |
|
|
1348 |
|
pMB->cbp = cbp; |
1349 |
|
} |
1350 |
|
|
1351 |
|
early_out: |
1352 |
|
pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad; |
1353 |
|
|
1354 |
|
if (Data->rrv) { |
1355 |
|
Data->currentMV[0].x = RRV_MV_SCALEDOWN(Data->currentMV[0].x); |
1356 |
|
Data->currentMV[0].y = RRV_MV_SCALEDOWN(Data->currentMV[0].y); |
1357 |
|
} |
1358 |
|
|
1359 |
|
if (mode == MODE_INTER && mcsel == 0) { |
1360 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0]; |
1361 |
|
|
1362 |
|
if(Data->qpel) { |
1363 |
|
pMB->qmvs[0] = pMB->qmvs[1] |
1364 |
|
= pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0]; |
1365 |
|
pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predMV.x; |
1366 |
|
pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predMV.y; |
1367 |
|
} else { |
1368 |
|
pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x; |
1369 |
|
pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y; |
1370 |
|
} |
1371 |
|
|
1372 |
|
} else if (mode == MODE_INTER ) { // but mcsel == 1 |
1373 |
|
|
1374 |
|
pMB->mcsel = 1; |
1375 |
|
if (Data->qpel) { |
1376 |
|
pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; |
1377 |
|
pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2; |
1378 |
|
pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2; |
1379 |
|
} else |
1380 |
|
pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; |
1381 |
|
|
1382 |
|
} else |
1383 |
|
if (mode == MODE_INTER4V) ; /* anything here? */ |
1384 |
|
else /* INTRA, NOT_CODED */ |
1385 |
|
ZeroMacroblockP(pMB, 0); |
1386 |
|
|
1387 |
|
pMB->mode = mode; |
1388 |
|
} |
1389 |
|
|
1390 |
|
static __inline void |
1391 |
ModeDecision(SearchData * const Data, |
ModeDecision(SearchData * const Data, |
1392 |
MACROBLOCK * const pMB, |
MACROBLOCK * const pMB, |
1393 |
const MACROBLOCK * const pMBs, |
const MACROBLOCK * const pMBs, |
1580 |
uint32_t mb_height = pParam->mb_height; |
uint32_t mb_height = pParam->mb_height; |
1581 |
const uint32_t iEdgedWidth = pParam->edged_width; |
const uint32_t iEdgedWidth = pParam->edged_width; |
1582 |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
const uint32_t MotionFlags = MakeGoodMotionFlags(current->motion_flags, current->vop_flags, current->vol_flags); |
1583 |
|
int stat_thresh = 0; |
1584 |
|
|
1585 |
uint32_t x, y; |
uint32_t x, y; |
1586 |
uint32_t iIntra = 0; |
uint32_t iIntra = 0; |
1593 |
int32_t temp[8]; uint32_t dir; |
int32_t temp[8]; uint32_t dir; |
1594 |
VECTOR currentMV[5]; |
VECTOR currentMV[5]; |
1595 |
VECTOR currentQMV[5]; |
VECTOR currentQMV[5]; |
1596 |
|
VECTOR currentMV2[5]; |
1597 |
|
VECTOR currentQMV2[5]; |
1598 |
int32_t iMinSAD[5]; |
int32_t iMinSAD[5]; |
1599 |
|
int32_t iMinSAD2[5]; |
1600 |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
DECLARE_ALIGNED_MATRIX(dct_space, 3, 64, int16_t, CACHE_LINE); |
1601 |
SearchData Data; |
SearchData Data; |
1602 |
memset(&Data, 0, sizeof(SearchData)); |
memset(&Data, 0, sizeof(SearchData)); |
1603 |
Data.iEdgedWidth = iEdgedWidth; |
Data.iEdgedWidth = iEdgedWidth; |
1604 |
Data.currentMV = currentMV; |
Data.currentMV = currentMV; |
1605 |
Data.currentQMV = currentQMV; |
Data.currentQMV = currentQMV; |
1606 |
|
Data.currentMV2 = currentMV2; |
1607 |
|
Data.currentQMV2 = currentQMV2; |
1608 |
Data.iMinSAD = iMinSAD; |
Data.iMinSAD = iMinSAD; |
1609 |
|
Data.iMinSAD2 = iMinSAD2; |
1610 |
Data.temp = temp; |
Data.temp = temp; |
1611 |
Data.dir = &dir; |
Data.dir = &dir; |
1612 |
Data.iFcode = current->fcode; |
Data.iFcode = current->fcode; |
1629 |
for (y = 0; y < mb_height; y++) { |
for (y = 0; y < mb_height; y++) { |
1630 |
for (x = 0; x < mb_width; x++) { |
for (x = 0; x < mb_width; x++) { |
1631 |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
MACROBLOCK *pMB = &pMBs[x + y * pParam->mb_width]; |
1632 |
|
MACROBLOCK *prevMB = &reference->mbs[x + y * pParam->mb_width]; |
1633 |
|
|
1634 |
if (!Data.rrv) pMB->sad16 = |
if (!Data.rrv) pMB->sad16 = |
1635 |
sad16v(pCurrent->y + (x + y * iEdgedWidth) * 16, |
sad16v(pCurrent->y + (x + y * iEdgedWidth) * 16, |
1662 |
} |
} |
1663 |
} |
} |
1664 |
|
|
1665 |
|
if(MotionFlags & XVID_ME_DETECT_STATIC_MOTION) { |
1666 |
|
if(x > 0 && y > 0 && x < pParam->mb_width) |
1667 |
|
if(MVequal((&pMBs[(x-1) + y * pParam->mb_width])->mvs[0], zeroMV) && |
1668 |
|
MVequal((&pMBs[x + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && |
1669 |
|
MVequal((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && |
1670 |
|
MVequal(prevMB->mvs[0], zeroMV)) { |
1671 |
|
stat_thresh = MAX((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
1672 |
|
MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1673 |
|
MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
1674 |
|
prevMB->sad16))); |
1675 |
|
} |
1676 |
|
else |
1677 |
|
stat_thresh = MIN((&pMBs[(x-1) + y * pParam->mb_width])->sad16, |
1678 |
|
MIN((&pMBs[x + (y-1) * pParam->mb_width])->sad16, |
1679 |
|
MIN((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, |
1680 |
|
prevMB->sad16))); |
1681 |
|
} |
1682 |
|
|
1683 |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
if ((current->vop_flags & XVID_VOP_CARTOON) && |
1684 |
(sad00 < pMB->quant * 4 * skip_thresh)) { /* favorize (0,0) vector for cartoons */ |
(sad00 < pMB->quant * 4 * skip_thresh) || (sad00 < stat_thresh)) { /* favorize (0,0) vector for cartoons */ |
1685 |
ZeroMacroblockP(pMB, sad00); |
ZeroMacroblockP(pMB, sad00); |
1686 |
continue; |
continue; |
1687 |
} |
} |
1690 |
y, MotionFlags, current->vop_flags, current->vol_flags, |
y, MotionFlags, current->vop_flags, current->vol_flags, |
1691 |
&Data, pParam, pMBs, reference->mbs, pMB); |
&Data, pParam, pMBs, reference->mbs, pMB); |
1692 |
|
|
1693 |
|
if(current->vop_flags & XVID_VOP_FAST_MODEDECISION_RD) { |
1694 |
|
ModeDecision_Fast(&Data, pMB, pMBs, x, y, pParam, |
1695 |
|
MotionFlags, current->vop_flags, current->vol_flags, |
1696 |
|
pCurrent, pRef, pGMC, current->coding_type); |
1697 |
|
} |
1698 |
|
else { |
1699 |
ModeDecision(&Data, pMB, pMBs, x, y, pParam, |
ModeDecision(&Data, pMB, pMBs, x, y, pParam, |
1700 |
MotionFlags, current->vop_flags, current->vol_flags, |
MotionFlags, current->vop_flags, current->vol_flags, |
1701 |
pCurrent, pRef, pGMC, current->coding_type); |
pCurrent, pRef, pGMC, current->coding_type); |
1702 |
|
} |
1703 |
|
|
1704 |
if (pMB->mode == MODE_INTRA) |
if (pMB->mode == MODE_INTRA) |
1705 |
if (++iIntra > iLimit) return 1; |
if (++iIntra > iLimit) return 1; |
1923 |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
pParam->width, pParam->height, Data->iFcode, 2, 0); |
1924 |
Data->qpel_precision = 1; |
Data->qpel_precision = 1; |
1925 |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
if (MotionFlags & XVID_ME_QUARTERPELREFINE16) |
1926 |
|
if(MotionFlags & XVID_ME_FASTREFINE16) |
1927 |
|
SubpelRefine_Fast(Data, CheckCandidate); |
1928 |
|
else |
1929 |
SubpelRefine(Data, CheckCandidate); |
SubpelRefine(Data, CheckCandidate); |
1930 |
} |
} |
1931 |
|
|
2125 |
SearchData * const Data) |
SearchData * const Data) |
2126 |
{ |
{ |
2127 |
|
|
2128 |
int i, mask; |
int i; |
2129 |
VECTOR pmv[7]; |
VECTOR pmv[7]; |
2130 |
MainSearchFunc *MainSearchPtr; |
MainSearchFunc *MainSearchPtr; |
2131 |
*Data->iMinSAD = MV_MAX_ERROR; |
*Data->iMinSAD = MV_MAX_ERROR; |
2161 |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
else if (MotionFlags & XVID_ME_ADVANCEDDIAMOND16) MainSearchPtr = AdvDiamondSearch; |
2162 |
else MainSearchPtr = DiamondSearch; |
else MainSearchPtr = DiamondSearch; |
2163 |
|
|
2164 |
mask = make_mask(pmv, 7, *Data->dir); |
if (*Data->iMinSAD > 512) { |
2165 |
|
unsigned int mask = make_mask(pmv, 7, *Data->dir); |
2166 |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
MainSearchPtr(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate16no4v); |
2167 |
|
} |
2168 |
|
|
2169 |
SubpelRefine(Data, CheckCandidate16no4v); |
SubpelRefine(Data, CheckCandidate16no4v); |
2170 |
|
|
2214 |
{ |
{ |
2215 |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
int dx = 0, dy = 0, b_dx = 0, b_dy = 0; |
2216 |
int32_t sum; |
int32_t sum; |
|
const int div = 1 + Data->qpel; |
|
2217 |
int k; |
int k; |
2218 |
const uint32_t stride = Data->iEdgedWidth/2; |
const uint32_t stride = Data->iEdgedWidth/2; |
2219 |
/* this is not full chroma compensation, only it's fullpel approximation. should work though */ |
/* this is not full chroma compensation, only it's fullpel approximation. should work though */ |
2220 |
|
|
2221 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
2222 |
dy += Data->directmvF[k].y / div; |
dy += Data->directmvF[k].y >> Data->qpel; |
2223 |
dx += Data->directmvF[k].x / div; |
dx += Data->directmvF[k].x >> Data->qpel; |
2224 |
b_dy += Data->directmvB[k].y / div; |
b_dy += Data->directmvB[k].y >> Data->qpel; |
2225 |
b_dx += Data->directmvB[k].x / div; |
b_dx += Data->directmvB[k].x >> Data->qpel; |
2226 |
} |
} |
2227 |
|
|
2228 |
dy = (dy >> 3) + roundtab_76[dy & 0xf]; |
dy = (dy >> 3) + roundtab_76[dy & 0xf]; |
2235 |
b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
b_Ref->u + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
2236 |
stride); |
stride); |
2237 |
|
|
2238 |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) return; /* no skip */ |
if (sum >= MAX_CHROMA_SAD_FOR_SKIP * Data->iQuant) return; /* no skip */ |
2239 |
|
|
2240 |
sum += sad8bi(pCur->v + 8*x + 8 * y * stride, |
sum += sad8bi(pCur->v + 8*x + 8 * y * stride, |
2241 |
f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2, |
f_Ref->v + (y*8 + dy/2) * stride + x*8 + dx/2, |
2242 |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
b_Ref->v + (y*8 + b_dy/2) * stride + x*8 + b_dx/2, |
2243 |
stride); |
stride); |
2244 |
|
|
2245 |
if (sum < MAX_CHROMA_SAD_FOR_SKIP * pMB->quant) { |
if (sum < MAX_CHROMA_SAD_FOR_SKIP * Data->iQuant) { |
2246 |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
pMB->mode = MODE_DIRECT_NONE_MV; /* skipped */ |
2247 |
for (k = 0; k < 4; k++) { |
for (k = 0; k < 4; k++) { |
2248 |
pMB->qmvs[k] = pMB->mvs[k]; |
pMB->qmvs[k] = pMB->mvs[k]; |
2327 |
CheckCandidate(0, 0, Data, 255); |
CheckCandidate(0, 0, Data, 255); |
2328 |
|
|
2329 |
/* initial (fast) skip decision */ |
/* initial (fast) skip decision */ |
2330 |
if (*Data->iMinSAD < pMB->quant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) { |
if (*Data->iMinSAD < Data->iQuant * INITIAL_SKIP_THRESH * (Data->chroma?3:2)) { |
2331 |
/* possible skip */ |
/* possible skip */ |
2332 |
if (Data->chroma) { |
if (Data->chroma) { |
2333 |
pMB->mode = MODE_DIRECT_NONE_MV; |
pMB->mode = MODE_DIRECT_NONE_MV; |
2556 |
Data.iEdgedWidth = pParam->edged_width; |
Data.iEdgedWidth = pParam->edged_width; |
2557 |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
Data.currentMV = currentMV; Data.currentQMV = currentQMV; |
2558 |
Data.iMinSAD = &iMinSAD; |
Data.iMinSAD = &iMinSAD; |
2559 |
Data.lambda16 = lambda_vec16[frame->quant]; |
Data.lambda16 = lambda_vec16[MAX(frame->quant-2, 2)]; |
2560 |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0; |
Data.qpel = pParam->vol_flags & XVID_VOL_QUARTERPEL ? 1 : 0; |
2561 |
Data.rounding = 0; |
Data.rounding = 0; |
2562 |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
Data.chroma = frame->motion_flags & XVID_ME_CHROMA_BVOP; |
2563 |
Data.temp = temp; |
Data.temp = temp; |
2564 |
Data.dir = &dir; |
Data.dir = &dir; |
2565 |
|
Data.iQuant = frame->quant; |
2566 |
|
|
2567 |
Data.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */ |
Data.RefQ = f_refV->u; /* a good place, also used in MC (for similar purpose) */ |
2568 |
|
|
2585 |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
Data.Cur = frame->image.y + (j * Data.iEdgedWidth + i) * 16; |
2586 |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
Data.CurU = frame->image.u + (j * Data.iEdgedWidth/2 + i) * 8; |
2587 |
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; |
|
2588 |
|
|
2589 |
/* direct search comes first, because it (1) checks for SKIP-mode |
/* direct search comes first, because it (1) checks for SKIP-mode |
2590 |
and (2) sets very good predictions for forward and backward search */ |
and (2) sets very good predictions for forward and backward search */ |
2630 |
&Data); |
&Data); |
2631 |
|
|
2632 |
/* final skip decision */ |
/* final skip decision */ |
2633 |
if ( (skip_sad < frame->quant * MAX_SAD00_FOR_SKIP * 2) |
if ( (skip_sad < Data.iQuant * MAX_SAD00_FOR_SKIP * 2) |
2634 |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
&& ((100*best_sad)/(skip_sad+1) > FINAL_SKIP_THRESH) ) |
2635 |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |
SkipDecisionB(&frame->image, f_ref, b_ref, pMB, i, j, &Data); |
2636 |
|
|
2672 |
VECTOR pmv[3]; |
VECTOR pmv[3]; |
2673 |
MACROBLOCK * const pMB = &pMBs[x + y * pParam->mb_width]; |
MACROBLOCK * const pMB = &pMBs[x + y * pParam->mb_width]; |
2674 |
|
|
2675 |
|
unsigned int simplicity = 0; |
2676 |
|
|
2677 |
for (i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
for (i = 0; i < 5; i++) Data->iMinSAD[i] = MV_MAX_ERROR; |
2678 |
|
|
2679 |
|
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
2680 |
|
pParam->width, pParam->height, Data->iFcode - Data->qpel - 1, 0, 0); |
2681 |
|
|
2682 |
|
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
2683 |
|
Data->RefP[0] = pRef + (x + y * pParam->edged_width) * 16; |
2684 |
|
|
2685 |
|
pmv[0].x = pMB->mvs[0].x; |
2686 |
|
pmv[0].y = pMB->mvs[0].y; |
2687 |
|
|
2688 |
|
CheckCandidate32I(pmv[0].x, pmv[0].y, Data, 0); |
2689 |
|
|
2690 |
|
if (*Data->iMinSAD > 200) { |
2691 |
|
|
2692 |
|
pmv[1].x = pmv[1].y = 0; |
2693 |
|
|
2694 |
/* median is only used as prediction. it doesn't have to be real */ |
/* median is only used as prediction. it doesn't have to be real */ |
2695 |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
if (x == 1 && y == 1) Data->predMV.x = Data->predMV.y = 0; |
2696 |
else |
else |
2700 |
Data->predMV = (pMB - 1)->mvs[0]; /* left instead of median */ |
Data->predMV = (pMB - 1)->mvs[0]; /* left instead of median */ |
2701 |
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 */ |
2702 |
|
|
2703 |
get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 4, |
pmv[2].x = Data->predMV.x; |
2704 |
pParam->width, pParam->height, Data->iFcode - Data->qpel, 1, 0); |
pmv[2].y = Data->predMV.y; |
|
|
|
|
Data->Cur = pCur + (x + y * pParam->edged_width) * 16; |
|
|
Data->RefP[0] = pRef + (x + y * pParam->edged_width) * 16; |
|
|
|
|
|
pmv[1].x = EVEN(pMB->mvs[0].x); |
|
|
pmv[1].y = EVEN(pMB->mvs[0].y); |
|
|
pmv[2].x = EVEN(Data->predMV.x); |
|
|
pmv[2].y = EVEN(Data->predMV.y); |
|
|
pmv[0].x = pmv[0].y = 0; |
|
|
|
|
|
CheckCandidate32I(0, 0, Data, 0); |
|
|
|
|
|
if (*Data->iMinSAD > 4 * MAX_SAD00_FOR_SKIP) { |
|
2705 |
|
|
2706 |
if (!vector_repeats(pmv, 1)) |
if (!vector_repeats(pmv, 1)) |
2707 |
CheckCandidate32I(pmv[1].x, pmv[1].y, Data, 1); |
CheckCandidate32I(pmv[1].x, pmv[1].y, Data, 1); |
2708 |
if (!vector_repeats(pmv, 2)) |
if (!vector_repeats(pmv, 2)) |
2709 |
CheckCandidate32I(pmv[2].x, pmv[2].y, Data, 2); |
CheckCandidate32I(pmv[2].x, pmv[2].y, Data, 2); |
2710 |
|
|
2711 |
if (*Data->iMinSAD > 4 * MAX_SAD00_FOR_SKIP) { /* diamond only if needed */ |
if (*Data->iMinSAD > 500) { /* diamond only if needed */ |
2712 |
unsigned int mask = make_mask(pmv, 3, *Data->dir); |
unsigned int mask = make_mask(pmv, 3, *Data->dir); |
2713 |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, 255/*mask*/, CheckCandidate32I); |
DiamondSearch(Data->currentMV->x, Data->currentMV->y, Data, mask, CheckCandidate32I); |
2714 |
} |
} else simplicity++; |
2715 |
} |
|
2716 |
|
if (*Data->iMinSAD > 500) /* refinement from 2-pixel to 1-pixel */ |
2717 |
|
SubpelRefine(Data, CheckCandidate32I); |
2718 |
|
else simplicity++; |
2719 |
|
} else simplicity++; |
2720 |
|
|
2721 |
for (i = 0; i < 4; i++) { |
for (i = 0; i < 4; i++) { |
2722 |
MACROBLOCK * MB = &pMBs[x + (i&1) + (y+(i>>1)) * pParam->mb_width]; |
MACROBLOCK * MB = &pMBs[x + (i&1) + (y+(i>>1)) * pParam->mb_width]; |
2723 |
MB->mvs[0] = MB->mvs[1] = MB->mvs[2] = MB->mvs[3] = Data->currentMV[i]; |
MB->mvs[0] = MB->mvs[1] = MB->mvs[2] = MB->mvs[3] = Data->currentMV[i]; |
2724 |
MB->mode = MODE_INTER; |
MB->mode = MODE_INTER; |
2725 |
MB->sad16 = Data->iMinSAD[i+1]; |
/* if we skipped some search steps, we have to assume that SAD would be lower with them */ |
2726 |
|
MB->sad16 = Data->iMinSAD[i+1] - (simplicity<<7); |
2727 |
} |
} |
2728 |
} |
} |
2729 |
|
|
2730 |
#define INTRA_THRESH 2200 |
#define INTRA_THRESH 2200 |
2731 |
#define INTER_THRESH 50 |
#define INTER_THRESH 40 |
2732 |
#define INTRA_THRESH2 95 |
#define INTRA_THRESH2 95 |
2733 |
|
|
2734 |
int |
int |
2759 |
Data.temp = temp; |
Data.temp = temp; |
2760 |
Data.dir = &dir; |
Data.dir = &dir; |
2761 |
Data.qpel = (pParam->vol_flags & XVID_VOL_QUARTERPEL)? 1: 0; |
Data.qpel = (pParam->vol_flags & XVID_VOL_QUARTERPEL)? 1: 0; |
2762 |
|
Data.qpel_precision = 0; |
2763 |
|
|
2764 |
if (intraCount != 0) { |
if (intraCount != 0) { |
2765 |
if (intraCount < 10) // we're right after an I frame |
if (intraCount < 10) // we're right after an I frame |
2769 |
IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra; |
IntraThresh -= (IntraThresh * (maxIntra - 8*(maxIntra - intraCount)))/maxIntra; |
2770 |
} |
} |
2771 |
|
|
2772 |
InterThresh -= 12 * bCount; |
InterThresh -= 20 * bCount; |
2773 |
if (InterThresh < 15 + b_thresh) InterThresh = 15 + b_thresh; |
if (InterThresh < 10 + b_thresh) InterThresh = 10 + b_thresh; |
2774 |
|
|
2775 |
if (sadInit) (*sadInit) (); |
if (sadInit) (*sadInit) (); |
2776 |
|
|
2802 |
} |
} |
2803 |
|
|
2804 |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
if (pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0) |
2805 |
if (dev > 500 && pMB->sad16 < 1000) |
if (dev > 1000 && pMB->sad16 < 1000) |
2806 |
sSAD += 1000; |
sSAD += 1000; |
2807 |
|
|
2808 |
sSAD += (dev < 3000) ? pMB->sad16 : pMB->sad16/2; /* blocks with big contrast differences usually have large SAD - while they look very good in b-frames */ |
sSAD += (dev < 4000) ? pMB->sad16 : pMB->sad16/2; /* blocks with big contrast differences usually have large SAD - while they look very good in b-frames */ |
2809 |
} |
} |
2810 |
} |
} |
2811 |
} |
} |