[svn] / branches / release-1_0-branch / xvidcore / src / prediction / mbprediction.c Repository:
ViewVC logotype

Diff of /branches/release-1_0-branch/xvidcore/src/prediction/mbprediction.c

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

revision 252, Sun Jun 30 10:46:29 2002 UTC revision 499, Sat Sep 21 03:11:36 2002 UTC
# Line 1  Line 1 
1   /******************************************************************************  /*****************************************************************************
2    *                                                                            *   *
3    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *   *  XVID MPEG-4 VIDEO CODEC
4    *                                                                            *   *  - Prediction functions -
5    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *   *
6    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *   *  Copyright(C) 2001-2002 - Michael Militzer <isibaar@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *  Copyright(C) 2001-2002 - Peter Ross <pross@xvid.org>
8    *  use may infringe existing patents or copyrights, and any such use         *   *
9    *  would be at such party's own risk.  The original developer of this        *   *  This program is an implementation of a part of one or more MPEG-4
10    *  software module and his/her company, and subsequent editors and their     *   *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
11    *  companies, will have no liability for use of this software or             *   *  to use this software module in hardware or software products are
12    *  modifications or derivatives thereof.                                     *   *  advised that its use may infringe existing patents or copyrights, and
13    *                                                                            *   *  any such use would be at such party's own risk.  The original
14    *  XviD is free software; you can redistribute it and/or modify it           *   *  developer of this software module and his/her company, and subsequent
15    *  under the terms of the GNU General Public License as published by         *   *  editors and their companies, will have no liability for use of this
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  software or modifications or derivatives thereof.
17    *  (at your option) any later version.                                       *   *
18    *                                                                            *   *  This program is free software; you can redistribute it and/or modify
19    *  XviD is distributed in the hope that it will be useful, but               *   *  it under the terms of the GNU General Public License as published by
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  the Free Software Foundation; either version 2 of the License, or
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *  (at your option) any later version.
22    *  GNU General Public License for more details.                              *   *
23    *                                                                            *   *  This program is distributed in the hope that it will be useful,
24    *  You should have received a copy of the GNU General Public License         *   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25    *  along with this program; if not, write to the Free Software               *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *   *  GNU General Public License for more details.
27    *                                                                            *   *
28    ******************************************************************************/   *  You should have received a copy of the GNU General Public License
29     *  along with this program; if not, write to the Free Software
30   /******************************************************************************   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
31    *                                                                            *   *
32    *  mbprediction.c                                                            *   * $Id: mbprediction.c,v 1.9 2002-09-21 03:07:56 suxen_drol Exp $
33    *                                                                            *   *
34    *  Copyright (C) 2001 - Michael Militzer <isibaar@xvid.org>                  *   ****************************************************************************/
   *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *  
   *                                                                            *  
   *  For more information visit the XviD homepage: http://www.xvid.org         *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  Revision history:                                                         *  
   *                                                                            *  
   *  29.06.2002 predict_acdc() bounding                                        *  
   *  12.12.2001 improved calc_acdc_prediction; removed need for memcpy         *  
   *  15.12.2001 moved pmv displacement to motion estimation                    *  
   *  30.11.2001 mmx cbp support                                                *  
   *  17.11.2001 initial version                                                *  
   *                                                                            *  
   ******************************************************************************/  
35    
36  #include "../encoder.h"  #include "../encoder.h"
37  #include "mbprediction.h"  #include "mbprediction.h"
# Line 60  Line 43 
43  #define DIV_DIV(A,B)    ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) )  #define DIV_DIV(A,B)    ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) )
44    
45    
46    /*****************************************************************************
47     * Local inlined function
48     ****************************************************************************/
49    
50  static int __inline  static int __inline
51  rescale(int predict_quant,  rescale(int predict_quant,
52                  int current_quant,                  int current_quant,
# Line 70  Line 57 
57  }  }
58    
59    
60    /*****************************************************************************
61     * Local data
62     ****************************************************************************/
63    
64  static const int16_t default_acdc_values[15] = {  static const int16_t default_acdc_values[15] = {
65          1024,          1024,
66          0, 0, 0, 0, 0, 0, 0,          0, 0, 0, 0, 0, 0, 0,
# Line 77  Line 68 
68  };  };
69    
70    
71    /*****************************************************************************
72     * Functions
73     ****************************************************************************/
74    
75    
76  /*      get dc/ac prediction direction for a single block and place  /*      get dc/ac prediction direction for a single block and place
77          predictor values into MB->pred_values[j][..]          predictor values into MB->pred_values[j][..]
78  */  */
# Line 408  Line 404 
404          }          }
405    
406  }  }
   
   
   
   
 /*  
   get_pmvdata2: get_pmvdata with bounding  
 */  
 #define OFFSET(x,y,stride)   ((x)+((y)*(stride)))  
   
 int  
 get_pmvdata2(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 int bound)  
 {  
         const int mbpos = OFFSET(x, y ,x_dim);  
   
         /*  
          * 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  
          */  
   
         int xin1, xin2, xin3;  
         int yin1, yin2, yin3;  
         int vec1, vec2, vec3;  
   
         int pos1, pos2, pos3;  
         int num_cand = 0;               // number of candidates  
         int last_cand;                  // last candidate  
   
         uint32_t index = x + y * x_dim;  
         const VECTOR zeroMV = { 0, 0 };  
   
         /*  
          * 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 ]    [   |   ]  
          */  
   
         switch (block) {  
         case 0:  
                 xin1 = x - 1;  
                 yin1 = y;  
                 vec1 = 1;                               /* left */  
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 2;                               /* top */  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;                               /* top right */  
                 break;  
         case 1:  
                 xin1 = x;  
                 yin1 = y;  
                 vec1 = 0;  
                 xin2 = x;  
                 yin2 = y - 1;  
                 vec2 = 3;  
                 xin3 = x + 1;  
                 yin3 = y - 1;  
                 vec3 = 2;  
                 break;  
         case 2:  
                 xin1 = x - 1;  
                 yin1 = y;  
                 vec1 = 3;  
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
                 break;  
         default:  
                 xin1 = x;  
                 yin1 = y;  
                 vec1 = 2;  
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
         }  
   
         pos1 = OFFSET(xin1, yin1, x_dim);  
         pos2 = OFFSET(xin2, yin2, x_dim);  
         pos3 = OFFSET(xin3, yin3, x_dim);  
   
         // left  
         if (xin1 < 0 || pos1 < bound) {  
                 pmv[1] = zeroMV;  
                 psad[1] = MV_MAX_ERROR;  
         } else {  
                 pmv[1] = pMBs[xin1 + yin1 * x_dim].mvs[vec1];  
                 psad[1] = pMBs[xin1 + yin1 * x_dim].sad8[vec1];  
                 num_cand++;  
                 last_cand = 1;  
         }  
   
         // top  
         if (yin2 < 0 || pos2 < bound) {  
                 pmv[2] = zeroMV;  
                 psad[2] = MV_MAX_ERROR;  
         } else {  
                 pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];  
                 psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];  
                 num_cand++;  
                 last_cand = 2;  
         }  
   
   
         // top right  
         if (yin3 < 0 || pos3 < bound || xin3 >= (int)x_dim) {  
                 pmv[3] = zeroMV;  
                 psad[3] = MV_MAX_ERROR;  
                 //DPRINTF(DPRINTF_MV, "top-right");  
         } else {  
                 pmv[3] = pMBs[xin3 + yin3 * x_dim].mvs[vec3];  
                 psad[3] = pMBs[xin2 + yin2 * x_dim].sad8[vec3];  
                 num_cand++;  
                 last_cand = 3;  
         }  
   
         if (num_cand == 1)  
         {  
                 /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i) last=%i",  
                         pmv[1].x, pmv[1].y,  
                         pmv[2].x, pmv[2].y,  
                         pmv[3].x, pmv[3].y, last_cand - 1);  
                 */  
   
                 pmv[0] = pmv[last_cand];  
                 psad[0] = psad[last_cand];  
                 return 0;  
         }  
   
         /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i)",  
                 pmv[1].x, pmv[1].y,  
                 pmv[2].x, pmv[2].y,  
                 pmv[3].x, pmv[3].y);*/  
   
         if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {  
                 pmv[0] = pmv[1];  
                 psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);  
                 return 1;  
         }  
   
         /* median,minimum */  
   
         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].y =  
                 MIN(MAX(pmv[1].y, pmv[2].y),  
                         MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));  
         psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);  
   
         return 0;  
 }  

Legend:
Removed from v.252  
changed lines
  Added in v.499

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