--- estimation_pvop.c 2005/03/02 20:22:10 1.13 +++ estimation_pvop.c 2005/03/31 22:14:20 1.17 @@ -21,7 +21,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: estimation_pvop.c,v 1.13 2005/03/02 20:22:10 Isibaar Exp $ + * $Id: estimation_pvop.c,v 1.17 2005/03/31 22:14:20 Isibaar Exp $ * ****************************************************************************/ @@ -41,22 +41,22 @@ #include "motion_inlines.h" static const int xvid_me_lambda_vec8[32] = - { 0 ,(int)(1.00235 * NEIGH_TEND_8X8 + 0.5), - (int)(1.15582*NEIGH_TEND_8X8 + 0.5), (int)(1.31976*NEIGH_TEND_8X8 + 0.5), - (int)(1.49591*NEIGH_TEND_8X8 + 0.5), (int)(1.68601*NEIGH_TEND_8X8 + 0.5), - (int)(1.89187*NEIGH_TEND_8X8 + 0.5), (int)(2.11542*NEIGH_TEND_8X8 + 0.5), - (int)(2.35878*NEIGH_TEND_8X8 + 0.5), (int)(2.62429*NEIGH_TEND_8X8 + 0.5), - (int)(2.91455*NEIGH_TEND_8X8 + 0.5), (int)(3.23253*NEIGH_TEND_8X8 + 0.5), - (int)(3.58158*NEIGH_TEND_8X8 + 0.5), (int)(3.96555*NEIGH_TEND_8X8 + 0.5), - (int)(4.38887*NEIGH_TEND_8X8 + 0.5), (int)(4.85673*NEIGH_TEND_8X8 + 0.5), - (int)(5.37519*NEIGH_TEND_8X8 + 0.5), (int)(5.95144*NEIGH_TEND_8X8 + 0.5), - (int)(6.59408*NEIGH_TEND_8X8 + 0.5), (int)(7.31349*NEIGH_TEND_8X8 + 0.5), - (int)(8.12242*NEIGH_TEND_8X8 + 0.5), (int)(9.03669*NEIGH_TEND_8X8 + 0.5), - (int)(10.0763*NEIGH_TEND_8X8 + 0.5), (int)(11.2669*NEIGH_TEND_8X8 + 0.5), - (int)(12.6426*NEIGH_TEND_8X8 + 0.5), (int)(14.2493*NEIGH_TEND_8X8 + 0.5), - (int)(16.1512*NEIGH_TEND_8X8 + 0.5), (int)(18.442*NEIGH_TEND_8X8 + 0.5), - (int)(21.2656*NEIGH_TEND_8X8 + 0.5), (int)(24.8580*NEIGH_TEND_8X8 + 0.5), - (int)(29.6436*NEIGH_TEND_8X8 + 0.5), (int)(36.4949*NEIGH_TEND_8X8 + 0.5) + { 0 ,(int)(1.0 * NEIGH_TEND_8X8 + 0.5), + (int)(2.0*NEIGH_TEND_8X8 + 0.5), (int)(3.0*NEIGH_TEND_8X8 + 0.5), + (int)(4.0*NEIGH_TEND_8X8 + 0.5), (int)(5.0*NEIGH_TEND_8X8 + 0.5), + (int)(6.0*NEIGH_TEND_8X8 + 0.5), (int)(7.0*NEIGH_TEND_8X8 + 0.5), + (int)(8.0*NEIGH_TEND_8X8 + 0.5), (int)(9.0*NEIGH_TEND_8X8 + 0.5), + (int)(10.0*NEIGH_TEND_8X8 + 0.5), (int)(11.0*NEIGH_TEND_8X8 + 0.5), + (int)(12.0*NEIGH_TEND_8X8 + 0.5), (int)(13.0*NEIGH_TEND_8X8 + 0.5), + (int)(14.0*NEIGH_TEND_8X8 + 0.5), (int)(15.0*NEIGH_TEND_8X8 + 0.5), + (int)(16.0*NEIGH_TEND_8X8 + 0.5), (int)(17.0*NEIGH_TEND_8X8 + 0.5), + (int)(18.0*NEIGH_TEND_8X8 + 0.5), (int)(19.0*NEIGH_TEND_8X8 + 0.5), + (int)(20.0*NEIGH_TEND_8X8 + 0.5), (int)(21.0*NEIGH_TEND_8X8 + 0.5), + (int)(22.0*NEIGH_TEND_8X8 + 0.5), (int)(23.0*NEIGH_TEND_8X8 + 0.5), + (int)(24.0*NEIGH_TEND_8X8 + 0.5), (int)(25.0*NEIGH_TEND_8X8 + 0.5), + (int)(26.0*NEIGH_TEND_8X8 + 0.5), (int)(27.0*NEIGH_TEND_8X8 + 0.5), + (int)(28.0*NEIGH_TEND_8X8 + 0.5), (int)(29.0*NEIGH_TEND_8X8 + 0.5), + (int)(30.0*NEIGH_TEND_8X8 + 0.5), (int)(31.0*NEIGH_TEND_8X8 + 0.5) }; static void @@ -82,8 +82,8 @@ sad = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp); t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision); - sad += (data->lambda16 * t * sad)>>10; - data->temp[0] += (data->lambda8 * t * (data->temp[0] + NEIGH_8X8_BIAS))>>10; + sad += (data->lambda16 * t); + data->temp[0] += (data->lambda8 * t); if (data->chroma) { if (sad >= data->iMinSAD[0]) goto no16; @@ -129,7 +129,7 @@ sad = sad8(data->Cur, Reference, data->iEdgedWidth); t = d_mv_bits(x, y, data->predMV, data->iFcode, data->qpel^data->qpel_precision); - sad += (data->lambda8 * t * (sad+NEIGH_8X8_BIAS))>>10; + sad += (data->lambda8 * t); if (sad < *(data->iMinSAD)) { *(data->iMinSAD) = sad; @@ -423,7 +423,7 @@ Data->predMV, Data->iFcode, 0); } - *(Data->iMinSAD) += (Data->lambda8 * i * (*Data->iMinSAD + NEIGH_8X8_BIAS))>>10; + *(Data->iMinSAD) += (Data->lambda8 * i); if (MotionFlags & (XVID_ME_EXTSEARCH8|XVID_ME_HALFPELREFINE8|XVID_ME_QUARTERPELREFINE8)) { @@ -557,8 +557,8 @@ else Data->predMV = pmv[0]; i = d_mv_bits(0, 0, Data->predMV, Data->iFcode, 0); - Data->iMinSAD[0] = pMB->sad16 + ((Data->lambda16 * i * pMB->sad16)>>10); - Data->iMinSAD[1] = pMB->sad8[0] + ((Data->lambda8 * i * (pMB->sad8[0]+NEIGH_8X8_BIAS)) >> 10); + Data->iMinSAD[0] = pMB->sad16 + (Data->lambda16 * i); + Data->iMinSAD[1] = pMB->sad8[0] + (Data->lambda8 * i); Data->iMinSAD[2] = pMB->sad8[1]; Data->iMinSAD[3] = pMB->sad8[2]; Data->iMinSAD[4] = pMB->sad8[3]; @@ -858,11 +858,19 @@ } if(MotionFlags & XVID_ME_DETECT_STATIC_MOTION) { + VECTOR *cmpMV; + VECTOR staticMV = { 0, 0 }; + + if (current->coding_type == S_VOP) + cmpMV = &pMB->amv; + else + cmpMV = &staticMV; + if(x > 0 && y > 0 && x < pParam->mb_width) { - if(MVequal((&pMBs[(x-1) + y * pParam->mb_width])->mvs[0], zeroMV) && - MVequal((&pMBs[x + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && - MVequal((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mvs[0], zeroMV) && - MVequal(prevMB->mvs[0], zeroMV)) { + if(MVequal((&pMBs[(x-1) + y * pParam->mb_width])->mvs[0], *cmpMV) && + MVequal((&pMBs[x + (y-1) * pParam->mb_width])->mvs[0], *cmpMV) && + MVequal((&pMBs[(x+1) + (y-1) * pParam->mb_width])->mvs[0], *cmpMV) && + MVequal(prevMB->mvs[0], *cmpMV)) { stat_thresh = MAX((&pMBs[(x-1) + y * pParam->mb_width])->sad16, MAX((&pMBs[x + (y-1) * pParam->mb_width])->sad16, MAX((&pMBs[(x+1) + (y-1) * pParam->mb_width])->sad16, @@ -876,12 +884,44 @@ } } - /* favorize (0,0) vector for cartoons */ - if ((current->vop_flags & XVID_VOP_CARTOON) && - ((sad00 < pMB->quant * 4 * skip_thresh) || (sad00 < stat_thresh))) { - ZeroMacroblockP(pMB, sad00); - pMB->cbp = 0x2f; - continue; + /* favorize (0,0) or global vector for cartoons */ + if (current->vop_flags & XVID_VOP_CARTOON) { + if (current->coding_type == S_VOP) { + int32_t iSAD = sad16(pCurrent->y + (x + y * iEdgedWidth) * 16, + pGMC->y + 16*y*iEdgedWidth + 16*x, iEdgedWidth, 65536); + + if (Data.chroma) { + iSAD += sad8(pCurrent->u + x*8 + y*(iEdgedWidth/2)*8, pGMC->u + 8*y*(iEdgedWidth/2) + 8*x, iEdgedWidth/2); + iSAD += sad8(pCurrent->v + (x + y*(iEdgedWidth/2))*8, pGMC->v + 8*y*(iEdgedWidth/2) + 8*x, iEdgedWidth/2); + } + + if (iSAD <= stat_thresh) { /* mode decision GMC */ + pMB->mode = MODE_INTER; + pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = iSAD; + pMB->mcsel = 1; + if (Data.qpel) { + pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] = pMB->qmvs[3] = pMB->amv; + pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = pMB->amv.x/2; + pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = pMB->amv.y/2; + } else + pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] = pMB->mvs[3] = pMB->amv; + + continue; + } + } + else if (sad00 < stat_thresh) { + VECTOR predMV; + if (current->vol_flags & XVID_VOL_QUARTERPEL) + predMV = get_qpmv2(current->mbs, mb_width, 0, x, y, 0); + else + predMV = get_pmv2(current->mbs, mb_width, 0, x, y, 0); + + ZeroMacroblockP(pMB, sad00); + pMB->cbp = 0x3f; + pMB->pmvs[0].x = - predMV.x; + pMB->pmvs[0].y = - predMV.y; + continue; + } } SearchP(pRef, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,