[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 655, Sun Nov 17 00:57:58 2002 UTC revision 816, Thu Feb 6 00:48:08 2003 UTC
# Line 50  Line 50 
50   *  exception also makes it possible to release a modified version which   *  exception also makes it possible to release a modified version which
51   *  carries forward this exception.   *  carries forward this exception.
52   *   *
53   * $Id: mbcoding.c,v 1.33 2002-11-17 00:57:57 edgomez Exp $   * $Id: mbcoding.c,v 1.40 2003-02-06 00:48:08 edgomez Exp $
54   *   *
55   ****************************************************************************/   ****************************************************************************/
56    
# Line 66  Line 66 
66  #define ABS(X) (((X)>0)?(X):-(X))  #define ABS(X) (((X)>0)?(X):-(X))
67  #define CLIP(X,A) (X > A) ? (A) : (X)  #define CLIP(X,A) (X > A) ? (A) : (X)
68    
69    /* #define BIGLUT */
70    
71    #ifdef BIGLUT
72    #define LEVELOFFSET 2048
73    #else
74    #define LEVELOFFSET 32
75    #endif
76    
77  /*****************************************************************************  /*****************************************************************************
78   * Local data   * Local data
79   ****************************************************************************/   ****************************************************************************/
80    
81  /* msvc sp5+pp gets confused if they globals are made static */  static REVERSE_EVENT DCT3D[2][4096];
 VLC intra_table[524032];  
 VLC inter_table[524032];  
82    
83  static VLC DCT3Dintra[4096];  #ifdef BIGLUT
84  static VLC DCT3Dinter[4096];  static VLC coeff_VLC[2][2][4096][64];
85    static VLC *intra_table, *inter_table;
86    #else
87    static VLC coeff_VLC[2][2][64][64];
88    #endif
89    
90  /*****************************************************************************  /*****************************************************************************
91   * Vector Length Coding Initialization   * Vector Length Coding Initialization
# Line 84  Line 94 
94  void  void
95  init_vlc_tables(void)  init_vlc_tables(void)
96  {  {
97            uint32_t i, j, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
98    
99          int32_t k, l, i, intra, last;  #ifdef BIGLUT
100          VLC *vlc[2];          intra_table = (VLC*)coeff_VLC[1];
101          VLC const **coeff_ptr;          inter_table = (VLC*)coeff_VLC[0];
102          VLC *vlc1, *vlc2;  #endif
   
         vlc1 = DCT3Dintra;  
         vlc2 = DCT3Dinter;  
   
         vlc[0] = intra_table;  
         vlc[1] = inter_table;  
   
         /*  
          * Generate encoding vlc lookup tables  
          * the lookup table idea is taken from the excellent fame project  
          * by Vivien Chapellier  
          */  
         for (i = 0; i < 4; i++) {  
                 intra = i % 2;  
                 last = i / 2;  
   
                 coeff_ptr = coeff_vlc[last + 2 * intra];  
   
                 for (k = -2047; k < 2048; k++) {        // level  
                         int8_t const *max_level_ptr = max_level[last + 2 * intra];  
                         int8_t const *max_run_ptr = max_run[last + 2 * intra];  
103    
                         for (l = 0; l < 64; l++) {      // run  
                                 int32_t level = k;  
                                 ptr_t run = l;  
104    
105                                  if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run          for (intra = 0; intra < 2; intra++)
106                    for (i = 0; i < 4096; i++)
107                            DCT3D[intra][i].event.level = 0;
108    
109                                          vlc[intra]->code = 0;          for (intra = 0; intra < 2; intra++)
110                                          vlc[intra]->len = 0;                  for (last = 0; last < 2; last++)
111                                          goto loop_end;                  {
112                                  } else {                          for (run = 0; run < 63 + last; run++)
113                                          if (level > 0)  // correct level                                  for (level = 0; level < 32 << intra; level++)
114                                                  level -= max_level_ptr[run];                                  {
115                                          else  #ifdef BIGLUT
116                                                  level += max_level_ptr[run];                                          offset = LEVELOFFSET;
117    #else
118                                          if ((abs(level) <= max_level_ptr[run]) &&                                          offset = !intra * LEVELOFFSET;
119                                                  (run <= (uint32_t) max_run_ptr[abs(level)])) {  #endif
120                                            coeff_VLC[intra][last][level + offset][run].len = 128;
121                                                  vlc[intra]->code = 0x06;                                  }
                                                 vlc[intra]->len = 8;  
                                                 goto loop_end;  
122                                          }                                          }
123    
124                                          if (level > 0)  // still here?          for (intra = 0; intra < 2; intra++)
125                                                  level += max_level_ptr[run];    // restore level                  for (i = 0; i < 102; i++)
126                                          else                  {
127                                                  level -= max_level_ptr[run];  #ifdef BIGLUT
128                            offset = LEVELOFFSET;
129                                          run -= max_run_ptr[abs(level)] + 1;     // and change run  #else
130                            offset = !intra * LEVELOFFSET;
131                                          if ((abs(level) <= max_level_ptr[run]) &&  #endif
132                                                  (run <= (uint32_t) max_run_ptr[abs(level)])) {                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++)
133                            {
134                                    DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
135                                    DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
136                            }
137    
138                                                  vlc[intra]->code = 0x0e;                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code
139                                                  vlc[intra]->len = 9;                                  = coeff_tab[intra][i].vlc.code << 1;
140                                                  goto loop_end;                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
141                                    = coeff_tab[intra][i].vlc.len + 1;
142    #ifndef BIGLUT
143                            if (!intra)
144    #endif
145                            {
146                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
147                                            = (coeff_tab[intra][i].vlc.code << 1) | 1;
148                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
149                                            = coeff_tab[intra][i].vlc.len + 1;
150                                          }                                          }
                                         run += max_run_ptr[abs(level)] + 1;  
151                                  }                                  }
152    
153                                  vlc[intra]->code =          for (intra = 0; intra < 2; intra++)
154                                          (uint32_t) ((l << 14) | (0x1e + last) << 20) | (1 << 13) |                  for (last = 0; last < 2; last++)
155                                          ((k & 0xfff) << 1) | 1;                          for (run = 0; run < 63 + last; run++)
156                            {
157                                  vlc[intra]->len = 30;                                  for (level = 1; level < (uint32_t)(32 << intra); level++)
158                                  vlc[intra]++;                                  {
159                                            if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
160                                  continue;                                  continue;
161    
162                            loop_end:  #ifdef BIGLUT
163                                  if (level != 0) {                                          offset = LEVELOFFSET;
164                                          vlc[intra]->code =  #else
165                                                  (vlc[intra]->                                          offset = !intra * LEVELOFFSET;
166                                                   code << (coeff_ptr[run][abs(level) - 1].len +  #endif
167                                                                    1)) | (coeff_ptr[run][abs(level) -                      level_esc = level - max_level[intra][last][run];
168                                                                                                                  1].code << 1);                                          run_esc = run - 1 - max_run[intra][last][level];
169                                          vlc[intra]->len =  
170                                                  (coeff_ptr[run][abs(level) - 1].len + 1) +                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])
171                                                  vlc[intra]->len;                                          {
172                                                    escape     = ESCAPE1;
173                                          if (level < 0)                                                  escape_len = 7 + 1;
174                                                  vlc[intra]->code += 1;                                                  run_esc    = run;
                                 }  
   
                                 vlc[intra]++;  
175                          }                          }
176                                            else
177                                            {
178                                                    if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])
179                                                    {
180                                                            escape     = ESCAPE2;
181                                                            escape_len = 7 + 2;
182                                                            level_esc  = level;
183                                                    }
184                                                    else
185                                                    {
186    #ifndef BIGLUT
187                                                            if (!intra)
188    #endif
189                                                            {
190                                                                    coeff_VLC[intra][last][level + offset][run].code
191                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
192                                                                    coeff_VLC[intra][last][level + offset][run].len = 30;
193                                                                            coeff_VLC[intra][last][offset - level][run].code
194                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;
195                                                                    coeff_VLC[intra][last][offset - level][run].len = 30;
196                  }                  }
197                                                            continue;
198          }          }
   
         for (i = 0; i < 4096; i++) {  
                 if (i >= 512) {  
                         *vlc1 = DCT3Dtab3[(i >> 5) - 16];  
                         *vlc2 = DCT3Dtab0[(i >> 5) - 16];  
                 } else if (i >= 128) {  
                         *vlc1 = DCT3Dtab4[(i >> 2) - 32];  
                         *vlc2 = DCT3Dtab1[(i >> 2) - 32];  
                 } else if (i >= 8) {  
                         *vlc1 = DCT3Dtab5[i - 8];  
                         *vlc2 = DCT3Dtab2[i - 8];  
                 } else {  
                         *vlc1 = ERRtab[i];  
                         *vlc2 = ERRtab[i];  
199                  }                  }
200    
201                  vlc1++;                                          coeff_VLC[intra][last][level + offset][run].code
202                  vlc2++;                                                  = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
203                                                    |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
204                                            coeff_VLC[intra][last][level + offset][run].len
205                                                    = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
206    #ifndef BIGLUT
207                                            if (!intra)
208    #endif
209                                            {
210                                                    coeff_VLC[intra][last][offset - level][run].code
211                                                            = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
212                                                            |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
213                                                    coeff_VLC[intra][last][offset - level][run].len
214                                                            = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
215                                            }
216          }          }
         DCT3D[0] = DCT3Dinter;  
         DCT3D[1] = DCT3Dintra;  
217    
218    #ifdef BIGLUT
219                                    for (level = (uint32_t)(32 << intra); level < 2048; level++)
220                                    {
221                                            coeff_VLC[intra][last][level + offset][run].code
222                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
223                                            coeff_VLC[intra][last][level + offset][run].len = 30;
224    
225                                            coeff_VLC[intra][last][offset - level][run].code
226                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;
227                                            coeff_VLC[intra][last][offset - level][run].len = 30;
228                                    }
229    #else
230                                    if (!intra)
231                                    {
232                                            coeff_VLC[intra][last][0][run].code
233                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
234                                            coeff_VLC[intra][last][0][run].len = 30;
235                                    }
236    #endif
237                            }
238  }  }
239    
240  /*****************************************************************************  /*****************************************************************************
# Line 261  Line 296 
296    
297  }  }
298    
299    #ifdef BIGLUT
300    
301  static __inline void  static __inline void
302  CodeCoeff(Bitstream * bs,  CodeCoeff(Bitstream * bs,
303                    const int16_t qcoeff[64],                    const int16_t qcoeff[64],
# Line 280  Line 317 
317                  j++;                  j++;
318    
319          do {          do {
320                  vlc = table + 64 * 2047 + (v << 6) + j - last;                  vlc = table + 64 * 2048 + (v << 6) + j - last;
321                  last = ++j;                  last = ++j;
322    
323                  // count zeroes                  /* count zeroes */
324                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
325                          j++;                          j++;
326    
327                  // write code                  /* write code */
328                  if (j != 64) {                  if (j != 64) {
329                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
330                  } else {                  } else {
331                          vlc += 64 * 4095;                          vlc += 64 * 4096;
332                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
333                          break;                          break;
334                  }                  }
# Line 299  Line 336 
336    
337  }  }
338    
339    #else
340    
341    static __inline void
342    CodeCoeffInter(Bitstream * bs,
343                      const int16_t qcoeff[64],
344                      const uint16_t * zigzag)
345    {
346            uint32_t i, run, prev_run, code, len;
347            int32_t level, prev_level, level_shifted;
348    
349            i       = 0;
350            run = 0;
351    
352            while (!(level = qcoeff[zigzag[i++]]))
353                    run++;
354    
355            prev_level = level;
356            prev_run   = run;
357            run = 0;
358    
359            while (i < 64)
360            {
361                    if ((level = qcoeff[zigzag[i++]]) != 0)
362                    {
363                            level_shifted = prev_level + 32;
364                            if (!(level_shifted & -64))
365                            {
366                                    code = coeff_VLC[0][0][level_shifted][prev_run].code;
367                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
368                            }
369                            else
370                            {
371                                    code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
372                                    len  = 30;
373                            }
374                            BitstreamPutBits(bs, code, len);
375                            prev_level = level;
376                            prev_run   = run;
377                            run = 0;
378                    }
379                    else
380                            run++;
381            }
382    
383            level_shifted = prev_level + 32;
384            if (!(level_shifted & -64))
385            {
386                    code = coeff_VLC[0][1][level_shifted][prev_run].code;
387                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
388            }
389            else
390            {
391                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
392                    len  = 30;
393            }
394            BitstreamPutBits(bs, code, len);
395    }
396    
397    static __inline void
398    CodeCoeffIntra(Bitstream * bs,
399                      const int16_t qcoeff[64],
400                      const uint16_t * zigzag)
401    {
402            uint32_t i, abs_level, run, prev_run, code, len;
403            int32_t level, prev_level;
404    
405            i       = 1;
406            run = 0;
407    
408            while (!(level = qcoeff[zigzag[i++]]))
409                    run++;
410    
411            prev_level = level;
412            prev_run   = run;
413            run = 0;
414    
415            while (i < 64)
416            {
417                    if ((level = qcoeff[zigzag[i++]]) != 0)
418                    {
419                            abs_level = ABS(prev_level);
420                            abs_level = abs_level < 64 ? abs_level : 0;
421                            code      = coeff_VLC[1][0][abs_level][prev_run].code;
422                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
423                            if (len != 128)
424                                    code |= (prev_level < 0);
425                            else
426                            {
427                            code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
428                                    len  = 30;
429                            }
430                            BitstreamPutBits(bs, code, len);
431                            prev_level = level;
432                            prev_run   = run;
433                            run = 0;
434                    }
435                    else
436                            run++;
437            }
438    
439            abs_level = ABS(prev_level);
440            abs_level = abs_level < 64 ? abs_level : 0;
441            code      = coeff_VLC[1][1][abs_level][prev_run].code;
442            len               = coeff_VLC[1][1][abs_level][prev_run].len;
443            if (len != 128)
444                    code |= (prev_level < 0);
445            else
446            {
447                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
448                    len  = 30;
449            }
450            BitstreamPutBits(bs, code, len);
451    }
452    
453    #endif
454    
455  /*****************************************************************************  /*****************************************************************************
456   * Local functions   * Local functions
457   ****************************************************************************/   ****************************************************************************/
# Line 315  Line 468 
468    
469          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
470    
471          // write mcbpc          /* write mcbpc */
472          if (frame->coding_type == I_VOP) {          if (frame->coding_type == I_VOP) {
473                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
474                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
# Line 326  Line 479 
479                                                   mcbpc_inter_tab[mcbpc].len);                                                   mcbpc_inter_tab[mcbpc].len);
480          }          }
481    
482          // ac prediction flag          /* ac prediction flag */
483          if (pMB->acpred_directions[0])          if (pMB->acpred_directions[0])
484                  BitstreamPutBits(bs, 1, 1);                  BitstreamPutBits(bs, 1, 1);
485          else          else
486                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
487    
488          // write cbpy          /* write cbpy */
489          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
490    
491          // write dquant          /* write dquant */
492          if (pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA_Q)
493                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
494    
495          // write interlacing          /* write interlacing */
496          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
497                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
498          }          }
499          // code block coeffs          /* code block coeffs */
500          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
501                  if (i < 4)                  if (i < 4)
502                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
# Line 355  Line 508 
508                  if (pMB->cbp & (1 << (5 - i))) {                  if (pMB->cbp & (1 << (5 - i))) {
509                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
510    
511    #ifdef BIGLUT
512                          CodeCoeff(bs, &qcoeff[i * 64], intra_table,                          CodeCoeff(bs, &qcoeff[i * 64], intra_table,
513                                            scan_tables[pMB->acpred_directions[i]], 1);                                            scan_tables[pMB->acpred_directions[i]], 1);
514    #else
515                            CodeCoeffIntra(bs, &qcoeff[i * 64], scan_tables[pMB->acpred_directions[i]]);
516    #endif
517                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
518                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
519                  }                  }
# Line 380  Line 536 
536          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
537          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
538    
539          // write mcbpc          /* write mcbpc */
540          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
541                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
542    
543          // write cbpy          /* write cbpy */
544          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
545    
546          // write dquant          /* write dquant */
547          if (pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER_Q)
548                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, pMB->dquant, 2);
549    
550          // interlacing          /* interlacing */
551          if (frame->global_flags & XVID_INTERLACING) {          if (frame->global_flags & XVID_INTERLACING) {
552                  if (pMB->cbp) {                  if (pMB->cbp) {
553                          BitstreamPutBit(bs, pMB->field_dct);                          BitstreamPutBit(bs, pMB->field_dct);
554                          DPRINTF(DPRINTF_DEBUG, "codep: field_dct: %d", pMB->field_dct);                          DPRINTF(DPRINTF_DEBUG, "codep: field_dct: %d", pMB->field_dct);
555                  }                  }
556    
557                  // if inter block, write field ME flag                  /* if inter block, write field ME flag */
558                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
559                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, pMB->field_pred);
560                          DPRINTF(DPRINTF_DEBUG, "codep: field_pred: %d", pMB->field_pred);                          DPRINTF(DPRINTF_DEBUG, "codep: field_pred: %d", pMB->field_pred);
561    
562                          // write field prediction references                          /* write field prediction references */
563                          if (pMB->field_pred) {                          if (pMB->field_pred) {
564                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
565                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
566                          }                          }
567                  }                  }
568          }          }
569          // code motion vector(s)          /* code motion vector(s) */
570          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
571                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
572                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
# Line 418  Line 574 
574    
575          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
576    
577          // code block coeffs          /* code block coeffs */
578          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
579                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i)))
580    #ifdef BIGLUT
581                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);
582    #else
583                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);
584    #endif
585    
586          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
587          pStat->iTextBits += bits;          pStat->iTextBits += bits;
# Line 441  Line 601 
601  {  {
602    
603          if (frame->coding_type == P_VOP) {          if (frame->coding_type == P_VOP) {
604                          BitstreamPutBit(bs, 0); // coded                          BitstreamPutBit(bs, 0); /* coded */
605          }          }
606    
607          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
# Line 455  Line 615 
615  void  void
616  MBSkip(Bitstream * bs)  MBSkip(Bitstream * bs)
617  {  {
618          BitstreamPutBit(bs, 1); // not coded          BitstreamPutBit(bs, 1); /* not coded */
619          return;          return;
620  }  }
621    
# Line 659  Line 819 
819  {  {
820    
821          uint32_t mode;          uint32_t mode;
         const VLC *tab;  
822          int32_t level;          int32_t level;
823            REVERSE_EVENT *reverse_event;
824    
825          if (short_video_header)         // inter-VLCs will be used for both intra and inter blocks          if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */
826                  intra = 0;                  intra = 0;
827    
828          tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];          if (BitstreamShowBits(bs, 7) != ESCAPE) {
829                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
830    
831          if (tab->code == -1)                  if ((level = reverse_event->event.level) == 0)
832                  goto error;                  goto error;
833    
834          BitstreamSkip(bs, tab->len);                  *last = reverse_event->event.last;
835                    *run  = reverse_event->event.run;
836    
837          if (tab->code != ESCAPE) {                  BitstreamSkip(bs, reverse_event->len);
838                  if (!intra) {  
839                          *run = (tab->code >> 4) & 255;                  return BitstreamGetBits(bs, 1) ? -level : level;
                         level = tab->code & 15;  
                         *last = (tab->code >> 12) & 1;  
                 } else {  
                         *run = (tab->code >> 8) & 255;  
                         level = tab->code & 255;  
                         *last = (tab->code >> 16) & 1;  
                 }  
                 return BitstreamGetBit(bs) ? -level : level;  
840          }          }
841    
842            BitstreamSkip(bs, 7);
843    
844          if (short_video_header) {          if (short_video_header) {
845                  // escape mode 4 - H.263 type, only used if short_video_header = 1                  /* escape mode 4 - H.263 type, only used if short_video_header = 1  */
846                  *last = BitstreamGetBit(bs);                  *last = BitstreamGetBit(bs);
847                  *run = BitstreamGetBits(bs, 6);                  *run = BitstreamGetBits(bs, 6);
848                  level = BitstreamGetBits(bs, 8);                  level = BitstreamGetBits(bs, 8);
# Line 694  Line 850 
850                  if (level == 0 || level == 128)                  if (level == 0 || level == 128)
851                          DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level);                          DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level);
852    
853                  return (level >= 128 ? -(256 - level) : level);                  return (level << 24) >> 24;
854          }          }
855    
856          mode = BitstreamShowBits(bs, 2);          mode = BitstreamShowBits(bs, 2);
# Line 702  Line 858 
858          if (mode < 3) {          if (mode < 3) {
859                  BitstreamSkip(bs, (mode == 2) ? 2 : 1);                  BitstreamSkip(bs, (mode == 2) ? 2 : 1);
860    
861                  tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];                  reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
862                  if (tab->code == -1)  
863                    if ((level = reverse_event->event.level) == 0)
864                          goto error;                          goto error;
865    
866                  BitstreamSkip(bs, tab->len);                  *last = reverse_event->event.last;
867                    *run  = reverse_event->event.run;
868    
869                  if (!intra) {                  BitstreamSkip(bs, reverse_event->len);
                         *run = (tab->code >> 4) & 255;  
                         level = tab->code & 15;  
                         *last = (tab->code >> 12) & 1;  
                 } else {  
                         *run = (tab->code >> 8) & 255;  
                         level = tab->code & 255;  
                         *last = (tab->code >> 16) & 1;  
                 }  
870    
871                  if (mode < 2)                   // first escape mode, level is offset                  if (mode < 2)                   /* first escape mode, level is offset */
872                          level += max_level[*last + (!intra << 1)][*run];        // need to add back the max level                          level += max_level[intra][*last][*run];
873                  else if (mode == 2)             // second escape mode, run is offset                  else                                    /* second escape mode, run is offset */
874                          *run += max_run[*last + (!intra << 1)][level] + 1;                          *run += max_run[intra][*last][level] + 1;
875    
876                  return BitstreamGetBit(bs) ? -level : level;                  return BitstreamGetBits(bs, 1) ? -level : level;
877          }          }
878          // third escape mode - fixed length codes  
879            /* third escape mode - fixed length codes */
880          BitstreamSkip(bs, 2);          BitstreamSkip(bs, 2);
881          *last = BitstreamGetBits(bs, 1);          *last = BitstreamGetBits(bs, 1);
882          *run = BitstreamGetBits(bs, 6);          *run = BitstreamGetBits(bs, 6);
883          BitstreamSkip(bs, 1);           // marker          BitstreamSkip(bs, 1);           /* marker */
884          level = BitstreamGetBits(bs, 12);          level = BitstreamGetBits(bs, 12);
885          BitstreamSkip(bs, 1);           // marker          BitstreamSkip(bs, 1);           /* marker */
886    
887          return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;          return (level << 20) >> 20;
888    
889    error:    error:
890          *run = VLC_ERROR;          *run = VLC_ERROR;
891          return 0;          return 0;
   
892  }  }
893    
894  /*****************************************************************************  /*****************************************************************************
# Line 767  Line 917 
917                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
918    
919                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);
920                  //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));                  /*DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); */
921    
922                  if (level < -127 || level > 127) {                  if (level < -2047 || level > 2047) {
923                          DPRINTF(DPRINTF_DEBUG, "warning: intra_overflow: %d", level);                          DPRINTF(DPRINTF_DEBUG, "warning: intra_overflow: %d", level);
924                  }                  }
925                  coeff++;                  coeff++;
# Line 801  Line 951 
951    
952                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);
953    
954                  if (level < -127 || level > 127) {                  if (level < -2047 || level > 2047) {
955                          DPRINTF(DPRINTF_DEBUG, "warning: inter_overflow: %d", level);                          DPRINTF(DPRINTF_DEBUG, "warning: inter_overflow: %d", level);
956                  }                  }
957                  p++;                  p++;

Legend:
Removed from v.655  
changed lines
  Added in v.816

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