[svn] / branches / dev-api-3 / xvidcore / src / motion / motion_est.c Repository:
ViewVC logotype

Diff of /branches/dev-api-3/xvidcore/src/motion/motion_est.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 576, Thu Oct 3 08:26:19 2002 UTC revision 600, Thu Oct 17 13:27:22 2002 UTC
# Line 37  Line 37 
37  #include "../prediction/mbprediction.h"  #include "../prediction/mbprediction.h"
38  #include "../global.h"  #include "../global.h"
39  #include "../utils/timer.h"  #include "../utils/timer.h"
40    #include "../image/interpolate8x8.h"
41  #include "motion_est.h"  #include "motion_est.h"
42  #include "motion.h"  #include "motion.h"
43  #include "sad.h"  #include "sad.h"
# Line 51  Line 52 
52  #define CHECK_CANDIDATE(X,Y,D) { \  #define CHECK_CANDIDATE(X,Y,D) { \
53  (*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); }  (*CheckCandidate)((const int)(X),(const int)(Y), (D), &iDirection, data ); }
54    
55    #define GET_REFERENCE(X, Y, REF) { \
56            switch ( (((X)&1)<<1) + ((Y)&1) ) \
57            { \
58                    case 0 : REF = data->Ref + (X)/2 + ((Y)/2)*(data->iEdgedWidth); break; \
59                    case 1 : REF = data->RefV + (X)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \
60                    case 2 : REF = data->RefH + ((X)-1)/2 + ((Y)/2)*(data->iEdgedWidth); break; \
61                    default : REF = data->RefHV + ((X)-1)/2 + (((Y)-1)/2)*(data->iEdgedWidth); break; \
62            } \
63    }
64    
65  #define iDiamondSize 2  #define iDiamondSize 2
66    
67  static __inline int  static __inline int
# Line 84  Line 95 
95  static void  static void
96  CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate16(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
97  {  {
         int32_t * const sad = data->temp;  
98          int t;          int t;
99          const uint8_t * Reference;          const uint8_t * Reference;
100    
# Line 98  Line 108 
108                  default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;                  default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;
109          }          }
110    
111          data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, sad+1);          data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp + 1);
112    
113            if(data->quarterpel)
114                    t = d_mv_bits(2*x - data->predQMV.x, 2*y - data->predQMV.y, data->iFcode);
115            else
116          t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);          t = d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);
117    
118          data->temp[0] += lambda_vec16[data->iQuant] * t;          data->temp[0] += lambda_vec16[data->iQuant] * t;
119          data->temp[1] += lambda_vec8[data->iQuant] * t;          data->temp[1] += lambda_vec8[data->iQuant] * t;
120    
# Line 137  Line 151 
151                  default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;                  default : Reference = data->RefHV + (x-1)/2 + ((y-1)/2)*(data->iEdgedWidth); break;
152          }          }
153    
154            if(data->quarterpel)
155                    sad = lambda_vec16[data->iQuant] *
156                          d_mv_bits(2*x - data->predQMV.x, 2*y - data->predQMV.y, data->iFcode);
157            else
158          sad = lambda_vec16[data->iQuant] *          sad = lambda_vec16[data->iQuant] *
159                          d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);                          d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);
160          sad += sad16(data->Cur, Reference, data->iEdgedWidth, 256*4096);  
161            sad += sad16(data->Cur, Reference, data->iEdgedWidth, MV_MAX_ERROR);
162    
163          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
164                  *(data->iMinSAD) = sad;                  *(data->iMinSAD) = sad;
# Line 148  Line 167 
167  }  }
168    
169  static void  static void
170    CheckCandidate16_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
171    
172    // CheckCandidate16 variant which expects x and y in quarter pixel resolution
173    // Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!)
174    // around currentMV!
175    {
176            int t;
177            uint8_t * Reference = (uint8_t *) data->RefQ;
178            const uint8_t *ref1, *ref2, *ref3, *ref4;
179            VECTOR halfpelMV = *(data->currentMV);
180    
181            int32_t iEdgedWidth = data->iEdgedWidth;
182            uint32_t rounding = data->rounding;
183    
184            if (( x > data->max_dx) || ( x < data->min_dx)
185                    || ( y > data->max_dy) || (y < data->min_dy)) return;
186    
187            switch( ((x&1)<<1) + (y&1) )
188            {
189            case 0: // pure halfpel position - shouldn't happen during a refinement step
190                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, (const uint8_t *) Reference);
191                    break;
192    
193            case 1: // x halfpel, y qpel - top or bottom during qpel refinement
194                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
195                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
196    
197                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
198                    interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding);
199                    interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding);
200                    interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding);
201                    break;
202    
203            case 2: // x qpel, y halfpel - left or right during qpel refinement
204                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
205                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2);
206    
207                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
208                    interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding);
209                    interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding);
210                    interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding);
211                    break;
212    
213            default: // x and y in qpel resolution - the "corners" (top left/right and
214                             // bottom left/right) during qpel refinement
215                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
216                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
217                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3);
218                    GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4);
219    
220                    interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);
221                    interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding);
222                    interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding);
223                    interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding);
224                    break;
225            }
226    
227            data->temp[0] = sad16v(data->Cur, Reference, data->iEdgedWidth, data->temp+1);
228    
229            t = d_mv_bits(x - data->predQMV.x, y - data->predQMV.y, data->iFcode);
230            data->temp[0] += lambda_vec16[data->iQuant] * t;
231            data->temp[1] += lambda_vec8[data->iQuant] * t;
232    
233            if (data->temp[0] < data->iMinSAD[0]) {
234                    data->iMinSAD[0] = data->temp[0];
235                    data->currentQMV[0].x = x; data->currentQMV[0].y = y;
236            /*      *dir = Direction;*/ }
237    
238            if (data->temp[1] < data->iMinSAD[1]) {
239                    data->iMinSAD[1] = data->temp[1]; data->currentQMV[1].x = x; data->currentQMV[1].y = y; }
240            if (data->temp[2] < data->iMinSAD[2]) {
241                    data->iMinSAD[2] = data->temp[2]; data->currentQMV[2].x = x; data->currentQMV[2].y = y; }
242            if (data->temp[3] < data->iMinSAD[3]) {
243                    data->iMinSAD[3] = data->temp[3]; data->currentQMV[3].x = x; data->currentQMV[3].y = y; }
244            if (data->temp[4] < data->iMinSAD[4]) {
245                    data->iMinSAD[4] = data->temp[4]; data->currentQMV[4].x = x; data->currentQMV[4].y = y; }
246    }
247    
248    static void
249    CheckCandidate16no4v_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
250    
251    // CheckCandidate16no4v variant which expects x and y in quarter pixel resolution
252    // Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!)
253    // around currentMV!
254    {
255            int32_t sad;
256            uint8_t * Reference = (uint8_t *) data->RefQ;
257            const uint8_t *ref1, *ref2, *ref3, *ref4;
258            VECTOR halfpelMV = *(data->currentMV);
259    
260            int32_t iEdgedWidth = data->iEdgedWidth;
261            uint32_t rounding = data->rounding;
262    
263            if (( x > data->max_dx) || ( x < data->min_dx)
264                    || ( y > data->max_dy) || (y < data->min_dy)) return;
265    
266            switch( ((x&1)<<1) + (y&1) )
267            {
268            case 0: // pure halfpel position - shouldn't happen during a refinement step
269                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, (const uint8_t *) Reference);
270                    break;
271    
272            case 1: // x halfpel, y qpel - top or bottom during qpel refinement
273                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
274                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
275    
276                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
277                    interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding);
278                    interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding);
279                    interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding);
280                    break;
281    
282            case 2: // x qpel, y halfpel - left or right during qpel refinement
283                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
284                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2);
285    
286                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
287                    interpolate8x8_avg2(Reference+8, ref1+8, ref2+8, iEdgedWidth, rounding);
288                    interpolate8x8_avg2(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, iEdgedWidth, rounding);
289                    interpolate8x8_avg2(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, iEdgedWidth, rounding);
290                    break;
291    
292            default: // x and y in qpel resolution - the "corners" (top left/right and
293                             // bottom left/right) during qpel refinement
294                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
295                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
296                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3);
297                    GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4);
298    
299                    interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);
300                    interpolate8x8_avg4(Reference+8, ref1+8, ref2+8, ref3+8, ref4+8, iEdgedWidth, rounding);
301                    interpolate8x8_avg4(Reference+8*iEdgedWidth, ref1+8*iEdgedWidth, ref2+8*iEdgedWidth, ref3+8*iEdgedWidth, ref4+8*iEdgedWidth, iEdgedWidth, rounding);
302                    interpolate8x8_avg4(Reference+8*iEdgedWidth+8, ref1+8*iEdgedWidth+8, ref2+8*iEdgedWidth+8, ref3+8*iEdgedWidth+8, ref4+8*iEdgedWidth+8, iEdgedWidth, rounding);
303                    break;
304            }
305    
306            sad = lambda_vec16[data->iQuant] *
307                            d_mv_bits(x - data->predQMV.x, y - data->predQMV.y, data->iFcode);
308            sad += sad16(data->Cur, Reference, data->iEdgedWidth, MV_MAX_ERROR);
309    
310            if (sad < *(data->iMinSAD)) {
311                    *(data->iMinSAD) = sad;
312                    data->currentQMV[0].x = x; data->currentQMV[0].y = y;
313    //              *dir = Direction;
314            }
315    }
316    
317    static void
318  CheckCandidate16no4vI(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)  CheckCandidate16no4vI(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
319  {  {
320          int32_t sad;          int32_t sad;
# Line 328  Line 495 
495          }          }
496    
497          sad = sad8(data->Cur, Reference, data->iEdgedWidth);          sad = sad8(data->Cur, Reference, data->iEdgedWidth);
498    
499            if(data->quarterpel)
500                    sad += lambda_vec8[data->iQuant] * d_mv_bits(2*x - data->predQMV.x, 2*y - data->predQMV.y, data->iFcode);
501            else
502          sad += lambda_vec8[data->iQuant] * d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);          sad += lambda_vec8[data->iQuant] * d_mv_bits(x - data->predMV.x, y - data->predMV.y, data->iFcode);
503    
504          if (sad < *(data->iMinSAD)) {          if (sad < *(data->iMinSAD)) {
# Line 336  Line 507 
507                  *dir = Direction; }                  *dir = Direction; }
508  }  }
509    
510    static void
511    CheckCandidate8_qpel(const int x, const int y, const int Direction, int * const dir, const SearchData * const data)
512    // CheckCandidate16no4v variant which expects x and y in quarter pixel resolution
513    // Important: This is no general usable routine! x and y must be +/-1 (qpel resolution!)
514    // around currentMV!
515    
516    {
517            int32_t sad;
518            uint8_t *Reference = (uint8_t *) data->RefQ;
519            const uint8_t *ref1, *ref2, *ref3, *ref4;
520            VECTOR halfpelMV = *(data->currentMV);
521    
522            int32_t iEdgedWidth = data->iEdgedWidth;
523            uint32_t rounding = data->rounding;
524    
525            if (( x > data->max_dx) || ( x < data->min_dx)
526                    || ( y > data->max_dy) || (y < data->min_dy)) return;
527    
528            switch( ((x&1)<<1) + (y&1) )
529            {
530            case 0: // pure halfpel position - shouldn't happen during a refinement step
531                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, (const uint8_t *) Reference);
532                    break;
533    
534            case 1: // x halfpel, y qpel - top or bottom during qpel refinement
535                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
536                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
537    
538                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
539                    break;
540    
541            case 2: // x qpel, y halfpel - left or right during qpel refinement
542                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
543                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref2);
544    
545                    interpolate8x8_avg2(Reference, ref1, ref2, iEdgedWidth, rounding);
546                    break;
547    
548            default: // x and y in qpel resolution - the "corners" (top left/right and
549                             // bottom left/right) during qpel refinement
550                    GET_REFERENCE(halfpelMV.x, halfpelMV.y, ref1);
551                    GET_REFERENCE(halfpelMV.x, y - halfpelMV.y, ref2);
552                    GET_REFERENCE(x - halfpelMV.x, halfpelMV.y, ref3);
553                    GET_REFERENCE(x - halfpelMV.x, y - halfpelMV.y, ref4);
554    
555                    interpolate8x8_avg4(Reference, ref1, ref2, ref3, ref4, iEdgedWidth, rounding);
556                    break;
557            }
558    
559            sad = sad8(data->Cur, Reference, data->iEdgedWidth);
560            sad += lambda_vec8[data->iQuant] * d_mv_bits(x - data->predQMV.x, y - data->predQMV.y, data->iFcode);
561    
562            if (sad < *(data->iMinSAD)) {
563                    *(data->iMinSAD) = sad;
564                    data->currentQMV->x = x; data->currentQMV->y = y;
565                    *dir = Direction; }
566    }
567    
568  /* CHECK_CANDIATE FUNCTIONS END */  /* CHECK_CANDIATE FUNCTIONS END */
569    
570  /* MAINSEARCH FUNCTIONS START */  /* MAINSEARCH FUNCTIONS START */
# Line 504  Line 733 
733          CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0);          CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0);
734  }  }
735    
736    
737    static void
738    QuarterpelRefine(const SearchData * const data)
739    {
740    /* Perform quarter pixel refinement*/
741    
742            VECTOR backupMV = *(data->currentQMV);
743            int iDirection; //not needed
744    
745            CHECK_CANDIDATE(backupMV.x - 1, backupMV.y - 1, 0);
746            CHECK_CANDIDATE(backupMV.x + 1, backupMV.y - 1, 0);
747            CHECK_CANDIDATE(backupMV.x - 1, backupMV.y + 1, 0);
748            CHECK_CANDIDATE(backupMV.x + 1, backupMV.y + 1, 0);
749    
750            CHECK_CANDIDATE(backupMV.x - 1, backupMV.y, 0);
751            CHECK_CANDIDATE(backupMV.x + 1, backupMV.y, 0);
752    
753            CHECK_CANDIDATE(backupMV.x, backupMV.y + 1, 0);
754            CHECK_CANDIDATE(backupMV.x, backupMV.y - 1, 0);
755    
756    }
757    
758  static __inline int  static __inline int
759  SkipDecisionP(const IMAGE * current, const IMAGE * reference,  SkipDecisionP(const IMAGE * current, const IMAGE * reference,
760                                                          const int x, const int y,                                                          const int x, const int y,
# Line 530  Line 781 
781          pMB->mode = MODE_NOT_CODED;          pMB->mode = MODE_NOT_CODED;
782          pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;          pMB->mvs[0].x = pMB->mvs[1].x = pMB->mvs[2].x = pMB->mvs[3].x = 0;
783          pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;          pMB->mvs[0].y = pMB->mvs[1].y = pMB->mvs[2].y = pMB->mvs[3].y = 0;
784    
785            pMB->qmvs[0].x = pMB->qmvs[1].x = pMB->qmvs[2].x = pMB->qmvs[3].x = 0;
786            pMB->qmvs[0].y = pMB->qmvs[1].y = pMB->qmvs[2].y = pMB->qmvs[3].y = 0;
787    
788          pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;          pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] = pMB->sad8[3] = sad;
789  }  }
790    
# Line 551  Line 806 
806          uint32_t x, y;          uint32_t x, y;
807          uint32_t iIntra = 0;          uint32_t iIntra = 0;
808          int32_t InterBias, quant = current->quant;          int32_t InterBias, quant = current->quant;
809            uint8_t *qimage;
810    
811          // some pre-initialized thingies for SearchP          // some pre-initialized thingies for SearchP
812          int32_t temp[5];          int32_t temp[5];
813          VECTOR currentMV[5];          VECTOR currentMV[5];
814            VECTOR currentQMV[5];
815          int32_t iMinSAD[5];          int32_t iMinSAD[5];
816          SearchData Data;          SearchData Data;
817          Data.iEdgedWidth = pParam->edged_width;          Data.iEdgedWidth = pParam->edged_width;
818          Data.currentMV = currentMV;          Data.currentMV = currentMV;
819            Data.currentQMV = currentQMV;
820          Data.iMinSAD = iMinSAD;          Data.iMinSAD = iMinSAD;
821          Data.temp = temp;          Data.temp = temp;
822          Data.iFcode = current->fcode;          Data.iFcode = current->fcode;
823            Data.rounding = pParam->m_rounding_type;
824            Data.quarterpel = pParam->m_quarterpel;
825    
826            if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL)
827                    return 1; // allocate some mem for qpel interpolated blocks
828                                      // somehow this is dirty since I think we shouldn't use malloc outside
829                                      // encoder_create() - so please fix me!
830    
831          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
832    
# Line 592  Line 857 
857                                  if (pMB->sad16 < pMB->quant * INITIAL_SKIP_THRESH) {                                  if (pMB->sad16 < pMB->quant * INITIAL_SKIP_THRESH) {
858                                                  SkipMacroblockP(pMB, sad00);                                                  SkipMacroblockP(pMB, sad00);
859                                                  continue;                                                  continue;
860                                            sad00 = 256 * 4096;
861                                  }                                  }
862                          } else sad00 = 256*4096; // skip not allowed - for final skip decision                          } else sad00 = 256*4096; // skip not allowed - for final skip decision
863    
864                          SearchP(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,                          SearchP(pRef->y, pRefH->y, pRefV->y, pRefHV->y, qimage, pCurrent, x,
865                                                  y, current->motion_flags, pMB->quant,                                                  y, current->motion_flags, pMB->quant,
866                                                  &Data, pParam, pMBs, reference->mbs,                                                  &Data, pParam, pMBs, reference->mbs,
867                                                  current->global_flags & XVID_INTER4V, pMB);                                                  current->global_flags & XVID_INTER4V, pMB);
# Line 620  Line 886 
886                                                    pParam->edged_width);                                                    pParam->edged_width);
887    
888                                  if (deviation < (pMB->sad16 - InterBias)) {                                  if (deviation < (pMB->sad16 - InterBias)) {
889                                          if (++iIntra >= iLimit) return 1;                                          if (++iIntra >= iLimit) { free(qimage); return 1; }
890                                          pMB->mode = MODE_INTRA;                                          pMB->mode = MODE_INTRA;
891                                          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] =                                          pMB->mvs[0] = pMB->mvs[1] = pMB->mvs[2] =
892                                                          pMB->mvs[3] = zeroMV;                                                          pMB->mvs[3] = zeroMV;
893                                            pMB->qmvs[0] = pMB->qmvs[1] = pMB->qmvs[2] =
894                                                            pMB->qmvs[3] = zeroMV;
895                                          pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] =                                          pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] = pMB->sad8[2] =
896                                                  pMB->sad8[3] = 0;                                                  pMB->sad8[3] = 0;
897                                  }                                  }
898                          }                          }
899                  }                  }
900          }          }
901            free(qimage);
902          return 0;          return 0;
903  }  }
904    
# Line 691  Line 960 
960                  const uint8_t * const pRefH,                  const uint8_t * const pRefH,
961                  const uint8_t * const pRefV,                  const uint8_t * const pRefV,
962                  const uint8_t * const pRefHV,                  const uint8_t * const pRefHV,
963                    const uint8_t * const pRefQ,
964                  const IMAGE * const pCur,                  const IMAGE * const pCur,
965                  const int x,                  const int x,
966                  const int y,                  const int y,
# Line 707  Line 977 
977          int i, iDirection = 255, mask, threshA;          int i, iDirection = 255, mask, threshA;
978          VECTOR pmv[7];          VECTOR pmv[7];
979    
980            Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0);
981    
982          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp);  //has to be changed to get_pmv(2)()          get_pmvdata2(pMBs, pParam->mb_width, 0, x, y, 0, pmv, Data->temp);  //has to be changed to get_pmv(2)()
983          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,
984                                  pParam->width, pParam->height, Data->iFcode);                                  pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel);
985    
986          Data->predMV = pmv[0];          Data->predMV = pmv[0];
987    
988          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16;          Data->Cur = pCur->y + (x + y * Data->iEdgedWidth) * 16;
989          Data->Ref = pRef + (x + Data->iEdgedWidth*y)*16;          Data->Ref = pRef + (x + Data->iEdgedWidth*y)*16;
990          Data->RefH = pRefH + (x + Data->iEdgedWidth*y) * 16;          Data->RefH = pRefH + (x + Data->iEdgedWidth*y) * 16;
991          Data->RefV = pRefV + (x + Data->iEdgedWidth*y) * 16;          Data->RefV = pRefV + (x + Data->iEdgedWidth*y) * 16;
992          Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16;          Data->RefHV = pRefHV + (x + Data->iEdgedWidth*y) * 16;
993            Data->RefQ = pRefQ;
994    
995          Data->iQuant = iQuant;          Data->iQuant = iQuant;
996    
# Line 731  Line 1005 
1005          if (inter4v) CheckCandidate = CheckCandidate16;          if (inter4v) CheckCandidate = CheckCandidate16;
1006          else CheckCandidate = CheckCandidate16no4v;          else CheckCandidate = CheckCandidate16no4v;
1007    
1008          for(i = 0;  i < 5; i++) Data->currentMV[i].x = Data->currentMV[i].y = 0;          for(i = 0;  i < 5; i++)
1009                    Data->currentMV[i].x = Data->currentMV[i].y = 0;
1010    
1011            if(Data->quarterpel)
1012                    i = d_mv_bits(Data->predQMV.x, Data->predQMV.y, Data->iFcode);
1013            else
1014          i = d_mv_bits(Data->predMV.x, Data->predMV.y, Data->iFcode);          i = d_mv_bits(Data->predMV.x, Data->predMV.y, Data->iFcode);
1015    
1016          Data->iMinSAD[0] = pMB->sad16 + lambda_vec16[iQuant] * i;          Data->iMinSAD[0] = pMB->sad16 + lambda_vec16[iQuant] * i;
1017          Data->iMinSAD[1] = pMB->sad8[0] + lambda_vec8[iQuant] * i;          Data->iMinSAD[1] = pMB->sad8[0] + lambda_vec8[iQuant] * i;
1018          Data->iMinSAD[2] = pMB->sad8[1];          Data->iMinSAD[2] = pMB->sad8[1];
# Line 810  Line 1089 
1089    
1090          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data);          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data);
1091    
1092            for(i = 0; i < 5; i++) {
1093                    Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors
1094                    Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
1095            }
1096    
1097            if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) {
1098    
1099                    if(inter4v)
1100                            CheckCandidate = CheckCandidate16_qpel;
1101                    else
1102                            CheckCandidate = CheckCandidate16no4v_qpel;
1103    
1104                    get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1105                                      pParam->width, pParam->height, Data->iFcode, 0); // get real range
1106    
1107                    QuarterpelRefine(Data);
1108            }
1109    
1110          if (inter4v) {          if (inter4v) {
1111                  SearchData Data8;                  SearchData Data8;
1112                  Data8.iFcode = Data->iFcode;                  Data8.iFcode = Data->iFcode;
# Line 829  Line 1126 
1126                  pMB->mvs[0] = pMB->mvs[1]                  pMB->mvs[0] = pMB->mvs[1]
1127                          = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];                          = pMB->mvs[2] = pMB->mvs[3] = Data->currentMV[0];
1128    
1129                    pMB->qmvs[0] = pMB->qmvs[1]
1130                            = pMB->qmvs[2] = pMB->qmvs[3] = Data->currentQMV[0];
1131    
1132                  pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] =                  pMB->sad16 = pMB->sad8[0] = pMB->sad8[1] =
1133                          pMB->sad8[2] = pMB->sad8[3] =  Data->iMinSAD[0];                          pMB->sad8[2] = pMB->sad8[3] =  Data->iMinSAD[0];
1134    
1135                    if(pParam->m_quarterpel) {
1136                            pMB->pmvs[0].x = Data->currentQMV[0].x - Data->predQMV.x;
1137                            pMB->pmvs[0].y = Data->currentQMV[0].y - Data->predQMV.y;
1138                    }
1139                    else {
1140                  pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;                  pMB->pmvs[0].x = Data->currentMV[0].x - Data->predMV.x;
1141                  pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;                  pMB->pmvs[0].y = Data->currentMV[0].y - Data->predMV.y;
1142                    }
1143          } else {          } else {
1144  // INTER4V MODE; all other things are already set in Search8  // INTER4V MODE; all other things are already set in Search8
1145                  pMB->mode = MODE_INTER4V;                  pMB->mode = MODE_INTER4V;
1146                  pMB->sad16 = Data->iMinSAD[1] + Data->iMinSAD[2] +                  pMB->sad16 = Data->iMinSAD[1] + Data->iMinSAD[2] +
1147                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * iQuant;                          Data->iMinSAD[3] + Data->iMinSAD[4] + IMV16X16 * iQuant;
1148          }          }
   
1149  }  }
1150    
1151  static void  static void
# Line 854  Line 1159 
1159                  SearchData * const Data)                  SearchData * const Data)
1160  {  {
1161          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);
1162            Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);
1163          Data->iMinSAD = OldData->iMinSAD + 1 + block;          Data->iMinSAD = OldData->iMinSAD + 1 + block;
1164          Data->currentMV = OldData->currentMV + 1 + block;          Data->currentMV = OldData->currentMV + 1 + block;
1165            Data->currentQMV = OldData->currentQMV + 1 + block;
1166            Data->quarterpel = OldData->quarterpel;
1167    
1168            if(Data->quarterpel) // add d_mv_bits[qpel] everywhere but not in 0 (it's already there)
1169            {
1170                    if (block != 0)
1171                            *(Data->iMinSAD) += lambda_vec8[Data->iQuant] *
1172                                                                    d_mv_bits(Data->currentQMV->x - Data->predQMV.x,
1173                                                                                      Data->currentQMV->y - Data->predQMV.y,
1174                                                                                      Data->iFcode);
1175    
1176            } else // add d_mv_bits[hpel] everywhere but not in 0 (it's already there)
1177          if (block != 0)          if (block != 0)
1178                  *(Data->iMinSAD) += lambda_vec8[Data->iQuant] *                  *(Data->iMinSAD) += lambda_vec8[Data->iQuant] *
1179                                                                  d_mv_bits(      Data->currentMV->x - Data->predMV.x,                                                                  d_mv_bits(      Data->currentMV->x - Data->predMV.x,
# Line 869  Line 1186 
1186                  Data->RefH = OldData->RefH + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefH = OldData->RefH + 8 * ((block&1) + pParam->edged_width*(block>>1));
1187                  Data->RefV = OldData->RefV + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefV = OldData->RefV + 8 * ((block&1) + pParam->edged_width*(block>>1));
1188                  Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1));
1189                    Data->RefQ = OldData->RefQ;
1190    
1191                  Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1));                  Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1));
1192    
1193                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,                  get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1194                                  pParam->width, pParam->height, OldData->iFcode);                                  pParam->width, pParam->height, OldData->iFcode, pParam->m_quarterpel);
1195    
1196                  CheckCandidate = CheckCandidate8;                  CheckCandidate = CheckCandidate8;
1197    
1198                  if (MotionFlags & PMV_EXTSEARCH8) {                  if (MotionFlags & PMV_EXTSEARCH8) {
1199                            int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD
1200    
1201                          MainSearchFunc *MainSearchPtr;                          MainSearchFunc *MainSearchPtr;
1202                          if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch;                          if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch;
1203                                  else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;                                  else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;
1204                                          else MainSearchPtr = DiamondSearch;                                          else MainSearchPtr = DiamondSearch;
1205    
1206                          (*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255);    }                          (*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255);
1207    
1208                            if(*(Data->iMinSAD) < temp_sad) { //found a better match?
1209                                            Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector
1210                                            Data->currentQMV->y = 2 * Data->currentMV->y;
1211                            }
1212                    }
1213    
1214                  if (MotionFlags & PMV_HALFPELREFINE8) HalfpelRefine(Data);                  if (MotionFlags & PMV_HALFPELREFINE8) {
1215                            int32_t temp_sad = *(Data->iMinSAD); // store current MinSAD
1216    
1217                            HalfpelRefine(Data); // perform halfpel refine of current best vector
1218    
1219                            if(*(Data->iMinSAD) < temp_sad) { // we have found a better match
1220                                    Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector
1221                                    Data->currentQMV->y = 2 * Data->currentMV->y;
1222          }          }
1223                    }
1224    
1225                    if((Data->quarterpel) && (!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) &&
1226                       (MotionFlags & PMV_QUARTERPELREFINE8)) {
1227    
1228                            CheckCandidate = CheckCandidate8_qpel;
1229    
1230                            get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1231                                    pParam->width, pParam->height, OldData->iFcode, 0); // get real range
1232    
1233                            QuarterpelRefine(Data);
1234                    }
1235            }
1236    
1237            if(pParam->m_quarterpel) {
1238                    pMB->pmvs[block].x = Data->currentQMV->x - Data->predQMV.x;
1239                    pMB->pmvs[block].y = Data->currentQMV->y - Data->predQMV.y;
1240            }
1241            else {
1242          pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;          pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;
1243          pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;          pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
1244            }
1245    
1246          pMB->mvs[block] = *(Data->currentMV);          pMB->mvs[block] = *(Data->currentMV);
1247          pMB->sad8[block] =  4 * (*Data->iMinSAD);          pMB->qmvs[block] = *(Data->currentQMV);
1248    
1249            pMB->sad8[block] =  4 * (*Data->iMinSAD); // Isibaar: why?
1250  }  }
1251    
1252  /* B-frames code starts here */  /* B-frames code starts here */
# Line 979  Line 1332 
1332          Data->predMV = *predMV;          Data->predMV = *predMV;
1333    
1334          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,
1335                                  pParam->width, pParam->height, iFcode);                                  pParam->width, pParam->height, iFcode, pParam->m_quarterpel);
1336    
1337          pmv[0] = Data->predMV;          pmv[0] = Data->predMV;
1338          PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current);          PreparePredictionsBF(pmv, x, y, pParam->mb_width, pMB, mode_current);
# Line 1094  Line 1447 
1447    
1448  // skip decision  // skip decision
1449          if (*Data->iMinSAD - 2 * lambda_vec16[Data->iQuant] < (int32_t)Data->iQuant * SKIP_THRESH_B) {          if (*Data->iMinSAD - 2 * lambda_vec16[Data->iQuant] < (int32_t)Data->iQuant * SKIP_THRESH_B) {
1450                  //checking chroma. everything copied from MC                  //possible skip - checking chroma. everything copied from MC
1451                  //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
1452                  int sum, dx, dy, b_dx, b_dy;                  int sum, dx, dy, b_dx, b_dy;
1453    
# Line 1216  Line 1569 
1569    
1570          fData->currentMV[0] = pMB->mvs[0];          fData->currentMV[0] = pMB->mvs[0];
1571          fData->currentMV[1] = pMB->b_mvs[0];          fData->currentMV[1] = pMB->b_mvs[0];
1572          get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode);          get_range(&fData->min_dx, &fData->max_dx, &fData->min_dy, &fData->max_dy, x, y, 16, pParam->width, pParam->height, fcode, pParam->m_quarterpel);
1573          get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode);          get_range(&bData.min_dx, &bData.max_dx, &bData.min_dy, &bData.max_dy, x, y, 16, pParam->width, pParam->height, bcode, pParam->m_quarterpel);
1574    
1575          if (fData->currentMV[0].x > fData->max_dx) fData->currentMV[0].x = fData->max_dx;          if (fData->currentMV[0].x > fData->max_dx) fData->currentMV[0].x = fData->max_dx;
1576          if (fData->currentMV[0].x < fData->min_dx) fData->currentMV[0].x = fData->min_dy;          if (fData->currentMV[0].x < fData->min_dx) fData->currentMV[0].x = fData->min_dy;
# Line 1404  Line 1757 
1757    
1758  /* Hinted ME starts here */  /* Hinted ME starts here */
1759    
1760  static __inline void  static void
1761  Search8hinted(  const SearchData * const OldData,  Search8hinted(  const SearchData * const OldData,
1762                                  const int x, const int y,                                  const int x, const int y,
1763                                  const uint32_t MotionFlags,                                  const uint32_t MotionFlags,
1764                                  const MBParam * const pParam,                                  const MBParam * const pParam,
1765                                  MACROBLOCK * const pMB,                                  MACROBLOCK * const pMB,
1766                                  const MACROBLOCK * const pMBs,                                  const MACROBLOCK * const pMBs,
1767                                  const int block)                  const int block,
1768                    SearchData * const Data)
1769  {  {
1770          SearchData Data;          int32_t temp_sad;
1771          MainSearchFunc *MainSearchPtr;          MainSearchFunc *MainSearchPtr;
1772            Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);
1773            Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);
1774            Data->iMinSAD = OldData->iMinSAD + 1 + block;
1775            Data->currentMV = OldData->currentMV + 1 + block;
1776            Data->currentQMV = OldData->currentQMV + 1 + block;
1777            Data->quarterpel = OldData->quarterpel;
1778    
1779          Data.predMV = get_pmv2(pMBs, pParam->mb_width, 0, x/2 , y/2, block);          if (block != 0) {
1780          Data.iMinSAD = OldData->iMinSAD + 1 + block;                  if(pParam->m_quarterpel) {
1781          Data.currentMV = OldData->currentMV+1+block;                          *(Data->iMinSAD) += lambda_vec8[Data->iQuant] *
1782          Data.iFcode = OldData->iFcode;                                                                          d_mv_bits(      Data->currentQMV->x - Data->predQMV.x,
1783          Data.iQuant = OldData->iQuant;                                                                                                  Data->currentQMV->y - Data->predQMV.y,
1784                                                                                                    Data->iFcode);
1785          Data.Ref = OldData->Ref + 8 * ((block&1) + pParam->edged_width*(block>>1));                  }
1786          Data.RefH = OldData->RefH + 8 * ((block&1) + pParam->edged_width*(block>>1));                  else {
1787          Data.RefV = OldData->RefV + 8 * ((block&1) + pParam->edged_width*(block>>1));                          *(Data->iMinSAD) += lambda_vec8[Data->iQuant] *
1788          Data.RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1));                                                                          d_mv_bits(      Data->currentMV->x - Data->predMV.x,
1789          Data.iEdgedWidth = pParam->edged_width;                                                                                                  Data->currentMV->y - Data->predMV.y,
1790          Data.Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1));                                                                                                  Data->iFcode);
1791                    }
1792            }
1793    
1794          CheckCandidate = CheckCandidate8;          Data->Ref = OldData->Ref + 8 * ((block&1) + pParam->edged_width*(block>>1));
1795            Data->RefH = OldData->RefH + 8 * ((block&1) + pParam->edged_width*(block>>1));
1796            Data->RefV = OldData->RefV + 8 * ((block&1) + pParam->edged_width*(block>>1));
1797            Data->RefHV = OldData->RefHV + 8 * ((block&1) + pParam->edged_width*(block>>1));
1798            Data->RefQ = OldData->RefQ;
1799    
1800          if (block != 0)          Data->Cur = OldData->Cur + 8 * ((block&1) + pParam->edged_width*(block>>1));
1801                  *(Data.iMinSAD) += lambda_vec8[Data.iQuant] *  
1802                                                                  d_mv_bits(      Data.currentMV->x - Data.predMV.x,          get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1803                                                                                          Data.currentMV->y - Data.predMV.y,                                  pParam->width, pParam->height, OldData->iFcode, pParam->m_quarterpel);
                                                                                         Data.iFcode);  
1804    
1805            CheckCandidate = CheckCandidate8;
1806    
1807          get_range(&Data.min_dx, &Data.max_dx, &Data.min_dy, &Data.max_dy, x, y, 8,          temp_sad = *(Data->iMinSAD); // store current MinSAD
                                 pParam->width, pParam->height, OldData->iFcode);  
   
         if (pMB->mode == MODE_INTER4V) {  
                 int dummy;  
                 CheckCandidate8(pMB->mvs[block].x, pMB->mvs[block].y, 0, &dummy, &Data); }  
1808    
1809          if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch;          if (MotionFlags & PMV_USESQUARES8) MainSearchPtr = SquareSearch;
1810                  else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;                  else if (MotionFlags & PMV_ADVANCEDDIAMOND8) MainSearchPtr = AdvDiamondSearch;
1811                          else MainSearchPtr = DiamondSearch;                          else MainSearchPtr = DiamondSearch;
1812    
1813          (*MainSearchPtr)(Data.currentMV->x, Data.currentMV->y, &Data, 255);          (*MainSearchPtr)(Data->currentMV->x, Data->currentMV->y, Data, 255);
1814    
1815            if(*(Data->iMinSAD) < temp_sad) {
1816                    Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector
1817                    Data->currentQMV->y = 2 * Data->currentMV->y;
1818            }
1819    
1820            if (MotionFlags & PMV_HALFPELREFINE8) {
1821                    temp_sad = *(Data->iMinSAD); // store current MinSAD
1822    
1823          if (MotionFlags & PMV_HALFPELREFINE8) HalfpelRefine(&Data);                  HalfpelRefine(Data); // perform halfpel refine of current best vector
1824    
1825          pMB->pmvs[block].x = Data.currentMV->x - Data.predMV.x;                  if(*(Data->iMinSAD) < temp_sad) { // we have found a better match
1826          pMB->pmvs[block].y = Data.currentMV->y - Data.predMV.y;                          Data->currentQMV->x = 2 * Data->currentMV->x; // update our qpel vector
1827          pMB->mvs[block] = *(Data.currentMV);                          Data->currentQMV->y = 2 * Data->currentMV->y;
1828          pMB->sad8[block] =  4 * (*(Data.iMinSAD));                  }
1829            }
1830    
1831            if((Data->quarterpel) && (!(Data->currentQMV->x & 1)) && (!(Data->currentQMV->y & 1)) &&
1832               (MotionFlags & PMV_QUARTERPELREFINE8)) {
1833    
1834                    CheckCandidate = CheckCandidate8_qpel;
1835    
1836                    get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 8,
1837                                      pParam->width, pParam->height, OldData->iFcode, 0); // get real range
1838    
1839                    QuarterpelRefine(Data);
1840            }
1841    
1842            if(pParam->m_quarterpel) {
1843                    pMB->pmvs[block].x = Data->currentQMV->x - Data->predQMV.x;
1844                    pMB->pmvs[block].y = Data->currentQMV->y - Data->predQMV.y;
1845            }
1846            else {
1847                    pMB->pmvs[block].x = Data->currentMV->x - Data->predMV.x;
1848                    pMB->pmvs[block].y = Data->currentMV->y - Data->predMV.y;
1849            }
1850    
1851            pMB->mvs[block] = *(Data->currentMV);
1852            pMB->qmvs[block] = *(Data->currentQMV);
1853    
1854            pMB->sad8[block] =  4 * (*Data->iMinSAD);
1855  }  }
1856    
1857    
# Line 1465  Line 1860 
1860                                  const uint8_t * const pRefH,                                  const uint8_t * const pRefH,
1861                                  const uint8_t * const pRefV,                                  const uint8_t * const pRefV,
1862                                  const uint8_t * const pRefHV,                                  const uint8_t * const pRefHV,
1863                                    const uint8_t * const pRefQ,
1864                                  const IMAGE * const pCur,                                  const IMAGE * const pCur,
1865                                  const int x,                                  const int x,
1866                                  const int y,                                  const int y,
# Line 1482  Line 1878 
1878          int i, t;          int i, t;
1879          MainSearchFunc * MainSearchPtr;          MainSearchFunc * MainSearchPtr;
1880    
1881            Data->predQMV = get_qpmv2(pMBs, pParam->mb_width, 0, x, y, 0);
1882          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);
1883          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,
1884                                  pParam->width, pParam->height, Data->iFcode);                                  pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel);
1885    
1886          Data->Cur = pCur->y + (x + y * iEdgedWidth) * 16;          Data->Cur = pCur->y + (x + y * iEdgedWidth) * 16;
1887          Data->Ref = pRef + (x + iEdgedWidth*y)*16;          Data->Ref = pRef + (x + iEdgedWidth*y)*16;
1888          Data->RefH = pRefH + (x + iEdgedWidth*y) * 16;          Data->RefH = pRefH + (x + iEdgedWidth*y) * 16;
1889          Data->RefV = pRefV + (x + iEdgedWidth*y) * 16;          Data->RefV = pRefV + (x + iEdgedWidth*y) * 16;
1890          Data->RefHV = pRefHV + (x + iEdgedWidth*y) * 16;          Data->RefHV = pRefHV + (x + iEdgedWidth*y) * 16;
1891            Data->RefQ = pRefQ;
1892    
1893          Data->iQuant = iQuant;          Data->iQuant = iQuant;
1894    
1895          if (!(MotionFlags & PMV_HALFPEL16)) {          if (!(MotionFlags & PMV_HALFPEL16)) {
# Line 1536  Line 1935 
1935    
1936          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data);          if (MotionFlags & PMV_HALFPELREFINE16) HalfpelRefine(Data);
1937    
1938            for(i = 0; i < 5; i++) {
1939                    Data->currentQMV[i].x = 2 * Data->currentMV[i].x; // initialize qpel vectors
1940                    Data->currentQMV[i].y = 2 * Data->currentMV[i].y;
1941            }
1942    
1943            if((pParam->m_quarterpel) && (MotionFlags & PMV_QUARTERPELREFINE16)) {
1944          if (inter4v)          if (inter4v)
1945                  for(i = 0; i < 4; i++)                          CheckCandidate = CheckCandidate16_qpel;
1946                          Search8hinted(Data, 2*x+(i&1), 2*y+(i>>1), MotionFlags, pParam, pMB, pMBs, i);                  else
1947                            CheckCandidate = CheckCandidate16no4v_qpel;
1948    
1949                    get_range(&Data->min_dx, &Data->max_dx, &Data->min_dy, &Data->max_dy, x, y, 16,
1950                                      pParam->width, pParam->height, Data->iFcode, 0); // get real range
1951    
1952                    QuarterpelRefine(Data);
1953            }
1954    
1955            if (inter4v) {
1956                    SearchData Data8;
1957                    Data8.iFcode = Data->iFcode;
1958                    Data8.iQuant = Data->iQuant;
1959                    Data8.iEdgedWidth = Data->iEdgedWidth;
1960                    Search8hinted(Data, 2*x, 2*y, MotionFlags, pParam, pMB, pMBs, 0, &Data8);
1961                    Search8hinted(Data, 2*x + 1, 2*y, MotionFlags, pParam, pMB, pMBs, 1, &Data8);
1962                    Search8hinted(Data, 2*x, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 2, &Data8);
1963                    Search8hinted(Data, 2*x + 1, 2*y + 1, MotionFlags, pParam, pMB, pMBs, 3, &Data8);
1964            }
1965    
1966          if (!(inter4v) ||          if (!(inter4v) ||
1967                  (Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + Data->iMinSAD[3] +                  (Data->iMinSAD[0] < Data->iMinSAD[1] + Data->iMinSAD[2] + Data->iMinSAD[3] +
# Line 1576  Line 1999 
1999          const IMAGE *const pRef = &reference->image;          const IMAGE *const pRef = &reference->image;
2000    
2001          uint32_t x, y;          uint32_t x, y;
2002            uint8_t *qimage;
2003          int32_t temp[5], quant = current->quant;          int32_t temp[5], quant = current->quant;
2004          int32_t iMinSAD[5];          int32_t iMinSAD[5];
2005          VECTOR currentMV[5];          VECTOR currentMV[5];
2006            VECTOR currentQMV[5];
2007          SearchData Data;          SearchData Data;
2008          Data.iEdgedWidth = pParam->edged_width;          Data.iEdgedWidth = pParam->edged_width;
2009          Data.currentMV = currentMV;          Data.currentMV = currentMV;
2010            Data.currentQMV = currentQMV;
2011          Data.iMinSAD = iMinSAD;          Data.iMinSAD = iMinSAD;
2012          Data.temp = temp;          Data.temp = temp;
2013          Data.iFcode = current->fcode;          Data.iFcode = current->fcode;
2014            Data.rounding = pParam->m_rounding_type;
2015    
2016            if((qimage = (uint8_t *) malloc(32 * pParam->edged_width)) == NULL)
2017                    return; // allocate some mem for qpel interpolated blocks
2018                                      // somehow this is dirty since I think we shouldn't use malloc outside
2019                                      // encoder_create() - so please fix me!
2020    
2021          if (sadInit) (*sadInit) ();          if (sadInit) (*sadInit) ();
2022    
# Line 1608  Line 2040 
2040                                          pMB->quant = quant;                                          pMB->quant = quant;
2041                                  }                                  }
2042    
2043                          SearchPhinted(pRef->y, pRefH->y, pRefV->y, pRefHV->y, pCurrent, x,                          SearchPhinted(pRef->y, pRefH->y, pRefV->y, pRefHV->y, qimage, pCurrent, x,
2044                                                          y, current->motion_flags, pMB->quant,                                                          y, current->motion_flags, pMB->quant,
2045                                                          pParam, pMBs, current->global_flags & XVID_INTER4V, pMB,                                                          pParam, pMBs, current->global_flags & XVID_INTER4V, pMB,
2046                                                          &Data);                                                          &Data);
2047    
2048                  }                  }
2049          }          }
2050            free(qimage);
2051  }  }
2052    
2053  static __inline int  static __inline int
# Line 1634  Line 2067 
2067          *(Data->iMinSAD) = MV_MAX_ERROR;          *(Data->iMinSAD) = MV_MAX_ERROR;
2068          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);          Data->predMV = get_pmv2(pMBs, pParam->mb_width, 0, x, y, 0);
2069          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,
2070                                  pParam->width, pParam->height, Data->iFcode);                                  pParam->width, pParam->height, Data->iFcode, pParam->m_quarterpel);
2071    
2072          Data->Cur = pCur + (x + y * pParam->edged_width) * 16;          Data->Cur = pCur + (x + y * pParam->edged_width) * 16;
2073          Data->Ref = pRef + (x + y * pParam->edged_width) * 16;          Data->Ref = pRef + (x + y * pParam->edged_width) * 16;

Legend:
Removed from v.576  
changed lines
  Added in v.600

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4