[cvs] / xvidcore / src / prediction / mbprediction.h Repository:
ViewVC logotype

Diff of /xvidcore/src/prediction/mbprediction.h

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

revision 1.12, Wed Jul 3 12:32:50 2002 UTC revision 1.14, Sat Sep 7 13:43:00 2002 UTC
# Line 30  Line 30 
30   *   *
31   *************************************************************************/   *************************************************************************/
32    
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  29.06.2002 get_pmvdata() bounding                                         *  
   *                                                                            *  
   ******************************************************************************/  
   
   
33  #ifndef _MBPREDICTION_H_  #ifndef _MBPREDICTION_H_
34  #define _MBPREDICTION_H_  #define _MBPREDICTION_H_
35    
# Line 54  Line 45 
45    
46  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
47    
48    /*****************************************************************************
49     * Prototypes
50     ****************************************************************************/
51    
52  void MBPrediction(FRAMEINFO * frame,    /* <-- The parameter for ACDC and MV prediction */  void MBPrediction(FRAMEINFO * frame,    /* <-- The parameter for ACDC and MV prediction */
53    
54                                    uint32_t x_pos,       /* <-- The x position of the MB to be searched  */                                    uint32_t x_pos,       /* <-- The x position of the MB to be searched  */
# Line 83  Line 78 
78                                  const int bound);                                  const int bound);
79    
80    
81  /* get_pmvdata returns the median predictor and nothing else */  /*****************************************************************************
82     * Inlined functions
83  static __inline VECTOR   ****************************************************************************/
 get_pmv(const MACROBLOCK * const pMBs,  
                 const uint32_t x,  
                 const uint32_t y,  
                 const uint32_t x_dim,  
                 const uint32_t block)  
 {  
   
         int xin1, xin2, xin3;  
         int yin1, yin2, yin3;  
         int vec1, vec2, vec3;  
         VECTOR lneigh, tneigh, trneigh; /* left neighbour, top neighbour, topright neighbour */  
         VECTOR median;  
   
         static VECTOR zeroMV = { 0, 0 };  
         uint32_t index = x + y * x_dim;  
   
         /* first row (special case) */  
         if (y == 0 && (block == 0 || block == 1)) {  
                 if ((x == 0) && (block == 0))   // first column, first block  
                 {  
                         return zeroMV;  
                 }  
                 if (block == 1)                 // second block; has only a left neighbour  
                 {  
                         return pMBs[index].mvs[0];  
                 } else {                                /* block==0, but x!=0, so again, there is a left neighbour */  
   
                         return pMBs[index - 1].mvs[1];  
                 }  
         }  
84    
85          /*          /*
86           * MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
# Line 130  Line 95 
95           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
96           */           */
97    
98    static __inline VECTOR
99    get_pmv2(const MACROBLOCK * const mbs,
100             const int mb_width,
101             const int bound,
102             const int x,
103             const int y,
104             const int block)
105    {
106            static const VECTOR zeroMV = { 0, 0 };
107    
108        int lx, ly, lz;         /* left */
109        int tx, ty, tz;         /* top */
110        int rx, ry, rz;         /* top-right */
111        int lpos, tpos, rpos;
112        int num_cand, last_cand;
113    
114            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
115    
116          switch (block) {          switch (block) {
117          case 0:          case 0:
118                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 1;
119                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 2;
120                  vec1 = 1;                               /* left */                  rx = x + 1;     ry = y - 1;     rz = 2;
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 2;                               /* top */  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;                               /* top right */  
121                  break;                  break;
122          case 1:          case 1:
123                  xin1 = x;                  lx = x;         ly = y;         lz = 0;
124                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 3;
125                  vec1 = 0;                  rx = x + 1;     ry = y - 1;     rz = 2;
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 3;  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;  
126                  break;                  break;
127          case 2:          case 2:
128                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 3;
129                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
130                  vec1 = 3;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
131                  break;                  break;
132          default:          default:
133                  xin1 = x;                  lx = x;         ly = y;         lz = 2;
134                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
135                  vec1 = 2;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
136          }          }
137    
138        lpos = lx + ly * mb_width;
139        rpos = rx + ry * mb_width;
140        tpos = tx + ty * mb_width;
141        num_cand = 0;
142    
143          if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t) x_dim) {      if (lpos >= bound && lx >= 0) {
144                  lneigh = zeroMV;          num_cand++;
145            last_cand = 1;
146            pmv[1] = mbs[lpos].mvs[lz];
147          } else {          } else {
148                  lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];          pmv[1] = zeroMV;
149          }          }
150    
151          if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) {      if (tpos >= bound) {
152                  tneigh = zeroMV;          num_cand++;
153            last_cand = 2;
154            pmv[2] = mbs[tpos].mvs[tz];
155          } else {          } else {
156                  tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];          pmv[2] = zeroMV;
157          }          }
158    
159          if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) {      if (rpos >= bound && rx < mb_width) {
160                  trneigh = zeroMV;          num_cand++;
161            last_cand = 3;
162            pmv[3] = mbs[rpos].mvs[rz];
163          } else {          } else {
164                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];          pmv[3] = zeroMV;
165          }          }
166    
167          /* median,minimum */      /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
168            if (num_cand != 1) {
169                    /* set median */
170    
171          median.x =                  pmv[0].x =
172                  MIN(MAX(lneigh.x, tneigh.x),                          MIN(MAX(pmv[1].x, pmv[2].x),
173                          MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));                                  MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
174          median.y =                  pmv[0].y =
175                  MIN(MAX(lneigh.y, tneigh.y),                          MIN(MAX(pmv[1].y, pmv[2].y),
176                          MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));                                  MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
177          return median;                  return pmv[0];
178  }  }
179    
180             return pmv[last_cand];  /* no point calculating median mv */
181    }
182    
 /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD  
    instead of only Median MV */  
183    
 static __inline int  
 get_pmvdata(const MACROBLOCK * const pMBs,  
                         const uint32_t x,  
                         const uint32_t y,  
                         const uint32_t x_dim,  
                         const uint32_t block,  
                         VECTOR * const pmv,  
                         int32_t * const psad)  
 {  
184    
185          /*          /*
186           * pmv are filled with:           * pmv are filled with:
# Line 233  Line 195 
195           *  [3]: topright neighbour's SAD           *  [3]: topright neighbour's SAD
196           */           */
197    
198          int xin1, xin2, xin3;  static __inline int
199          int yin1, yin2, yin3;  get_pmvdata2(const MACROBLOCK * const mbs,
200          int vec1, vec2, vec3;           const int mb_width,
201             const int bound,
202          uint32_t index = x + y * x_dim;           const int x,
203          const VECTOR zeroMV = { 0, 0 };           const int y,
204             const int block,
205          // first row of blocks (special case)                   VECTOR * const pmv,
206          if (y == 0 && (block == 0 || block == 1)) {                   int32_t * const psad)
                 if ((x == 0) && (block == 0))   // first column, first block  
                 {  
                         pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;  
                         psad[0] = 0;  
                         psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;  
                         return 0;  
                 }  
                 if (block == 1)                 // second block; has only a left neighbour  
207                  {                  {
208                          pmv[0] = pmv[1] = pMBs[index].mvs[0];          static const VECTOR zeroMV = { 0, 0 };
                         pmv[2] = pmv[3] = zeroMV;  
                         psad[0] = psad[1] = pMBs[index].sad8[0];  
                         psad[2] = psad[3] = MV_MAX_ERROR;  
                         return 0;  
                 } else {                                /* block==0, but x!=0, so again, there is a left neighbour */  
   
                         pmv[0] = pmv[1] = pMBs[index - 1].mvs[1];  
                         pmv[2] = pmv[3] = zeroMV;  
                         psad[0] = psad[1] = pMBs[index - 1].sad8[1];  
                         psad[2] = psad[3] = MV_MAX_ERROR;  
                         return 0;  
                 }  
         }  
209    
210          /*      int lx, ly, lz;         /* left */
211           * MODE_INTER, vm18 page 48      int tx, ty, tz;         /* top */
212           * MODE_INTER4V vm18 page 51      int rx, ry, rz;         /* top-right */
213           *      int lpos, tpos, rpos;
214           *  (x,y-1)      (x+1,y-1)      int num_cand, last_cand;
          *  [   |   ]    [   |   ]  
          *  [ 2 | 3 ]    [ 2 |   ]  
          *  
          *  (x-1,y)      (x,y)        (x+1,y)  
          *  [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]  
          *  [   | 3 ]    [ 2 | 3 ]    [   |   ]  
          */  
215    
216          switch (block) {          switch (block) {
217          case 0:          case 0:
218                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 1;
219                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 2;
220                  vec1 = 1;                               /* left */                  rx = x + 1;     ry = y - 1;     rz = 2;
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 2;                               /* top */  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;                               /* top right */  
221                  break;                  break;
222          case 1:          case 1:
223                  xin1 = x;                  lx = x;         ly = y;         lz = 0;
224                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 3;
225                  vec1 = 0;                  rx = x + 1;     ry = y - 1;     rz = 2;
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 3;  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;  
226                  break;                  break;
227          case 2:          case 2:
228                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 3;
229                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
230                  vec1 = 3;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
231                  break;                  break;
232          default:          default:
233                  xin1 = x;                  lx = x;         ly = y;         lz = 2;
234                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
235                  vec1 = 2;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
236          }          }
237    
238        lpos = lx + ly * mb_width;
239        rpos = rx + ry * mb_width;
240        tpos = tx + ty * mb_width;
241        num_cand = 0;
242    
243          if (xin1 < 0 || xin1 >= (int32_t) x_dim) {      if (lpos >= bound && lx >= 0) {
244            num_cand++;
245            last_cand = 1;
246            pmv[1] = mbs[lpos].mvs[lz];
247                    psad[1] = mbs[lpos].sad8[lz];
248        } else {
249                  pmv[1] = zeroMV;                  pmv[1] = zeroMV;
250                  psad[1] = MV_MAX_ERROR;                  psad[1] = MV_MAX_ERROR;
         } else {  
                 pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];  
                 psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];  
251          }          }
252    
253          if (xin2 < 0 || xin2 >= (int32_t) x_dim) {      if (tpos >= bound) {
254            num_cand++;
255            last_cand = 2;
256            pmv[2]= mbs[tpos].mvs[tz];
257            psad[2] = mbs[tpos].sad8[tz];
258        } else {
259                  pmv[2] = zeroMV;                  pmv[2] = zeroMV;
260                  psad[2] = MV_MAX_ERROR;                  psad[2] = MV_MAX_ERROR;
         } else {  
                 pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];  
                 psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];  
261          }          }
262    
263          if (xin3 < 0 || xin3 >= (int32_t) x_dim) {      if (rpos >= bound && rx < mb_width) {
264            num_cand++;
265            last_cand = 3;
266            pmv[3] = mbs[rpos].mvs[rz];
267            psad[3] = mbs[rpos].sad8[rz];
268        } else {
269                  pmv[3] = zeroMV;                  pmv[3] = zeroMV;
270                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;
271          } else {      }
272                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];  
273                  psad[3] = pMBs[xin3 + yin3 * x_dim].sad8[vec3];          /* original pmvdata() compatibility hack */
274            if (x == 0 && y == 0 && block == 0)
275            {
276                    pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
277                    psad[0] = 0;
278                    psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
279                    return 0;
280            }
281    
282        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
283            if (num_cand == 1) {
284                    pmv[0] = pmv[last_cand];
285                    psad[0] = psad[last_cand];
286            // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
287    
288                    /* original pmvdata() compatibility hack */
289                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
290          }          }
291    
292          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
293                  pmv[0] = pmv[1];                  pmv[0] = pmv[1];
294                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
295                  return 1;                  return 1;
296                    /* compatibility patch */
297                    //return y==0 && block <= 1 ? 0 : 1;
298          }          }
299    
300          /* median,minimum */          /* set median, minimum */
301    
302          pmv[0].x =          pmv[0].x =
303                  MIN(MAX(pmv[1].x, pmv[2].x),                  MIN(MAX(pmv[1].x, pmv[2].x),
# Line 364  Line 305 
305          pmv[0].y =          pmv[0].y =
306                  MIN(MAX(pmv[1].y, pmv[2].y),                  MIN(MAX(pmv[1].y, pmv[2].y),
307                          MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));                          MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
308    
309          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
310    
311          return 0;          return 0;
312  }  }
313    
314    /* copies of get_pmv and get_pmvdata for prediction from integer search */
         /*  
          * MODE_INTER, vm18 page 48  
          * MODE_INTER4V vm18 page 51  
          *  
          *   (x,y-1)      (x+1,y-1)  
          *   [   |   ]    [   |   ]  
          *   [ 2 | 3 ]    [ 2 |   ]  
          *  
          *   (x-1,y)       (x,y)        (x+1,y)  
          *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]  
          *   [   | 3 ]    [ 2 | 3 ]    [   |   ]  
          */  
315    
316  static __inline VECTOR  static __inline VECTOR
317  get_pmv2(const MACROBLOCK * const mbs,  get_ipmv(const MACROBLOCK * const mbs,
318           const int mb_width,           const int mb_width,
319           const int bound,           const int bound,
320           const int x,           const int x,
# Line 431  Line 361 
361      if (lpos >= bound && lx >= 0) {      if (lpos >= bound && lx >= 0) {
362          num_cand++;          num_cand++;
363          last_cand = 1;          last_cand = 1;
364          pmv[1] = mbs[lpos].mvs[lz];          pmv[1] = mbs[lpos].i_mvs[lz];
365      } else {      } else {
366          pmv[1] = zeroMV;          pmv[1] = zeroMV;
367      }      }
# Line 439  Line 369 
369      if (tpos >= bound) {      if (tpos >= bound) {
370          num_cand++;          num_cand++;
371          last_cand = 2;          last_cand = 2;
372          pmv[2] = mbs[tpos].mvs[tz];          pmv[2] = mbs[tpos].i_mvs[tz];
373      } else {      } else {
374          pmv[2] = zeroMV;          pmv[2] = zeroMV;
375      }      }
# Line 447  Line 377 
377      if (rpos >= bound && rx < mb_width) {      if (rpos >= bound && rx < mb_width) {
378          num_cand++;          num_cand++;
379          last_cand = 3;          last_cand = 3;
380          pmv[3] = mbs[rpos].mvs[rz];          pmv[3] = mbs[rpos].i_mvs[rz];
381      } else {      } else {
382          pmv[3] = zeroMV;          pmv[3] = zeroMV;
383      }      }
384    
385      /* if only one valid candidate preictor, the invalid candiates are set to the canidate */      /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
386          if (num_cand != 1) {          if (num_cand != 1) {
387                  /* set median */                  /* set median */
388    
# Line 468  Line 398 
398           return pmv[last_cand];  /* no point calculating median mv */           return pmv[last_cand];  /* no point calculating median mv */
399  }  }
400    
   
   
         /*  
          * pmv are filled with:  
          *  [0]: Median (or whatever is correct in a special case)  
          *  [1]: left neighbour  
          *  [2]: top neighbour  
          *  [3]: topright neighbour  
          * psad are filled with:  
          *  [0]: minimum of [1] to [3]  
          *  [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)  
          *  [2]: top neighbour's SAD  
          *  [3]: topright neighbour's SAD  
          */  
401  static __inline int  static __inline int
402  get_pmvdata2(const MACROBLOCK * const mbs,  get_ipmvdata(const MACROBLOCK * const mbs,
403           const int mb_width,           const int mb_width,
404           const int bound,           const int bound,
405           const int x,           const int x,
# Line 530  Line 446 
446      if (lpos >= bound && lx >= 0) {      if (lpos >= bound && lx >= 0) {
447          num_cand++;          num_cand++;
448          last_cand = 1;          last_cand = 1;
449          pmv[1] = mbs[lpos].mvs[lz];          pmv[1] = mbs[lpos].i_mvs[lz];
450                  psad[1] = mbs[lpos].sad8[lz];                  psad[1] = mbs[lpos].i_sad8[lz];
451      } else {      } else {
452          pmv[1] = zeroMV;          pmv[1] = zeroMV;
453                  psad[1] = MV_MAX_ERROR;                  psad[1] = MV_MAX_ERROR;
# Line 540  Line 456 
456      if (tpos >= bound) {      if (tpos >= bound) {
457          num_cand++;          num_cand++;
458          last_cand = 2;          last_cand = 2;
459          pmv[2]= mbs[tpos].mvs[tz];          pmv[2]= mbs[tpos].i_mvs[tz];
460          psad[2] = mbs[tpos].sad8[tz];          psad[2] = mbs[tpos].i_sad8[tz];
461      } else {      } else {
462          pmv[2] = zeroMV;          pmv[2] = zeroMV;
463                  psad[2] = MV_MAX_ERROR;                  psad[2] = MV_MAX_ERROR;
# Line 550  Line 466 
466      if (rpos >= bound && rx < mb_width) {      if (rpos >= bound && rx < mb_width) {
467          num_cand++;          num_cand++;
468          last_cand = 3;          last_cand = 3;
469          pmv[3] = mbs[rpos].mvs[rz];          pmv[3] = mbs[rpos].i_mvs[rz];
470          psad[3] = mbs[rpos].sad8[rz];          psad[3] = mbs[rpos].i_sad8[rz];
471      } else {      } else {
472          pmv[3] = zeroMV;          pmv[3] = zeroMV;
473                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.14

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