[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.2, Thu Mar 28 20:57:25 2002 UTC revision 1.5, Sun Apr 28 23:36:28 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(MBParam *pParam,       /* <-- 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           */
                   MACROBLOCK *MB_array           /* <-> the array of all the MB Infomations */  
     );  
54    
55  void add_acdc(MACROBLOCK *pMB,  void add_acdc(MACROBLOCK *pMB,
56                                  uint32_t block,                                  uint32_t block,
# Line 29  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,
69                                  int32_t iDcScaler,                                  int32_t iDcScaler,
70                                  int16_t predictors[8]);                                  int16_t predictors[8]);
71    
72    /* get_pmvdata returns the median predictor and nothing else */
73    
74    static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs,
75                                   const uint32_t x,
76                                   const uint32_t y,
77                                   const uint32_t x_dim,
78                                   const uint32_t block)
79    {
80    
81            int xin1, xin2, xin3;
82            int yin1, yin2, yin3;
83            int vec1, vec2, vec3;
84            VECTOR lneigh,tneigh,trneigh; /* left neighbour, top neighbour, topright neighbour */
85            VECTOR median;
86    
87            static VECTOR zeroMV = {0,0};
88            uint32_t index = x + y * x_dim;
89    
90            /* first row (special case) */
91            if (y == 0 && (block == 0 || block == 1))
92            {
93                    if ((x == 0) && (block == 0))           // first column, first block
94                    {
95                            return zeroMV;
96                    }
97                    if (block == 1)         // second block; has only a left neighbour
98                    {
99                            return pMBs[index].mvs[0];
100                    }
101                    else /* block==0, but x!=0, so again, there is a left neighbour*/
102                    {
103                            return pMBs[index-1].mvs[1];
104                    }
105            }
106    
107            /*
108             * MODE_INTER, vm18 page 48
109             * MODE_INTER4V vm18 page 51
110             *
111             *   (x,y-1)      (x+1,y-1)
112             *   [   |   ]    [   |   ]
113             *   [ 2 | 3 ]    [ 2 |   ]
114             *
115             *   (x-1,y)       (x,y)        (x+1,y)
116             *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
117             *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
118             */
119    
120            switch (block)
121            {
122            case 0:
123                    xin1 = x - 1;   yin1 = y;       vec1 = 1;       /* left */
124                    xin2 = x;       yin2 = y - 1;   vec2 = 2;       /* top */
125                    xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;       /* top right */
126                    break;
127            case 1:
128                    xin1 = x;               yin1 = y;               vec1 = 0;
129                    xin2 = x;               yin2 = y - 1;   vec2 = 3;
130                    xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;
131                    break;
132            case 2:
133                    xin1 = x - 1;   yin1 = y;               vec1 = 3;
134                    xin2 = x;               yin2 = y;               vec2 = 0;
135                    xin3 = x;               yin3 = y;               vec3 = 1;
136                    break;
137            default:
138                    xin1 = x;               yin1 = y;               vec1 = 2;
139                    xin2 = x;               yin2 = y;               vec2 = 0;
140                    xin3 = x;               yin3 = y;               vec3 = 1;
141            }
142    
143    
144            if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t)x_dim)
145            {
146                    lneigh = zeroMV;
147            }
148            else
149            {
150                    lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
151            }
152    
153            if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim)
154            {
155                    tneigh = zeroMV;
156            }
157            else
158            {
159                    tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
160            }
161    
162            if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim)
163            {
164                    trneigh = zeroMV;
165            }
166            else
167            {
168                    trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
169            }
170    
171            /* median,minimum */
172    
173            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)));
175            return median;
176    }
177    
178    
179  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD  /* This is somehow a copy of get_pmv, but returning all MVs and Minimum SAD
180     instead of only Median MV */     instead of only Median MV */
181    
# Line 46  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 94  Line 236 
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 169  Line 311 
311                  return 1;                  return 1;
312          }          }
313    
314          // median,minimum          /* median,minimum */
315    
316          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)));
317          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)));
318          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);
319    
320          return 0;          return 0;
321  }  }
322    
323    
324    
325  #endif /* _MBPREDICTION_H_ */  #endif /* _MBPREDICTION_H_ */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.5

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