[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.9, Wed Jun 12 20:38:40 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(FRAMEINFO * frame,    /* <-- The parameter for ACDC and MV prediction */
49    
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    
52                    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 */
53    
54                    uint32_t x_dim,                /* <-- Number of macroblocks in a row */                    uint32_t x_dim,                /* <-- Number of macroblocks in a row */
55                    int16_t *qcoeff        /* <-> The quantized DCT coefficients */  
56      );                                    int16_t * qcoeff);    /* <-> The quantized DCT coefficients           */
57    
58  void add_acdc(MACROBLOCK *pMB,  void add_acdc(MACROBLOCK *pMB,
59                                  uint32_t block,                                  uint32_t block,
# Line 28  Line 63 
63    
64    
65  void predict_acdc(MACROBLOCK *pMBs,  void predict_acdc(MACROBLOCK *pMBs,
66                                  uint32_t x, uint32_t y, uint32_t mb_width,                                    uint32_t x,
67                                      uint32_t y,
68                                      uint32_t mb_width,
69                                  uint32_t block,                                  uint32_t block,
70                                  int16_t qcoeff[64],                                  int16_t qcoeff[64],
71                                  uint32_t current_quant,                                  uint32_t current_quant,
# Line 37  Line 74 
74    
75  /* get_pmvdata returns the median predictor and nothing else */  /* get_pmvdata returns the median predictor and nothing else */
76    
77  static __inline VECTOR get_pmv(const MACROBLOCK * const pMBs,  static __inline VECTOR
78                                                          const uint32_t x, const uint32_t y,  get_pmv(const MACROBLOCK * const pMBs,
79                    const uint32_t x,
80                    const uint32_t y,
81                                                          const uint32_t x_dim,                                                          const uint32_t x_dim,
82                                                          const uint32_t block)                                                          const uint32_t block)
83  {  {
# Line 51  Line 90 
90    
91      static VECTOR zeroMV = {0,0};      static VECTOR zeroMV = {0,0};
92      uint32_t index = x + y * x_dim;      uint32_t index = x + y * x_dim;
 //    zeroMV.x = zeroMV.y = 0;  
93    
94          // first row (special case)          /* first row (special case) */
95      if (y == 0 && (block == 0 || block == 1))          if (y == 0 && (block == 0 || block == 1)) {
     {  
96                  if ((x == 0) && (block == 0))           // first column, first block                  if ((x == 0) && (block == 0))           // first column, first block
97                  {                  {
98                          return zeroMV;                          return zeroMV;
# Line 63  Line 100 
100                  if (block == 1)         // second block; has only a left neighbour                  if (block == 1)         // second block; has only a left neighbour
101                  {                  {
102                          return pMBs[index].mvs[0];                          return pMBs[index].mvs[0];
103                  }                  } else {                                /* block==0, but x!=0, so again, there is a left neighbour */
104                  else /* block==0, but x!=0, so again, there is a left neighbour*/  
                 {  
105                          return pMBs[index-1].mvs[1];                          return pMBs[index-1].mvs[1];
106                  }                  }
107      }      }
108    
109          /*          /*
110                  MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
111                  MODE_INTER4V vm18 page 51           * MODE_INTER4V vm18 page 51
112             *
113                                          (x,y-1)         (x+1,y-1)           *   (x,y-1)      (x+1,y-1)
114                                          [   |   ]       [       |   ]           *   [   |   ]    [   |   ]
115                                          [ 2 | 3 ]       [ 2 |   ]           *   [ 2 | 3 ]    [ 2 |   ]
116             *
117                  (x-1,y)         (x,y)           (x+1,y)           *   (x-1,y)       (x,y)        (x+1,y)
118                  [   | 1 ]       [ 0 | 1 ]       [ 0 |   ]           *   [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
119                  [   | 3 ]       [ 2 | 3 ]       [       |   ]           *   [   | 3 ]    [ 2 | 3 ]    [   |   ]
120          */          */
121    
122      switch (block)          switch (block) {
     {  
123          case 0:          case 0:
124                  xin1 = x - 1;   yin1 = y;       vec1 = 1;       /* left */                  xin1 = x - 1;
125                  xin2 = x;       yin2 = y - 1;   vec2 = 2;       /* top */                  yin1 = y;
126                  xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;       /* top right */                  vec1 = 1;                               /* left */
127                    xin2 = x;
128                    yin2 = y - 1;
129                    vec2 = 2;                               /* top */
130                    xin3 = x + 1;
131                    yin3 = y - 1;
132                    vec3 = 2;                               /* top right */
133                  break;                  break;
134          case 1:          case 1:
135                  xin1 = x;               yin1 = y;               vec1 = 0;                  xin1 = x;
136                  xin2 = x;               yin2 = y - 1;   vec2 = 3;                  yin1 = y;
137                  xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;                  vec1 = 0;
138                    xin2 = x;
139                    yin2 = y - 1;
140                    vec2 = 3;
141                    xin3 = x + 1;
142                    yin3 = y - 1;
143                    vec3 = 2;
144              break;              break;
145          case 2:          case 2:
146                  xin1 = x - 1;   yin1 = y;               vec1 = 3;                  xin1 = x - 1;
147                  xin2 = x;               yin2 = y;               vec2 = 0;                  yin1 = y;
148                  xin3 = x;               yin3 = y;               vec3 = 1;                  vec1 = 3;
149                    xin2 = x;
150                    yin2 = y;
151                    vec2 = 0;
152                    xin3 = x;
153                    yin3 = y;
154                    vec3 = 1;
155              break;              break;
156          default:          default:
157                  xin1 = x;               yin1 = y;               vec1 = 2;                  xin1 = x;
158                  xin2 = x;               yin2 = y;               vec2 = 0;                  yin1 = y;
159                  xin3 = x;               yin3 = y;               vec3 = 1;                  vec1 = 2;
160                    xin2 = x;
161                    yin2 = y;
162                    vec2 = 0;
163                    xin3 = x;
164                    yin3 = y;
165                    vec3 = 1;
166      }      }
167    
168    
169          if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t)x_dim)          if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t) x_dim) {
         {  
170                  lneigh = zeroMV;                  lneigh = zeroMV;
171          }          } else {
         else  
         {  
172                  lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];                  lneigh = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
173          }          }
174    
175          if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim)          if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t) x_dim) {
         {  
176                  tneigh = zeroMV;                  tneigh = zeroMV;
177          }          } else {
         else  
         {  
178                  tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];                  tneigh = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
179          }          }
180    
181          if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim)          if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t) x_dim) {
         {  
182                  trneigh = zeroMV;                  trneigh = zeroMV;
183          }          } else {
         else  
         {  
184                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];                  trneigh = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
185          }          }
186    
187          // median,minimum          /* median,minimum */
188    
189          median.x = MIN(MAX(lneigh.x, tneigh.x), MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));          median.x =
190          median.y = MIN(MAX(lneigh.y, tneigh.y), MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));                  MIN(MAX(lneigh.x, tneigh.x),
191                            MIN(MAX(tneigh.x, trneigh.x), MAX(lneigh.x, trneigh.x)));
192            median.y =
193                    MIN(MAX(lneigh.y, tneigh.y),
194                            MIN(MAX(tneigh.y, trneigh.y), MAX(lneigh.y, trneigh.y)));
195          return median;          return median;
196  }  }
197    
# Line 145  Line 199 
199  /* 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
200     instead of only Median MV */     instead of only Median MV */
201    
202  static __inline int get_pmvdata(const MACROBLOCK * const pMBs,  static __inline int
203                                                          const uint32_t x, const uint32_t y,  get_pmvdata(const MACROBLOCK * const pMBs,
204                            const uint32_t x,
205                            const uint32_t y,
206                                                          const uint32_t x_dim,                                                          const uint32_t x_dim,
207                                                          const uint32_t block,                                                          const uint32_t block,
208                                                          VECTOR * const pmv,                                                          VECTOR * const pmv,
209                                                          int32_t * const psad)                                                          int32_t * const psad)
210  {  {
211  /* pmv are filled with:  
212          [0]: Median (or whatever is correct in a special case)          /*
213          [1]: left neighbour           * pmv are filled with:
214          [2]: top neighbour,           *  [0]: Median (or whatever is correct in a special case)
215          [3]: topright neighbour,           *  [1]: left neighbour
216     psad are filled with:           *  [2]: top neighbour
217          [0]: minimum of [1] to [3]           *  [3]: topright neighbour
218          [1]: left neighbour's SAD       // [1] to [3] are actually not needed           * psad are filled with:
219          [2]: top neighbour's SAD,           *  [0]: minimum of [1] to [3]
220          [3]: topright neighbour's SAD,           *  [1]: left neighbour's SAD (NB:[1] to [3] are actually not needed)
221             *  [2]: top neighbour's SAD
222             *  [3]: topright neighbour's SAD
223  */  */
224    
225      int xin1, xin2, xin3;      int xin1, xin2, xin3;
226      int yin1, yin2, yin3;      int yin1, yin2, yin3;
227      int vec1, vec2, vec3;      int vec1, vec2, vec3;
228    
     static VECTOR zeroMV;  
229      uint32_t index = x + y * x_dim;      uint32_t index = x + y * x_dim;
230      zeroMV.x = zeroMV.y = 0;          const VECTOR zeroMV = { 0, 0 };
231    
232          // first row (special case)          // first row of blocks (special case)
233      if (y == 0 && (block == 0 || block == 1))          if (y == 0 && (block == 0 || block == 1)) {
     {  
234                  if ((x == 0) && (block == 0))           // first column, first block                  if ((x == 0) && (block == 0))           // first column, first block
235                  {                  {
236                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;                          pmv[0] = pmv[1] = pmv[2] = pmv[3] = zeroMV;
237                          psad[0] = psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;                          psad[0] = 0;
238                            psad[1] = psad[2] = psad[3] = MV_MAX_ERROR;
239                          return 0;                          return 0;
240                  }                  }
241                  if (block == 1)         // second block; has only a left neighbour                  if (block == 1)         // second block; has only a left neighbour
# Line 188  Line 245 
245                          psad[0] = psad[1] = pMBs[index].sad8[0];                          psad[0] = psad[1] = pMBs[index].sad8[0];
246                          psad[2] = psad[3] = MV_MAX_ERROR;                          psad[2] = psad[3] = MV_MAX_ERROR;
247                          return 0;                          return 0;
248                  }                  } else {                                /* block==0, but x!=0, so again, there is a left neighbour */
249                  else /* block==0, but x!=0, so again, there is a left neighbour*/  
                 {  
250                          pmv[0] = pmv[1] = pMBs[index-1].mvs[1];                          pmv[0] = pmv[1] = pMBs[index-1].mvs[1];
251                          pmv[2] = pmv[3] = zeroMV;                          pmv[2] = pmv[3] = zeroMV;
252                          psad[0] = psad[1] = pMBs[index-1].sad8[1];                          psad[0] = psad[1] = pMBs[index-1].sad8[1];
# Line 200  Line 256 
256      }      }
257    
258          /*          /*
259                  MODE_INTER, vm18 page 48           * MODE_INTER, vm18 page 48
260                  MODE_INTER4V vm18 page 51           * MODE_INTER4V vm18 page 51
261             *
262                                          (x,y-1)         (x+1,y-1)           *  (x,y-1)      (x+1,y-1)
263                                          [   |   ]       [       |   ]           *  [   |   ]    [   |   ]
264                                          [ 2 | 3 ]       [ 2 |   ]           *  [ 2 | 3 ]    [ 2 |   ]
265             *
266                  (x-1,y)         (x,y)           (x+1,y)           *  (x-1,y)      (x,y)        (x+1,y)
267                  [   | 1 ]       [ 0 | 1 ]       [ 0 |   ]           *  [   | 1 ]    [ 0 | 1 ]    [ 0 |   ]
268                  [   | 3 ]       [ 2 | 3 ]       [       |   ]           *  [   | 3 ]    [ 2 | 3 ]    [   |   ]
269          */          */
270    
271      switch (block)          switch (block) {
     {  
272          case 0:          case 0:
273                  xin1 = x - 1;   yin1 = y;       vec1 = 1;       /* left */                  xin1 = x - 1;
274                  xin2 = x;       yin2 = y - 1;   vec2 = 2;       /* top */                  yin1 = y;
275                  xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;       /* top right */                  vec1 = 1;                               /* left */
276                    xin2 = x;
277                    yin2 = y - 1;
278                    vec2 = 2;                               /* top */
279                    xin3 = x + 1;
280                    yin3 = y - 1;
281                    vec3 = 2;                               /* top right */
282                  break;                  break;
283          case 1:          case 1:
284                  xin1 = x;               yin1 = y;               vec1 = 0;                  xin1 = x;
285                  xin2 = x;               yin2 = y - 1;   vec2 = 3;                  yin1 = y;
286                  xin3 = x + 1;   yin3 = y - 1;   vec3 = 2;                  vec1 = 0;
287                    xin2 = x;
288                    yin2 = y - 1;
289                    vec2 = 3;
290                    xin3 = x + 1;
291                    yin3 = y - 1;
292                    vec3 = 2;
293              break;              break;
294          case 2:          case 2:
295                  xin1 = x - 1;   yin1 = y;               vec1 = 3;                  xin1 = x - 1;
296                  xin2 = x;               yin2 = y;               vec2 = 0;                  yin1 = y;
297                  xin3 = x;               yin3 = y;               vec3 = 1;                  vec1 = 3;
298                    xin2 = x;
299                    yin2 = y;
300                    vec2 = 0;
301                    xin3 = x;
302                    yin3 = y;
303                    vec3 = 1;
304              break;              break;
305          default:          default:
306                  xin1 = x;               yin1 = y;               vec1 = 2;                  xin1 = x;
307                  xin2 = x;               yin2 = y;               vec2 = 0;                  yin1 = y;
308                  xin3 = x;               yin3 = y;               vec3 = 1;                  vec1 = 2;
309                    xin2 = x;
310                    yin2 = y;
311                    vec2 = 0;
312                    xin3 = x;
313                    yin3 = y;
314                    vec3 = 1;
315      }      }
316    
317    
318          if (xin1 < 0 || /* yin1 < 0  || */ xin1 >= (int32_t)x_dim)          if (xin1 < 0 || xin1 >= (int32_t) x_dim) {
         {  
319                  pmv[1] = zeroMV;                  pmv[1] = zeroMV;
320                  psad[1] = MV_MAX_ERROR;                  psad[1] = MV_MAX_ERROR;
321          }          } else {
         else  
         {  
322                  pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];                  pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];
323                  psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];                  psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];
324          }          }
325    
326          if (xin2 < 0 || /* yin2 < 0 || */ xin2 >= (int32_t)x_dim)          if (xin2 < 0 || xin2 >= (int32_t) x_dim) {
         {  
327                  pmv[2] = zeroMV;                  pmv[2] = zeroMV;
328                  psad[2] = MV_MAX_ERROR;                  psad[2] = MV_MAX_ERROR;
329          }          } else {
         else  
         {  
330                  pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];                  pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];
331                  psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];                  psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];
332          }          }
333    
334          if (xin3 < 0 || /* yin3 < 0 || */ xin3 >= (int32_t)x_dim)          if (xin3 < 0 || xin3 >= (int32_t) x_dim) {
         {  
335                  pmv[3] = zeroMV;                  pmv[3] = zeroMV;
336                  psad[3] = MV_MAX_ERROR;                  psad[3] = MV_MAX_ERROR;
337          }          } else {
         else  
         {  
338                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];                  pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];
339                  psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];                  psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];
340          }          }
341    
342          if ( (MVequal(pmv[1],pmv[2])) && (MVequal(pmv[1],pmv[3])) )          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {
343          {       pmv[0]=pmv[1];                  pmv[0] = pmv[1];
344                  psad[0]=psad[1];                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);
345                  return 1;                  return 1;
346          }          }
347    
348          // median,minimum          /* median,minimum */
349    
350          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 =
351          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)));                  MIN(MAX(pmv[1].x, pmv[2].x),
352                            MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
353            pmv[0].y =
354                    MIN(MAX(pmv[1].y, pmv[2].y),
355                            MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
356          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);          psad[0]=MIN(MIN(psad[1],psad[2]),psad[3]);
357    
358          return 0;          return 0;
359  }  }
360    

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

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