[cvs] / xvidcore / src / prediction / mbprediction.c Repository:
ViewVC logotype

Diff of /xvidcore/src/prediction/mbprediction.c

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

revision 1.14, Mon Mar 22 22:36:24 2004 UTC revision 1.19, Tue Aug 10 15:00:21 2010 UTC
# Line 84  Line 84 
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 = NULL;
88    
89          /* grab left,top and diag macroblocks */          /* grab left,top and diag macroblocks */
90    
# Line 94  Line 94 
94                  (pMBs[index - 1].mode == MODE_INTRA ||                  (pMBs[index - 1].mode == MODE_INTRA ||
95                   pMBs[index - 1].mode == MODE_INTRA_Q)) {                   pMBs[index - 1].mode == MODE_INTRA_Q)) {
96    
97                  left = pMBs[index - 1].pred_values[0];                  left = (int16_t*)pMBs[index - 1].pred_values[0];
98                  left_quant = pMBs[index - 1].quant;                  left_quant = pMBs[index - 1].quant;
99          }          }
100          /* top macroblock */          /* top macroblock */
# Line 103  Line 103 
103                  (pMBs[index - mb_width].mode == MODE_INTRA ||                  (pMBs[index - mb_width].mode == MODE_INTRA ||
104                   pMBs[index - mb_width].mode == MODE_INTRA_Q)) {                   pMBs[index - mb_width].mode == MODE_INTRA_Q)) {
105    
106                  top = pMBs[index - mb_width].pred_values[0];                  top = (int16_t*)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 */
# Line 112  Line 112 
112                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||
113                   pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {                   pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {
114    
115                  diag = pMBs[index - 1 - mb_width].pred_values[0];                  diag = (int16_t*)pMBs[index - 1 - mb_width].pred_values[0];
116          }          }
117    
118          current = pMBs[index].pred_values[0];          current = (int16_t*)pMBs[index].pred_values[0];
119    
120          /* now grab pLeft, pTop, pDiag _blocks_ */          /* now grab pLeft, pTop, pDiag _blocks_ */
121    
# Line 184  Line 184 
184                  break;                  break;
185          }          }
186    
187          /*          /* determine ac prediction direction & ac/dc predictor place rescaled ac/dc
188           * determine ac prediction direction & ac/dc predictor place rescaled ac/dc           * predictions into predictors[] for later use */
          * predictions into predictors[] for later use  
          */  
   
189          if (abs(pLeft[0] - pDiag[0]) < abs(pDiag[0] - pTop[0])) {          if (abs(pLeft[0] - pDiag[0]) < abs(pDiag[0] - pTop[0])) {
190                  *acpred_direction = 1;  /* vertical */                  *acpred_direction = 1;  /* vertical */
191                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);
# Line 209  Line 206 
206     store current coeffs to pred_values[] for future prediction     store current coeffs to pred_values[] for future prediction
207  */  */
208    
209    /* Up to this version, no DC clipping was performed, so we try to be backward
210     * compatible to avoid artifacts */
211    #define BS_VERSION_BUGGY_DC_CLIPPING 34
212    
213  void  void
214  add_acdc(MACROBLOCK * pMB,  add_acdc(MACROBLOCK * pMB,
215                   uint32_t block,                   uint32_t block,
216                   int16_t dct_codes[64],                   int16_t dct_codes[64],
217                   uint32_t iDcScaler,                   uint32_t iDcScaler,
218                   int16_t predictors[8])                   int16_t predictors[8],
219                     const int bsversion)
220  {  {
221          uint8_t acpred_direction = pMB->acpred_directions[block];          uint8_t acpred_direction = pMB->acpred_directions[block];
222          int16_t *pCurrent = pMB->pred_values[block];          int16_t *pCurrent = (int16_t*)pMB->pred_values[block];
223          uint32_t i;          uint32_t i;
224    
225          DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]);          DPRINTF(XVID_DEBUG_COEFF,"predictor[0] %i\n", predictors[0]);
226    
227          dct_codes[0] += predictors[0];  /* dc prediction */          dct_codes[0] += predictors[0];  /* dc prediction */
228          pCurrent[0] = dct_codes[0] * iDcScaler;          pCurrent[0] = dct_codes[0] * iDcScaler;
229            if (bsversion > BS_VERSION_BUGGY_DC_CLIPPING) {
230                    pCurrent[0] = CLIP(pCurrent[0], -2048, 2047);
231            }
232    
233          if (acpred_direction == 1) {          if (acpred_direction == 1) {
234                  for (i = 1; i < 8; i++) {                  for (i = 1; i < 8; i++) {
# Line 266  Line 270 
270  S2 = sum of all qcoeff  S2 = sum of all qcoeff
271  */  */
272    
273  int  static int
274  calc_acdc_coeff(MACROBLOCK * pMB,  calc_acdc_coeff(MACROBLOCK * pMB,
275                    uint32_t block,                    uint32_t block,
276                    int16_t qcoeff[64],                    int16_t qcoeff[64],
277                    uint32_t iDcScaler,                    uint32_t iDcScaler,
278                    int16_t predictors[8])                    int16_t predictors[8])
279  {  {
280          int16_t *pCurrent = pMB->pred_values[block];          int16_t *pCurrent = (int16_t*)pMB->pred_values[block];
281          uint32_t i;          uint32_t i;
282          int S1 = 0, S2 = 0;          int S1 = 0, S2 = 0;
283    
# Line 281  Line 285 
285          /* store current coeffs to pred_values[] for future prediction */          /* store current coeffs to pred_values[] for future prediction */
286    
287          pCurrent[0] = qcoeff[0] * iDcScaler;          pCurrent[0] = qcoeff[0] * iDcScaler;
288            pCurrent[0] = CLIP(pCurrent[0], -2048, 2047);
289          for (i = 1; i < 8; i++) {          for (i = 1; i < 8; i++) {
290                  pCurrent[i] = qcoeff[i];                  pCurrent[i] = qcoeff[i];
291                  pCurrent[i + 7] = qcoeff[i * 8];                  pCurrent[i + 7] = qcoeff[i * 8];
# Line 322  Line 327 
327    
328  /* returns the bits *saved* if prediction is enabled */  /* returns the bits *saved* if prediction is enabled */
329    
330  int  static int
331  calc_acdc_bits(MACROBLOCK * pMB,  calc_acdc_bits(MACROBLOCK * pMB,
332                    uint32_t block,                    uint32_t block,
333                    int16_t qcoeff[64],                    int16_t qcoeff[64],
# Line 330  Line 335 
335                    int16_t predictors[8])                    int16_t predictors[8])
336  {  {
337          const int direction = pMB->acpred_directions[block];          const int direction = pMB->acpred_directions[block];
338          int16_t *pCurrent = pMB->pred_values[block];          int16_t *pCurrent = (int16_t*)pMB->pred_values[block];
339          int16_t tmp[8];          int16_t tmp[8];
340          unsigned int i;          unsigned int i;
341          int Z1, Z2;          int Z1, Z2;
342    
343          /* store current coeffs to pred_values[] for future prediction */          /* store current coeffs to pred_values[] for future prediction */
344          pCurrent[0] = qcoeff[0] * iDcScaler;          pCurrent[0] = qcoeff[0] * iDcScaler;
345            pCurrent[0] = CLIP(pCurrent[0], -2048, 2047);
346          for (i = 1; i < 8; i++) {          for (i = 1; i < 8; i++) {
347                  pCurrent[i] = qcoeff[i];                  pCurrent[i] = qcoeff[i];
348                  pCurrent[i + 7] = qcoeff[i * 8];                  pCurrent[i + 7] = qcoeff[i * 8];
# Line 380  Line 386 
386    
387  /* apply predictors[] to qcoeff */  /* apply predictors[] to qcoeff */
388    
389  void  static void
390  apply_acdc(MACROBLOCK * pMB,  apply_acdc(MACROBLOCK * pMB,
391                     uint32_t block,                     uint32_t block,
392                     int16_t qcoeff[64],                     int16_t qcoeff[64],
# Line 518  Line 524 
524          return pmv[last_cand];  /* no point calculating median mv */          return pmv[last_cand];  /* no point calculating median mv */
525  }  }
526    
527    VECTOR get_pmv2_interlaced(const MACROBLOCK * const mbs,
528       const int mb_width,
529       const int bound,
530       const int x,
531       const int y,
532       const int block)
533    {
534      int lx, ly, lz;   /* left */
535      int tx, ty, tz;   /* top */
536      int rx, ry, rz;   /* top-right */
537      int lpos, tpos, rpos;
538      int num_cand = 0, last_cand = 1;
539    
540      VECTOR pmv[4];  /* left neighbour, top neighbour, top-right neighbour */
541    
542      lx=x-1; ly=y;   lz=1;
543      tx=x;   ty=y-1; tz=2;
544      rx=x+1; ry=y-1; rz=2;
545    
546      lpos=lx+ly*mb_width;
547      rpos=rx+ry*mb_width;
548      tpos=tx+ty*mb_width;
549    
550      if(lx>=0 && lpos>=bound)
551      {
552        num_cand++;
553        if(mbs[lpos].field_pred)
554         pmv[1] = mbs[lpos].mvs_avg;
555        else
556         pmv[1] = mbs[lpos].mvs[lz];
557      }
558      else
559      {
560        pmv[1] = zeroMV;
561      }
562    
563      if(tpos>=bound)
564      {
565        num_cand++;
566        last_cand=2;
567        if(mbs[tpos].field_pred)
568         pmv[2] = mbs[tpos].mvs_avg;
569        else
570         pmv[2] = mbs[tpos].mvs[tz];
571      }
572      else
573      {
574        pmv[2] = zeroMV;
575      }
576    
577      if(rx<mb_width && rpos>=bound)
578      {
579        num_cand++;
580        last_cand = 3;
581        if(mbs[rpos].field_pred)
582         pmv[3] = mbs[rpos].mvs_avg;
583        else
584         pmv[3] = mbs[rpos].mvs[rz];
585      }
586      else
587      {
588        pmv[3] = zeroMV;
589      }
590    
591      /* If there're more than one candidate, we return the median vector */
592      if(num_cand>1)
593      {
594        /* set median */
595        pmv[0].x = MIN(MAX(pmv[1].x, pmv[2].x),
596                   MIN(MAX(pmv[2].x, pmv[3].x), MAX(pmv[1].x, pmv[3].x)));
597        pmv[0].y = MIN(MAX(pmv[1].y, pmv[2].y),
598                   MIN(MAX(pmv[2].y, pmv[3].y), MAX(pmv[1].y, pmv[3].y)));
599    
600        return pmv[0];
601      }
602    
603      return pmv[last_cand];  /* no point calculating median mv */
604    }
605    
606  VECTOR  VECTOR
607  get_qpmv2(const MACROBLOCK * const mbs,  get_qpmv2(const MACROBLOCK * const mbs,
608                  const int mb_width,                  const int mb_width,

Legend:
Removed from v.1.14  
changed lines
  Added in v.1.19

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