[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.4, Thu Apr 25 20:39:02 2002 UTC revision 1.7, Tue May 7 19:40:36 2002 UTC
# Line 1  Line 1 
1    /**************************************************************************
2     *
3     *  XVID MPEG-4 VIDEO CODEC
4     *  -  MB prediction header file  -
5     *
6     *  This program is an implementation of a part of one or more MPEG-4
7     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
8     *  to use this software module in hardware or software products are
9     *  advised that its use may infringe existing patents or copyrights, and
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
12     *  editors and their companies, will have no liability for use of this
13     *  software or modifications or derivatives thereof.
14     *
15     *  This program is free software; you can redistribute it and/or modify
16     *  it under the terms of the GNU General Public License as published by
17     *  the xvid_free Software Foundation; either version 2 of the License, or
18     *  (at your option) any later version.
19     *
20     *  This program is distributed in the hope that it will be useful,
21     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
22     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     *  GNU General Public License for more details.
24     *
25     *  You should have received a copy of the GNU General Public License
26     *  along with this program; if not, write to the xvid_free Software
27     *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28     *
29     *  $Id$
30     *
31     *************************************************************************/
32    
33  #ifndef _MBPREDICTION_H_  #ifndef _MBPREDICTION_H_
34  #define _MBPREDICTION_H_  #define _MBPREDICTION_H_
35    
# Line 8  Line 40 
40  #define MIN(X, Y) ((X)<(Y)?(X):(Y))  #define MIN(X, Y) ((X)<(Y)?(X):(Y))
41  #define MAX(X, Y) ((X)>(Y)?(X):(Y))  #define MAX(X, Y) ((X)>(Y)?(X):(Y))
42    
43  // very large value  /* very large value */
44  #define MV_MAX_ERROR    (4096 * 256)  #define MV_MAX_ERROR    (4096 * 256)
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  void MBPrediction(FRAMEINFO *frame,      /* <-- the parameter for ACDC and MV prediction */  void MBPrediction(
49            FRAMEINFO *frame, /* <-- The parameter for ACDC and MV prediction */
50                    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 */
51                    uint32_t y_pos,                /* <-- The y position of the MB to be searched */                    uint32_t y_pos,                /* <-- The y position of the MB to be searched */
52                    uint32_t x_dim,                /* <-- Number of macroblocks in a row */                    uint32_t x_dim,                /* <-- Number of macroblocks in a row */
53                    int16_t *qcoeff        /* <-> The quantized DCT coefficients */          int16_t *qcoeff); /* <-> The quantized DCT coefficients           */
     );  
54    
55  void add_acdc(MACROBLOCK *pMB,  void add_acdc(MACROBLOCK *pMB,
56                                  uint32_t block,                                  uint32_t block,
# Line 28  Line 60 
60    
61    
62  void predict_acdc(MACROBLOCK *pMBs,  void predict_acdc(MACROBLOCK *pMBs,
63                                  uint32_t x, uint32_t y, uint32_t mb_width,                    uint32_t x,
64                      uint32_t y,
65                      uint32_t mb_width,
66                                  uint32_t block,                                  uint32_t block,
67                                  int16_t qcoeff[64],                                  int16_t qcoeff[64],
68                                  uint32_t current_quant,                                  uint32_t current_quant,
# Line 38  Line 72 
72  /* get_pmvdata returns the median predictor and nothing else */  /* get_pmvdata returns the median predictor and nothing else */
73    
74  static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs,  static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs,
75                                                          const uint32_t x, const uint32_t y,                                 const uint32_t x,
76                                   const uint32_t y,
77                                                          const uint32_t x_dim,                                                          const uint32_t x_dim,
78                                                          const uint32_t block)                                                          const uint32_t block)
79  {  {
# Line 51  Line 86 
86    
87      static VECTOR zeroMV = {0,0};      static VECTOR zeroMV = {0,0};
88      uint32_t index = x + y * x_dim;      uint32_t index = x + y * x_dim;
 //    zeroMV.x = zeroMV.y = 0;  
89    
90          // first row (special case)          /* first row (special case) */
91      if (y == 0 && (block == 0 || block == 1))      if (y == 0 && (block == 0 || block == 1))
92      {      {
93                  if ((x == 0) && (block == 0))           // first column, first block                  if ((x == 0) && (block == 0))           // first column, first block
# Line 71  Line 105 
105      }      }
106    
107          /*          /*
108                  MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
109                  MODE_INTER4V vm18 page 51           * MODE_INTER4V vm18 page 51
110             *
111                                          (x,y-1)         (x+1,y-1)           *   (x,y-1)      (x+1,y-1)
112                                          [   |   ]       [       |   ]           *   [   |   ]    [   |   ]
113                                          [ 2 | 3 ]       [ 2 |   ]           *   [ 2 | 3 ]    [ 2 |   ]
114             *
115                  (x-1,y)         (x,y)           (x+1,y)           *   (x-1,y)       (x,y)        (x+1,y)
116                  [   | 1 ]       [ 0 | 1 ]       [ 0 |   ]           *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
117                  [   | 3 ]       [ 2 | 3 ]       [       |   ]           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
118          */          */
119    
120      switch (block)      switch (block)
# Line 134  Line 168 
168                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
169          }          }
170    
171          // median,minimum          /* median,minimum */
172    
173          median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));          median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));
174          median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));          median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));
# Line 152  Line 186 
186                                                          VECTOR * const pmv,                                                          VECTOR * const pmv,
187                                                          int32_t * const psad)                                                          int32_t * const psad)
188  {  {
189  /* pmv are filled with:  
190          [0]: Median (or whatever is correct in a special case)          /*
191          [1]: left neighbour           * pmv are filled with:
192          [2]: top neighbour,           *  [0]: Median (or whatever is correct in a special case)
193          [3]: topright neighbour,           *  [1]: left neighbour
194     psad are filled with:           *  [2]: top neighbour
195          [0]: minimum of [1] to [3]           *  [3]: topright neighbour
196          [1]: left neighbour's SAD       // [1] to [3] are actually not needed           * psad are filled with:
197          [2]: top neighbour's SAD,           *  [0]: minimum of [1] to [3]
198          [3]: topright neighbour's SAD,           *  [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)
199             *  [2]: top neighbour's SAD
200             *  [3]: topright neighbour's SAD
201  */  */
202    
203      int xin1, xin2, xin3;      int xin1, xin2, xin3;
# Line 178  Line 214 
214                  if ((x == 0) && (block == 0))           // first column, first block                  if ((x == 0) && (block == 0))           // first column, first block
215                  {                  {
216                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
217                          psad[0] = psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;                          psad[0] = psad[1] = psad[2] = psad[3] = 0;
218                          return 0;                          return 0;
219                  }                  }
220                  if (block == 1)         // second block; has only a left neighbour                  if (block == 1)         // second block; has only a left neighbour
# Line 186  Line 222 
222                          pmv[0] = pmv[1] = pMBs[index].mvs[0];                          pmv[0] = pmv[1] = pMBs[index].mvs[0];
223                          pmv[2] = pmv[3] = zeroMV;                          pmv[2] = pmv[3] = zeroMV;
224                          psad[0] = psad[1] = pMBs[index].sad8[0];                          psad[0] = psad[1] = pMBs[index].sad8[0];
225                          psad[2] = psad[3] = MV_MAX_ERROR;                          psad[2] = psad[3] = 0;
226                          return 0;                          return 0;
227                  }                  }
228                  else /* block==0, but x!=0, so again, there is a left neighbour*/                  else /* block==0, but x!=0, so again, there is a left neighbour*/
# Line 194  Line 230 
230                          pmv[0] = pmv[1] = pMBs[index-1].mvs[1];                          pmv[0] = pmv[1] = pMBs[index-1].mvs[1];
231                          pmv[2] = pmv[3] = zeroMV;                          pmv[2] = pmv[3] = zeroMV;
232                          psad[0] = psad[1] = pMBs[index-1].sad8[1];                          psad[0] = psad[1] = pMBs[index-1].sad8[1];
233                          psad[2] = psad[3] = MV_MAX_ERROR;                          psad[2] = psad[3] = 0;
234                          return 0;                          return 0;
235                  }                  }
236      }      }
237    
238          /*          /*
239                  MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
240                  MODE_INTER4V vm18 page 51           * MODE_INTER4V vm18 page 51
241             *
242                                          (x,y-1)         (x+1,y-1)           *  (x,y-1)      (x+1,y-1)
243                                          [   |   ]       [       |   ]           *  [   |   ]    [   |   ]
244                                          [ 2 | 3 ]       [ 2 |   ]           *  [ 2 | 3 ]    [ 2 |   ]
245             *
246                  (x-1,y)         (x,y)           (x+1,y)           *  (x-1,y)      (x,y)        (x+1,y)
247                  [   | 1 ]       [ 0 | 1 ]       [ 0 |   ]           *  [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
248                  [   | 3 ]       [ 2 | 3 ]       [       |   ]           *  [   | 3 ]    [ 2 | 3 ]    [   |   ]
249          */          */
250    
251      switch (block)      switch (block)
# Line 270  Line 306 
306          }          }
307    
308          if ( (MVequal(pmv[1],pmv[2])) && (MVequal(pmv[1],pmv[3])) )          if ( (MVequal(pmv[1],pmv[2])) && (MVequal(pmv[1],pmv[3])) )
309          {       pmv[0]=pmv[1];          {
310                  psad[0]=psad[1];                  pmv[0]=pmv[1];
311                    psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);
312                  return 1;                  return 1;
313          }          }
314    
315          // median,minimum          /* median,minimum */
316    
317          pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));          pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x), MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
318          pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));          pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y), MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
319          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);
320    
321          return 0;          return 0;
322  }  }
323    

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.7

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