[svn] / trunk / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /trunk/xvidcore/src/bitstream/mbcoding.c

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

revision 133, Tue Apr 23 00:05:31 2002 UTC revision 153, Thu May 2 00:36:50 2002 UTC
# Line 29  Line 29 
29    
30   /******************************************************************************   /******************************************************************************
31    *                                                                            *    *                                                                            *
32    *  bitstream.c                                                               *    *  mbcoding.c                                                                *
33    *                                                                            *    *                                                                            *
34    *  Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au>                    *    *  Copyright (C) 2002 - Michael Militzer <isibaar@xvid.org>                  *
35    *                                                                            *    *                                                                            *
36    *  For more information visit the XviD homepage: http://www.xvid.org         *    *  For more information visit the XviD homepage: http://www.xvid.org         *
37    *                                                                            *    *                                                                            *
# Line 41  Line 41 
41    *                                                                                                                                                        *    *                                                                                                                                                        *
42    *  Revision history:                                                         *    *  Revision history:                                                         *
43    *                                                                            *    *                                                                            *
44    *  14.04.2002 bframe encoding    *  14.04.2002 bframe encoding                                                                                            *
45    *  08.03.2002 initial version; isibaar                                                           *    *  08.03.2002 initial version; isibaar                                                           *
46    *                                                                                                                                                        *    *                                                                                                                                                        *
47    ******************************************************************************/    ******************************************************************************/
# Line 60  Line 60 
60  #define ABS(X) (((X)>0)?(X):-(X))  #define ABS(X) (((X)>0)?(X):-(X))
61  #define CLIP(X,A) (X > A) ? (A) : (X)  #define CLIP(X,A) (X > A) ? (A) : (X)
62    
63  VLC intra_table[65536];  VLC intra_table[524032];
64  VLC inter_table[65536];  VLC inter_table[524032];
65    
66  VLC DCT3Dintra[4096];  VLC DCT3Dintra[4096];
67  VLC DCT3Dinter[4096];  VLC DCT3Dinter[4096];
68    
 static int16_t clip_table[4096];  
   
69  void init_vlc_tables(void)  void init_vlc_tables(void)
70  {  {
71    
# Line 82  Line 80 
80          vlc[0] = intra_table;          vlc[0] = intra_table;
81          vlc[1] = inter_table;          vlc[1] = inter_table;
82    
         // initialize the clipping table  
         for(i = -2048; i < 2048; i++) {  
                 clip_table[i + 2048] = i;  
                 if(i < -255)  
                         clip_table[i + 2048] = -255;  
                 if(i > 255)  
                         clip_table[i + 2048] = 255;  
         }  
   
83          // generate encoding vlc lookup tables          // generate encoding vlc lookup tables
84            // the lookup table idea is taken from the excellent fame project by Vivien Chapellier
85          for(i = 0; i < 4; i++) {          for(i = 0; i < 4; i++) {
86                  intra = i % 2;                  intra = i % 2;
87                  last = i / 2;                  last = i / 2;
88    
89                  coeff_ptr = coeff_vlc[last + 2 * intra];                  coeff_ptr = coeff_vlc[last + 2 * intra];
90    
91                  for(k = -255; k < 256; k++) { // level                  for(k = -2047; k < 2048; k++) { // level
92                          int8_t *max_level_ptr = max_level[last + 2 * intra];                          int8_t *max_level_ptr = max_level[last + 2 * intra];
93                          int8_t *max_run_ptr = max_run[last + 2 * intra];                          int8_t *max_run_ptr = max_run[last + 2 * intra];
94    
# Line 193  Line 183 
183  }  }
184    
185  static __inline void CodeVector(Bitstream *bs,  static __inline void CodeVector(Bitstream *bs,
186                                  int16_t value,                                  int32_t value,
187                                  int16_t f_code,                                  int32_t f_code,
188                                  Statistics *pStat)                                  Statistics *pStat)
189  {  {
190    
# Line 246  Line 236 
236    
237    
238  static __inline void CodeCoeff(Bitstream *bs,  static __inline void CodeCoeff(Bitstream *bs,
239                                 int16_t qcoeff[64],                                 const int16_t qcoeff[64],
240                                 VLC *table,                                 VLC *table,
241                                 const uint16_t *zigzag,                                 const uint16_t *zigzag,
242                                 uint16_t intra)                                 uint16_t intra)
# Line 259  Line 249 
249          j = intra;          j = intra;
250          last = intra;          last = intra;
251    
252          while((v = qcoeff[zigzag[j]]) == 0) j++;          while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;
253    
254          do {          do {
255                  // count zeroes                  vlc = table + 64 * 2047 + (v << 6) + j - last;
                 vlc = table + 64*255 + (clip_table[2048+v] << 6) + j - last;  
256                  last = ++j;                  last = ++j;
257    
258                    // count zeroes
259                  while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;                  while(j < 64 && (v = qcoeff[zigzag[j]]) == 0) j++;
260    
261                  // write code                  // write code
262                  if(j != 64) {                  if(j != 64) {
263                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
264                  } else {                  } else {
265                          vlc += 64*511;                          vlc += 64 * 4095;
266                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
267                          break;                          break;
268                  }                  }
# Line 280  Line 271 
271  }  }
272    
273    
274  static void CodeBlockIntra(const MBParam * pParam,  static void CodeBlockIntra(const FRAMEINFO * frame,
275                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
276                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
277                             Bitstream * bs,                             Bitstream * bs,
# Line 292  Line 283 
283          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
284    
285          // write mcbpc          // write mcbpc
286          if(pParam->coding_type == I_VOP) {          if(frame->coding_type == I_VOP) {
287                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
288                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len);                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len);
289          }          }
# Line 315  Line 306 
306                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
307    
308          // write interlacing          // write interlacing
309          if (pParam->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING)
310          {          {
311                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
312          }          }
# Line 350  Line 341 
341  }  }
342    
343    
344  static void CodeBlockInter(const MBParam * pParam,  static void CodeBlockInter(const FRAMEINFO * frame,
345                             const MACROBLOCK *pMB,                             const MACROBLOCK *pMB,
346                             int16_t qcoeff[6*64],                             int16_t qcoeff[6*64],
347                             Bitstream * bs,                             Bitstream * bs,
# Line 374  Line 365 
365                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
366    
367          // interlacing          // interlacing
368          if (pParam->global_flags & XVID_INTERLACING)          if (frame->global_flags & XVID_INTERLACING)
369          {          {
370                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
371                  DEBUG1("codep: field_dct: ", pMB->field_dct);                  DEBUG1("codep: field_dct: ", pMB->field_dct);
# Line 397  Line 388 
388          // code motion vector(s)          // code motion vector(s)
389          for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++)          for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++)
390          {          {
391                  CodeVector(bs, pMB->pmvs[i].x, pParam->fixed_code, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
392                  CodeVector(bs, pMB->pmvs[i].y, pParam->fixed_code, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
393          }          }
394    
395          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
# Line 414  Line 405 
405  }  }
406    
407    
408  void MBCoding(const MBParam * pParam,  void MBCoding(const FRAMEINFO * frame,
409                MACROBLOCK *pMB,                MACROBLOCK *pMB,
410                int16_t qcoeff[6*64],                int16_t qcoeff[6*64],
411                Bitstream * bs,                Bitstream * bs,
# Line 423  Line 414 
414    
415          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);          int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);
416    
417          if(pParam->coding_type == P_VOP) {          if(frame->coding_type == P_VOP) {
418                  if(pMB->cbp == 0 && pMB->mode == MODE_INTER &&                  if(pMB->cbp == 0 && pMB->mode == MODE_INTER &&
419                     pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)                     pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)
420                  {                  {
# Line 435  Line 426 
426          }          }
427    
428          if(intra)          if(intra)
429                  CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
430          else          else
431                  CodeBlockInter(pParam, pMB, qcoeff, bs, pStat);                  CodeBlockInter(frame, pMB, qcoeff, bs, pStat);
432    
433  }  }
434    
# Line 511  Line 502 
502    
503  void MBCodingBVOP(const MACROBLOCK * mb,  void MBCodingBVOP(const MACROBLOCK * mb,
504                                    const int16_t qcoeff[6*64],                                    const int16_t qcoeff[6*64],
505                                    const int16_t fcode,                                    const int32_t fcode,
506                                    const int16_t bcode,                                    const int32_t bcode,
507                                    Bitstream * bs,                                    Bitstream * bs,
508                                    Statistics * pStat)                                    Statistics * pStat)
509  {  {

Legend:
Removed from v.133  
changed lines
  Added in v.153

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