[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.44.2.15, Fri Oct 3 13:47:00 2003 UTC revision 1.46.2.1, Sun Aug 22 13:15:15 2004 UTC
# Line 36  Line 36 
36    
37  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
38    
 /* #define BIGLUT */  
   
 #ifdef BIGLUT  
 #define LEVELOFFSET 2048  
 #else  
39  #define LEVELOFFSET 32  #define LEVELOFFSET 32
 #endif  
40    
41    /* Initialized once during xvid_global call
42     * RO access is thread safe */
43  static REVERSE_EVENT DCT3D[2][4096];  static REVERSE_EVENT DCT3D[2][4096];
   
 #ifdef BIGLUT  
 static VLC coeff_VLC[2][2][4096][64];  
 VLC *intra_table;  
 static VLC *inter_table;  
 #else  
44  static VLC coeff_VLC[2][2][64][64];  static VLC coeff_VLC[2][2][64][64];
 #endif  
45    
46  /* not really MB related, but VLCs are only available here */  /* not really MB related, but VLCs are only available here */
47  void bs_put_spritetrajectory(Bitstream * bs, const int val)  void bs_put_spritetrajectory(Bitstream * bs, const int val)
# Line 91  Line 80 
80          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
81          int32_t l;          int32_t l;
82    
 #ifdef BIGLUT  
         intra_table = coeff_VLC[1];  
         inter_table = coeff_VLC[0];  
 #endif  
   
   
83          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++)
84                  for (i = 0; i < 4096; i++)                  for (i = 0; i < 4096; i++)
85                          DCT3D[intra][i].event.level = 0;                          DCT3D[intra][i].event.level = 0;
86    
87          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++) {
88                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++) {
89                  {                          for (run = 0; run < 63 + last; run++) {
90                          for (run = 0; run < 63 + last; run++)                                  for (level = 0; level < (uint32_t)(32 << intra); level++) {
                                 for (level = 0; level < (uint32_t)(32 << intra); level++)  
                                 {  
 #ifdef BIGLUT  
                                         offset = LEVELOFFSET;  
 #else  
91                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
 #endif  
92                                          coeff_VLC[intra][last][level + offset][run].len = 128;                                          coeff_VLC[intra][last][level + offset][run].len = 128;
93                                  }                                  }
94                  }                  }
95                    }
96            }
97    
98          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++) {
99                  for (i = 0; i < 102; i++)                  for (i = 0; i < 102; i++) {
                 {  
 #ifdef BIGLUT  
                         offset = LEVELOFFSET;  
 #else  
100                          offset = !intra * LEVELOFFSET;                          offset = !intra * LEVELOFFSET;
101  #endif  
102                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++)                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++) {
                         {  
103                                  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;
104                                  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;
105                          }                          }
# Line 134  Line 108 
108                                  = coeff_tab[intra][i].vlc.code << 1;                                  = coeff_tab[intra][i].vlc.code << 1;
109                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
110                                  = coeff_tab[intra][i].vlc.len + 1;                                  = coeff_tab[intra][i].vlc.len + 1;
111  #ifndef BIGLUT  
112                          if (!intra)                          if (!intra) {
 #endif  
                         {  
113                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
114                                          = (coeff_tab[intra][i].vlc.code << 1) | 1;                                          = (coeff_tab[intra][i].vlc.code << 1) | 1;
115                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
116                                          = coeff_tab[intra][i].vlc.len + 1;                                          = coeff_tab[intra][i].vlc.len + 1;
117                          }                          }
118                  }                  }
119            }
120    
121            for (intra = 0; intra < 2; intra++) {
122                    for (last = 0; last < 2; last++) {
123                            for (run = 0; run < 63 + last; run++) {
124                                    for (level = 1; level < (uint32_t)(32 << intra); level++) {
125    
         for (intra = 0; intra < 2; intra++)  
                 for (last = 0; last < 2; last++)  
                         for (run = 0; run < 63 + last; run++)  
                         {  
                                 for (level = 1; level < (uint32_t)(32 << intra); level++)  
                                 {  
126                                          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])
127                                              continue;                                              continue;
128    
 #ifdef BIGLUT  
                                         offset = LEVELOFFSET;  
 #else  
129                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
 #endif  
130                      level_esc = level - max_level[intra][last][run];                      level_esc = level - max_level[intra][last][run];
131                                          run_esc = run - 1 - max_run[intra][last][level];                                          run_esc = run - 1 - max_run[intra][last][level];
                                         /*use this test to use shorter esc2 codes when possible  
                                         if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]  
                                                 && !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1  
                                                          > coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/  
132    
133                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]) {
                                         {  
134                                                  escape     = ESCAPE1;                                                  escape     = ESCAPE1;
135                                                  escape_len = 7 + 1;                                                  escape_len = 7 + 1;
136                                                  run_esc    = run;                                                  run_esc    = run;
137                                          }                                          } else {
138                                          else                                                  if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc]) {
                                         {  
                                                 if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])  
                                                 {  
139                                                          escape     = ESCAPE2;                                                          escape     = ESCAPE2;
140                                                          escape_len = 7 + 2;                                                          escape_len = 7 + 2;
141                                                          level_esc  = level;                                                          level_esc  = level;
142                                                  }                                                  } else {
143                                                  else                                                          if (!intra) {
                                                 {  
 #ifndef BIGLUT  
                                                         if (!intra)  
 #endif  
                                                         {  
144                                                                  coeff_VLC[intra][last][level + offset][run].code                                                                  coeff_VLC[intra][last][level + offset][run].code
145                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
146                                                                  coeff_VLC[intra][last][level + offset][run].len = 30;                                                                  coeff_VLC[intra][last][level + offset][run].len = 30;
# Line 202  Line 157 
157                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
158                                          coeff_VLC[intra][last][level + offset][run].len                                          coeff_VLC[intra][last][level + offset][run].len
159                                                  = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;                                                  = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
160  #ifndef BIGLUT  
161                                          if (!intra)                                          if (!intra) {
 #endif  
                                         {  
162                                                  coeff_VLC[intra][last][offset - level][run].code                                                  coeff_VLC[intra][last][offset - level][run].code
163                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
164                                                          |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;                                                          |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
# Line 214  Line 167 
167                                          }                                          }
168                                  }                                  }
169    
170  #ifdef BIGLUT                                  if (!intra) {
                                 for (level = 32 << intra; level < 2048; level++)  
                                 {  
                                         coeff_VLC[intra][last][level + offset][run].code  
                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;  
                                         coeff_VLC[intra][last][level + offset][run].len = 30;  
   
                                         coeff_VLC[intra][last][offset - level][run].code  
                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;  
                                         coeff_VLC[intra][last][offset - level][run].len = 30;  
                                 }  
 #else  
                                 if (!intra)  
                                 {  
171                                          coeff_VLC[intra][last][0][run].code                                          coeff_VLC[intra][last][0][run].code
172                                                  = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;                                                  = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
173                                          coeff_VLC[intra][last][0][run].len = 30;                                          coeff_VLC[intra][last][0][run].len = 30;
174                                  }                                  }
 #endif  
175                          }                          }
176  /* init sprite_trajectory tables */                  }
177  /* even if GMC is not specified (it might be used later...) */          }
178    
179            /* init sprite_trajectory tables
180             * even if GMC is not specified (it might be used later...) */
181    
182          sprite_trajectory_code[0+16384].code = 0;          sprite_trajectory_code[0+16384].code = 0;
183          sprite_trajectory_code[0+16384].len = 0;          sprite_trajectory_code[0+16384].len = 0;
184          for (k=0;k<14;k++)          for (k=0;k<14;k++) {
         {  
185                  int limit = (1<<k);                  int limit = (1<<k);
186    
187                  for (l=-(2*limit-1); l <= -limit; l++)                  for (l=-(2*limit-1); l <= -limit; l++) {
                 {  
188                          sprite_trajectory_code[l+16384].code = (2*limit-1)+l;                          sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
189                          sprite_trajectory_code[l+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
190                  }                  }
191    
192                  for (l=limit; l<= 2*limit-1; l++)                  for (l=limit; l<= 2*limit-1; l++) {
                 {  
193                          sprite_trajectory_code[l+16384].code = l;                          sprite_trajectory_code[l+16384].code = l;
194                          sprite_trajectory_code[l+16384].len = k+1;                          sprite_trajectory_code[l+16384].len = k+1;
195                  }                  }
# Line 312  Line 251 
251    
252  }  }
253    
 #ifdef BIGLUT  
   
 static __inline void  
 CodeCoeff(Bitstream * bs,  
                   const int16_t qcoeff[64],  
                   VLC * table,  
                   const uint16_t * zigzag,  
                   uint16_t intra)  
 {  
   
         uint32_t j, last;  
         short v;  
         VLC *vlc;  
   
         j = intra;  
         last = intra;  
   
         while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                 j++;  
   
         do {  
                 vlc = table + 64 * 2048 + (v << 6) + j - last;  
                 last = ++j;  
   
                 /* count zeroes */  
                 while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                         j++;  
   
                 /* write code */  
                 if (j != 64) {  
                         BitstreamPutBits(bs, vlc->code, vlc->len);  
                 } else {  
                         vlc += 64 * 4096;  
                         BitstreamPutBits(bs, vlc->code, vlc->len);  
                         break;  
                 }  
         } while (1);  
   
 }  
   
   
   
 /* returns the number of bits required to encode qcoeff */  
 int  
 CodeCoeff_CalcBits(const int16_t qcoeff[64],  
                   VLC * table,  
                   const uint16_t * zigzag,  
                   uint16_t intra)  
 {  
         int bits = 0;  
         uint32_t j, last;  
         short v;  
         VLC *vlc;  
   
         j = intra;  
         last = intra;  
   
         while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                 j++;  
   
         if (j >= 64) return 0;  /* empty block */  
   
         do {  
                 vlc = table + 64 * 2048 + (v << 6) + j - last;  
                 last = ++j;  
   
                 /* count zeroes */  
                 while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)  
                         j++;  
   
                 /* write code */  
                 if (j != 64) {  
                         bits += vlc->len;  
                 } else {  
                         vlc += 64 * 4096;  
                         bits += vlc->len;  
                         break;  
                 }  
         } while (1);  
   
         return bits;  
 }  
   
   
 #else  
   
254  static __inline void  static __inline void
255  CodeCoeffInter(Bitstream * bs,  CodeCoeffInter(Bitstream * bs,
256                    const int16_t qcoeff[64],                    const int16_t qcoeff[64],
# Line 602  Line 455 
455          return bits;          return bits;
456  }  }
457    
458    static const int iDQtab[5] = {
 #endif  
   
   
 static int iDQtab[5] = {  
459          1, 0, -1 /* no change */, 2, 3          1, 0, -1 /* no change */, 2, 3
460  };  };
461  #define DQ_VALUE2INDEX(value)  iDQtab[(value)+2]  #define DQ_VALUE2INDEX(value)  iDQtab[(value)+2]
# Line 668  Line 517 
517    
518                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
519    
 #ifdef BIGLUT  
                         CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);  
 #else  
520                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
 #endif  
521    
522                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
523                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 718  Line 563 
563                  }                  }
564    
565                  /* if inter block, write field ME flag */                  /* if inter block, write field ME flag */
566                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if ((pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) && (pMB->mcsel == 0)) {
567                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, 0 /*pMB->field_pred*/); /* not implemented yet */
568                          DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred);                          DPRINTF(XVID_DEBUG_MB,"codep: field_pred: %i\n", pMB->field_pred);
569    
570                          /* write field prediction references */                          /* write field prediction references */
571    #if 0 /* Remove the #if once field_pred is supported */
572                          if (pMB->field_pred) {                          if (pMB->field_pred) {
573                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
574                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
575                          }                          }
576    #endif
577                  }                  }
578          }          }
579          /* code motion vector(s) if motion is local  */          /* code motion vector(s) if motion is local  */
# Line 740  Line 587 
587    
588          /* code block coeffs */          /* code block coeffs */
589          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
590                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i))) {
                 {  
591                          const uint16_t *scan_table =                          const uint16_t *scan_table =
592                                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?                                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
593                                  scan_tables[2] : scan_tables[0];                                  scan_tables[2] : scan_tables[0];
594    
 #ifdef BIGLUT  
                         CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);  
 #else  
595                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
 #endif  
596                  }                  }
597    
598          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
# Line 852  Line 694 
694          const uint16_t *scan_table =          const uint16_t *scan_table =
695                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?                  frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
696                  scan_tables[2] : scan_tables[0];                  scan_tables[2] : scan_tables[0];
697            int bits;
698    
699    
700  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
# Line 893  Line 736 
736                          BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */                          BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */
737    
738                          /* write field prediction references */                          /* write field prediction references */
739                  /*      if (mb->field_pred) {  #if 0 /* Remove the #if once field_pred is supported */
740                            if (mb->field_pred) {
741                                  BitstreamPutBit(bs, mb->field_for_top);                                  BitstreamPutBit(bs, mb->field_for_top);
742                                  BitstreamPutBit(bs, mb->field_for_bot);                                  BitstreamPutBit(bs, mb->field_for_bot);
743                          }*/                          }
744    #endif
745                  }                  }
746          }          }
747    
# Line 917  Line 762 
762                  default: break;                  default: break;
763          }          }
764    
765            bits = BitstreamPos(bs);
766          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
767                  if (mb->cbp & (1 << (5 - i))) {                  if (mb->cbp & (1 << (5 - i))) {
768  #ifdef BIGLUT                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
                         CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);  
 #else  
                         CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);  
 #endif  
769                  }                  }
770          }          }
771            pStat->iTextBits += BitstreamPos(bs) - bits;
772  }  }
773    
774    

Legend:
Removed from v.1.44.2.15  
changed lines
  Added in v.1.46.2.1

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