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

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

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

revision 1.25.2.11, Thu Jan 16 21:16:04 2003 UTC revision 1.42, Sat Feb 15 15:22:18 2003 UTC
# Line 72  Line 72 
72    
73  #ifdef BIGLUT  #ifdef BIGLUT
74  static VLC coeff_VLC[2][2][4096][64];  static VLC coeff_VLC[2][2][4096][64];
75  static VLC *intra_table, *inter_table;  VLC *intra_table;
76    static VLC *inter_table;
77  #else  #else
78  static VLC coeff_VLC[2][2][64][64];  static VLC coeff_VLC[2][2][64][64];
79  #endif  #endif
# Line 109  Line 110 
110  void  void
111  init_vlc_tables(void)  init_vlc_tables(void)
112  {  {
113          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset, limit;          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
114          int32_t l;          int32_t l;
115    
116  #ifdef BIGLUT  #ifdef BIGLUT
# Line 126  Line 127 
127                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++)
128                  {                  {
129                          for (run = 0; run < 63 + last; run++)                          for (run = 0; run < 63 + last; run++)
130                                  for (level = 0; level < 32 << intra; level++)                                  for (level = 0; level < (uint32_t)(32 << intra); level++)
131                                  {                                  {
132  #ifdef BIGLUT  #ifdef BIGLUT
133                                          offset = LEVELOFFSET;                                          offset = LEVELOFFSET;
# Line 145  Line 146 
146  #else  #else
147                          offset = !intra * LEVELOFFSET;                          offset = !intra * LEVELOFFSET;
148  #endif  #endif
149                          for (j = 0; j < 1 << (12 - coeff_tab[intra][i].vlc.len); j++)                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++)
150                          {                          {
151                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
152                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
# Line 170  Line 171 
171                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++)
172                          for (run = 0; run < 63 + last; run++)                          for (run = 0; run < 63 + last; run++)
173                          {                          {
174                                  for (level = 1; level < 32 << intra; level++)                                  for (level = 1; level < (uint32_t)(32 << intra); level++)
175                                  {                                  {
176                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
177                                              continue;                                              continue;
# Line 195  Line 196 
196                                          }                                          }
197                                          else                                          else
198                                          {                                          {
199                                                  if (level <= max_level[intra][last][run_esc] && run_esc <= max_run[intra][last][level])                                                  if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])
200                                                  {                                                  {
201                                                          escape     = ESCAPE2;                                                          escape     = ESCAPE2;
202                                                          escape_len = 7 + 2;                                                          escape_len = 7 + 2;
# Line 266  Line 267 
267    
268                  for (l=-(2*limit-1); l <= -limit; l++)                  for (l=-(2*limit-1); l <= -limit; l++)
269                  {                  {
270                          sprite_trajectory_code[i+16384].code = (2*limit-1)+l;                          sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
271                          sprite_trajectory_code[i+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
272                  }                  }
273    
274                  for (l=limit; l<= 2*limit-1; l++)                  for (l=limit; l<= 2*limit-1; l++)
275                  {                  {
276                          sprite_trajectory_code[i+16384].code = l;                          sprite_trajectory_code[l+16384].code = l;
277                          sprite_trajectory_code[i+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
278                  }                  }
279          }          }
280  }  }
# Line 373  Line 374 
374    
375  }  }
376    
377    
378    
379    /* returns the number of bits required to encode qcoeff */
380    int
381    CodeCoeff_CalcBits(const int16_t qcoeff[64],
382                      VLC * table,
383                      const uint16_t * zigzag,
384                      uint16_t intra)
385    {
386            int bits = 0;
387            uint32_t j, last;
388            short v;
389            VLC *vlc;
390    
391            j = intra;
392            last = intra;
393    
394            while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
395                    j++;
396    
397            if (j >= 64) return 0;  /* empty block */
398    
399            do {
400                    vlc = table + 64 * 2048 + (v << 6) + j - last;
401                    last = ++j;
402    
403                    /* count zeroes */
404                    while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
405                            j++;
406    
407                    /* write code */
408                    if (j != 64) {
409                            bits += vlc->len;
410                    } else {
411                            vlc += 64 * 4096;
412                            bits += vlc->len;
413                            break;
414                    }
415            } while (1);
416    
417            return bits;
418    }
419    
420    
421  #else  #else
422    
423  static __inline void  static __inline void
# Line 442  Line 487 
487          i       = 1;          i       = 1;
488          run = 0;          run = 0;
489    
490          while (!(level = qcoeff[zigzag[i++]]))          while (i<64 && !(level = qcoeff[zigzag[i++]]))
491                  run++;                  run++;
492    
493          prev_level = level;          prev_level = level;
# Line 487  Line 532 
532          BitstreamPutBits(bs, code, len);          BitstreamPutBits(bs, code, len);
533  }  }
534    
535    
536    
537    /* returns the number of bits required to encode qcoeff */
538    
539    int
540    CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
541    {
542            int bits = 0;
543            uint32_t i, abs_level, run, prev_run, len;
544            int32_t level, prev_level;
545    
546            i       = 1;
547            run = 0;
548    
549            while (i<64 && !(level = qcoeff[zigzag[i++]]))
550                    run++;
551    
552            if (i >= 64) return 0;  /* empty block */
553    
554            prev_level = level;
555            prev_run   = run;
556            run = 0;
557    
558            while (i < 64)
559            {
560                    if ((level = qcoeff[zigzag[i++]]) != 0)
561                    {
562                            abs_level = ABS(prev_level);
563                            abs_level = abs_level < 64 ? abs_level : 0;
564                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
565                            bits      += len!=128 ? len : 30;
566    
567                            prev_level = level;
568                            prev_run   = run;
569                            run = 0;
570                    }
571                    else
572                            run++;
573            }
574    
575            abs_level = ABS(prev_level);
576            abs_level = abs_level < 64 ? abs_level : 0;
577            len               = coeff_VLC[1][1][abs_level][prev_run].len;
578            bits      += len!=128 ? len : 30;
579    
580            return bits;
581    }
582    
583    int
584    CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
585    {
586            uint32_t i, run, prev_run, len;
587            int32_t level, prev_level, level_shifted;
588            int bits = 0;
589    
590            i       = 0;
591            run = 0;
592    
593            while (!(level = qcoeff[zigzag[i++]]))
594                    run++;
595    
596            prev_level = level;
597            prev_run   = run;
598            run = 0;
599    
600            while (i < 64) {
601                    if ((level = qcoeff[zigzag[i++]]) != 0) {
602                            level_shifted = prev_level + 32;
603                            if (!(level_shifted & -64))
604                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
605                            else
606                                    len  = 30;
607    
608                            bits += len;
609                            prev_level = level;
610                            prev_run   = run;
611                            run = 0;
612                    }
613                    else
614                            run++;
615            }
616    
617            level_shifted = prev_level + 32;
618            if (!(level_shifted & -64))
619                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
620            else
621                    len  = 30;
622            bits += len;
623    
624            return bits;
625    }
626    
627    
628  #endif  #endif
629    
630  static __inline void  static __inline void

Legend:
Removed from v.1.25.2.11  
changed lines
  Added in v.1.42

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