[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.8, Sat Jan 4 04:23:53 2003 UTC revision 1.44, Fri Feb 21 08:32:34 2003 UTC
# Line 49  Line 49 
49    ******************************************************************************/    ******************************************************************************/
50    
51    
52    #include <stdio.h>
53  #include <stdlib.h>  #include <stdlib.h>
54  #include "../portab.h"  #include "../portab.h"
55    #include "../global.h"
56  #include "bitstream.h"  #include "bitstream.h"
57  #include "zigzag.h"  #include "zigzag.h"
58  #include "vlc_codes.h"  #include "vlc_codes.h"
# Line 59  Line 60 
60    
61  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
62    
63  #define ABS(X) (((X)>0)?(X):-(X))  /* #define BIGLUT */
 #define CLIP(X,A) (X > A) ? (A) : (X)  
   
 VLC intra_table[4*2048*64];  
 VLC inter_table[4*2048*64];  
64    
65  VLC DCT3Dintra[4096];  #ifdef BIGLUT
66  VLC DCT3Dinter[4096];  #define LEVELOFFSET 2048
67    #else
68    #define LEVELOFFSET 32
69    #endif
70    
71    static REVERSE_EVENT DCT3D[2][4096];
72    
73    #ifdef BIGLUT
74    static VLC coeff_VLC[2][2][4096][64];
75    VLC *intra_table;
76    static VLC *inter_table;
77    #else
78    static VLC coeff_VLC[2][2][64][64];
79    #endif
80    
81  /* not really MB related, but VLCs are only available here */  /* not really MB related, but VLCs are only available here */
82  void bs_put_spritetrajectory(Bitstream * bs, const int val)  void bs_put_spritetrajectory(Bitstream * bs, const int val)
# Line 100  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;
114            int32_t l;
115    
116          int32_t k, l, i, intra, last;  #ifdef BIGLUT
117          VLC *vlc[2];          intra_table = coeff_VLC[1];
118          VLC **coeff_ptr;          inter_table = coeff_VLC[0];
119          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 *max_level_ptr = max_level[last + 2 * intra];  
                         int8_t *max_run_ptr = max_run[last + 2 * intra];  
   
                         for (l = 0; l < 64; l++) {      // run  
                                 int32_t level = k;  
                                 ptr_t run = l;  
   
                                 if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run  
   
                                         vlc[intra]->code = 0;  
                                         vlc[intra]->len = 0;  
                                         goto loop_end;  
                                 } else {  
                                         if (level > 0)  // correct level  
                                                 level -= max_level_ptr[run];  
                                         else  
                                                 level += max_level_ptr[run];  
   
                                         if ((abs(level) <= max_level_ptr[run]) &&  
                                                 (run <= (uint32_t) max_run_ptr[abs(level)])) {  
120    
                                                 vlc[intra]->code = 0x06;  
                                                 vlc[intra]->len = 8;  
                                                 goto loop_end;  
                                         }  
121    
122                                          if (level > 0)  // still here?          for (intra = 0; intra < 2; intra++)
123                                                  level += max_level_ptr[run];    // restore level                  for (i = 0; i < 4096; i++)
124                                          else                          DCT3D[intra][i].event.level = 0;
                                                 level -= max_level_ptr[run];  
125    
126                                          run -= max_run_ptr[abs(level)] + 1;     // and change run          for (intra = 0; intra < 2; intra++)
127                    for (last = 0; last < 2; last++)
128                    {
129                            for (run = 0; run < 63 + last; run++)
130                                    for (level = 0; level < (uint32_t)(32 << intra); level++)
131                                    {
132    #ifdef BIGLUT
133                                            offset = LEVELOFFSET;
134    #else
135                                            offset = !intra * LEVELOFFSET;
136    #endif
137                                            coeff_VLC[intra][last][level + offset][run].len = 128;
138                                    }
139                    }
140    
141                                          if ((abs(level) <= max_level_ptr[run]) &&          for (intra = 0; intra < 2; intra++)
142                                                  (run <= (uint32_t) max_run_ptr[abs(level)])) {                  for (i = 0; i < 102; i++)
143                    {
144    #ifdef BIGLUT
145                            offset = LEVELOFFSET;
146    #else
147                            offset = !intra * LEVELOFFSET;
148    #endif
149                            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;
152                                    DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
153                            }
154    
155                                                  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
156                                                  vlc[intra]->len = 9;                                  = coeff_tab[intra][i].vlc.code << 1;
157                                                  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
158                                    = coeff_tab[intra][i].vlc.len + 1;
159    #ifndef BIGLUT
160                            if (!intra)
161    #endif
162                            {
163                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
164                                            = (coeff_tab[intra][i].vlc.code << 1) | 1;
165                                    coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len
166                                            = coeff_tab[intra][i].vlc.len + 1;
167                                          }                                          }
                                         run += max_run_ptr[abs(level)] + 1;  
168                                  }                                  }
169    
170                                  vlc[intra]->code =          for (intra = 0; intra < 2; intra++)
171                                          (uint32_t) ((l << 14) | (0x1e + last) << 20) | (1 << 13) |                  for (last = 0; last < 2; last++)
172                                          ((k & 0xfff) << 1) | 1;                          for (run = 0; run < 63 + last; run++)
173                            {
174                                  vlc[intra]->len = 30;                                  for (level = 1; level < (uint32_t)(32 << intra); level++)
175                                  vlc[intra]++;                                  {
176                                            if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
177                                  continue;                                  continue;
178    
179                            loop_end:  #ifdef BIGLUT
180                                  if (level != 0) {                                          offset = LEVELOFFSET;
181                                          vlc[intra]->code =  #else
182                                                  (vlc[intra]->                                          offset = !intra * LEVELOFFSET;
183                                                   code << (coeff_ptr[run][abs(level) - 1].len +  #endif
184                                                                    1)) | (coeff_ptr[run][abs(level) -                      level_esc = level - max_level[intra][last][run];
185                                                                                                                  1].code << 1);                                          run_esc = run - 1 - max_run[intra][last][level];
186                                          vlc[intra]->len =                                          /*use this test to use shorter esc2 codes when possible
187                                                  (coeff_ptr[run][abs(level) - 1].len + 1) +                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]
188                                                  vlc[intra]->len;                                                  && !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1
189                                                             > coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/
190                                          if (level < 0)  
191                                                  vlc[intra]->code += 1;                                          if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])
192                                  }                                          {
193                                                    escape     = ESCAPE1;
194                                  vlc[intra]++;                                                  escape_len = 7 + 1;
195                                                    run_esc    = run;
196                          }                          }
197                                            else
198                                            {
199                                                    if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])
200                                                    {
201                                                            escape     = ESCAPE2;
202                                                            escape_len = 7 + 2;
203                                                            level_esc  = level;
204                  }                  }
205                                                    else
206                                                    {
207    #ifndef BIGLUT
208                                                            if (!intra)
209    #endif
210                                                            {
211                                                                    coeff_VLC[intra][last][level + offset][run].code
212                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
213                                                                    coeff_VLC[intra][last][level + offset][run].len = 30;
214                                                                            coeff_VLC[intra][last][offset - level][run].code
215                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-(int32_t)level & 0xfff) << 1) | 1;
216                                                                    coeff_VLC[intra][last][offset - level][run].len = 30;
217                                                            }
218                                                            continue;
219          }          }
   
         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];  
220                  }                  }
221    
222                  vlc1++;                                          coeff_VLC[intra][last][level + offset][run].code
223                  vlc2++;                                                  = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
224                                                    |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
225                                            coeff_VLC[intra][last][level + offset][run].len
226                                                    = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
227    #ifndef BIGLUT
228                                            if (!intra)
229    #endif
230                                            {
231                                                    coeff_VLC[intra][last][offset - level][run].code
232                                                            = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
233                                                            |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
234                                                    coeff_VLC[intra][last][offset - level][run].len
235                                                            = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
236                                            }
237          }          }
         DCT3D[0] = DCT3Dinter;  
         DCT3D[1] = DCT3Dintra;  
238    
239    #ifdef BIGLUT
240                                    for (level = 32 << intra; level < 2048; level++)
241                                    {
242                                            coeff_VLC[intra][last][level + offset][run].code
243                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
244                                            coeff_VLC[intra][last][level + offset][run].len = 30;
245    
246                                            coeff_VLC[intra][last][offset - level][run].code
247                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;
248                                            coeff_VLC[intra][last][offset - level][run].len = 30;
249                                    }
250    #else
251                                    if (!intra)
252                                    {
253                                            coeff_VLC[intra][last][0][run].code
254                                                    = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
255                                            coeff_VLC[intra][last][0][run].len = 30;
256                                    }
257    #endif
258                            }
259  /* init sprite_trajectory tables */  /* init sprite_trajectory tables */
260  /* even if GMC is not specified (it might be used later...) */  /* even if GMC is not specified (it might be used later...) */
261    
# Line 223  Line 265 
265          {          {
266                  int limit = (1<<k);                  int limit = (1<<k);
267    
268                  for (i=-(2*limit-1); i<= -limit; i++)                  for (l=-(2*limit-1); l <= -limit; l++)
269                  {                  {
270                          sprite_trajectory_code[i+16384].code = (2*limit-1)+i;                          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 (i=limit; i<= 2*limit-1; i++)                  for (l=limit; l<= 2*limit-1; l++)
275                  {                  {
276                          sprite_trajectory_code[i+16384].code = i;                          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 292  Line 334 
334    
335  }  }
336    
337    #ifdef BIGLUT
338    
339  static __inline void  static __inline void
340  CodeCoeff(Bitstream * bs,  CodeCoeff(Bitstream * bs,
# Line 312  Line 355 
355                  j++;                  j++;
356    
357          do {          do {
358                  vlc = table + 64 * 2047 + (v << 6) + j - last;                  vlc = table + 64 * 2048 + (v << 6) + j - last;
359                  last = ++j;                  last = ++j;
360    
361                  // count zeroes                  /* count zeroes */
362                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
363                          j++;                          j++;
364    
365                  // write code                  /* write code */
366                  if (j != 64) {                  if (j != 64) {
367                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
368                  } else {                  } else {
369                          vlc += 64 * 4095;                          vlc += 64 * 4096;
370                          BitstreamPutBits(bs, vlc->code, vlc->len);                          BitstreamPutBits(bs, vlc->code, vlc->len);
371                          break;                          break;
372                  }                  }
# Line 332  Line 375 
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
422    
423    static __inline void
424    CodeCoeffInter(Bitstream * bs,
425                      const int16_t qcoeff[64],
426                      const uint16_t * zigzag)
427    {
428            uint32_t i, run, prev_run, code, len;
429            int32_t level, prev_level, level_shifted;
430    
431            i       = 0;
432            run = 0;
433    
434            while (!(level = qcoeff[zigzag[i++]]))
435                    run++;
436    
437            prev_level = level;
438            prev_run   = run;
439            run = 0;
440    
441            while (i < 64)
442            {
443                    if ((level = qcoeff[zigzag[i++]]) != 0)
444                    {
445                            level_shifted = prev_level + 32;
446                            if (!(level_shifted & -64))
447                            {
448                                    code = coeff_VLC[0][0][level_shifted][prev_run].code;
449                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
450                            }
451                            else
452                            {
453                                    code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
454                                    len  = 30;
455                            }
456                            BitstreamPutBits(bs, code, len);
457                            prev_level = level;
458                            prev_run   = run;
459                            run = 0;
460                    }
461                    else
462                            run++;
463            }
464    
465            level_shifted = prev_level + 32;
466            if (!(level_shifted & -64))
467            {
468                    code = coeff_VLC[0][1][level_shifted][prev_run].code;
469                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
470            }
471            else
472            {
473                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
474                    len  = 30;
475            }
476            BitstreamPutBits(bs, code, len);
477    }
478    
479    static __inline void
480    CodeCoeffIntra(Bitstream * bs,
481                      const int16_t qcoeff[64],
482                      const uint16_t * zigzag)
483    {
484            uint32_t i, abs_level, run, prev_run, code, len;
485            int32_t level, prev_level;
486    
487            i       = 1;
488            run = 0;
489    
490            while (i<64 && !(level = qcoeff[zigzag[i++]]))
491                    run++;
492    
493            prev_level = level;
494            prev_run   = run;
495            run = 0;
496    
497            while (i < 64)
498            {
499                    if ((level = qcoeff[zigzag[i++]]) != 0)
500                    {
501                            abs_level = ABS(prev_level);
502                            abs_level = abs_level < 64 ? abs_level : 0;
503                            code      = coeff_VLC[1][0][abs_level][prev_run].code;
504                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
505                            if (len != 128)
506                                    code |= (prev_level < 0);
507                            else
508                            {
509                            code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
510                                    len  = 30;
511                            }
512                            BitstreamPutBits(bs, code, len);
513                            prev_level = level;
514                            prev_run   = run;
515                            run = 0;
516                    }
517                    else
518                            run++;
519            }
520    
521            abs_level = ABS(prev_level);
522            abs_level = abs_level < 64 ? abs_level : 0;
523            code      = coeff_VLC[1][1][abs_level][prev_run].code;
524            len               = coeff_VLC[1][1][abs_level][prev_run].len;
525            if (len != 128)
526                    code |= (prev_level < 0);
527            else
528            {
529                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
530                    len  = 30;
531            }
532            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
629    
630  static __inline void  static __inline void
631  CodeBlockIntra(const FRAMEINFO * const frame,  CodeBlockIntra(const FRAMEINFO * const frame,
632                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
# Line 388  Line 683 
683    
684                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
685    
686    #ifdef BIGLUT
687                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);
688    #else
689                            CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
690    #endif
691    
692                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
693                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 408  Line 707 
707    
708          int32_t i;          int32_t i;
709          uint32_t bits, mcbpc, cbpy;          uint32_t bits, mcbpc, cbpy;
         int mcsel=0;  
710    
711          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
712          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
# Line 418  Line 716 
716                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
717    
718          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
719          {                  BitstreamPutBit(bs, pMB->mcsel);                // mcsel: '0'=local motion, '1'=GMC
                 if (frame->quarterpel) {  
                         if ( (pMB->qmvs[0].x == frame->GMC_MV.x) && (pMB->qmvs[0].y == frame->GMC_MV.y) )  
                                 mcsel=1;  
                 } else {  
                         if ( (pMB->mvs[0].x == frame->GMC_MV.x) && (pMB->mvs[0].y == frame->GMC_MV.y) )  
                                 mcsel=1;  
                 }  
                 BitstreamPutBit(bs, mcsel);             // mcsel: '0'=local motion, '1'=GMC  
         }  
720    
721          // write cbpy          // write cbpy
722          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
# Line 456  Line 745 
745                  }                  }
746          }          }
747          // code motion vector(s) if motion is local          // code motion vector(s) if motion is local
748          if (mcsel==0)          if (!pMB->mcsel)
749                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {                  for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
750                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                          CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
751                          CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                          CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
# Line 472  Line 761 
761                                  frame->global_flags & XVID_ALTERNATESCAN ?                                  frame->global_flags & XVID_ALTERNATESCAN ?
762                                  scan_tables[2] : scan_tables[0];                                  scan_tables[2] : scan_tables[0];
763    
764    #ifdef BIGLUT
765                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);
766    #else
767                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
768    #endif
769                  }                  }
770    
771          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
# Line 626  Line 919 
919    
920          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
921                  if (mb->cbp & (1 << (5 - i))) {                  if (mb->cbp & (1 << (5 - i))) {
922                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[direction], 0);  #ifdef BIGLUT
923                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);
924    #else
925                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);
926    #endif
927                  }                  }
928          }          }
929  }  }
# Line 683  Line 980 
980    
981          uint32_t index;          uint32_t index;
982    
983          index = CLIP(BitstreamShowBits(bs, 9), 256);          index = MIN(BitstreamShowBits(bs, 9), 256);
984    
985          BitstreamSkip(bs, mcbpc_inter_table[index].len);          BitstreamSkip(bs, mcbpc_inter_table[index].len);
986    
# Line 818  Line 1115 
1115    
1116  }  }
1117    
1118    static __inline int
1119    get_coeff(Bitstream * bs,
1120                      int *run,
1121                      int *last,
1122                      int intra,
1123                      int short_video_header)
1124    {
1125    
1126            uint32_t mode;
1127            int32_t level;
1128            REVERSE_EVENT *reverse_event;
1129    
1130            if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */
1131                    intra = 0;
1132    
1133            if (BitstreamShowBits(bs, 7) != ESCAPE) {
1134                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1135    
1136                    if ((level = reverse_event->event.level) == 0)
1137                            goto error;
1138    
1139                    *last = reverse_event->event.last;
1140                    *run  = reverse_event->event.run;
1141    
1142                    BitstreamSkip(bs, reverse_event->len);
1143    
1144                    return BitstreamGetBits(bs, 1) ? -level : level;
1145            }
1146    
1147            BitstreamSkip(bs, 7);
1148    
1149            if (short_video_header) {
1150                    /* escape mode 4 - H.263 type, only used if short_video_header = 1  */
1151                    *last = BitstreamGetBit(bs);
1152                    *run = BitstreamGetBits(bs, 6);
1153                    level = BitstreamGetBits(bs, 8);
1154    
1155                    if (level == 0 || level == 128)
1156                            DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level);
1157    
1158                    return (level << 24) >> 24;
1159            }
1160    
1161            mode = BitstreamShowBits(bs, 2);
1162    
1163            if (mode < 3) {
1164                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1165    
1166                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1167    
1168                    if ((level = reverse_event->event.level) == 0)
1169                            goto error;
1170    
1171                    *last = reverse_event->event.last;
1172                    *run  = reverse_event->event.run;
1173    
1174                    BitstreamSkip(bs, reverse_event->len);
1175    
1176                    if (mode < 2)                   /* first escape mode, level is offset */
1177                            level += max_level[intra][*last][*run];
1178                    else                                    /* second escape mode, run is offset */
1179                            *run += max_run[intra][*last][level] + 1;
1180    
1181                    return BitstreamGetBits(bs, 1) ? -level : level;
1182            }
1183    
1184            /* third escape mode - fixed length codes */
1185            BitstreamSkip(bs, 2);
1186            *last = BitstreamGetBits(bs, 1);
1187            *run = BitstreamGetBits(bs, 6);
1188            BitstreamSkip(bs, 1);           /* marker */
1189            level = BitstreamGetBits(bs, 12);
1190            BitstreamSkip(bs, 1);           /* marker */
1191    
1192            return (level << 20) >> 20;
1193    
1194      error:
1195            *run = VLC_ERROR;
1196            return 0;
1197    }
1198    
1199  void  void
1200  get_intra_block(Bitstream * bs,  get_intra_block(Bitstream * bs,
1201                                  int16_t * block,                                  int16_t * block,
# Line 881  Line 1259 
1259          } while (!last);          } while (!last);
1260    
1261  }  }
1262    
1263    /*****************************************************************************
1264     * VLC tables and other constant arrays
1265     ****************************************************************************/
1266    
1267    VLC_TABLE const coeff_tab[2][102] =
1268    {
1269            /* intra = 0 */
1270            {
1271                    {{ 2,  2}, {0, 0, 1}},
1272                    {{15,  4}, {0, 0, 2}},
1273                    {{21,  6}, {0, 0, 3}},
1274                    {{23,  7}, {0, 0, 4}},
1275                    {{31,  8}, {0, 0, 5}},
1276                    {{37,  9}, {0, 0, 6}},
1277                    {{36,  9}, {0, 0, 7}},
1278                    {{33, 10}, {0, 0, 8}},
1279                    {{32, 10}, {0, 0, 9}},
1280                    {{ 7, 11}, {0, 0, 10}},
1281                    {{ 6, 11}, {0, 0, 11}},
1282                    {{32, 11}, {0, 0, 12}},
1283                    {{ 6,  3}, {0, 1, 1}},
1284                    {{20,  6}, {0, 1, 2}},
1285                    {{30,  8}, {0, 1, 3}},
1286                    {{15, 10}, {0, 1, 4}},
1287                    {{33, 11}, {0, 1, 5}},
1288                    {{80, 12}, {0, 1, 6}},
1289                    {{14,  4}, {0, 2, 1}},
1290                    {{29,  8}, {0, 2, 2}},
1291                    {{14, 10}, {0, 2, 3}},
1292                    {{81, 12}, {0, 2, 4}},
1293                    {{13,  5}, {0, 3, 1}},
1294                    {{35,  9}, {0, 3, 2}},
1295                    {{13, 10}, {0, 3, 3}},
1296                    {{12,  5}, {0, 4, 1}},
1297                    {{34,  9}, {0, 4, 2}},
1298                    {{82, 12}, {0, 4, 3}},
1299                    {{11,  5}, {0, 5, 1}},
1300                    {{12, 10}, {0, 5, 2}},
1301                    {{83, 12}, {0, 5, 3}},
1302                    {{19,  6}, {0, 6, 1}},
1303                    {{11, 10}, {0, 6, 2}},
1304                    {{84, 12}, {0, 6, 3}},
1305                    {{18,  6}, {0, 7, 1}},
1306                    {{10, 10}, {0, 7, 2}},
1307                    {{17,  6}, {0, 8, 1}},
1308                    {{ 9, 10}, {0, 8, 2}},
1309                    {{16,  6}, {0, 9, 1}},
1310                    {{ 8, 10}, {0, 9, 2}},
1311                    {{22,  7}, {0, 10, 1}},
1312                    {{85, 12}, {0, 10, 2}},
1313                    {{21,  7}, {0, 11, 1}},
1314                    {{20,  7}, {0, 12, 1}},
1315                    {{28,  8}, {0, 13, 1}},
1316                    {{27,  8}, {0, 14, 1}},
1317                    {{33,  9}, {0, 15, 1}},
1318                    {{32,  9}, {0, 16, 1}},
1319                    {{31,  9}, {0, 17, 1}},
1320                    {{30,  9}, {0, 18, 1}},
1321                    {{29,  9}, {0, 19, 1}},
1322                    {{28,  9}, {0, 20, 1}},
1323                    {{27,  9}, {0, 21, 1}},
1324                    {{26,  9}, {0, 22, 1}},
1325                    {{34, 11}, {0, 23, 1}},
1326                    {{35, 11}, {0, 24, 1}},
1327                    {{86, 12}, {0, 25, 1}},
1328                    {{87, 12}, {0, 26, 1}},
1329                    {{ 7,  4}, {1, 0, 1}},
1330                    {{25,  9}, {1, 0, 2}},
1331                    {{ 5, 11}, {1, 0, 3}},
1332                    {{15,  6}, {1, 1, 1}},
1333                    {{ 4, 11}, {1, 1, 2}},
1334                    {{14,  6}, {1, 2, 1}},
1335                    {{13,  6}, {1, 3, 1}},
1336                    {{12,  6}, {1, 4, 1}},
1337                    {{19,  7}, {1, 5, 1}},
1338                    {{18,  7}, {1, 6, 1}},
1339                    {{17,  7}, {1, 7, 1}},
1340                    {{16,  7}, {1, 8, 1}},
1341                    {{26,  8}, {1, 9, 1}},
1342                    {{25,  8}, {1, 10, 1}},
1343                    {{24,  8}, {1, 11, 1}},
1344                    {{23,  8}, {1, 12, 1}},
1345                    {{22,  8}, {1, 13, 1}},
1346                    {{21,  8}, {1, 14, 1}},
1347                    {{20,  8}, {1, 15, 1}},
1348                    {{19,  8}, {1, 16, 1}},
1349                    {{24,  9}, {1, 17, 1}},
1350                    {{23,  9}, {1, 18, 1}},
1351                    {{22,  9}, {1, 19, 1}},
1352                    {{21,  9}, {1, 20, 1}},
1353                    {{20,  9}, {1, 21, 1}},
1354                    {{19,  9}, {1, 22, 1}},
1355                    {{18,  9}, {1, 23, 1}},
1356                    {{17,  9}, {1, 24, 1}},
1357                    {{ 7, 10}, {1, 25, 1}},
1358                    {{ 6, 10}, {1, 26, 1}},
1359                    {{ 5, 10}, {1, 27, 1}},
1360                    {{ 4, 10}, {1, 28, 1}},
1361                    {{36, 11}, {1, 29, 1}},
1362                    {{37, 11}, {1, 30, 1}},
1363                    {{38, 11}, {1, 31, 1}},
1364                    {{39, 11}, {1, 32, 1}},
1365                    {{88, 12}, {1, 33, 1}},
1366                    {{89, 12}, {1, 34, 1}},
1367                    {{90, 12}, {1, 35, 1}},
1368                    {{91, 12}, {1, 36, 1}},
1369                    {{92, 12}, {1, 37, 1}},
1370                    {{93, 12}, {1, 38, 1}},
1371                    {{94, 12}, {1, 39, 1}},
1372                    {{95, 12}, {1, 40, 1}}
1373            },
1374            /* intra = 1 */
1375            {
1376                    {{ 2,  2}, {0, 0, 1}},
1377                    {{15,  4}, {0, 0, 3}},
1378                    {{21,  6}, {0, 0, 6}},
1379                    {{23,  7}, {0, 0, 9}},
1380                    {{31,  8}, {0, 0, 10}},
1381                    {{37,  9}, {0, 0, 13}},
1382                    {{36,  9}, {0, 0, 14}},
1383                    {{33, 10}, {0, 0, 17}},
1384                    {{32, 10}, {0, 0, 18}},
1385                    {{ 7, 11}, {0, 0, 21}},
1386                    {{ 6, 11}, {0, 0, 22}},
1387                    {{32, 11}, {0, 0, 23}},
1388                    {{ 6,  3}, {0, 0, 2}},
1389                    {{20,  6}, {0, 1, 2}},
1390                    {{30,  8}, {0, 0, 11}},
1391                    {{15, 10}, {0, 0, 19}},
1392                    {{33, 11}, {0, 0, 24}},
1393                    {{80, 12}, {0, 0, 25}},
1394                    {{14,  4}, {0, 1, 1}},
1395                    {{29,  8}, {0, 0, 12}},
1396                    {{14, 10}, {0, 0, 20}},
1397                    {{81, 12}, {0, 0, 26}},
1398                    {{13,  5}, {0, 0, 4}},
1399                    {{35,  9}, {0, 0, 15}},
1400                    {{13, 10}, {0, 1, 7}},
1401                    {{12,  5}, {0, 0, 5}},
1402                    {{34,  9}, {0, 4, 2}},
1403                    {{82, 12}, {0, 0, 27}},
1404                    {{11,  5}, {0, 2, 1}},
1405                    {{12, 10}, {0, 2, 4}},
1406                    {{83, 12}, {0, 1, 9}},
1407                    {{19,  6}, {0, 0, 7}},
1408                    {{11, 10}, {0, 3, 4}},
1409                    {{84, 12}, {0, 6, 3}},
1410                    {{18,  6}, {0, 0, 8}},
1411                    {{10, 10}, {0, 4, 3}},
1412                    {{17,  6}, {0, 3, 1}},
1413                    {{ 9, 10}, {0, 8, 2}},
1414                    {{16,  6}, {0, 4, 1}},
1415                    {{ 8, 10}, {0, 5, 3}},
1416                    {{22,  7}, {0, 1, 3}},
1417                    {{85, 12}, {0, 1, 10}},
1418                    {{21,  7}, {0, 2, 2}},
1419                    {{20,  7}, {0, 7, 1}},
1420                    {{28,  8}, {0, 1, 4}},
1421                    {{27,  8}, {0, 3, 2}},
1422                    {{33,  9}, {0, 0, 16}},
1423                    {{32,  9}, {0, 1, 5}},
1424                    {{31,  9}, {0, 1, 6}},
1425                    {{30,  9}, {0, 2, 3}},
1426                    {{29,  9}, {0, 3, 3}},
1427                    {{28,  9}, {0, 5, 2}},
1428                    {{27,  9}, {0, 6, 2}},
1429                    {{26,  9}, {0, 7, 2}},
1430                    {{34, 11}, {0, 1, 8}},
1431                    {{35, 11}, {0, 9, 2}},
1432                    {{86, 12}, {0, 2, 5}},
1433                    {{87, 12}, {0, 7, 3}},
1434                    {{ 7,  4}, {1, 0, 1}},
1435                    {{25,  9}, {0, 11, 1}},
1436                    {{ 5, 11}, {1, 0, 6}},
1437                    {{15,  6}, {1, 1, 1}},
1438                    {{ 4, 11}, {1, 0, 7}},
1439                    {{14,  6}, {1, 2, 1}},
1440                    {{13,  6}, {0, 5, 1}},
1441                    {{12,  6}, {1, 0, 2}},
1442                    {{19,  7}, {1, 5, 1}},
1443                    {{18,  7}, {0, 6, 1}},
1444                    {{17,  7}, {1, 3, 1}},
1445                    {{16,  7}, {1, 4, 1}},
1446                    {{26,  8}, {1, 9, 1}},
1447                    {{25,  8}, {0, 8, 1}},
1448                    {{24,  8}, {0, 9, 1}},
1449                    {{23,  8}, {0, 10, 1}},
1450                    {{22,  8}, {1, 0, 3}},
1451                    {{21,  8}, {1, 6, 1}},
1452                    {{20,  8}, {1, 7, 1}},
1453                    {{19,  8}, {1, 8, 1}},
1454                    {{24,  9}, {0, 12, 1}},
1455                    {{23,  9}, {1, 0, 4}},
1456                    {{22,  9}, {1, 1, 2}},
1457                    {{21,  9}, {1, 10, 1}},
1458                    {{20,  9}, {1, 11, 1}},
1459                    {{19,  9}, {1, 12, 1}},
1460                    {{18,  9}, {1, 13, 1}},
1461                    {{17,  9}, {1, 14, 1}},
1462                    {{ 7, 10}, {0, 13, 1}},
1463                    {{ 6, 10}, {1, 0, 5}},
1464                    {{ 5, 10}, {1, 1, 3}},
1465                    {{ 4, 10}, {1, 2, 2}},
1466                    {{36, 11}, {1, 3, 2}},
1467                    {{37, 11}, {1, 4, 2}},
1468                    {{38, 11}, {1, 15, 1}},
1469                    {{39, 11}, {1, 16, 1}},
1470                    {{88, 12}, {0, 14, 1}},
1471                    {{89, 12}, {1, 0, 8}},
1472                    {{90, 12}, {1, 5, 2}},
1473                    {{91, 12}, {1, 6, 2}},
1474                    {{92, 12}, {1, 17, 1}},
1475                    {{93, 12}, {1, 18, 1}},
1476                    {{94, 12}, {1, 19, 1}},
1477                    {{95, 12}, {1, 20, 1}}
1478            }
1479    };
1480    
1481    /* constants taken from momusys/vm_common/inlcude/max_level.h */
1482    uint8_t const max_level[2][2][64] = {
1483            {
1484                    /* intra = 0, last = 0 */
1485                    {
1486                            12, 6, 4, 3, 3, 3, 3, 2,
1487                            2, 2, 2, 1, 1, 1, 1, 1,
1488                            1, 1, 1, 1, 1, 1, 1, 1,
1489                            1, 1, 1, 0, 0, 0, 0, 0,
1490                            0, 0, 0, 0, 0, 0, 0, 0,
1491                            0, 0, 0, 0, 0, 0, 0, 0,
1492                            0, 0, 0, 0, 0, 0, 0, 0,
1493                            0, 0, 0, 0, 0, 0, 0, 0
1494                    },
1495                    /* intra = 0, last = 1 */
1496                    {
1497                            3, 2, 1, 1, 1, 1, 1, 1,
1498                            1, 1, 1, 1, 1, 1, 1, 1,
1499                            1, 1, 1, 1, 1, 1, 1, 1,
1500                            1, 1, 1, 1, 1, 1, 1, 1,
1501                            1, 1, 1, 1, 1, 1, 1, 1,
1502                            1, 0, 0, 0, 0, 0, 0, 0,
1503                            0, 0, 0, 0, 0, 0, 0, 0,
1504                            0, 0, 0, 0, 0, 0, 0, 0
1505                    }
1506            },
1507            {
1508                    /* intra = 1, last = 0 */
1509                    {
1510                            27, 10, 5, 4, 3, 3, 3, 3,
1511                            2, 2, 1, 1, 1, 1, 1, 0,
1512                            0, 0, 0, 0, 0, 0, 0, 0,
1513                            0, 0, 0, 0, 0, 0, 0, 0,
1514                            0, 0, 0, 0, 0, 0, 0, 0,
1515                            0, 0, 0, 0, 0, 0, 0, 0,
1516                            0, 0, 0, 0, 0, 0, 0, 0,
1517                            0, 0, 0, 0, 0, 0, 0, 0
1518                    },
1519                    /* intra = 1, last = 1 */
1520                    {
1521                            8, 3, 2, 2, 2, 2, 2, 1,
1522                            1, 1, 1, 1, 1, 1, 1, 1,
1523                            1, 1, 1, 1, 1, 0, 0, 0,
1524                            0, 0, 0, 0, 0, 0, 0, 0,
1525                            0, 0, 0, 0, 0, 0, 0, 0,
1526                            0, 0, 0, 0, 0, 0, 0, 0,
1527                            0, 0, 0, 0, 0, 0, 0, 0,
1528                            0, 0, 0, 0, 0, 0, 0, 0
1529                    }
1530            }
1531    };
1532    
1533    uint8_t const max_run[2][2][64] = {
1534            {
1535                    /* intra = 0, last = 0 */
1536                    {
1537                            0, 26, 10, 6, 2, 1, 1, 0,
1538                            0, 0, 0, 0, 0, 0, 0, 0,
1539                            0, 0, 0, 0, 0, 0, 0, 0,
1540                            0, 0, 0, 0, 0, 0, 0, 0,
1541                            0, 0, 0, 0, 0, 0, 0, 0,
1542                            0, 0, 0, 0, 0, 0, 0, 0,
1543                            0, 0, 0, 0, 0, 0, 0, 0,
1544                            0, 0, 0, 0, 0, 0, 0, 0,
1545                    },
1546                    /* intra = 0, last = 1 */
1547                    {
1548                            0, 40, 1, 0, 0, 0, 0, 0,
1549                            0, 0, 0, 0, 0, 0, 0, 0,
1550                            0, 0, 0, 0, 0, 0, 0, 0,
1551                            0, 0, 0, 0, 0, 0, 0, 0,
1552                            0, 0, 0, 0, 0, 0, 0, 0,
1553                            0, 0, 0, 0, 0, 0, 0, 0,
1554                            0, 0, 0, 0, 0, 0, 0, 0,
1555                            0, 0, 0, 0, 0, 0, 0, 0,
1556                    }
1557            },
1558            {
1559                    /* intra = 1, last = 0 */
1560                    {
1561                            0, 14, 9, 7, 3, 2, 1, 1,
1562                            1, 1, 1, 0, 0, 0, 0, 0,
1563                            0, 0, 0, 0, 0, 0, 0, 0,
1564                            0, 0, 0, 0, 0, 0, 0, 0,
1565                            0, 0, 0, 0, 0, 0, 0, 0,
1566                            0, 0, 0, 0, 0, 0, 0, 0,
1567                            0, 0, 0, 0, 0, 0, 0, 0,
1568                            0, 0, 0, 0, 0, 0, 0, 0,
1569                    },
1570                    /* intra = 1, last = 1 */
1571                    {
1572                            0, 20, 6, 1, 0, 0, 0, 0,
1573                            0, 0, 0, 0, 0, 0, 0, 0,
1574                            0, 0, 0, 0, 0, 0, 0, 0,
1575                            0, 0, 0, 0, 0, 0, 0, 0,
1576                            0, 0, 0, 0, 0, 0, 0, 0,
1577                            0, 0, 0, 0, 0, 0, 0, 0,
1578                            0, 0, 0, 0, 0, 0, 0, 0,
1579                            0, 0, 0, 0, 0, 0, 0, 0,
1580                    }
1581            }
1582    };
1583    
1584    /******************************************************************
1585     * encoder tables                                                 *
1586     ******************************************************************/
1587    
1588    VLC sprite_trajectory_code[32768];
1589    
1590    VLC sprite_trajectory_len[15] = {
1591            { 0x00 , 2},
1592            { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
1593            { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8},
1594            { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
1595    
1596    
1597    /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
1598       the sign bit must be added afterwards. */
1599    
1600    /* MCBPC Indexing by cbpc in first two bits, mode in last two.
1601     CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
1602     Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
1603    
1604    VLC mcbpc_intra_tab[15] = {
1605            {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
1606            {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
1607            {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
1608            {0x00, 0}, {0x03, 3}, {0x03, 6}
1609    };
1610    
1611    /* MCBPC inter.
1612       Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
1613    
1614    VLC mcbpc_inter_tab[29] = {
1615            {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
1616            {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
1617            {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
1618            {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
1619    };
1620    
1621    const VLC cbpy_tab[16] = {
1622            {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
1623            {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
1624    };
1625    
1626    const VLC dcy_tab[511] = {
1627            {0x100, 15}, {0x101, 15}, {0x102, 15}, {0x103, 15},
1628            {0x104, 15}, {0x105, 15}, {0x106, 15}, {0x107, 15},
1629            {0x108, 15}, {0x109, 15}, {0x10a, 15}, {0x10b, 15},
1630            {0x10c, 15}, {0x10d, 15}, {0x10e, 15}, {0x10f, 15},
1631            {0x110, 15}, {0x111, 15}, {0x112, 15}, {0x113, 15},
1632            {0x114, 15}, {0x115, 15}, {0x116, 15}, {0x117, 15},
1633            {0x118, 15}, {0x119, 15}, {0x11a, 15}, {0x11b, 15},
1634            {0x11c, 15}, {0x11d, 15}, {0x11e, 15}, {0x11f, 15},
1635            {0x120, 15}, {0x121, 15}, {0x122, 15}, {0x123, 15},
1636            {0x124, 15}, {0x125, 15}, {0x126, 15}, {0x127, 15},
1637            {0x128, 15}, {0x129, 15}, {0x12a, 15}, {0x12b, 15},
1638            {0x12c, 15}, {0x12d, 15}, {0x12e, 15}, {0x12f, 15},
1639            {0x130, 15}, {0x131, 15}, {0x132, 15}, {0x133, 15},
1640            {0x134, 15}, {0x135, 15}, {0x136, 15}, {0x137, 15},
1641            {0x138, 15}, {0x139, 15}, {0x13a, 15}, {0x13b, 15},
1642            {0x13c, 15}, {0x13d, 15}, {0x13e, 15}, {0x13f, 15},
1643            {0x140, 15}, {0x141, 15}, {0x142, 15}, {0x143, 15},
1644            {0x144, 15}, {0x145, 15}, {0x146, 15}, {0x147, 15},
1645            {0x148, 15}, {0x149, 15}, {0x14a, 15}, {0x14b, 15},
1646            {0x14c, 15}, {0x14d, 15}, {0x14e, 15}, {0x14f, 15},
1647            {0x150, 15}, {0x151, 15}, {0x152, 15}, {0x153, 15},
1648            {0x154, 15}, {0x155, 15}, {0x156, 15}, {0x157, 15},
1649            {0x158, 15}, {0x159, 15}, {0x15a, 15}, {0x15b, 15},
1650            {0x15c, 15}, {0x15d, 15}, {0x15e, 15}, {0x15f, 15},
1651            {0x160, 15}, {0x161, 15}, {0x162, 15}, {0x163, 15},
1652            {0x164, 15}, {0x165, 15}, {0x166, 15}, {0x167, 15},
1653            {0x168, 15}, {0x169, 15}, {0x16a, 15}, {0x16b, 15},
1654            {0x16c, 15}, {0x16d, 15}, {0x16e, 15}, {0x16f, 15},
1655            {0x170, 15}, {0x171, 15}, {0x172, 15}, {0x173, 15},
1656            {0x174, 15}, {0x175, 15}, {0x176, 15}, {0x177, 15},
1657            {0x178, 15}, {0x179, 15}, {0x17a, 15}, {0x17b, 15},
1658            {0x17c, 15}, {0x17d, 15}, {0x17e, 15}, {0x17f, 15},
1659            {0x80, 13}, {0x81, 13}, {0x82, 13}, {0x83, 13},
1660            {0x84, 13}, {0x85, 13}, {0x86, 13}, {0x87, 13},
1661            {0x88, 13}, {0x89, 13}, {0x8a, 13}, {0x8b, 13},
1662            {0x8c, 13}, {0x8d, 13}, {0x8e, 13}, {0x8f, 13},
1663            {0x90, 13}, {0x91, 13}, {0x92, 13}, {0x93, 13},
1664            {0x94, 13}, {0x95, 13}, {0x96, 13}, {0x97, 13},
1665            {0x98, 13}, {0x99, 13}, {0x9a, 13}, {0x9b, 13},
1666            {0x9c, 13}, {0x9d, 13}, {0x9e, 13}, {0x9f, 13},
1667            {0xa0, 13}, {0xa1, 13}, {0xa2, 13}, {0xa3, 13},
1668            {0xa4, 13}, {0xa5, 13}, {0xa6, 13}, {0xa7, 13},
1669            {0xa8, 13}, {0xa9, 13}, {0xaa, 13}, {0xab, 13},
1670            {0xac, 13}, {0xad, 13}, {0xae, 13}, {0xaf, 13},
1671            {0xb0, 13}, {0xb1, 13}, {0xb2, 13}, {0xb3, 13},
1672            {0xb4, 13}, {0xb5, 13}, {0xb6, 13}, {0xb7, 13},
1673            {0xb8, 13}, {0xb9, 13}, {0xba, 13}, {0xbb, 13},
1674            {0xbc, 13}, {0xbd, 13}, {0xbe, 13}, {0xbf, 13},
1675            {0x40, 11}, {0x41, 11}, {0x42, 11}, {0x43, 11},
1676            {0x44, 11}, {0x45, 11}, {0x46, 11}, {0x47, 11},
1677            {0x48, 11}, {0x49, 11}, {0x4a, 11}, {0x4b, 11},
1678            {0x4c, 11}, {0x4d, 11}, {0x4e, 11}, {0x4f, 11},
1679            {0x50, 11}, {0x51, 11}, {0x52, 11}, {0x53, 11},
1680            {0x54, 11}, {0x55, 11}, {0x56, 11}, {0x57, 11},
1681            {0x58, 11}, {0x59, 11}, {0x5a, 11}, {0x5b, 11},
1682            {0x5c, 11}, {0x5d, 11}, {0x5e, 11}, {0x5f, 11},
1683            {0x20, 9}, {0x21, 9}, {0x22, 9}, {0x23, 9},
1684            {0x24, 9}, {0x25, 9}, {0x26, 9}, {0x27, 9},
1685            {0x28, 9}, {0x29, 9}, {0x2a, 9}, {0x2b, 9},
1686            {0x2c, 9}, {0x2d, 9}, {0x2e, 9}, {0x2f, 9},
1687            {0x10, 7}, {0x11, 7}, {0x12, 7}, {0x13, 7},
1688            {0x14, 7}, {0x15, 7}, {0x16, 7}, {0x17, 7},
1689            {0x10, 6}, {0x11, 6}, {0x12, 6}, {0x13, 6},
1690            {0x08, 4}, {0x09, 4}, {0x06, 3}, {0x03, 3},
1691            {0x07, 3}, {0x0a, 4}, {0x0b, 4}, {0x14, 6},
1692            {0x15, 6}, {0x16, 6}, {0x17, 6}, {0x18, 7},
1693            {0x19, 7}, {0x1a, 7}, {0x1b, 7}, {0x1c, 7},
1694            {0x1d, 7}, {0x1e, 7}, {0x1f, 7}, {0x30, 9},
1695            {0x31, 9}, {0x32, 9}, {0x33, 9}, {0x34, 9},
1696            {0x35, 9}, {0x36, 9}, {0x37, 9}, {0x38, 9},
1697            {0x39, 9}, {0x3a, 9}, {0x3b, 9}, {0x3c, 9},
1698            {0x3d, 9}, {0x3e, 9}, {0x3f, 9}, {0x60, 11},
1699            {0x61, 11}, {0x62, 11}, {0x63, 11}, {0x64, 11},
1700            {0x65, 11}, {0x66, 11}, {0x67, 11}, {0x68, 11},
1701            {0x69, 11}, {0x6a, 11}, {0x6b, 11}, {0x6c, 11},
1702            {0x6d, 11}, {0x6e, 11}, {0x6f, 11}, {0x70, 11},
1703            {0x71, 11}, {0x72, 11}, {0x73, 11}, {0x74, 11},
1704            {0x75, 11}, {0x76, 11}, {0x77, 11}, {0x78, 11},
1705            {0x79, 11}, {0x7a, 11}, {0x7b, 11}, {0x7c, 11},
1706            {0x7d, 11}, {0x7e, 11}, {0x7f, 11}, {0xc0, 13},
1707            {0xc1, 13}, {0xc2, 13}, {0xc3, 13}, {0xc4, 13},
1708            {0xc5, 13}, {0xc6, 13}, {0xc7, 13}, {0xc8, 13},
1709            {0xc9, 13}, {0xca, 13}, {0xcb, 13}, {0xcc, 13},
1710            {0xcd, 13}, {0xce, 13}, {0xcf, 13}, {0xd0, 13},
1711            {0xd1, 13}, {0xd2, 13}, {0xd3, 13}, {0xd4, 13},
1712            {0xd5, 13}, {0xd6, 13}, {0xd7, 13}, {0xd8, 13},
1713            {0xd9, 13}, {0xda, 13}, {0xdb, 13}, {0xdc, 13},
1714            {0xdd, 13}, {0xde, 13}, {0xdf, 13}, {0xe0, 13},
1715            {0xe1, 13}, {0xe2, 13}, {0xe3, 13}, {0xe4, 13},
1716            {0xe5, 13}, {0xe6, 13}, {0xe7, 13}, {0xe8, 13},
1717            {0xe9, 13}, {0xea, 13}, {0xeb, 13}, {0xec, 13},
1718            {0xed, 13}, {0xee, 13}, {0xef, 13}, {0xf0, 13},
1719            {0xf1, 13}, {0xf2, 13}, {0xf3, 13}, {0xf4, 13},
1720            {0xf5, 13}, {0xf6, 13}, {0xf7, 13}, {0xf8, 13},
1721            {0xf9, 13}, {0xfa, 13}, {0xfb, 13}, {0xfc, 13},
1722            {0xfd, 13}, {0xfe, 13}, {0xff, 13}, {0x180, 15},
1723            {0x181, 15}, {0x182, 15}, {0x183, 15}, {0x184, 15},
1724            {0x185, 15}, {0x186, 15}, {0x187, 15}, {0x188, 15},
1725            {0x189, 15}, {0x18a, 15}, {0x18b, 15}, {0x18c, 15},
1726            {0x18d, 15}, {0x18e, 15}, {0x18f, 15}, {0x190, 15},
1727            {0x191, 15}, {0x192, 15}, {0x193, 15}, {0x194, 15},
1728            {0x195, 15}, {0x196, 15}, {0x197, 15}, {0x198, 15},
1729            {0x199, 15}, {0x19a, 15}, {0x19b, 15}, {0x19c, 15},
1730            {0x19d, 15}, {0x19e, 15}, {0x19f, 15}, {0x1a0, 15},
1731            {0x1a1, 15}, {0x1a2, 15}, {0x1a3, 15}, {0x1a4, 15},
1732            {0x1a5, 15}, {0x1a6, 15}, {0x1a7, 15}, {0x1a8, 15},
1733            {0x1a9, 15}, {0x1aa, 15}, {0x1ab, 15}, {0x1ac, 15},
1734            {0x1ad, 15}, {0x1ae, 15}, {0x1af, 15}, {0x1b0, 15},
1735            {0x1b1, 15}, {0x1b2, 15}, {0x1b3, 15}, {0x1b4, 15},
1736            {0x1b5, 15}, {0x1b6, 15}, {0x1b7, 15}, {0x1b8, 15},
1737            {0x1b9, 15}, {0x1ba, 15}, {0x1bb, 15}, {0x1bc, 15},
1738            {0x1bd, 15}, {0x1be, 15}, {0x1bf, 15}, {0x1c0, 15},
1739            {0x1c1, 15}, {0x1c2, 15}, {0x1c3, 15}, {0x1c4, 15},
1740            {0x1c5, 15}, {0x1c6, 15}, {0x1c7, 15}, {0x1c8, 15},
1741            {0x1c9, 15}, {0x1ca, 15}, {0x1cb, 15}, {0x1cc, 15},
1742            {0x1cd, 15}, {0x1ce, 15}, {0x1cf, 15}, {0x1d0, 15},
1743            {0x1d1, 15}, {0x1d2, 15}, {0x1d3, 15}, {0x1d4, 15},
1744            {0x1d5, 15}, {0x1d6, 15}, {0x1d7, 15}, {0x1d8, 15},
1745            {0x1d9, 15}, {0x1da, 15}, {0x1db, 15}, {0x1dc, 15},
1746            {0x1dd, 15}, {0x1de, 15}, {0x1df, 15}, {0x1e0, 15},
1747            {0x1e1, 15}, {0x1e2, 15}, {0x1e3, 15}, {0x1e4, 15},
1748            {0x1e5, 15}, {0x1e6, 15}, {0x1e7, 15}, {0x1e8, 15},
1749            {0x1e9, 15}, {0x1ea, 15}, {0x1eb, 15}, {0x1ec, 15},
1750            {0x1ed, 15}, {0x1ee, 15}, {0x1ef, 15}, {0x1f0, 15},
1751            {0x1f1, 15}, {0x1f2, 15}, {0x1f3, 15}, {0x1f4, 15},
1752            {0x1f5, 15}, {0x1f6, 15}, {0x1f7, 15}, {0x1f8, 15},
1753            {0x1f9, 15}, {0x1fa, 15}, {0x1fb, 15}, {0x1fc, 15},
1754            {0x1fd, 15}, {0x1fe, 15}, {0x1ff, 15},
1755    };
1756    
1757    const VLC dcc_tab[511] = {
1758            {0x100, 16}, {0x101, 16}, {0x102, 16}, {0x103, 16},
1759            {0x104, 16}, {0x105, 16}, {0x106, 16}, {0x107, 16},
1760            {0x108, 16}, {0x109, 16}, {0x10a, 16}, {0x10b, 16},
1761            {0x10c, 16}, {0x10d, 16}, {0x10e, 16}, {0x10f, 16},
1762            {0x110, 16}, {0x111, 16}, {0x112, 16}, {0x113, 16},
1763            {0x114, 16}, {0x115, 16}, {0x116, 16}, {0x117, 16},
1764            {0x118, 16}, {0x119, 16}, {0x11a, 16}, {0x11b, 16},
1765            {0x11c, 16}, {0x11d, 16}, {0x11e, 16}, {0x11f, 16},
1766            {0x120, 16}, {0x121, 16}, {0x122, 16}, {0x123, 16},
1767            {0x124, 16}, {0x125, 16}, {0x126, 16}, {0x127, 16},
1768            {0x128, 16}, {0x129, 16}, {0x12a, 16}, {0x12b, 16},
1769            {0x12c, 16}, {0x12d, 16}, {0x12e, 16}, {0x12f, 16},
1770            {0x130, 16}, {0x131, 16}, {0x132, 16}, {0x133, 16},
1771            {0x134, 16}, {0x135, 16}, {0x136, 16}, {0x137, 16},
1772            {0x138, 16}, {0x139, 16}, {0x13a, 16}, {0x13b, 16},
1773            {0x13c, 16}, {0x13d, 16}, {0x13e, 16}, {0x13f, 16},
1774            {0x140, 16}, {0x141, 16}, {0x142, 16}, {0x143, 16},
1775            {0x144, 16}, {0x145, 16}, {0x146, 16}, {0x147, 16},
1776            {0x148, 16}, {0x149, 16}, {0x14a, 16}, {0x14b, 16},
1777            {0x14c, 16}, {0x14d, 16}, {0x14e, 16}, {0x14f, 16},
1778            {0x150, 16}, {0x151, 16}, {0x152, 16}, {0x153, 16},
1779            {0x154, 16}, {0x155, 16}, {0x156, 16}, {0x157, 16},
1780            {0x158, 16}, {0x159, 16}, {0x15a, 16}, {0x15b, 16},
1781            {0x15c, 16}, {0x15d, 16}, {0x15e, 16}, {0x15f, 16},
1782            {0x160, 16}, {0x161, 16}, {0x162, 16}, {0x163, 16},
1783            {0x164, 16}, {0x165, 16}, {0x166, 16}, {0x167, 16},
1784            {0x168, 16}, {0x169, 16}, {0x16a, 16}, {0x16b, 16},
1785            {0x16c, 16}, {0x16d, 16}, {0x16e, 16}, {0x16f, 16},
1786            {0x170, 16}, {0x171, 16}, {0x172, 16}, {0x173, 16},
1787            {0x174, 16}, {0x175, 16}, {0x176, 16}, {0x177, 16},
1788            {0x178, 16}, {0x179, 16}, {0x17a, 16}, {0x17b, 16},
1789            {0x17c, 16}, {0x17d, 16}, {0x17e, 16}, {0x17f, 16},
1790            {0x80, 14}, {0x81, 14}, {0x82, 14}, {0x83, 14},
1791            {0x84, 14}, {0x85, 14}, {0x86, 14}, {0x87, 14},
1792            {0x88, 14}, {0x89, 14}, {0x8a, 14}, {0x8b, 14},
1793            {0x8c, 14}, {0x8d, 14}, {0x8e, 14}, {0x8f, 14},
1794            {0x90, 14}, {0x91, 14}, {0x92, 14}, {0x93, 14},
1795            {0x94, 14}, {0x95, 14}, {0x96, 14}, {0x97, 14},
1796            {0x98, 14}, {0x99, 14}, {0x9a, 14}, {0x9b, 14},
1797            {0x9c, 14}, {0x9d, 14}, {0x9e, 14}, {0x9f, 14},
1798            {0xa0, 14}, {0xa1, 14}, {0xa2, 14}, {0xa3, 14},
1799            {0xa4, 14}, {0xa5, 14}, {0xa6, 14}, {0xa7, 14},
1800            {0xa8, 14}, {0xa9, 14}, {0xaa, 14}, {0xab, 14},
1801            {0xac, 14}, {0xad, 14}, {0xae, 14}, {0xaf, 14},
1802            {0xb0, 14}, {0xb1, 14}, {0xb2, 14}, {0xb3, 14},
1803            {0xb4, 14}, {0xb5, 14}, {0xb6, 14}, {0xb7, 14},
1804            {0xb8, 14}, {0xb9, 14}, {0xba, 14}, {0xbb, 14},
1805            {0xbc, 14}, {0xbd, 14}, {0xbe, 14}, {0xbf, 14},
1806            {0x40, 12}, {0x41, 12}, {0x42, 12}, {0x43, 12},
1807            {0x44, 12}, {0x45, 12}, {0x46, 12}, {0x47, 12},
1808            {0x48, 12}, {0x49, 12}, {0x4a, 12}, {0x4b, 12},
1809            {0x4c, 12}, {0x4d, 12}, {0x4e, 12}, {0x4f, 12},
1810            {0x50, 12}, {0x51, 12}, {0x52, 12}, {0x53, 12},
1811            {0x54, 12}, {0x55, 12}, {0x56, 12}, {0x57, 12},
1812            {0x58, 12}, {0x59, 12}, {0x5a, 12}, {0x5b, 12},
1813            {0x5c, 12}, {0x5d, 12}, {0x5e, 12}, {0x5f, 12},
1814            {0x20, 10}, {0x21, 10}, {0x22, 10}, {0x23, 10},
1815            {0x24, 10}, {0x25, 10}, {0x26, 10}, {0x27, 10},
1816            {0x28, 10}, {0x29, 10}, {0x2a, 10}, {0x2b, 10},
1817            {0x2c, 10}, {0x2d, 10}, {0x2e, 10}, {0x2f, 10},
1818            {0x10, 8}, {0x11, 8}, {0x12, 8}, {0x13, 8},
1819            {0x14, 8}, {0x15, 8}, {0x16, 8}, {0x17, 8},
1820            {0x08, 6}, {0x09, 6}, {0x0a, 6}, {0x0b, 6},
1821            {0x04, 4}, {0x05, 4}, {0x04, 3}, {0x03, 2},
1822            {0x05, 3}, {0x06, 4}, {0x07, 4}, {0x0c, 6},
1823            {0x0d, 6}, {0x0e, 6}, {0x0f, 6}, {0x18, 8},
1824            {0x19, 8}, {0x1a, 8}, {0x1b, 8}, {0x1c, 8},
1825            {0x1d, 8}, {0x1e, 8}, {0x1f, 8}, {0x30, 10},
1826            {0x31, 10}, {0x32, 10}, {0x33, 10}, {0x34, 10},
1827            {0x35, 10}, {0x36, 10}, {0x37, 10}, {0x38, 10},
1828            {0x39, 10}, {0x3a, 10}, {0x3b, 10}, {0x3c, 10},
1829            {0x3d, 10}, {0x3e, 10}, {0x3f, 10}, {0x60, 12},
1830            {0x61, 12}, {0x62, 12}, {0x63, 12}, {0x64, 12},
1831            {0x65, 12}, {0x66, 12}, {0x67, 12}, {0x68, 12},
1832            {0x69, 12}, {0x6a, 12}, {0x6b, 12}, {0x6c, 12},
1833            {0x6d, 12}, {0x6e, 12}, {0x6f, 12}, {0x70, 12},
1834            {0x71, 12}, {0x72, 12}, {0x73, 12}, {0x74, 12},
1835            {0x75, 12}, {0x76, 12}, {0x77, 12}, {0x78, 12},
1836            {0x79, 12}, {0x7a, 12}, {0x7b, 12}, {0x7c, 12},
1837            {0x7d, 12}, {0x7e, 12}, {0x7f, 12}, {0xc0, 14},
1838            {0xc1, 14}, {0xc2, 14}, {0xc3, 14}, {0xc4, 14},
1839            {0xc5, 14}, {0xc6, 14}, {0xc7, 14}, {0xc8, 14},
1840            {0xc9, 14}, {0xca, 14}, {0xcb, 14}, {0xcc, 14},
1841            {0xcd, 14}, {0xce, 14}, {0xcf, 14}, {0xd0, 14},
1842            {0xd1, 14}, {0xd2, 14}, {0xd3, 14}, {0xd4, 14},
1843            {0xd5, 14}, {0xd6, 14}, {0xd7, 14}, {0xd8, 14},
1844            {0xd9, 14}, {0xda, 14}, {0xdb, 14}, {0xdc, 14},
1845            {0xdd, 14}, {0xde, 14}, {0xdf, 14}, {0xe0, 14},
1846            {0xe1, 14}, {0xe2, 14}, {0xe3, 14}, {0xe4, 14},
1847            {0xe5, 14}, {0xe6, 14}, {0xe7, 14}, {0xe8, 14},
1848            {0xe9, 14}, {0xea, 14}, {0xeb, 14}, {0xec, 14},
1849            {0xed, 14}, {0xee, 14}, {0xef, 14}, {0xf0, 14},
1850            {0xf1, 14}, {0xf2, 14}, {0xf3, 14}, {0xf4, 14},
1851            {0xf5, 14}, {0xf6, 14}, {0xf7, 14}, {0xf8, 14},
1852            {0xf9, 14}, {0xfa, 14}, {0xfb, 14}, {0xfc, 14},
1853            {0xfd, 14}, {0xfe, 14}, {0xff, 14}, {0x180, 16},
1854            {0x181, 16}, {0x182, 16}, {0x183, 16}, {0x184, 16},
1855            {0x185, 16}, {0x186, 16}, {0x187, 16}, {0x188, 16},
1856            {0x189, 16}, {0x18a, 16}, {0x18b, 16}, {0x18c, 16},
1857            {0x18d, 16}, {0x18e, 16}, {0x18f, 16}, {0x190, 16},
1858            {0x191, 16}, {0x192, 16}, {0x193, 16}, {0x194, 16},
1859            {0x195, 16}, {0x196, 16}, {0x197, 16}, {0x198, 16},
1860            {0x199, 16}, {0x19a, 16}, {0x19b, 16}, {0x19c, 16},
1861            {0x19d, 16}, {0x19e, 16}, {0x19f, 16}, {0x1a0, 16},
1862            {0x1a1, 16}, {0x1a2, 16}, {0x1a3, 16}, {0x1a4, 16},
1863            {0x1a5, 16}, {0x1a6, 16}, {0x1a7, 16}, {0x1a8, 16},
1864            {0x1a9, 16}, {0x1aa, 16}, {0x1ab, 16}, {0x1ac, 16},
1865            {0x1ad, 16}, {0x1ae, 16}, {0x1af, 16}, {0x1b0, 16},
1866            {0x1b1, 16}, {0x1b2, 16}, {0x1b3, 16}, {0x1b4, 16},
1867            {0x1b5, 16}, {0x1b6, 16}, {0x1b7, 16}, {0x1b8, 16},
1868            {0x1b9, 16}, {0x1ba, 16}, {0x1bb, 16}, {0x1bc, 16},
1869            {0x1bd, 16}, {0x1be, 16}, {0x1bf, 16}, {0x1c0, 16},
1870            {0x1c1, 16}, {0x1c2, 16}, {0x1c3, 16}, {0x1c4, 16},
1871            {0x1c5, 16}, {0x1c6, 16}, {0x1c7, 16}, {0x1c8, 16},
1872            {0x1c9, 16}, {0x1ca, 16}, {0x1cb, 16}, {0x1cc, 16},
1873            {0x1cd, 16}, {0x1ce, 16}, {0x1cf, 16}, {0x1d0, 16},
1874            {0x1d1, 16}, {0x1d2, 16}, {0x1d3, 16}, {0x1d4, 16},
1875            {0x1d5, 16}, {0x1d6, 16}, {0x1d7, 16}, {0x1d8, 16},
1876            {0x1d9, 16}, {0x1da, 16}, {0x1db, 16}, {0x1dc, 16},
1877            {0x1dd, 16}, {0x1de, 16}, {0x1df, 16}, {0x1e0, 16},
1878            {0x1e1, 16}, {0x1e2, 16}, {0x1e3, 16}, {0x1e4, 16},
1879            {0x1e5, 16}, {0x1e6, 16}, {0x1e7, 16}, {0x1e8, 16},
1880            {0x1e9, 16}, {0x1ea, 16}, {0x1eb, 16}, {0x1ec, 16},
1881            {0x1ed, 16}, {0x1ee, 16}, {0x1ef, 16}, {0x1f0, 16},
1882            {0x1f1, 16}, {0x1f2, 16}, {0x1f3, 16}, {0x1f4, 16},
1883            {0x1f5, 16}, {0x1f6, 16}, {0x1f7, 16}, {0x1f8, 16},
1884            {0x1f9, 16}, {0x1fa, 16}, {0x1fb, 16}, {0x1fc, 16},
1885            {0x1fd, 16}, {0x1fe, 16}, {0x1ff, 16},
1886    };
1887    
1888    
1889    const VLC mb_motion_table[65] = {
1890            {0x05, 13}, {0x07, 13}, {0x05, 12}, {0x07, 12},
1891            {0x09, 12}, {0x0b, 12}, {0x0d, 12}, {0x0f, 12},
1892            {0x09, 11}, {0x0b, 11}, {0x0d, 11}, {0x0f, 11},
1893            {0x11, 11}, {0x13, 11}, {0x15, 11}, {0x17, 11},
1894            {0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11},
1895            {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10},
1896            {0x17, 10}, {0x07, 8}, {0x09, 8}, {0x0b, 8},
1897            {0x07, 7}, {0x03, 5}, {0x03, 4}, {0x03, 3},
1898            {0x01, 1}, {0x02, 3}, {0x02, 4}, {0x02, 5},
1899            {0x06, 7}, {0x0a, 8}, {0x08, 8}, {0x06, 8},
1900            {0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11},
1901            {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11},
1902            {0x18, 11}, {0x16, 11}, {0x14, 11}, {0x12, 11},
1903            {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},
1904            {0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12},
1905            {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},
1906            {0x04, 13}
1907    };
1908    
1909    
1910    /******************************************************************
1911     * decoder tables                                                 *
1912     ******************************************************************/
1913    
1914    VLC const mcbpc_intra_table[64] = {
1915            {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4},  {4, 4},  {4, 4},  {4, 4},
1916            {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
1917            {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},
1918            {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3},
1919            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1920            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1921            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1922            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1}
1923    };
1924    
1925    VLC const mcbpc_inter_table[257] = {
1926            {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},
1927            {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},
1928            {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
1929            {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
1930            {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
1931            {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6},
1932            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1933            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1934            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1935            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1936            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1937            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1938            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1939            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1940            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1941            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1942            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1943            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1944            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1945            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1946            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1947            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1948            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1949            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1950            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1951            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1952            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1953            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1954            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1955            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1956            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1957            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1958            {0, 1}
1959    };
1960    
1961    VLC const cbpy_table[64] = {
1962            {-1, 0}, {-1, 0}, {6, 6},  {9, 6},  {8, 5},  {8, 5},  {4, 5},  {4, 5},
1963            {2, 5},  {2, 5},  {1, 5},  {1, 5},  {0, 4},  {0, 4},  {0, 4},  {0, 4},
1964            {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
1965            {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4},  {5, 4},  {5, 4},  {5, 4},
1966            {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4},  {3, 4},  {3, 4},  {3, 4},
1967            {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4},  {7, 4},  {7, 4},  {7, 4},
1968            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
1969            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}
1970    };
1971    
1972    VLC const TMNMVtab0[] = {
1973            {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},
1974            {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}
1975    };
1976    
1977    VLC const TMNMVtab1[] = {
1978            {12, 10}, {-12, 10}, {11, 10}, {-11, 10},
1979            {10, 9}, {10, 9}, {-10, 9}, {-10, 9},
1980            {9, 9}, {9, 9}, {-9, 9}, {-9, 9},
1981            {8, 9}, {8, 9}, {-8, 9}, {-8, 9},
1982            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1983            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1984            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1985            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1986            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1987            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1988            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
1989            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
1990            {5, 7}, {5, 7}, {5, 7}, {5, 7},
1991            {5, 7}, {5, 7}, {5, 7}, {5, 7},
1992            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
1993            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
1994            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1995            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1996            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1997            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1998            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1999            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
2000            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
2001            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}
2002    };
2003    
2004    VLC const TMNMVtab2[] = {
2005            {32, 12}, {-32, 12}, {31, 12}, {-31, 12},
2006            {30, 11}, {30, 11}, {-30, 11}, {-30, 11},
2007            {29, 11}, {29, 11}, {-29, 11}, {-29, 11},
2008            {28, 11}, {28, 11}, {-28, 11}, {-28, 11},
2009            {27, 11}, {27, 11}, {-27, 11}, {-27, 11},
2010            {26, 11}, {26, 11}, {-26, 11}, {-26, 11},
2011            {25, 11}, {25, 11}, {-25, 11}, {-25, 11},
2012            {24, 10}, {24, 10}, {24, 10}, {24, 10},
2013            {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10},
2014            {23, 10}, {23, 10}, {23, 10}, {23, 10},
2015            {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10},
2016            {22, 10}, {22, 10}, {22, 10}, {22, 10},
2017            {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10},
2018            {21, 10}, {21, 10}, {21, 10}, {21, 10},
2019            {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10},
2020            {20, 10}, {20, 10}, {20, 10}, {20, 10},
2021            {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10},
2022            {19, 10}, {19, 10}, {19, 10}, {19, 10},
2023            {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10},
2024            {18, 10}, {18, 10}, {18, 10}, {18, 10},
2025            {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10},
2026            {17, 10}, {17, 10}, {17, 10}, {17, 10},
2027            {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10},
2028            {16, 10}, {16, 10}, {16, 10}, {16, 10},
2029            {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10},
2030            {15, 10}, {15, 10}, {15, 10}, {15, 10},
2031            {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10},
2032            {14, 10}, {14, 10}, {14, 10}, {14, 10},
2033            {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10},
2034            {13, 10}, {13, 10}, {13, 10}, {13, 10},
2035            {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}
2036    };
2037    
2038    short const dc_threshold[] = {
2039            21514, 26984,  8307, 28531, 29798, 24951, 25970, 26912,
2040             8307, 25956, 26994, 25974,  8292, 29286, 28015, 29728,
2041            25960, 18208, 21838, 18208, 19536, 22560, 26998,  8260,
2042            28515, 25956,  8291, 25640, 30309, 27749, 11817, 22794,
2043            30063,  8306, 28531, 29798, 24951, 25970, 25632, 29545,
2044            29300, 25193, 29813, 29295, 26656, 29537, 29728,  8303,
2045            26983, 25974, 24864, 25443, 29541,  8307, 28532, 26912,
2046            29556, 29472, 30063, 25458,  8293, 28515, 25956,  2606
2047    };
2048    
2049    VLC const dc_lum_tab[] = {
2050            {0, 0}, {4, 3}, {3, 3}, {0, 3},
2051            {2, 2}, {2, 2}, {1, 2}, {1, 2},
2052    };

Legend:
Removed from v.1.25.2.8  
changed lines
  Added in v.1.44

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