[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.10, Fri Jun 28 15:14:40 2002 UTC revision 1.17, Sun Nov 17 00:35:33 2002 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  -  MB prediction header file  -   *  -  MB prediction header file  -
5   *   *
6   *  This program is an implementation of a part of one or more MPEG-4   *  Copyright(C) 2002 Christoph Lampert <gruel@web.de>
7   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending   *               2002 Peter Ross <pross@xvid.org>
8   *  to use this software module in hardware or software products are   *
9   *  advised that its use may infringe existing patents or copyrights, and   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
10   *  any such use would be at such party's own risk.  The original   *
11   *  developer of this software module and his/her company, and subsequent   *  XviD is free software; you can redistribute it and/or modify it
12   *  editors and their companies, will have no liability for use of this   *  under the terms of the GNU General Public License as published by
13   *  software or modifications or derivatives thereof.   *  the Free Software Foundation; either version 2 of the License, or
  *  
  *  This program is free software; you can redistribute it and/or modify  
  *  it under the terms of the GNU General Public License as published by  
  *  the xvid_free Software Foundation; either version 2 of the License, or  
14   *  (at your option) any later version.   *  (at your option) any later version.
15   *   *
16   *  This program is distributed in the hope that it will be useful,   *  This program is distributed in the hope that it will be useful,
# Line 23  Line 19 
19   *  GNU General Public License for more details.   *  GNU General Public License for more details.
20   *   *
21   *  You should have received a copy of the GNU General Public License   *  You should have received a copy of the GNU General Public License
22   *  along with this program; if not, write to the xvid_free Software   *  along with this program; if not, write to the Free Software
23   *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
24     *
25     *  Under section 8 of the GNU General Public License, the copyright
26     *  holders of XVID explicitly forbid distribution in the following
27     *  countries:
28     *
29     *    - Japan
30     *    - United States of America
31     *
32     *  Linking XviD statically or dynamically with other modules is making a
33     *  combined work based on XviD.  Thus, the terms and conditions of the
34     *  GNU General Public License cover the whole combination.
35     *
36     *  As a special exception, the copyright holders of XviD give you
37     *  permission to link XviD with independent modules that communicate with
38     *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the
39     *  license terms of these independent modules, and to copy and distribute
40     *  the resulting combined work under terms of your choice, provided that
41     *  every copy of the combined work is accompanied by a complete copy of
42     *  the source code of XviD (the version of XviD used to produce the
43     *  combined work), being distributed under the terms of the GNU General
44     *  Public License plus this exception.  An independent module is a module
45     *  which is not derived from or based on XviD.
46     *
47     *  Note that people who make modified versions of XviD are not obligated
48     *  to grant this special exception for their modified versions; it is
49     *  their choice whether to do so.  The GNU General Public License gives
50     *  permission to release a modified version without this exception; this
51     *  exception also makes it possible to release a modified version which
52     *  carries forward this exception.
53   *   *
54   *  $Id$   *  $Id$
55   *   *
56   *************************************************************************/   *************************************************************************/
57    
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  29.06.2002 get_pmvdata() bounding                                         *  
   *                                                                            *  
   ******************************************************************************/  
   
   
58  #ifndef _MBPREDICTION_H_  #ifndef _MBPREDICTION_H_
59  #define _MBPREDICTION_H_  #define _MBPREDICTION_H_
60    
# Line 54  Line 70 
70    
71  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )  #define MVequal(A,B) ( ((A).x)==((B).x) && ((A).y)==((B).y) )
72    
73    /*****************************************************************************
74     * Prototypes
75     ****************************************************************************/
76    
77  void MBPrediction(FRAMEINFO * frame,    /* <-- The parameter for ACDC and MV prediction */  void MBPrediction(FRAMEINFO * frame,    /* <-- The parameter for ACDC and MV prediction */
78    
79                                    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 80  Line 100 
100                                    uint32_t current_quant,                                    uint32_t current_quant,
101                                    int32_t iDcScaler,                                    int32_t iDcScaler,
102                                    int16_t predictors[8],                                    int16_t predictors[8],
103                                  const unsigned int bound_x,                                  const int bound);
                                 const unsigned int bound_y);  
104    
105    
106  /* get_pmvdata returns the median predictor and nothing else */  /*****************************************************************************
107     * Inlined functions
108  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];  
                 }  
         }  
109    
110          /*          /*
111           * MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
# Line 131  Line 120 
120           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
121           */           */
122    
123    static __inline VECTOR
124    get_pmv2(const MACROBLOCK * const mbs,
125             const int mb_width,
126             const int bound,
127             const int x,
128             const int y,
129             const int block)
130    {
131            static const VECTOR zeroMV = { 0, 0 };
132    
133        int lx, ly, lz;         /* left */
134        int tx, ty, tz;         /* top */
135        int rx, ry, rz;         /* top-right */
136        int lpos, tpos, rpos;
137        int num_cand, last_cand;
138    
139            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
140    
141          switch (block) {          switch (block) {
142          case 0:          case 0:
143                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 1;
144                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 2;
145                  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 */  
146                  break;                  break;
147          case 1:          case 1:
148                  xin1 = x;                  lx = x;         ly = y;         lz = 0;
149                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 3;
150                  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;  
151                  break;                  break;
152          case 2:          case 2:
153                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 3;
154                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
155                  vec1 = 3;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
156                  break;                  break;
157          default:          default:
158                  xin1 = x;                  lx = x;         ly = y;         lz = 2;
159                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
160                  vec1 = 2;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
161          }          }
162    
163        lpos = lx + ly * mb_width;
164          if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t) x_dim) {      rpos = rx + ry * mb_width;
165                  lneigh = zeroMV;      tpos = tx + ty * mb_width;
166        last_cand = num_cand = 0;
167    
168        if (lpos >= bound && lx >= 0) {
169            num_cand++;
170            last_cand = 1;
171            pmv[1] = mbs[lpos].mvs[lz];
172          } else {          } else {
173                  lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];          pmv[1] = zeroMV;
174          }          }
175    
176          if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) {      if (tpos >= bound) {
177                  tneigh = zeroMV;          num_cand++;
178            last_cand = 2;
179            pmv[2] = mbs[tpos].mvs[tz];
180          } else {          } else {
181                  tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];          pmv[2] = zeroMV;
182          }          }
183    
184          if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) {      if (rpos >= bound && rx < mb_width) {
185                  trneigh = zeroMV;          num_cand++;
186            last_cand = 3;
187            pmv[3] = mbs[rpos].mvs[rz];
188          } else {          } else {
189                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];          pmv[3] = zeroMV;
190          }          }
191    
192          /* median,minimum */      /*
193             * If there're more than one candidate, we return the median vector
194             * edgomez : the special case "no candidates" is handled the same way
195             *           because all vectors are set to zero. So the median vector
196             *           is {0,0}, and this is exactly the vector we must return
197             *           according to the mpeg4 specs.
198             */
199    
200            if (num_cand != 1) {
201                    /* set median */
202    
203          median.x =                  pmv[0].x =
204                  MIN(MAX(lneigh.x, tneigh.x),                          MIN(MAX(pmv[1].x, pmv[2].x),
205                          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)));
206          median.y =                  pmv[0].y =
207                  MIN(MAX(lneigh.y, tneigh.y),                          MIN(MAX(pmv[1].y, pmv[2].y),
208                          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)));
209          return median;                  return pmv[0];
210  }  }
211    
212             return pmv[last_cand];  /* no point calculating median mv */
213    }
214    
 /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD  
    instead of only Median MV */  
215    
 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,  
                         const unsigned int bound_x,  
                         const unsigned int bound_y)  
 {  
216    
217          /*          /*
218           * pmv are filled with:           * pmv are filled with:
# Line 236  Line 227 
227           *  [3]: topright neighbour's SAD           *  [3]: topright neighbour's SAD
228           */           */
229    
230          int xin1, xin2, xin3;  static __inline int
231          int yin1, yin2, yin3;  get_pmvdata2(const MACROBLOCK * const mbs,
232          int vec1, vec2, vec3;           const int mb_width,
233             const int bound,
234          uint32_t index = x + y * x_dim;           const int x,
235          const VECTOR zeroMV = { 0, 0 };           const int y,
236             const int block,
237          // first row of blocks (special case)                   VECTOR * const pmv,
238          /* if (y == 0 && (block == 0 || block == 1)) { */                   int32_t * const psad)
239          if (((y == bound_y && x >= bound_x) || (y == bound_y + 1 && x < bound_x))  {
240                  && (block == 0 || block == 1)) {          static const VECTOR zeroMV = { 0, 0 };
241    
242                  /* if ((x == 0) && (block == 0)) */     // first column, first block      int lx, ly, lz;         /* left */
243                  if ((x == 0 || (y == bound_y && x == bound_x)) && (block == 0)) // first column, first block      int tx, ty, tz;         /* top */
244        int rx, ry, rz;         /* top-right */
245        int lpos, tpos, rpos;
246        int num_cand, last_cand;
247    
248            switch (block) {
249            case 0:
250                    lx = x - 1;     ly = y;         lz = 1;
251                    tx = x;         ty = y - 1;     tz = 2;
252                    rx = x + 1;     ry = y - 1;     rz = 2;
253                    break;
254            case 1:
255                    lx = x;         ly = y;         lz = 0;
256                    tx = x;         ty = y - 1;     tz = 3;
257                    rx = x + 1;     ry = y - 1;     rz = 2;
258                    break;
259            case 2:
260                    lx = x - 1;     ly = y;         lz = 3;
261                    tx = x;         ty = y;         tz = 0;
262                    rx = x;         ry = y;         rz = 1;
263                    break;
264            default:
265                    lx = x;         ly = y;         lz = 2;
266                    tx = x;         ty = y;         tz = 0;
267                    rx = x;         ry = y;         rz = 1;
268            }
269    
270        lpos = lx + ly * mb_width;
271        rpos = rx + ry * mb_width;
272        tpos = tx + ty * mb_width;
273        last_cand = num_cand = 0;
274    
275        if (lpos >= bound && lx >= 0) {
276            num_cand++;
277            last_cand = 1;
278            pmv[1] = mbs[lpos].mvs[lz];
279                    psad[1] = mbs[lpos].sad8[lz];
280        } else {
281            pmv[1] = zeroMV;
282                    psad[1] = MV_MAX_ERROR;
283        }
284    
285        if (tpos >= bound) {
286            num_cand++;
287            last_cand = 2;
288            pmv[2]= mbs[tpos].mvs[tz];
289            psad[2] = mbs[tpos].sad8[tz];
290        } else {
291            pmv[2] = zeroMV;
292                    psad[2] = MV_MAX_ERROR;
293        }
294    
295        if (rpos >= bound && rx < mb_width) {
296            num_cand++;
297            last_cand = 3;
298            pmv[3] = mbs[rpos].mvs[rz];
299            psad[3] = mbs[rpos].sad8[rz];
300        } else {
301            pmv[3] = zeroMV;
302                    psad[3] = MV_MAX_ERROR;
303        }
304    
305            /* original pmvdata() compatibility hack */
306            if (x == 0 && y == 0 && block == 0)
307                  {                  {
308                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
309                          psad[0] = 0;                          psad[0] = 0;
310                          psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;                          psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
311                          return 0;                          return 0;
312                  }                  }
                 if (block == 1)                 // second block; has only a left neighbour  
                 {  
                         pmv[0] = pmv[1] = pMBs[index].mvs[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 */  
313    
314                          pmv[0] = pmv[1] = pMBs[index - 1].mvs[1];      /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
315                          pmv[2] = pmv[3] = zeroMV;          if (num_cand == 1) {
316                          psad[0] = psad[1] = pMBs[index - 1].sad8[1];                  pmv[0] = pmv[last_cand];
317                          psad[2] = psad[3] = MV_MAX_ERROR;                  psad[0] = psad[last_cand];
318                          return 0;          // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
319    
320                    /* original pmvdata() compatibility hack */
321                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
322                  }                  }
323    
324            if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
325                    pmv[0] = pmv[1];
326                    psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
327                    return 1;
328                    /* compatibility patch */
329                    //return y==0 && block <= 1 ? 0 : 1;
330          }          }
331    
332          /*          /* set median, minimum */
333           * MODE_INTER, vm18 page 48  
334           * MODE_INTER4V vm18 page 51          pmv[0].x =
335           *                  MIN(MAX(pmv[1].x, pmv[2].x),
336           *  (x,y-1)      (x+1,y-1)                          MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
337           *  [   |   ]    [   |   ]          pmv[0].y =
338           *  [ 2 | 3 ]    [ 2 |   ]                  MIN(MAX(pmv[1].y, pmv[2].y),
339           *                          MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
340           *  (x-1,y)      (x,y)        (x+1,y)  
341           *  [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
342           *  [   | 3 ]    [ 2 | 3 ]    [   |   ]  
343           */          return 0;
344    }
345    
346    /* copies of get_pmv and get_pmvdata for prediction from integer search */
347    
348    static __inline VECTOR
349    get_ipmv(const MACROBLOCK * const mbs,
350             const int mb_width,
351             const int bound,
352             const int x,
353             const int y,
354             const int block)
355    {
356            static const VECTOR zeroMV = { 0, 0 };
357    
358            int lx, ly, lz;         /* left */
359            int tx, ty, tz;         /* top */
360            int rx, ry, rz;         /* top-right */
361            int lpos, tpos, rpos;
362            int num_cand, last_cand;
363    
364            VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
365    
366          switch (block) {          switch (block) {
367          case 0:          case 0:
368                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 1;
369                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 2;
370                  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 */  
371                  break;                  break;
372          case 1:          case 1:
373                  xin1 = x;                  lx = x;         ly = y;         lz = 0;
374                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 3;
375                  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;  
376                  break;                  break;
377          case 2:          case 2:
378                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 3;
379                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
380                  vec1 = 3;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
381                  break;                  break;
382          default:          default:
383                  xin1 = x;                  lx = x;         ly = y;         lz = 2;
384                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
385                  vec1 = 2;                  rx = x;         ry = y;         rz = 1;
386                  xin2 = x;          }
387                  yin2 = y;  
388                  vec2 = 0;      lpos = lx + ly * mb_width;
389                  xin3 = x;      rpos = rx + ry * mb_width;
390                  yin3 = y;      tpos = tx + ty * mb_width;
391                  vec3 = 1;      last_cand = num_cand = 0;
392    
393        if (lpos >= bound && lx >= 0) {
394            num_cand++;
395            last_cand = 1;
396            pmv[1] = mbs[lpos].i_mvs[lz];
397        } else {
398            pmv[1] = zeroMV;
399        }
400    
401        if (tpos >= bound) {
402            num_cand++;
403            last_cand = 2;
404            pmv[2] = mbs[tpos].i_mvs[tz];
405        } else {
406            pmv[2] = zeroMV;
407        }
408    
409        if (rpos >= bound && rx < mb_width) {
410            num_cand++;
411            last_cand = 3;
412            pmv[3] = mbs[rpos].i_mvs[rz];
413        } else {
414            pmv[3] = zeroMV;
415        }
416    
417        /* if only one valid candidate predictor, the invalid candiates are set to the canidate */
418            if (num_cand != 1) {
419                    /* set median */
420    
421                    pmv[0].x =
422                            MIN(MAX(pmv[1].x, pmv[2].x),
423                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
424                    pmv[0].y =
425                            MIN(MAX(pmv[1].y, pmv[2].y),
426                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
427                    return pmv[0];
428          }          }
429    
430             return pmv[last_cand];  /* no point calculating median mv */
431    }
432    
433          if (xin1 < 0 || xin1 >= (int32_t) x_dim) {  static __inline int
434    get_ipmvdata(const MACROBLOCK * const mbs,
435             const int mb_width,
436             const int bound,
437             const int x,
438             const int y,
439             const int block,
440                     VECTOR * const pmv,
441                     int32_t * const psad)
442    {
443            static const VECTOR zeroMV = { 0, 0 };
444    
445        int lx, ly, lz;         /* left */
446        int tx, ty, tz;         /* top */
447        int rx, ry, rz;         /* top-right */
448        int lpos, tpos, rpos;
449        int num_cand, last_cand;
450    
451            switch (block) {
452            case 0:
453                    lx = x - 1;     ly = y;         lz = 1;
454                    tx = x;         ty = y - 1;     tz = 2;
455                    rx = x + 1;     ry = y - 1;     rz = 2;
456                    break;
457            case 1:
458                    lx = x;         ly = y;         lz = 0;
459                    tx = x;         ty = y - 1;     tz = 3;
460                    rx = x + 1;     ry = y - 1;     rz = 2;
461                    break;
462            case 2:
463                    lx = x - 1;     ly = y;         lz = 3;
464                    tx = x;         ty = y;         tz = 0;
465                    rx = x;         ry = y;         rz = 1;
466                    break;
467            default:
468                    lx = x;         ly = y;         lz = 2;
469                    tx = x;         ty = y;         tz = 0;
470                    rx = x;         ry = y;         rz = 1;
471            }
472    
473        lpos = lx + ly * mb_width;
474        rpos = rx + ry * mb_width;
475        tpos = tx + ty * mb_width;
476        last_cand = num_cand = 0;
477    
478        if (lpos >= bound && lx >= 0) {
479            num_cand++;
480            last_cand = 1;
481            pmv[1] = mbs[lpos].i_mvs[lz];
482                    psad[1] = mbs[lpos].i_sad8[lz];
483        } else {
484                  pmv[1] = zeroMV;                  pmv[1] = zeroMV;
485                  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];  
486          }          }
487    
488          if (xin2 < 0 || xin2 >= (int32_t) x_dim) {      if (tpos >= bound) {
489            num_cand++;
490            last_cand = 2;
491            pmv[2]= mbs[tpos].i_mvs[tz];
492            psad[2] = mbs[tpos].i_sad8[tz];
493        } else {
494                  pmv[2] = zeroMV;                  pmv[2] = zeroMV;
495                  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];  
496          }          }
497    
498          if (xin3 < 0 || xin3 >= (int32_t) x_dim) {      if (rpos >= bound && rx < mb_width) {
499            num_cand++;
500            last_cand = 3;
501            pmv[3] = mbs[rpos].i_mvs[rz];
502            psad[3] = mbs[rpos].i_sad8[rz];
503        } else {
504                  pmv[3] = zeroMV;                  pmv[3] = zeroMV;
505                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;
506          } else {      }
507                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];  
508                  psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];          /* original pmvdata() compatibility hack */
509            if (x == 0 && y == 0 && block == 0)
510            {
511                    pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
512                    psad[0] = 0;
513                    psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
514                    return 0;
515            }
516    
517        /* if only one valid candidate preictor, the invalid candiates are set to the canidate */
518            if (num_cand == 1) {
519                    pmv[0] = pmv[last_cand];
520                    psad[0] = psad[last_cand];
521            // return MVequal(pmv[0], zeroMV); /* no point calculating median mv and minimum sad */
522    
523                    /* original pmvdata() compatibility hack */
524                    return y==0 && block <= 1 ? 0 : MVequal(pmv[0], zeroMV);
525          }          }
526    
527          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
528                  pmv[0] = pmv[1];                  pmv[0] = pmv[1];
529                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
530                  return 1;                  return 1;
531                    /* compatibility patch */
532                    //return y==0 && block <= 1 ? 0 : 1;
533          }          }
534    
535          /* median,minimum */          /* set median, minimum */
536    
537          pmv[0].x =          pmv[0].x =
538                  MIN(MAX(pmv[1].x, pmv[2].x),                  MIN(MAX(pmv[1].x, pmv[2].x),
# Line 371  Line 540 
540          pmv[0].y =          pmv[0].y =
541                  MIN(MAX(pmv[1].y, pmv[2].y),                  MIN(MAX(pmv[1].y, pmv[2].y),
542                          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)));
543    
544          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
545    
546          return 0;          return 0;
547  }  }
548    
549    
   
550  #endif                                                  /* _MBPREDICTION_H_ */  #endif                                                  /* _MBPREDICTION_H_ */

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.17

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