[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

trunk/xvidcore/src/prediction/mbprediction.c revision 252, Sun Jun 30 10:46:29 2002 UTC branches/release-1_0-branch/xvidcore/src/prediction/mbprediction.c revision 1387, Mon Mar 22 23:56:55 2004 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 module -
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-2003 Michael Militzer <isibaar@xvid.org>
7    *  software module in hardware or software products are advised that its     *   *                2001-2003 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 free software ; you can redistribute it and/or modify
10    *  software module and his/her company, and subsequent editors and their     *   *  it under the terms of the GNU General Public License as published by
11    *  companies, will have no liability for use of this software or             *   *  the Free Software Foundation ; either version 2 of the License, or
12    *  modifications or derivatives thereof.                                     *   *  (at your option) any later version.
13    *                                                                            *   *
14    *  XviD is free software; you can redistribute it and/or modify it           *   *  This program is distributed in the hope that it will be useful,
15    *  under the terms of the GNU General Public License as published by         *   *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
16    *  the Free Software Foundation; either version 2 of the License, or         *   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    *  (at your option) any later version.                                       *   *  GNU General Public License for more details.
18    *                                                                            *   *
19    *  XviD is distributed in the hope that it will be useful, but               *   *  You should have received a copy of the GNU General Public License
20    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *   *  along with this program ; if not, write to the Free Software
21    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
22    *  GNU General Public License for more details.                              *   *
23    *                                                                            *   * $Id: mbprediction.c,v 1.14 2004-03-22 22:36:24 edgomez Exp $
24    *  You should have received a copy of the GNU General Public License         *   *
25    *  along with this program; if not, write to the Free Software               *   ****************************************************************************/
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *  
   *                                                                            *  
   ******************************************************************************/  
   
  /******************************************************************************  
   *                                                                            *  
   *  mbprediction.c                                                            *  
   *                                                                            *  
   *  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                                                *  
   *                                                                            *  
   ******************************************************************************/  
26    
27    #include <stdlib.h>
28    
29    #include "../global.h"
30  #include "../encoder.h"  #include "../encoder.h"
31  #include "mbprediction.h"  #include "mbprediction.h"
32  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
33  #include "../bitstream/cbp.h"  #include "../bitstream/cbp.h"
34    #include "../bitstream/mbcoding.h"
35    #include "../bitstream/zigzag.h"
 #define ABS(X) (((X)>0)?(X):-(X))  
 #define DIV_DIV(A,B)    ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) )  
36    
37    
38  static int __inline  static int __inline
# Line 105  Line 80 
80          const int16_t *pTop = default_acdc_values;          const int16_t *pTop = default_acdc_values;
81          const int16_t *pDiag = default_acdc_values;          const int16_t *pDiag = default_acdc_values;
82    
83          uint32_t index = x + y * mb_width;      // current macroblock          uint32_t index = x + y * mb_width;      /* current macroblock */
84          int *acpred_direction = &pMBs[index].acpred_directions[block];          int *acpred_direction = &pMBs[index].acpred_directions[block];
85          uint32_t i;          uint32_t i;
86    
87          left = top = diag = current = 0;          left = top = diag = current = 0;
88    
89          // grab left,top and diag macroblocks          /* grab left,top and diag macroblocks */
90    
91          // left macroblock          /* left macroblock */
92    
93          if (x && mbpos >= bound + 1  &&          if (x && mbpos >= bound + 1  &&
94                  (pMBs[index - 1].mode == MODE_INTRA ||                  (pMBs[index - 1].mode == MODE_INTRA ||
# Line 121  Line 96 
96    
97                  left = pMBs[index - 1].pred_values[0];                  left = pMBs[index - 1].pred_values[0];
98                  left_quant = pMBs[index - 1].quant;                  left_quant = pMBs[index - 1].quant;
                 //DEBUGI("LEFT", *(left+MBPRED_SIZE));  
99          }          }
100          // top macroblock          /* top macroblock */
101    
102          if (mbpos >= bound + (int)mb_width &&          if (mbpos >= bound + (int)mb_width &&
103                  (pMBs[index - mb_width].mode == MODE_INTRA ||                  (pMBs[index - mb_width].mode == MODE_INTRA ||
# Line 132  Line 106 
106                  top = pMBs[index - mb_width].pred_values[0];                  top = pMBs[index - mb_width].pred_values[0];
107                  top_quant = pMBs[index - mb_width].quant;                  top_quant = pMBs[index - mb_width].quant;
108          }          }
109          // diag macroblock          /* diag macroblock */
110    
111          if (x && mbpos >= bound + (int)mb_width + 1 &&          if (x && mbpos >= bound + (int)mb_width + 1 &&
112                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||
# Line 143  Line 117 
117    
118          current = pMBs[index].pred_values[0];          current = pMBs[index].pred_values[0];
119    
120          // now grab pLeft, pTop, pDiag _blocks_          /* now grab pLeft, pTop, pDiag _blocks_ */
121    
122          switch (block) {          switch (block) {
123    
# Line 210  Line 184 
184                  break;                  break;
185          }          }
186    
187          //  determine ac prediction direction & ac/dc predictor          /*
188          //  place rescaled ac/dc predictions into predictors[] for later use           * determine ac prediction direction & ac/dc predictor place rescaled ac/dc
189             * predictions into predictors[] for later use
190             */
191    
192          if (ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])) {          if (abs(pLeft[0] - pDiag[0]) < abs(pDiag[0] - pTop[0])) {
193                  *acpred_direction = 1;  // vertical                  *acpred_direction = 1;  /* vertical */
194                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);
195                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
196                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);
197                  }                  }
198          } else {          } else {
199                  *acpred_direction = 2;  // horizontal                  *acpred_direction = 2;  /* horizontal */
200                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);
201                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
202                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);
# Line 245  Line 221 
221          int16_t *pCurrent = pMB->pred_values[block];          int16_t *pCurrent = pMB->pred_values[block];
222          uint32_t i;          uint32_t i;
223    
224          DPRINTF(DPRINTF_COEFF,"predictor[0] %i", predictors[0]);          DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]);
225    
226          dct_codes[0] += predictors[0];  // dc prediction          dct_codes[0] += predictors[0];  /* dc prediction */
227          pCurrent[0] = dct_codes[0] * iDcScaler;          pCurrent[0] = dct_codes[0] * iDcScaler;
228    
229          if (acpred_direction == 1) {          if (acpred_direction == 1) {
230                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
231                          int level = dct_codes[i] + predictors[i];                          int level = dct_codes[i] + predictors[i];
232    
233                          DPRINTF(DPRINTF_COEFF,"predictor[%i] %i",i, predictors[i]);                          DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i, predictors[i]);
234    
235                          dct_codes[i] = level;                          dct_codes[i] = level;
236                          pCurrent[i] = level;                          pCurrent[i] = level;
# Line 263  Line 239 
239          } else if (acpred_direction == 2) {          } else if (acpred_direction == 2) {
240                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
241                          int level = dct_codes[i * 8] + predictors[i];                          int level = dct_codes[i * 8] + predictors[i];
242                          DPRINTF(DPRINTF_COEFF,"predictor[%i] %i",i*8, predictors[i]);                          DPRINTF(XVID_DEBUG_COEFF,"predictor[%i] %i\n",i*8, predictors[i]);
243    
244                          dct_codes[i * 8] = level;                          dct_codes[i * 8] = level;
245                          pCurrent[i + 7] = level;                          pCurrent[i + 7] = level;
# Line 279  Line 255 
255    
256    
257    
258  // ******************************************************************  /*****************************************************************************
259  // ******************************************************************   ****************************************************************************/
260    
261  /* encoder: subtract predictors from qcoeff[] and calculate S1/S2  /* encoder: subtract predictors from qcoeff[] and calculate S1/S2
262    
263  todo: perform [-127,127] clamping after prediction  returns sum of coeefficients *saved* if prediction is enabled
 clamping must adjust the coeffs, so dequant is done correctly  
264    
 S1/S2 are used  to determine if its worth predicting for AC  
265  S1 = sum of all (qcoeff - prediction)  S1 = sum of all (qcoeff - prediction)
266  S2 = sum of all qcoeff  S2 = sum of all qcoeff
267  */  */
268    
269  uint32_t  int
270  calc_acdc(MACROBLOCK * pMB,  calc_acdc_coeff(MACROBLOCK * pMB,
271                    uint32_t block,                    uint32_t block,
272                    int16_t qcoeff[64],                    int16_t qcoeff[64],
273                    uint32_t iDcScaler,                    uint32_t iDcScaler,
# Line 301  Line 275 
275  {  {
276          int16_t *pCurrent = pMB->pred_values[block];          int16_t *pCurrent = pMB->pred_values[block];
277          uint32_t i;          uint32_t i;
278          uint32_t S1 = 0, S2 = 0;          int S1 = 0, S2 = 0;
279    
280    
281          /* store current coeffs to pred_values[] for future prediction */          /* store current coeffs to pred_values[] for future prediction */
# Line 321  Line 295 
295                          int16_t level;                          int16_t level;
296    
297                          level = qcoeff[i];                          level = qcoeff[i];
298                          S2 += ABS(level);                          S2 += abs(level);
299                          level -= predictors[i];                          level -= predictors[i];
300                          S1 += ABS(level);                          S1 += abs(level);
301                          predictors[i] = level;                          predictors[i] = level;
302                  }                  }
303          } else                                          // acpred_direction == 2          } else                                          /* acpred_direction == 2 */
304          {          {
305                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
306                          int16_t level;                          int16_t level;
307    
308                          level = qcoeff[i * 8];                          level = qcoeff[i * 8];
309                          S2 += ABS(level);                          S2 += abs(level);
310                          level -= predictors[i];                          level -= predictors[i];
311                          S1 += ABS(level);                          S1 += abs(level);
312                          predictors[i] = level;                          predictors[i] = level;
313                  }                  }
314    
# Line 345  Line 319 
319  }  }
320    
321    
322    
323    /* returns the bits *saved* if prediction is enabled */
324    
325    int
326    calc_acdc_bits(MACROBLOCK * pMB,
327                      uint32_t block,
328                      int16_t qcoeff[64],
329                      uint32_t iDcScaler,
330                      int16_t predictors[8])
331    {
332            const int direction = pMB->acpred_directions[block];
333            int16_t *pCurrent = pMB->pred_values[block];
334            int16_t tmp[8];
335            unsigned int i;
336            int Z1, Z2;
337    
338            /* store current coeffs to pred_values[] for future prediction */
339            pCurrent[0] = qcoeff[0] * iDcScaler;
340            for (i = 1; i < 8; i++) {
341                    pCurrent[i] = qcoeff[i];
342                    pCurrent[i + 7] = qcoeff[i * 8];
343            }
344    
345    
346            /* dc prediction */
347            qcoeff[0] = qcoeff[0] - predictors[0];
348    
349            /* calc cost before ac prediction */
350            Z2 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[0]);
351    
352            /* apply ac prediction & calc cost*/
353            if (direction == 1) {
354                    for (i = 1; i < 8; i++) {
355                            tmp[i] = qcoeff[i];
356                            qcoeff[i] -= predictors[i];
357                            predictors[i] = qcoeff[i];
358                    }
359            }else{                                          /* acpred_direction == 2 */
360                    for (i = 1; i < 8; i++) {
361                            tmp[i] = qcoeff[i*8];
362                            qcoeff[i*8] -= predictors[i];
363                            predictors[i] = qcoeff[i*8];
364                    }
365            }
366    
367            Z1 = CodeCoeffIntra_CalcBits(qcoeff, scan_tables[direction]);
368    
369            /* undo prediction */
370            if (direction == 1) {
371                    for (i = 1; i < 8; i++)
372                            qcoeff[i] = tmp[i];
373            }else{                                          /* acpred_direction == 2 */
374                    for (i = 1; i < 8; i++)
375                            qcoeff[i*8] = tmp[i];
376            }
377    
378            return Z2-Z1;
379    }
380    
381  /* apply predictors[] to qcoeff */  /* apply predictors[] to qcoeff */
382    
383  void  void
# Line 353  Line 386 
386                     int16_t qcoeff[64],                     int16_t qcoeff[64],
387                     int16_t predictors[8])                     int16_t predictors[8])
388  {  {
389          uint32_t i;          unsigned int i;
390    
391          if (pMB->acpred_directions[block] == 1) {          if (pMB->acpred_directions[block] == 1) {
392                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++)
393                          qcoeff[i] = predictors[i];                          qcoeff[i] = predictors[i];
                 }  
394          } else {          } else {
395                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++)
396                          qcoeff[i * 8] = predictors[i];                          qcoeff[i * 8] = predictors[i];
397                  }                  }
398          }          }
 }  
399    
400    
401  void  void
# Line 376  Line 407 
407  {  {
408    
409          int32_t j;          int32_t j;
410          int32_t iDcScaler, iQuant = frame->quant;          int32_t iDcScaler, iQuant;
411          int32_t S = 0;          int S = 0;
412          int16_t predictors[6][8];          int16_t predictors[6][8];
413    
414          MACROBLOCK *pMB = &frame->mbs[x + y * mb_width];          MACROBLOCK *pMB = &frame->mbs[x + y * mb_width];
415        iQuant = pMB->quant;
416    
417          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {
418    
419                  for (j = 0; j < 6; j++) {                  for (j = 0; j < 6; j++) {
420                          iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);                          iDcScaler = get_dc_scaler(iQuant, j<4);
421    
422                          predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],                          predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],
423                                                   iQuant, iDcScaler, predictors[j], 0);                                                   iQuant, iDcScaler, predictors[j], 0);
424    
425                          S += calc_acdc(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);                          if ((frame->vop_flags & XVID_VOP_HQACPRED))
426                                    S += calc_acdc_bits(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);
427                            else
428                                    S += calc_acdc_coeff(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);
429    
430                  }                  }
431    
432                  if (S < 0)                              // dont predict                  if (S<=0) {                             /* dont predict */
433                  {                          for (j = 0; j < 6; j++)
                         for (j = 0; j < 6; j++) {  
434                                  pMB->acpred_directions[j] = 0;                                  pMB->acpred_directions[j] = 0;
                         }  
435                  } else {                  } else {
436                          for (j = 0; j < 6; j++) {                          for (j = 0; j < 6; j++)
437                                  apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]);                                  apply_acdc(pMB, j, &qcoeff[j * 64], predictors[j]);
438                          }                          }
439                  }  
440                  pMB->cbp = calc_cbp(qcoeff);                  pMB->cbp = calc_cbp(qcoeff);
441          }          }
   
442  }  }
443    
444    static const VECTOR zeroMV = { 0, 0 };
445    
446    VECTOR
447    get_pmv2(const MACROBLOCK * const mbs,
448  /*                  const int mb_width,
449    get_pmvdata2: get_pmvdata with bounding                  const int bound,
450  */                  const int x,
451  #define OFFSET(x,y,stride)   ((x)+((y)*(stride)))                  const int y,
452                    const int block)
 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)  
453  {  {
454          const int mbpos = OFFSET(x, y ,x_dim);          int lx, ly, lz;         /* left */
455            int tx, ty, tz;         /* top */
456          /*          int rx, ry, rz;         /* top-right */
457           * pmv are filled with:          int lpos, tpos, rpos;
458           *  [0]: Median (or whatever is correct in a special case)          int num_cand = 0, last_cand = 1;
          *  [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  
          */  
459    
460          int xin1, xin2, xin3;          VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
         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 ]    [   |   ]  
          */  
461    
462          switch (block) {          switch (block) {
463          case 0:          case 0:
464                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 1;
465                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 2;
466                  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 */  
467                  break;                  break;
468          case 1:          case 1:
469                  xin1 = x;                  lx = x;         ly = y;         lz = 0;
470                  yin1 = y;                  tx = x;         ty = y - 1;     tz = 3;
471                  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;  
472                  break;                  break;
473          case 2:          case 2:
474                  xin1 = x - 1;                  lx = x - 1;     ly = y;         lz = 3;
475                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
476                  vec1 = 3;                  rx = x;         ry = y;         rz = 1;
                 xin2 = x;  
                 yin2 = y;  
                 vec2 = 0;  
                 xin3 = x;  
                 yin3 = y;  
                 vec3 = 1;  
477                  break;                  break;
478          default:          default:
479                  xin1 = x;                  lx = x;         ly = y;         lz = 2;
480                  yin1 = y;                  tx = x;         ty = y;         tz = 0;
481                  vec1 = 2;                  rx = x;         ry = y;         rz = 1;
                 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;  
482          }          }
483    
484          // top          lpos = lx + ly * mb_width;
485          if (yin2 < 0 || pos2 < bound) {          rpos = rx + ry * mb_width;
486                  pmv[2] = zeroMV;          tpos = tx + ty * mb_width;
487                  psad[2] = MV_MAX_ERROR;  
488          } else {          if (lpos >= bound && lx >= 0) {
                 pmv[2] = pMBs[xin2 + yin2 * x_dim].mvs[vec2];  
                 psad[2] = pMBs[xin2 + yin2 * x_dim].sad8[vec2];  
489                  num_cand++;                  num_cand++;
490                  last_cand = 2;                  pmv[1] = mbs[lpos].mvs[lz];
491          }          } else pmv[1] = zeroMV;
492    
493            if (tpos >= bound) {
494                    num_cand++;
495                    last_cand = 2;
496                    pmv[2] = mbs[tpos].mvs[tz];
497            } else pmv[2] = zeroMV;
498    
499          // top right          if (rpos >= bound && rx < mb_width) {
         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];  
500                  num_cand++;                  num_cand++;
501                  last_cand = 3;                  last_cand = 3;
502                    pmv[3] = mbs[rpos].mvs[rz];
503            } else pmv[3] = zeroMV;
504    
505            /* If there're more than one candidate, we return the median vector */
506    
507            if (num_cand > 1) {
508                    /* set median */
509                    pmv[0].x =
510                            MIN(MAX(pmv[1].x, pmv[2].x),
511                                    MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
512                    pmv[0].y =
513                            MIN(MAX(pmv[1].y, pmv[2].y),
514                                    MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
515                    return pmv[0];
516            }
517    
518            return pmv[last_cand];  /* no point calculating median mv */
519          }          }
520    
521          if (num_cand == 1)  VECTOR
522    get_qpmv2(const MACROBLOCK * const mbs,
523                    const int mb_width,
524                    const int bound,
525                    const int x,
526                    const int y,
527                    const int block)
528          {          {
529                  /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i) last=%i",          int lx, ly, lz;         /* left */
530                          pmv[1].x, pmv[1].y,          int tx, ty, tz;         /* top */
531                          pmv[2].x, pmv[2].y,          int rx, ry, rz;         /* top-right */
532                          pmv[3].x, pmv[3].y, last_cand - 1);          int lpos, tpos, rpos;
533                  */          int num_cand = 0, last_cand = 1;
534    
535                  pmv[0] = pmv[last_cand];          VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
536                  psad[0] = psad[last_cand];  
537                  return 0;          switch (block) {
538            case 0:
539                    lx = x - 1;     ly = y;         lz = 1;
540                    tx = x;         ty = y - 1;     tz = 2;
541                    rx = x + 1;     ry = y - 1;     rz = 2;
542                    break;
543            case 1:
544                    lx = x;         ly = y;         lz = 0;
545                    tx = x;         ty = y - 1;     tz = 3;
546                    rx = x + 1;     ry = y - 1;     rz = 2;
547                    break;
548            case 2:
549                    lx = x - 1;     ly = y;         lz = 3;
550                    tx = x;         ty = y;         tz = 0;
551                    rx = x;         ry = y;         rz = 1;
552                    break;
553            default:
554                    lx = x;         ly = y;         lz = 2;
555                    tx = x;         ty = y;         tz = 0;
556                    rx = x;         ry = y;         rz = 1;
557          }          }
558    
559          /* DPRINTF(DPRINTF_MV,"cand0=(%i,%i), cand1=(%i,%i) cand2=(%i,%i)",          lpos = lx + ly * mb_width;
560                  pmv[1].x, pmv[1].y,          rpos = rx + ry * mb_width;
561                  pmv[2].x, pmv[2].y,          tpos = tx + ty * mb_width;
                 pmv[3].x, pmv[3].y);*/  
562    
563          if ((MVequal(pmv[1], pmv[2])) && (MVequal(pmv[1], pmv[3]))) {          if (lpos >= bound && lx >= 0) {
564                  pmv[0] = pmv[1];                  num_cand++;
565                  psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);                  pmv[1] = mbs[lpos].qmvs[lz];
566                  return 1;          } else pmv[1] = zeroMV;
         }  
567    
568          /* median,minimum */          if (tpos >= bound) {
569                    num_cand++;
570                    last_cand = 2;
571                    pmv[2] = mbs[tpos].qmvs[tz];
572            } else pmv[2] = zeroMV;
573    
574            if (rpos >= bound && rx < mb_width) {
575                    num_cand++;
576                    last_cand = 3;
577                    pmv[3] = mbs[rpos].qmvs[rz];
578            } else pmv[3] = zeroMV;
579    
580            /* If there're more than one candidate, we return the median vector */
581    
582            if (num_cand > 1) {
583                    /* set median */
584          pmv[0].x =          pmv[0].x =
585                  MIN(MAX(pmv[1].x, pmv[2].x),                  MIN(MAX(pmv[1].x, pmv[2].x),
586                          MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));                          MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
587          pmv[0].y =          pmv[0].y =
588                  MIN(MAX(pmv[1].y, pmv[2].y),                  MIN(MAX(pmv[1].y, pmv[2].y),
589                          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)));
590          psad[0] = MIN(MIN(psad[1], psad[2]), psad[3]);                  return pmv[0];
591            }
592    
593          return 0;          return pmv[last_cand];  /* no point calculating median mv */
594  }  }

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

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