[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.2, Thu Mar 28 20:57:25 2002 UTC revision 1.7.2.1, Sat Jan 4 06:14:33 2003 UTC
# Line 42  Line 42 
42    *                                                                            *    *                                                                            *
43    *  Revision history:                                                         *    *  Revision history:                                                         *
44    *                                                                            *    *                                                                            *
45      *  29.06.2002 predict_acdc() bounding                                        *
46    *  12.12.2001 improved calc_acdc_prediction; removed need for memcpy         *    *  12.12.2001 improved calc_acdc_prediction; removed need for memcpy         *
47    *  15.12.2001 moved pmv displacement to motion estimation                    *    *  15.12.2001 moved pmv displacement to motion estimation                    *
48    *  30.11.2001 mmx cbp support                                                *    *  30.11.2001 mmx cbp support                                                *
# Line 49  Line 50 
50    *                                                                            *    *                                                                            *
51    ******************************************************************************/    ******************************************************************************/
52    
53    #include "../global.h"
54  #include "../encoder.h"  #include "../encoder.h"
55  #include "mbprediction.h"  #include "mbprediction.h"
56  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
57  #include "../bitstream/cbp.h"  #include "../bitstream/cbp.h"
58    
59    
60  #define ABS(X) (((X)>0)?(X):-(X))  static int __inline
61  #define DIV_DIV(A,B)    ( (A) > 0 ? ((A)+((B)>>1))/(B) : ((A)-((B)>>1))/(B) )  rescale(int predict_quant,
62                    int current_quant,
63                    int coeff)
 static int __inline rescale(int predict_quant, int current_quant, int coeff)  
64  {  {
65          return (coeff != 0) ? DIV_DIV((coeff) * (predict_quant), (current_quant)) : 0;          return (coeff != 0) ? DIV_DIV((coeff) * (predict_quant),
66                                                                      (current_quant)) : 0;
67  }  }
68    
69    
# Line 77  Line 79 
79  */  */
80    
81    
82  void predict_acdc(MACROBLOCK *pMBs,  void
83                    uint32_t x, uint32_t y,       uint32_t mb_width,  predict_acdc(MACROBLOCK * pMBs,
84                             uint32_t x,
85                             uint32_t y,
86                             uint32_t mb_width,
87                    uint32_t block,                    uint32_t block,
88                    int16_t qcoeff[64],                    int16_t qcoeff[64],
89                    uint32_t current_quant,                    uint32_t current_quant,
90                    int32_t iDcScaler,                    int32_t iDcScaler,
91                    int16_t predictors[8])                           int16_t predictors[8],
92                            const int bound)
93    
94  {  {
95            const int mbpos = (y * mb_width) + x;
96          int16_t *left, *top, *diag, *current;          int16_t *left, *top, *diag, *current;
97    
98          int32_t left_quant = current_quant;          int32_t left_quant = current_quant;
# Line 104  Line 112 
112    
113          // left macroblock          // left macroblock
114    
115          if(x && (pMBs[index - 1].mode == MODE_INTRA          if (x && mbpos >= bound + 1  &&
116                   || pMBs[index - 1].mode == MODE_INTRA_Q)) {                  (pMBs[index - 1].mode == MODE_INTRA ||
117                     pMBs[index - 1].mode == MODE_INTRA_Q)) {
118    
119                  left = pMBs[index - 1].pred_values[0];                  left = pMBs[index - 1].pred_values[0];
120                  left_quant = pMBs[index - 1].quant;                  left_quant = pMBs[index - 1].quant;
121                  //DEBUGI("LEFT", *(left+MBPRED_SIZE));                  //DEBUGI("LEFT", *(left+MBPRED_SIZE));
122          }          }
   
123          // top macroblock          // top macroblock
124    
125          if(y && (pMBs[index - mb_width].mode == MODE_INTRA          if (mbpos >= bound + (int)mb_width &&
126                   || pMBs[index - mb_width].mode == MODE_INTRA_Q)) {                  (pMBs[index - mb_width].mode == MODE_INTRA ||
127                     pMBs[index - mb_width].mode == MODE_INTRA_Q)) {
128    
129                  top = pMBs[index - mb_width].pred_values[0];                  top = pMBs[index - mb_width].pred_values[0];
130                  top_quant = pMBs[index - mb_width].quant;                  top_quant = pMBs[index - mb_width].quant;
131          }          }
   
132          // diag macroblock          // diag macroblock
133    
134          if(x && y && (pMBs[index - 1 - mb_width].mode == MODE_INTRA          if (x && mbpos >= bound + (int)mb_width + 1 &&
135                        || pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {                  (pMBs[index - 1 - mb_width].mode == MODE_INTRA ||
136                     pMBs[index - 1 - mb_width].mode == MODE_INTRA_Q)) {
137    
138                  diag = pMBs[index - 1 - mb_width].pred_values[0];                  diag = pMBs[index - 1 - mb_width].pred_values[0];
139          }          }
# Line 204  Line 213 
213          if(ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])) {          if(ABS(pLeft[0] - pDiag[0]) < ABS(pDiag[0] - pTop[0])) {
214                  *acpred_direction = 1;             // vertical                  *acpred_direction = 1;             // vertical
215                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);                  predictors[0] = DIV_DIV(pTop[0], iDcScaler);
216                  for (i = 1; i < 8; i++)                  for (i = 1; i < 8; i++) {
                 {  
217                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);                          predictors[i] = rescale(top_quant, current_quant, pTop[i]);
218                  }                  }
219          }          } else {
         else  
         {  
220                  *acpred_direction = 2;             // horizontal                  *acpred_direction = 2;             // horizontal
221                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);                  predictors[0] = DIV_DIV(pLeft[0], iDcScaler);
222                  for (i = 1; i < 8; i++)                  for (i = 1; i < 8; i++) {
                 {  
223                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);                          predictors[i] = rescale(left_quant, current_quant, pLeft[i + 7]);
224                  }                  }
225          }          }
# Line 226  Line 231 
231  */  */
232    
233    
234  void add_acdc(MACROBLOCK *pMB,  void
235    add_acdc(MACROBLOCK * pMB,
236                uint32_t block,                uint32_t block,
237                int16_t dct_codes[64],                int16_t dct_codes[64],
238                uint32_t iDcScaler,                uint32_t iDcScaler,
# Line 236  Line 242 
242          int16_t * pCurrent = pMB->pred_values[block];          int16_t * pCurrent = pMB->pred_values[block];
243          uint32_t i;          uint32_t i;
244    
245            DPRINTF(DPRINTF_COEFF,"predictor[0] %i", predictors[0]);
246    
247          dct_codes[0] += predictors[0];  // dc prediction          dct_codes[0] += predictors[0];  // dc prediction
248          pCurrent[0] = dct_codes[0] * iDcScaler;          pCurrent[0] = dct_codes[0] * iDcScaler;
249    
250          if (acpred_direction == 1)          if (acpred_direction == 1) {
251          {                  for (i = 1; i < 8; i++) {
                 for (i = 1; i < 8; i++)  
                 {  
252                          int level = dct_codes[i] + predictors[i];                          int level = dct_codes[i] + predictors[i];
253    
254                            DPRINTF(DPRINTF_COEFF,"predictor[%i] %i",i, predictors[i]);
255    
256                          dct_codes[i] = level;                          dct_codes[i] = level;
257                          pCurrent[i] = level;                          pCurrent[i] = level;
258                          pCurrent[i+7] = dct_codes[i*8];                          pCurrent[i+7] = dct_codes[i*8];
259                  }                  }
260          }          } else if (acpred_direction == 2) {
261          else if (acpred_direction == 2)                  for (i = 1; i < 8; i++) {
         {  
                 for (i = 1; i < 8; i++)  
                 {  
262                          int level = dct_codes[i*8] + predictors[i];                          int level = dct_codes[i*8] + predictors[i];
263                            DPRINTF(DPRINTF_COEFF,"predictor[%i] %i",i*8, predictors[i]);
264    
265                          dct_codes[i*8] = level;                          dct_codes[i*8] = level;
266                          pCurrent[i+7] = level;                          pCurrent[i+7] = level;
267                          pCurrent[i] = dct_codes[i];                          pCurrent[i] = dct_codes[i];
268                  }                  }
269          }          } else {
270          else                  for (i = 1; i < 8; i++) {
         {  
                 for (i = 1; i < 8; i++)  
                 {  
271                          pCurrent[i] = dct_codes[i];                          pCurrent[i] = dct_codes[i];
272                          pCurrent[i+7] = dct_codes[i*8];                          pCurrent[i+7] = dct_codes[i*8];
273                  }                  }
# Line 284  Line 289 
289  S2 = sum of all qcoeff  S2 = sum of all qcoeff
290  */  */
291    
292  uint32_t calc_acdc(MACROBLOCK *pMB,  uint32_t
293    calc_acdc(MACROBLOCK * pMB,
294                     uint32_t block,                     uint32_t block,
295                     int16_t qcoeff[64],                     int16_t qcoeff[64],
296                     uint32_t iDcScaler,                     uint32_t iDcScaler,
# Line 307  Line 313 
313    
314          qcoeff[0] = qcoeff[0] - predictors[0];          qcoeff[0] = qcoeff[0] - predictors[0];
315    
316          if (pMB->acpred_directions[block] == 1)          if (pMB->acpred_directions[block] == 1) {
         {  
317                  for(i = 1; i < 8; i++) {                  for(i = 1; i < 8; i++) {
318                          int16_t level;                          int16_t level;
319    
# Line 318  Line 323 
323                          S1 += ABS(level);                          S1 += ABS(level);
324                          predictors[i] = level;                          predictors[i] = level;
325                  }                  }
326          }          } else                                          // acpred_direction == 2
         else // acpred_direction == 2  
327          {          {
328                  for(i = 1; i < 8; i++) {                  for(i = 1; i < 8; i++) {
329                          int16_t level;                          int16_t level;
# Line 340  Line 344 
344    
345  /* apply predictors[] to qcoeff */  /* apply predictors[] to qcoeff */
346    
347  void apply_acdc(MACROBLOCK *pMB,  void
348    apply_acdc(MACROBLOCK * pMB,
349                  uint32_t block,                  uint32_t block,
350                  int16_t qcoeff[64],                  int16_t qcoeff[64],
351                  int16_t predictors[8])                  int16_t predictors[8])
352  {  {
353          uint32_t i;          uint32_t i;
354    
355          if (pMB->acpred_directions[block] == 1)          if (pMB->acpred_directions[block] == 1) {
356          {                  for (i = 1; i < 8; i++) {
                 for(i = 1; i < 8; i++)  
                 {  
357                          qcoeff[i] = predictors[i];                          qcoeff[i] = predictors[i];
358                  }                  }
359          }          } else {
360          else                  for (i = 1; i < 8; i++) {
         {  
                 for(i = 1; i < 8; i++)  
                 {  
361                          qcoeff[i*8] = predictors[i];                          qcoeff[i*8] = predictors[i];
362                  }                  }
363          }          }
364  }  }
365    
366    
367  void MBPrediction(MBParam *pParam,  void
368    MBPrediction(FRAMEINFO * frame,
369                    uint32_t x,                    uint32_t x,
370                    uint32_t y,                    uint32_t y,
371                    uint32_t mb_width,                    uint32_t mb_width,
372                    int16_t qcoeff[6*64],                           int16_t qcoeff[6 * 64])
                   MACROBLOCK *mbs)  
373  {  {
374    
375          int32_t j;          int32_t j;
376          int32_t iDcScaler, iQuant = pParam->quant;          int32_t iDcScaler, iQuant = frame->quant;
377          int32_t S = 0;          int32_t S = 0;
378          int16_t predictors[6][8];          int16_t predictors[6][8];
379    
380          MACROBLOCK *pMB = &mbs[x + y * mb_width];          MACROBLOCK *pMB = &frame->mbs[x + y * mb_width];
381    
382          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {          if ((pMB->mode == MODE_INTRA) || (pMB->mode == MODE_INTRA_Q)) {
383    
384                  for(j = 0; j < 6; j++)                  for (j = 0; j < 6; j++) {
                 {  
385                          iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);                          iDcScaler = get_dc_scaler(iQuant, (j < 4) ? 1 : 0);
386    
387                          predict_acdc(mbs,                          predict_acdc(frame->mbs, x, y, mb_width, j, &qcoeff[j * 64],
388                                       x,                                                   iQuant, iDcScaler, predictors[j], 0);
389                                       y,  
390                                       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]);  
391    
392                  }                  }
393    
394                  if (S < 0)              // dont predict                  if (S < 0)              // dont predict
395                  {                  {
396                          for(j = 0; j < 6; j++)                          for (j = 0; j < 6; j++) {
                         {  
397                                  pMB->acpred_directions[j] = 0;                                  pMB->acpred_directions[j] = 0;
398                          }                          }
399                  }                  } else {
400                  else                          for (j = 0; j < 6; j++) {
                 {  
                         for(j = 0; j < 6; j++)  
                         {  
401                                  apply_acdc(pMB, j, &qcoeff[j*64], predictors[j]);                                  apply_acdc(pMB, j, &qcoeff[j*64], predictors[j]);
402                          }                          }
403                  }                  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.7.2.1

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