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

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

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

revision 194, Sun Jun 9 23:30:50 2002 UTC revision 195, Wed Jun 12 20:38:41 2002 UTC
# Line 59  Line 59 
59  #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) )
60    
61    
62  static int __inline rescale(int predict_quant, int current_quant, int coeff)  static int __inline
63    rescale(int predict_quant,
64                    int current_quant,
65                    int coeff)
66  {  {
67          return (coeff != 0) ? DIV_DIV((coeff) * (predict_quant), (current_quant)) : 0;          return (coeff != 0) ? DIV_DIV((coeff) * (predict_quant),
68                                                                      (current_quant)) : 0;
69  }  }
70    
71    
# Line 77  Line 81 
81  */  */
82    
83    
84  void predict_acdc(MACROBLOCK *pMBs,  void
85                    uint32_t x, uint32_t y,       uint32_t mb_width,  predict_acdc(MACROBLOCK * pMBs,
86                             uint32_t x,
87                             uint32_t y,
88                             uint32_t mb_width,
89                    uint32_t block,                    uint32_t block,
90                    int16_t qcoeff[64],                    int16_t qcoeff[64],
91                    uint32_t current_quant,                    uint32_t current_quant,
# Line 104  Line 111 
111    
112          // left macroblock          // left macroblock
113    
114          if(x && (pMBs[index - 1].mode == MODE_INTRA          if (x &&
115                   || pMBs[index - 1].mode == MODE_INTRA_Q)) {                  (pMBs[index - 1].mode == MODE_INTRA ||
116                     pMBs[index - 1].mode == MODE_INTRA_Q)) {
117    
118                  left = pMBs[index - 1].pred_values[0];                  left = pMBs[index - 1].pred_values[0];
119                  left_quant = pMBs[index - 1].quant;                  left_quant = pMBs[index - 1].quant;
120                  //DEBUGI("LEFT", *(left+MBPRED_SIZE));                  //DEBUGI("LEFT", *(left+MBPRED_SIZE));
121          }          }
   
122          // top macroblock          // top macroblock
123    
124          if(y && (pMBs[index - mb_width].mode == MODE_INTRA          if (y &&
125                   || pMBs[index - mb_width].mode == MODE_INTRA_Q)) {                  (pMBs[index - mb_width].mode == MODE_INTRA ||
126                     pMBs[index - mb_width].mode == MODE_INTRA_Q)) {
127    
128                  top = pMBs[index - mb_width].pred_values[0];                  top = pMBs[index - mb_width].pred_values[0];
129                  top_quant = pMBs[index - mb_width].quant;                  top_quant = pMBs[index - mb_width].quant;
130          }          }
   
131          // diag macroblock          // diag macroblock
132    
133          if(x && y && (pMBs[index - 1 - mb_width].mode == MODE_INTRA          if (x && y &&
134                        || pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||
135                     pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {
136    
137                  diag = pMBs[index - 1 - mb_width].pred_values[0];                  diag = pMBs[index - 1 - mb_width].pred_values[0];
138          }          }
# Line 204  Line 212 
212          if(ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])) {          if(ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])) {
213                  *acpred_direction = 1;             // vertical                  *acpred_direction = 1;             // vertical
214                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);
215                  for (i = 1; i < 8; i++)                  for (i = 1; i < 8; i++) {
                 {  
216                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);
217                  }                  }
218          }          } else {
         else  
         {  
219                  *acpred_direction = 2;             // horizontal                  *acpred_direction = 2;             // horizontal
220                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);
221                  for (i = 1; i < 8; i++)                  for (i = 1; i < 8; i++) {
                 {  
222                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);
223                  }                  }
224          }          }
# Line 226  Line 230 
230  */  */
231    
232    
233  void add_acdc(MACROBLOCK *pMB,  void
234    add_acdc(MACROBLOCK * pMB,
235                uint32_t block,                uint32_t block,
236                int16_t dct_codes[64],                int16_t dct_codes[64],
237                uint32_t iDcScaler,                uint32_t iDcScaler,
# Line 239  Line 244 
244          dct_codes[0] += predictors[0];  // dc prediction          dct_codes[0] += predictors[0];  // dc prediction
245          pCurrent[0] = dct_codes[0] * iDcScaler;          pCurrent[0] = dct_codes[0] * iDcScaler;
246    
247          if (acpred_direction == 1)          if (acpred_direction == 1) {
248          {                  for (i = 1; i < 8; i++) {
                 for (i = 1; i < 8; i++)  
                 {  
249                          int level = dct_codes[i] + predictors[i];                          int level = dct_codes[i] + predictors[i];
250    
251                          dct_codes[i] = level;                          dct_codes[i] = level;
252                          pCurrent[i] = level;                          pCurrent[i] = level;
253                          pCurrent[i+7] = dct_codes[i*8];                          pCurrent[i+7] = dct_codes[i*8];
254                  }                  }
255          }          } else if (acpred_direction == 2) {
256          else if (acpred_direction == 2)                  for (i = 1; i < 8; i++) {
         {  
                 for (i = 1; i < 8; i++)  
                 {  
257                          int level = dct_codes[i*8] + predictors[i];                          int level = dct_codes[i*8] + predictors[i];
258    
259                          dct_codes[i*8] = level;                          dct_codes[i*8] = level;
260                          pCurrent[i+7] = level;                          pCurrent[i+7] = level;
261                          pCurrent[i] = dct_codes[i];                          pCurrent[i] = dct_codes[i];
262                  }                  }
263          }          } else {
264          else                  for (i = 1; i < 8; i++) {
         {  
                 for (i = 1; i < 8; i++)  
                 {  
265                          pCurrent[i] = dct_codes[i];                          pCurrent[i] = dct_codes[i];
266                          pCurrent[i+7] = dct_codes[i*8];                          pCurrent[i+7] = dct_codes[i*8];
267                  }                  }
# Line 284  Line 283 
283  S2 = sum of all qcoeff  S2 = sum of all qcoeff
284  */  */
285    
286  uint32_t calc_acdc(MACROBLOCK *pMB,  uint32_t
287    calc_acdc(MACROBLOCK * pMB,
288                     uint32_t block,                     uint32_t block,
289                     int16_t qcoeff[64],                     int16_t qcoeff[64],
290                     uint32_t iDcScaler,                     uint32_t iDcScaler,
# Line 307  Line 307 
307    
308          qcoeff[0] = qcoeff[0] - predictors[0];          qcoeff[0] = qcoeff[0] - predictors[0];
309    
310          if (pMB->acpred_directions[block] == 1)          if (pMB->acpred_directions[block] == 1) {
         {  
311                  for(i = 1; i < 8; i++) {                  for(i = 1; i < 8; i++) {
312                          int16_t level;                          int16_t level;
313    
# Line 318  Line 317 
317                          S1 += ABS(level);                          S1 += ABS(level);
318                          predictors[i] = level;                          predictors[i] = level;
319                  }                  }
320          }          } else                                          // acpred_direction == 2
         else // acpred_direction == 2  
321          {          {
322                  for(i = 1; i < 8; i++) {                  for(i = 1; i < 8; i++) {
323                          int16_t level;                          int16_t level;
# Line 340  Line 338 
338    
339  /* apply predictors[] to qcoeff */  /* apply predictors[] to qcoeff */
340    
341  void apply_acdc(MACROBLOCK *pMB,  void
342    apply_acdc(MACROBLOCK * pMB,
343                  uint32_t block,                  uint32_t block,
344                  int16_t qcoeff[64],                  int16_t qcoeff[64],
345                  int16_t predictors[8])                  int16_t predictors[8])
346  {  {
347          uint32_t i;          uint32_t i;
348    
349          if (pMB->acpred_directions[block] == 1)          if (pMB->acpred_directions[block] == 1) {
350          {                  for (i = 1; i < 8; i++) {
                 for(i = 1; i < 8; i++)  
                 {  
351                          qcoeff[i] = predictors[i];                          qcoeff[i] = predictors[i];
352                  }                  }
353          }          } else {
354          else                  for (i = 1; i < 8; i++) {
         {  
                 for(i = 1; i < 8; i++)  
                 {  
355                          qcoeff[i*8] = predictors[i];                          qcoeff[i*8] = predictors[i];
356                  }                  }
357          }          }
358  }  }
359    
360    
361  void MBPrediction(FRAMEINFO *frame,  void
362    MBPrediction(FRAMEINFO * frame,
363                    uint32_t x,                    uint32_t x,
364                    uint32_t y,                    uint32_t y,
365                    uint32_t mb_width,                    uint32_t mb_width,
# Line 380  Line 375 
375    
376          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {
377    
378                  for(j = 0; j < 6; j++)                  for (j = 0; j < 6; j++) {
                 {  
379                          iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);                          iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);
380    
381                          predict_acdc(frame->mbs,                          predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],
382                                       x,                                                   iQuant, iDcScaler, predictors[j]);
383                                       y,  
384                                       mb_width,                          S += calc_acdc(pMB, j, &qcoeff[j * 64], iDcScaler, predictors[j]);
                                      j,  
                                      &qcoeff[j*64],  
                                      iQuant,  
                                      iDcScaler,  
                                      predictors[j]);  
   
                         S += calc_acdc(pMB,  
                                        j,  
                                        &qcoeff[j*64],  
                                        iDcScaler,  
                                        predictors[j]);  
385    
386                  }                  }
387    
388                  if (S < 0)              // dont predict                  if (S < 0)              // dont predict
389                  {                  {
390                          for(j = 0; j < 6; j++)                          for (j = 0; j < 6; j++) {
                         {  
391                                  pMB->acpred_directions[j] = 0;                                  pMB->acpred_directions[j] = 0;
392                          }                          }
393                  }                  } else {
394                  else                          for (j = 0; j < 6; j++) {
                 {  
                         for(j = 0; j < 6; j++)  
                         {  
395                                  apply_acdc(pMB, j, &qcoeff[j*64], predictors[j]);                                  apply_acdc(pMB, j, &qcoeff[j*64], predictors[j]);
396                          }                          }
397                  }                  }

Legend:
Removed from v.194  
changed lines
  Added in v.195

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