[svn] / branches / release-1_0-branch / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Diff of /branches/release-1_0-branch/xvidcore/src/bitstream/mbcoding.c

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

trunk/xvidcore/src/bitstream/mbcoding.c revision 451, Sun Sep 8 14:43:04 2002 UTC branches/release-1_0-branch/xvidcore/src/bitstream/mbcoding.c revision 1537, Sun Aug 22 13:16:12 2004 UTC
# Line 1  Line 1 
1  /*****************************************************************************  /*****************************************************************************
2   *   *
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Vector Length Coding tables -   *  - MB coding -
5   *   *
6   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *   *
  *  
  *  This program is an implementation of a part of one or more MPEG-4  
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
  *  
8   *  This program is free software; you can redistribute it and/or modify   *  This program is free software; you can redistribute it and/or modify
9   *  it under the terms of the GNU General Public License as published by   *  it under the terms of the GNU General Public License as published by
10   *  the Free Software Foundation; either version 2 of the License, or   *  the Free Software Foundation; either version 2 of the License, or
# Line 29  Line 19 
19   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
20   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21   *   *
22   * $Id: mbcoding.c,v 1.26 2002-09-08 14:43:04 edgomez Exp $   * $Id: mbcoding.c,v 1.46.2.1 2004-08-22 13:15:15 edgomez Exp $
23   *   *
24   ****************************************************************************/   ****************************************************************************/
25    
26    #include <stdio.h>
27  #include <stdlib.h>  #include <stdlib.h>
28    #include <string.h>
29    
30  #include "../portab.h"  #include "../portab.h"
31    #include "../global.h"
32  #include "bitstream.h"  #include "bitstream.h"
33  #include "zigzag.h"  #include "zigzag.h"
34  #include "vlc_codes.h"  #include "vlc_codes.h"
# Line 42  Line 36 
36    
37  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
38    
39  #define ABS(X) (((X)>0)?(X):-(X))  #define LEVELOFFSET 32
 #define CLIP(X,A) (X > A) ? (A) : (X)  
40    
41  /*****************************************************************************  /* Initialized once during xvid_global call
42   * Local data   * RO access is thread safe */
43   ****************************************************************************/  static REVERSE_EVENT DCT3D[2][4096];
44    static VLC coeff_VLC[2][2][64][64];
45    
46  static VLC intra_table[524032];  /* not really MB related, but VLCs are only available here */
47  static VLC inter_table[524032];  void bs_put_spritetrajectory(Bitstream * bs, const int val)
48    {
49            const int code = sprite_trajectory_code[val+16384].code;
50            const int len = sprite_trajectory_code[val+16384].len;
51            const int code2 = sprite_trajectory_len[len].code;
52            const int len2 = sprite_trajectory_len[len].len;
53    
54  static VLC DCT3Dintra[4096];  #if 0
55  static VLC DCT3Dinter[4096];          printf("GMC=%d Code/Len  = %d / %d ",val, code,len);
56            printf("Code2 / Len2 = %d / %d \n",code2,len2);
57    #endif
58    
59  /*****************************************************************************          BitstreamPutBits(bs, code2, len2);
60   * Functions          if (len) BitstreamPutBits(bs, code, len);
61   ****************************************************************************/  }
62    
63    int bs_get_spritetrajectory(Bitstream * bs)
64    {
65            int i;
66            for (i = 0; i < 12; i++)
67            {
68                    if (BitstreamShowBits(bs, sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code)
69                    {
70                            BitstreamSkip(bs, sprite_trajectory_len[i].len);
71                            return i;
72                    }
73            }
74            return -1;
75    }
76    
77  void  void
78  init_vlc_tables(void)  init_vlc_tables(void)
79  {  {
80            uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
81            int32_t l;
82    
83          int32_t k, l, i, intra, last;          for (intra = 0; intra < 2; intra++)
84          VLC *vlc[2];                  for (i = 0; i < 4096; i++)
85          VLC **coeff_ptr;                          DCT3D[intra][i].event.level = 0;
         VLC *vlc1, *vlc2;  
86    
87          vlc1 = DCT3Dintra;          for (intra = 0; intra < 2; intra++) {
88          vlc2 = DCT3Dinter;                  for (last = 0; last < 2; last++) {
89                            for (run = 0; run < 63 + last; run++) {
90                                    for (level = 0; level < (uint32_t)(32 << intra); level++) {
91                                            offset = !intra * LEVELOFFSET;
92                                            coeff_VLC[intra][last][level + offset][run].len = 128;
93                                    }
94                            }
95                    }
96            }
97    
98          vlc[0] = intra_table;          for (intra = 0; intra < 2; intra++) {
99          vlc[1] = inter_table;                  for (i = 0; i < 102; i++) {
100                            offset = !intra * LEVELOFFSET;
101    
102          /*                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++) {
103           * Generate encoding vlc lookup tables                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
104           * the lookup table idea is taken from the excellent fame project                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
105           * by Vivien Chapellier                          }
          */  
         for (i = 0; i < 4; i++) {  
                 intra = i % 2;  
                 last = i / 2;  
106    
107                  coeff_ptr = coeff_vlc[last + 2 * intra];                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code
108                                    = 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
110                                    = coeff_tab[intra][i].vlc.len + 1;
111    
112                  for (k = -2047; k < 2048; k++) {        // level                          if (!intra) {
113                          int8_t *max_level_ptr = max_level[last + 2 * intra];                                  coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code
114                          int8_t *max_run_ptr = max_run[last + 2 * intra];                                          = (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
116                                            = coeff_tab[intra][i].vlc.len + 1;
117                            }
118                    }
119            }
120    
121                          for (l = 0; l < 64; l++) {      // run          for (intra = 0; intra < 2; intra++) {
122                                  int32_t level = k;                  for (last = 0; last < 2; last++) {
123                                  ptr_t run = l;                          for (run = 0; run < 63 + last; run++) {
124                                    for (level = 1; level < (uint32_t)(32 << intra); level++) {
125    
126                                  if ((abs(level) <= max_level_ptr[run]) && (run <= (uint32_t) max_run_ptr[abs(level)])) {        // level < max_level and run < max_run                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
127                                                continue;
128    
129                                          vlc[intra]->code = 0;                                          offset = !intra * LEVELOFFSET;
130                                          vlc[intra]->len = 0;                      level_esc = level - max_level[intra][last][run];
131                                          goto loop_end;                                          run_esc = run - 1 - max_run[intra][last][level];
132    
133                                            if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]) {
134                                                    escape     = ESCAPE1;
135                                                    escape_len = 7 + 1;
136                                                    run_esc    = run;
137                                  } else {                                  } else {
138                                          if (level > 0)  // correct level                                                  if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc]) {
139                                                  level -= max_level_ptr[run];                                                          escape     = ESCAPE2;
140                                          else                                                          escape_len = 7 + 2;
141                                                  level += max_level_ptr[run];                                                          level_esc  = level;
142                                                    } else {
143                                          if ((abs(level) <= max_level_ptr[run]) &&                                                          if (!intra) {
144                                                  (run <= (uint32_t) max_run_ptr[abs(level)])) {                                                                  coeff_VLC[intra][last][level + offset][run].code
145                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
146                                                  vlc[intra]->code = 0x06;                                                                  coeff_VLC[intra][last][level + offset][run].len = 30;
147                                                  vlc[intra]->len = 8;                                                                          coeff_VLC[intra][last][offset - level][run].code
148                                                  goto loop_end;                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-(int32_t)level & 0xfff) << 1) | 1;
149                                                                    coeff_VLC[intra][last][offset - level][run].len = 30;
150                                          }                                          }
151                                                            continue;
                                         if (level > 0)  // still here?  
                                                 level += max_level_ptr[run];    // restore level  
                                         else  
                                                 level -= max_level_ptr[run];  
   
                                         run -= max_run_ptr[abs(level)] + 1;     // and change run  
   
                                         if ((abs(level) <= max_level_ptr[run]) &&  
                                                 (run <= (uint32_t) max_run_ptr[abs(level)])) {  
   
                                                 vlc[intra]->code = 0x0e;  
                                                 vlc[intra]->len = 9;  
                                                 goto loop_end;  
152                                          }                                          }
                                         run += max_run_ptr[abs(level)] + 1;  
153                                  }                                  }
154    
155                                  vlc[intra]->code =                                          coeff_VLC[intra][last][level + offset][run].code
156                                          (uint32_t) ((l << 14) | (0x1e + last) << 20) | (1 << 13) |                                                  = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
157                                          ((k & 0xfff) << 1) | 1;                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
158                                            coeff_VLC[intra][last][level + offset][run].len
159                                                    = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
160    
161                                  vlc[intra]->len = 30;                                          if (!intra) {
162                                  vlc[intra]++;                                                  coeff_VLC[intra][last][offset - level][run].code
163                                  continue;                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
164                                                            |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
165                                                    coeff_VLC[intra][last][offset - level][run].len
166                                                            = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
167                                            }
168                                    }
169    
170                            loop_end:                                  if (!intra) {
171                                  if (level != 0) {                                          coeff_VLC[intra][last][0][run].code
172                                          vlc[intra]->code =                                                  = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1;
173                                                  (vlc[intra]->                                          coeff_VLC[intra][last][0][run].len = 30;
                                                  code << (coeff_ptr[run][abs(level) - 1].len +  
                                                                   1)) | (coeff_ptr[run][abs(level) -  
                                                                                                                 1].code << 1);  
                                         vlc[intra]->len =  
                                                 (coeff_ptr[run][abs(level) - 1].len + 1) +  
                                                 vlc[intra]->len;  
   
                                         if (level < 0)  
                                                 vlc[intra]->code += 1;  
                                 }  
   
                                 vlc[intra]++;  
174                          }                          }
175                  }                  }
176          }          }
   
         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];  
177                  }                  }
178    
179                  vlc1++;          /* init sprite_trajectory tables
180                  vlc2++;           * even if GMC is not specified (it might be used later...) */
181    
182            sprite_trajectory_code[0+16384].code = 0;
183            sprite_trajectory_code[0+16384].len = 0;
184            for (k=0;k<14;k++) {
185                    int limit = (1<<k);
186    
187                    for (l=-(2*limit-1); l <= -limit; l++) {
188                            sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
189                            sprite_trajectory_code[l+16384].len = k+1;
190          }          }
         DCT3D[0] = DCT3Dinter;  
         DCT3D[1] = DCT3Dintra;  
191    
192                    for (l=limit; l<= 2*limit-1; l++) {
193                            sprite_trajectory_code[l+16384].code = l;
194                            sprite_trajectory_code[l+16384].len = k+1;
195                    }
196            }
197  }  }
198    
199  static __inline void  static __inline void
# Line 235  Line 251 
251    
252  }  }
253    
254    static __inline void
255    CodeCoeffInter(Bitstream * bs,
256                      const int16_t qcoeff[64],
257                      const uint16_t * zigzag)
258    {
259            uint32_t i, run, prev_run, code, len;
260            int32_t level, prev_level, level_shifted;
261    
262            i       = 0;
263            run = 0;
264    
265            while (!(level = qcoeff[zigzag[i++]]))
266                    run++;
267    
268            prev_level = level;
269            prev_run   = run;
270            run = 0;
271    
272            while (i < 64)
273            {
274                    if ((level = qcoeff[zigzag[i++]]) != 0)
275                    {
276                            level_shifted = prev_level + 32;
277                            if (!(level_shifted & -64))
278                            {
279                                    code = coeff_VLC[0][0][level_shifted][prev_run].code;
280                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
281                            }
282                            else
283                            {
284                                    code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
285                                    len  = 30;
286                            }
287                            BitstreamPutBits(bs, code, len);
288                            prev_level = level;
289                            prev_run   = run;
290                            run = 0;
291                    }
292                    else
293                            run++;
294            }
295    
296            level_shifted = prev_level + 32;
297            if (!(level_shifted & -64))
298            {
299                    code = coeff_VLC[0][1][level_shifted][prev_run].code;
300                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
301            }
302            else
303            {
304                    code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
305                    len  = 30;
306            }
307            BitstreamPutBits(bs, code, len);
308    }
309    
310  static __inline void  static __inline void
311  CodeCoeff(Bitstream * bs,  CodeCoeffIntra(Bitstream * bs,
312                    const int16_t qcoeff[64],                    const int16_t qcoeff[64],
313                    VLC * table,                    const uint16_t * zigzag)
                   const uint16_t * zigzag,  
                   uint16_t intra)  
314  {  {
315            uint32_t i, abs_level, run, prev_run, code, len;
316            int32_t level, prev_level;
317    
318          uint32_t j, last;          i       = 1;
319          short v;          run = 0;
         VLC *vlc;  
320    
321          j = intra;          while (i<64 && !(level = qcoeff[zigzag[i++]]))
322          last = intra;                  run++;
323    
324          while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)          prev_level = level;
325                  j++;          prev_run   = run;
326            run = 0;
327    
328          do {          while (i < 64)
329                  vlc = table + 64 * 2047 + (v << 6) + j - last;          {
330                  last = ++j;                  if ((level = qcoeff[zigzag[i++]]) != 0)
331                    {
332                            abs_level = abs(prev_level);
333                            abs_level = abs_level < 64 ? abs_level : 0;
334                            code      = coeff_VLC[1][0][abs_level][prev_run].code;
335                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
336                            if (len != 128)
337                                    code |= (prev_level < 0);
338                            else
339                            {
340                            code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
341                                    len  = 30;
342                            }
343                            BitstreamPutBits(bs, code, len);
344                            prev_level = level;
345                            prev_run   = run;
346                            run = 0;
347                    }
348                    else
349                            run++;
350            }
351    
352                  // count zeroes          abs_level = abs(prev_level);
353                  while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)          abs_level = abs_level < 64 ? abs_level : 0;
354                          j++;          code      = coeff_VLC[1][1][abs_level][prev_run].code;
355            len               = coeff_VLC[1][1][abs_level][prev_run].len;
356                  // write code          if (len != 128)
357                  if (j != 64) {                  code |= (prev_level < 0);
358                          BitstreamPutBits(bs, vlc->code, vlc->len);          else
359                  } else {          {
360                          vlc += 64 * 4095;                  code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1;
361                          BitstreamPutBits(bs, vlc->code, vlc->len);                  len  = 30;
362                          break;          }
363            BitstreamPutBits(bs, code, len);
364                  }                  }
         } while (1);  
365    
366    
367    
368    /* returns the number of bits required to encode qcoeff */
369    
370    int
371    CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
372    {
373            int bits = 0;
374            uint32_t i, abs_level, run, prev_run, len;
375            int32_t level, prev_level;
376    
377            i       = 1;
378            run = 0;
379    
380            while (i<64 && !(level = qcoeff[zigzag[i++]]))
381                    run++;
382    
383            if (i >= 64) return 0;  /* empty block */
384    
385            prev_level = level;
386            prev_run   = run;
387            run = 0;
388    
389            while (i < 64)
390            {
391                    if ((level = qcoeff[zigzag[i++]]) != 0)
392                    {
393                            abs_level = abs(prev_level);
394                            abs_level = abs_level < 64 ? abs_level : 0;
395                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
396                            bits      += len!=128 ? len : 30;
397    
398                            prev_level = level;
399                            prev_run   = run;
400                            run = 0;
401                    }
402                    else
403                            run++;
404  }  }
405    
406            abs_level = abs(prev_level);
407            abs_level = abs_level < 64 ? abs_level : 0;
408            len               = coeff_VLC[1][1][abs_level][prev_run].len;
409            bits      += len!=128 ? len : 30;
410    
411  static void          return bits;
412  CodeBlockIntra(const FRAMEINFO * frame,  }
413    
414    int
415    CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
416    {
417            uint32_t i, run, prev_run, len;
418            int32_t level, prev_level, level_shifted;
419            int bits = 0;
420    
421            i       = 0;
422            run = 0;
423    
424            while (!(level = qcoeff[zigzag[i++]]))
425                    run++;
426    
427            prev_level = level;
428            prev_run   = run;
429            run = 0;
430    
431            while (i < 64) {
432                    if ((level = qcoeff[zigzag[i++]]) != 0) {
433                            level_shifted = prev_level + 32;
434                            if (!(level_shifted & -64))
435                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
436                            else
437                                    len  = 30;
438    
439                            bits += len;
440                            prev_level = level;
441                            prev_run   = run;
442                            run = 0;
443                    }
444                    else
445                            run++;
446            }
447    
448            level_shifted = prev_level + 32;
449            if (!(level_shifted & -64))
450                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
451            else
452                    len  = 30;
453            bits += len;
454    
455            return bits;
456    }
457    
458    static const int iDQtab[5] = {
459            1, 0, -1 /* no change */, 2, 3
460    };
461    #define DQ_VALUE2INDEX(value)  iDQtab[(value)+2]
462    
463    
464    static __inline void
465    CodeBlockIntra(const FRAMEINFO * const frame,
466                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
467                             int16_t qcoeff[6 * 64],                             int16_t qcoeff[6 * 64],
468                             Bitstream * bs,                             Bitstream * bs,
# Line 287  Line 473 
473    
474          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
475    
476          // write mcbpc          /* write mcbpc */
477          if (frame->coding_type == I_VOP) {          if (frame->coding_type == I_VOP) {
478                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
479                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
# Line 298  Line 484 
484                                                   mcbpc_inter_tab[mcbpc].len);                                                   mcbpc_inter_tab[mcbpc].len);
485          }          }
486    
487          // ac prediction flag          /* ac prediction flag */
488          if (pMB->acpred_directions[0])          if (pMB->acpred_directions[0])
489                  BitstreamPutBits(bs, 1, 1);                  BitstreamPutBits(bs, 1, 1);
490          else          else
491                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
492    
493          // write cbpy          /* write cbpy */
494          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
495    
496          // write dquant          /* write dquant */
497          if (pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA_Q)
498                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
499    
500          // write interlacing          /* write interlacing */
501          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
502                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
503          }          }
504          // code block coeffs          /* code block coeffs */
505          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
506                  if (i < 4)                  if (i < 4)
507                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
# Line 325  Line 511 
511                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);
512    
513                  if (pMB->cbp & (1 << (5 - i))) {                  if (pMB->cbp & (1 << (5 - i))) {
514                            const uint16_t *scan_table =
515                                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
516                                    scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
517    
518                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
519    
520                          CodeCoeff(bs, &qcoeff[i * 64], intra_table,                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
                                           scan_tables[pMB->acpred_directions[i]], 1);  
521    
522                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
523                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
# Line 339  Line 528 
528    
529    
530  static void  static void
531  CodeBlockInter(const FRAMEINFO * frame,  CodeBlockInter(const FRAMEINFO * const frame,
532                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
533                             int16_t qcoeff[6 * 64],                             int16_t qcoeff[6 * 64],
534                             Bitstream * bs,                             Bitstream * bs,
# Line 352  Line 541 
541          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
542          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
543    
544          // write mcbpc          /* write mcbpc */
545          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
546                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
547    
548          // write cbpy          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
549          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);                  BitstreamPutBit(bs, pMB->mcsel);                /* mcsel: '0'=local motion, '1'=GMC */
550    
551          // write dquant          /* write cbpy */
552            BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
553    
554            /* write dquant */
555          if (pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER_Q)
556                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
557    
558          // interlacing          /* interlacing */
559          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
560                  if (pMB->cbp) {                  if (pMB->cbp) {
561                          BitstreamPutBit(bs, pMB->field_dct);                          BitstreamPutBit(bs, pMB->field_dct);
562                          DEBUG1("codep: field_dct: ", pMB->field_dct);                          DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", pMB->field_dct);
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                          DEBUG1("codep: field_pred: ", 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)          /* code motion vector(s) if motion is local  */
580            if (!pMB->mcsel)
581          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
582                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
583                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
# Line 390  Line 585 
585    
586          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
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                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                          const uint16_t *scan_table =
592                                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
593                                    scan_tables[2] : scan_tables[0];
594    
595                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
596                    }
597    
598          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
599          pStat->iTextBits += bits;          pStat->iTextBits += bits;
   
600  }  }
601    
602    
603  void  void
604  MBCoding(const FRAMEINFO * frame,  MBCoding(const FRAMEINFO * const frame,
605                   MACROBLOCK * pMB,                   MACROBLOCK * pMB,
606                   int16_t qcoeff[6 * 64],                   int16_t qcoeff[6 * 64],
607                   Bitstream * bs,                   Bitstream * bs,
608                   Statistics * pStat)                   Statistics * pStat)
609  {  {
610            if (frame->coding_type != I_VOP)
611          if (frame->coding_type == P_VOP) {                          BitstreamPutBit(bs, 0); /* not_coded */
                         BitstreamPutBit(bs, 0); // coded  
         }  
612    
613          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
614                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
# Line 420  Line 617 
617    
618  }  }
619    
   
 void  
 MBSkip(Bitstream * bs)  
 {  
         BitstreamPutBit(bs, 1); // not coded  
         return;  
 }  
   
   
620  /***************************************************************  /***************************************************************
621   * bframe encoding start   * bframe encoding start
622   ***************************************************************/   ***************************************************************/
# Line 441  Line 629 
629          3       0001b   forward mc+q            dbquant, mvdf          3       0001b   forward mc+q            dbquant, mvdf
630  */  */
631    
632  void  static __inline void
633  put_bvop_mbtype(Bitstream * bs,  put_bvop_mbtype(Bitstream * bs,
634                                  int value)                                  int value)
635  {  {
636          switch (value) {          switch (value) {
637          case 0:                  case MODE_FORWARD:
                 BitstreamPutBit(bs, 1);  
                 return;  
   
         case 1:  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 1);  
                 return;  
   
         case 2:  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 0);  
                 BitstreamPutBit(bs, 1);  
                 return;  
   
         case 3:  
638                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
639                    case MODE_BACKWARD:
640                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
641                    case MODE_INTERPOLATE:
642                  BitstreamPutBit(bs, 0);                  BitstreamPutBit(bs, 0);
643                    case MODE_DIRECT:
644                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
645                  return;                  default:
646                            break;
         default:;                                       // invalid!  
   
647          }          }
   
648  }  }
649    
650  /*  /*
# Line 481  Line 654 
654          +2      11b          +2      11b
655  */  */
656    
657  void  static __inline void
658  put_bvop_dbquant(Bitstream * bs,  put_bvop_dbquant(Bitstream * bs,
659                                   int value)                                   int value)
660  {  {
# Line 500  Line 673 
673                  BitstreamPutBit(bs, 1);                  BitstreamPutBit(bs, 1);
674                  return;                  return;
675    
676          default:;                                       // invalid          default:;                                       /* invalid */
677          }          }
678  }  }
679    
680    
681    
682  void  void
683  MBCodingBVOP(const MACROBLOCK * mb,  MBCodingBVOP(const FRAMEINFO * const frame,
684                             const MACROBLOCK * mb,
685                           const int16_t qcoeff[6 * 64],                           const int16_t qcoeff[6 * 64],
686                           const int32_t fcode,                           const int32_t fcode,
687                           const int32_t bcode,                           const int32_t bcode,
688                           Bitstream * bs,                           Bitstream * bs,
689                           Statistics * pStat)                           Statistics * pStat)
690  {  {
691          int i;          int vcode = fcode;
692            unsigned int i;
693    
694            const uint16_t *scan_table =
695                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
696                    scan_tables[2] : scan_tables[0];
697            int bits;
698    
699    
700  /*      ------------------------------------------------------------------  /*      ------------------------------------------------------------------
701                  when a block is skipped it is decoded DIRECT(0,0)                  when a block is skipped it is decoded DIRECT(0,0)
# Line 522  Line 703 
703          ------------------------------------------------------------------ */          ------------------------------------------------------------------ */
704    
705          if (mb->mode == MODE_DIRECT_NONE_MV) {          if (mb->mode == MODE_DIRECT_NONE_MV) {
706                  BitstreamPutBit(bs, 1); // skipped                  BitstreamPutBit(bs, 1); /* skipped */
707                  return;                  return;
708          }          }
709    
710          BitstreamPutBit(bs, 0);         // not skipped          BitstreamPutBit(bs, 0);         /* not skipped */
711    
712          if (mb->cbp == 0) {          if (mb->cbp == 0) {
713                  BitstreamPutBit(bs, 1); // cbp == 0                  BitstreamPutBit(bs, 1); /* cbp == 0 */
714          } else {          } else {
715                  BitstreamPutBit(bs, 0); // cbp == xxx                  BitstreamPutBit(bs, 0); /* cbp == xxx */
716          }          }
717    
718          put_bvop_mbtype(bs, mb->mode);          put_bvop_mbtype(bs, mb->mode);
# Line 541  Line 722 
722          }          }
723    
724          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {          if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
725                  put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0                  put_bvop_dbquant(bs, 0);        /* todo: mb->dquant = 0 */
726          }          }
727    
728          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_FORWARD) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
729                  CodeVector(bs, mb->pmvs[0].x, fcode, pStat);                  if (mb->cbp) {
730                  CodeVector(bs, mb->pmvs[0].y, fcode, pStat);                          BitstreamPutBit(bs, mb->field_dct);
731                            DPRINTF(XVID_DEBUG_MB,"codep: field_dct: %i\n", mb->field_dct);
732          }          }
733    
734          if (mb->mode == MODE_INTERPOLATE || mb->mode == MODE_BACKWARD) {                  /* if not direct block, write field ME flag */
735                  CodeVector(bs, mb->b_pmvs[0].x, bcode, pStat);                  if (mb->mode != MODE_DIRECT) {
736                  CodeVector(bs, mb->b_pmvs[0].y, bcode, pStat);                          BitstreamPutBit(bs, 0 /*mb->field_pred*/); /* field ME not implemented */
737    
738                            /* write field prediction references */
739    #if 0 /* Remove the #if once field_pred is supported */
740                            if (mb->field_pred) {
741                                    BitstreamPutBit(bs, mb->field_for_top);
742                                    BitstreamPutBit(bs, mb->field_for_bot);
743                            }
744    #endif
745          }          }
746            }
747    
748    
749          if (mb->mode == MODE_DIRECT) {          switch (mb->mode) {
750                  CodeVector(bs, mb->deltamv.x, 1, pStat);                /* fcode is always 1 for delta vector */                  case MODE_INTERPOLATE:
751                  CodeVector(bs, mb->deltamv.y, 1, pStat);                /* prediction is always (0,0) */                          CodeVector(bs, mb->pmvs[1].x, vcode, pStat); /* forward vector of interpolate mode */
752                            CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
753                    case MODE_BACKWARD:
754                            vcode = bcode;
755                    case MODE_FORWARD:
756                            CodeVector(bs, mb->pmvs[0].x, vcode, pStat);
757                            CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
758                            break;
759                    case MODE_DIRECT:
760                            CodeVector(bs, mb->pmvs[3].x, 1, pStat);        /* fcode is always 1 for delta vector */
761                            CodeVector(bs, mb->pmvs[3].y, 1, pStat);        /* prediction is always (0,0) */
762                    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                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
769                  }                  }
770          }          }
771            pStat->iTextBits += BitstreamPos(bs) - bits;
772  }  }
773    
774    
# Line 573  Line 778 
778   ***************************************************************/   ***************************************************************/
779    
780    
781  // for IVOP addbits == 0  /*
782  // for PVOP addbits == fcode - 1   * for IVOP addbits == 0
783  // for BVOP addbits == max(fcode,bcode) - 1   * for PVOP addbits == fcode - 1
784  // returns true or false   * for BVOP addbits == max(fcode,bcode) - 1
785     * returns true or false
786     */
787  int  int
788  check_resync_marker(Bitstream * bs, int addbits)  check_resync_marker(Bitstream * bs, int addbits)
789  {  {
# Line 618  Line 825 
825    
826          uint32_t index;          uint32_t index;
827    
828          index = CLIP(BitstreamShowBits(bs, 9), 256);          index = MIN(BitstreamShowBits(bs, 9), 256);
829    
830          BitstreamSkip(bs, mcbpc_inter_table[index].len);          BitstreamSkip(bs, mcbpc_inter_table[index].len);
831    
# Line 644  Line 851 
851    
852  }  }
853    
854  int  static __inline int
855  get_mv_data(Bitstream * bs)  get_mv_data(Bitstream * bs)
856  {  {
857    
# Line 690  Line 897 
897                  return data;                  return data;
898    
899          res = BitstreamGetBits(bs, fcode - 1);          res = BitstreamGetBits(bs, fcode - 1);
900          mv = ((ABS(data) - 1) * scale_fac) + res + 1;          mv = ((abs(data) - 1) * scale_fac) + res + 1;
901    
902          return data < 0 ? -mv : mv;          return data < 0 ? -mv : mv;
903    
# Line 753  Line 960 
960    
961  }  }
962    
963    static __inline int
964    get_coeff(Bitstream * bs,
965                      int *run,
966                      int *last,
967                      int intra,
968                      int short_video_header)
969    {
970    
971            uint32_t mode;
972            int32_t level;
973            REVERSE_EVENT *reverse_event;
974    
975            if (short_video_header)         /* inter-VLCs will be used for both intra and inter blocks */
976                    intra = 0;
977    
978            if (BitstreamShowBits(bs, 7) != ESCAPE) {
979                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
980    
981                    if ((level = reverse_event->event.level) == 0)
982                            goto error;
983    
984                    *last = reverse_event->event.last;
985                    *run  = reverse_event->event.run;
986    
987                    BitstreamSkip(bs, reverse_event->len);
988    
989                    return BitstreamGetBits(bs, 1) ? -level : level;
990            }
991    
992            BitstreamSkip(bs, 7);
993    
994            if (short_video_header) {
995                    /* escape mode 4 - H.263 type, only used if short_video_header = 1  */
996                    *last = BitstreamGetBit(bs);
997                    *run = BitstreamGetBits(bs, 6);
998                    level = BitstreamGetBits(bs, 8);
999    
1000                    if (level == 0 || level == 128)
1001                            DPRINTF(XVID_DEBUG_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d\n", level);
1002    
1003                    return (level << 24) >> 24;
1004            }
1005    
1006            mode = BitstreamShowBits(bs, 2);
1007    
1008            if (mode < 3) {
1009                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1010    
1011                    reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1012    
1013                    if ((level = reverse_event->event.level) == 0)
1014                            goto error;
1015    
1016                    *last = reverse_event->event.last;
1017                    *run  = reverse_event->event.run;
1018    
1019                    BitstreamSkip(bs, reverse_event->len);
1020    
1021                    if (mode < 2)                   /* first escape mode, level is offset */
1022                            level += max_level[intra][*last][*run];
1023                    else                                    /* second escape mode, run is offset */
1024                            *run += max_run[intra][*last][level] + 1;
1025    
1026                    return BitstreamGetBits(bs, 1) ? -level : level;
1027            }
1028    
1029            /* third escape mode - fixed length codes */
1030            BitstreamSkip(bs, 2);
1031            *last = BitstreamGetBits(bs, 1);
1032            *run = BitstreamGetBits(bs, 6);
1033            BitstreamSkip(bs, 1);           /* marker */
1034            level = BitstreamGetBits(bs, 12);
1035            BitstreamSkip(bs, 1);           /* marker */
1036    
1037            return (level << 20) >> 20;
1038    
1039      error:
1040            *run = VLC_ERROR;
1041            return 0;
1042    }
1043    
1044  void  void
1045  get_intra_block(Bitstream * bs,  get_intra_block(Bitstream * bs,
1046                                  int16_t * block,                                  int16_t * block,
# Line 761  Line 1049 
1049  {  {
1050    
1051          const uint16_t *scan = scan_tables[direction];          const uint16_t *scan = scan_tables[direction];
1052          int level;          int level, run, last;
         int run;  
         int last;  
1053    
1054          do {          do {
1055                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
1056                  if (run == -1) {                  if (run == -1) {
1057                          DEBUG("fatal: invalid run");                          DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
1058                          break;                          break;
1059                  }                  }
1060                  coeff += run;                  coeff += run;
1061                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
1062    
1063                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[coeff], level);
1064                  //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));  #if 0
1065                    DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[coeff], level, BitstreamShowBits(bs, 32));
1066    #endif
1067    
1068                  if (level < -127 || level > 127) {                  if (level < -2047 || level > 2047) {
1069                          DEBUG1("warning: intra_overflow", level);                          DPRINTF(XVID_DEBUG_ERROR,"warning: intra_overflow %i\n", level);
1070                  }                  }
1071                  coeff++;                  coeff++;
1072          } while (!last);          } while (!last);
# Line 787  Line 1075 
1075    
1076  void  void
1077  get_inter_block(Bitstream * bs,  get_inter_block(Bitstream * bs,
1078                                  int16_t * block)                                  int16_t * block,
1079                                    int direction)
1080  {  {
1081    
1082          const uint16_t *scan = scan_tables[0];          const uint16_t *scan = scan_tables[direction];
1083          int p;          int p;
1084          int level;          int level;
1085          int run;          int run;
# Line 800  Line 1089 
1089          do {          do {
1090                  level = get_coeff(bs, &run, &last, 0, 0);                  level = get_coeff(bs, &run, &last, 0, 0);
1091                  if (run == -1) {                  if (run == -1) {
1092                          DEBUG("fatal: invalid run");                          DPRINTF(XVID_DEBUG_ERROR,"fatal: invalid run");
1093                          break;                          break;
1094                  }                  }
1095                  p += run;                  p += run;
1096    
1097                  block[scan[p]] = level;                  block[scan[p]] = level;
1098    
1099                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);                  DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i\n", scan[p], level);
1100                  // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));                  /* DPRINTF(XVID_DEBUG_COEFF,"block[%i] %i %08x\n", scan[p], level, BitstreamShowBits(bs, 32)); */
1101    
1102                  if (level < -127 || level > 127) {                  if (level < -2047 || level > 2047) {
1103                          DEBUG1("warning: inter_overflow", level);                          DPRINTF(XVID_DEBUG_ERROR,"warning: inter overflow %i\n", level);
1104                  }                  }
1105                  p++;                  p++;
1106          } while (!last);          } while (!last);
1107    
1108  }  }
1109    
1110    
1111    /*****************************************************************************
1112     * VLC tables and other constant arrays
1113     ****************************************************************************/
1114    
1115    VLC_TABLE const coeff_tab[2][102] =
1116    {
1117            /* intra = 0 */
1118            {
1119                    {{ 2,  2}, {0, 0, 1}},
1120                    {{15,  4}, {0, 0, 2}},
1121                    {{21,  6}, {0, 0, 3}},
1122                    {{23,  7}, {0, 0, 4}},
1123                    {{31,  8}, {0, 0, 5}},
1124                    {{37,  9}, {0, 0, 6}},
1125                    {{36,  9}, {0, 0, 7}},
1126                    {{33, 10}, {0, 0, 8}},
1127                    {{32, 10}, {0, 0, 9}},
1128                    {{ 7, 11}, {0, 0, 10}},
1129                    {{ 6, 11}, {0, 0, 11}},
1130                    {{32, 11}, {0, 0, 12}},
1131                    {{ 6,  3}, {0, 1, 1}},
1132                    {{20,  6}, {0, 1, 2}},
1133                    {{30,  8}, {0, 1, 3}},
1134                    {{15, 10}, {0, 1, 4}},
1135                    {{33, 11}, {0, 1, 5}},
1136                    {{80, 12}, {0, 1, 6}},
1137                    {{14,  4}, {0, 2, 1}},
1138                    {{29,  8}, {0, 2, 2}},
1139                    {{14, 10}, {0, 2, 3}},
1140                    {{81, 12}, {0, 2, 4}},
1141                    {{13,  5}, {0, 3, 1}},
1142                    {{35,  9}, {0, 3, 2}},
1143                    {{13, 10}, {0, 3, 3}},
1144                    {{12,  5}, {0, 4, 1}},
1145                    {{34,  9}, {0, 4, 2}},
1146                    {{82, 12}, {0, 4, 3}},
1147                    {{11,  5}, {0, 5, 1}},
1148                    {{12, 10}, {0, 5, 2}},
1149                    {{83, 12}, {0, 5, 3}},
1150                    {{19,  6}, {0, 6, 1}},
1151                    {{11, 10}, {0, 6, 2}},
1152                    {{84, 12}, {0, 6, 3}},
1153                    {{18,  6}, {0, 7, 1}},
1154                    {{10, 10}, {0, 7, 2}},
1155                    {{17,  6}, {0, 8, 1}},
1156                    {{ 9, 10}, {0, 8, 2}},
1157                    {{16,  6}, {0, 9, 1}},
1158                    {{ 8, 10}, {0, 9, 2}},
1159                    {{22,  7}, {0, 10, 1}},
1160                    {{85, 12}, {0, 10, 2}},
1161                    {{21,  7}, {0, 11, 1}},
1162                    {{20,  7}, {0, 12, 1}},
1163                    {{28,  8}, {0, 13, 1}},
1164                    {{27,  8}, {0, 14, 1}},
1165                    {{33,  9}, {0, 15, 1}},
1166                    {{32,  9}, {0, 16, 1}},
1167                    {{31,  9}, {0, 17, 1}},
1168                    {{30,  9}, {0, 18, 1}},
1169                    {{29,  9}, {0, 19, 1}},
1170                    {{28,  9}, {0, 20, 1}},
1171                    {{27,  9}, {0, 21, 1}},
1172                    {{26,  9}, {0, 22, 1}},
1173                    {{34, 11}, {0, 23, 1}},
1174                    {{35, 11}, {0, 24, 1}},
1175                    {{86, 12}, {0, 25, 1}},
1176                    {{87, 12}, {0, 26, 1}},
1177                    {{ 7,  4}, {1, 0, 1}},
1178                    {{25,  9}, {1, 0, 2}},
1179                    {{ 5, 11}, {1, 0, 3}},
1180                    {{15,  6}, {1, 1, 1}},
1181                    {{ 4, 11}, {1, 1, 2}},
1182                    {{14,  6}, {1, 2, 1}},
1183                    {{13,  6}, {1, 3, 1}},
1184                    {{12,  6}, {1, 4, 1}},
1185                    {{19,  7}, {1, 5, 1}},
1186                    {{18,  7}, {1, 6, 1}},
1187                    {{17,  7}, {1, 7, 1}},
1188                    {{16,  7}, {1, 8, 1}},
1189                    {{26,  8}, {1, 9, 1}},
1190                    {{25,  8}, {1, 10, 1}},
1191                    {{24,  8}, {1, 11, 1}},
1192                    {{23,  8}, {1, 12, 1}},
1193                    {{22,  8}, {1, 13, 1}},
1194                    {{21,  8}, {1, 14, 1}},
1195                    {{20,  8}, {1, 15, 1}},
1196                    {{19,  8}, {1, 16, 1}},
1197                    {{24,  9}, {1, 17, 1}},
1198                    {{23,  9}, {1, 18, 1}},
1199                    {{22,  9}, {1, 19, 1}},
1200                    {{21,  9}, {1, 20, 1}},
1201                    {{20,  9}, {1, 21, 1}},
1202                    {{19,  9}, {1, 22, 1}},
1203                    {{18,  9}, {1, 23, 1}},
1204                    {{17,  9}, {1, 24, 1}},
1205                    {{ 7, 10}, {1, 25, 1}},
1206                    {{ 6, 10}, {1, 26, 1}},
1207                    {{ 5, 10}, {1, 27, 1}},
1208                    {{ 4, 10}, {1, 28, 1}},
1209                    {{36, 11}, {1, 29, 1}},
1210                    {{37, 11}, {1, 30, 1}},
1211                    {{38, 11}, {1, 31, 1}},
1212                    {{39, 11}, {1, 32, 1}},
1213                    {{88, 12}, {1, 33, 1}},
1214                    {{89, 12}, {1, 34, 1}},
1215                    {{90, 12}, {1, 35, 1}},
1216                    {{91, 12}, {1, 36, 1}},
1217                    {{92, 12}, {1, 37, 1}},
1218                    {{93, 12}, {1, 38, 1}},
1219                    {{94, 12}, {1, 39, 1}},
1220                    {{95, 12}, {1, 40, 1}}
1221            },
1222            /* intra = 1 */
1223            {
1224                    {{ 2,  2}, {0, 0, 1}},
1225                    {{15,  4}, {0, 0, 3}},
1226                    {{21,  6}, {0, 0, 6}},
1227                    {{23,  7}, {0, 0, 9}},
1228                    {{31,  8}, {0, 0, 10}},
1229                    {{37,  9}, {0, 0, 13}},
1230                    {{36,  9}, {0, 0, 14}},
1231                    {{33, 10}, {0, 0, 17}},
1232                    {{32, 10}, {0, 0, 18}},
1233                    {{ 7, 11}, {0, 0, 21}},
1234                    {{ 6, 11}, {0, 0, 22}},
1235                    {{32, 11}, {0, 0, 23}},
1236                    {{ 6,  3}, {0, 0, 2}},
1237                    {{20,  6}, {0, 1, 2}},
1238                    {{30,  8}, {0, 0, 11}},
1239                    {{15, 10}, {0, 0, 19}},
1240                    {{33, 11}, {0, 0, 24}},
1241                    {{80, 12}, {0, 0, 25}},
1242                    {{14,  4}, {0, 1, 1}},
1243                    {{29,  8}, {0, 0, 12}},
1244                    {{14, 10}, {0, 0, 20}},
1245                    {{81, 12}, {0, 0, 26}},
1246                    {{13,  5}, {0, 0, 4}},
1247                    {{35,  9}, {0, 0, 15}},
1248                    {{13, 10}, {0, 1, 7}},
1249                    {{12,  5}, {0, 0, 5}},
1250                    {{34,  9}, {0, 4, 2}},
1251                    {{82, 12}, {0, 0, 27}},
1252                    {{11,  5}, {0, 2, 1}},
1253                    {{12, 10}, {0, 2, 4}},
1254                    {{83, 12}, {0, 1, 9}},
1255                    {{19,  6}, {0, 0, 7}},
1256                    {{11, 10}, {0, 3, 4}},
1257                    {{84, 12}, {0, 6, 3}},
1258                    {{18,  6}, {0, 0, 8}},
1259                    {{10, 10}, {0, 4, 3}},
1260                    {{17,  6}, {0, 3, 1}},
1261                    {{ 9, 10}, {0, 8, 2}},
1262                    {{16,  6}, {0, 4, 1}},
1263                    {{ 8, 10}, {0, 5, 3}},
1264                    {{22,  7}, {0, 1, 3}},
1265                    {{85, 12}, {0, 1, 10}},
1266                    {{21,  7}, {0, 2, 2}},
1267                    {{20,  7}, {0, 7, 1}},
1268                    {{28,  8}, {0, 1, 4}},
1269                    {{27,  8}, {0, 3, 2}},
1270                    {{33,  9}, {0, 0, 16}},
1271                    {{32,  9}, {0, 1, 5}},
1272                    {{31,  9}, {0, 1, 6}},
1273                    {{30,  9}, {0, 2, 3}},
1274                    {{29,  9}, {0, 3, 3}},
1275                    {{28,  9}, {0, 5, 2}},
1276                    {{27,  9}, {0, 6, 2}},
1277                    {{26,  9}, {0, 7, 2}},
1278                    {{34, 11}, {0, 1, 8}},
1279                    {{35, 11}, {0, 9, 2}},
1280                    {{86, 12}, {0, 2, 5}},
1281                    {{87, 12}, {0, 7, 3}},
1282                    {{ 7,  4}, {1, 0, 1}},
1283                    {{25,  9}, {0, 11, 1}},
1284                    {{ 5, 11}, {1, 0, 6}},
1285                    {{15,  6}, {1, 1, 1}},
1286                    {{ 4, 11}, {1, 0, 7}},
1287                    {{14,  6}, {1, 2, 1}},
1288                    {{13,  6}, {0, 5, 1}},
1289                    {{12,  6}, {1, 0, 2}},
1290                    {{19,  7}, {1, 5, 1}},
1291                    {{18,  7}, {0, 6, 1}},
1292                    {{17,  7}, {1, 3, 1}},
1293                    {{16,  7}, {1, 4, 1}},
1294                    {{26,  8}, {1, 9, 1}},
1295                    {{25,  8}, {0, 8, 1}},
1296                    {{24,  8}, {0, 9, 1}},
1297                    {{23,  8}, {0, 10, 1}},
1298                    {{22,  8}, {1, 0, 3}},
1299                    {{21,  8}, {1, 6, 1}},
1300                    {{20,  8}, {1, 7, 1}},
1301                    {{19,  8}, {1, 8, 1}},
1302                    {{24,  9}, {0, 12, 1}},
1303                    {{23,  9}, {1, 0, 4}},
1304                    {{22,  9}, {1, 1, 2}},
1305                    {{21,  9}, {1, 10, 1}},
1306                    {{20,  9}, {1, 11, 1}},
1307                    {{19,  9}, {1, 12, 1}},
1308                    {{18,  9}, {1, 13, 1}},
1309                    {{17,  9}, {1, 14, 1}},
1310                    {{ 7, 10}, {0, 13, 1}},
1311                    {{ 6, 10}, {1, 0, 5}},
1312                    {{ 5, 10}, {1, 1, 3}},
1313                    {{ 4, 10}, {1, 2, 2}},
1314                    {{36, 11}, {1, 3, 2}},
1315                    {{37, 11}, {1, 4, 2}},
1316                    {{38, 11}, {1, 15, 1}},
1317                    {{39, 11}, {1, 16, 1}},
1318                    {{88, 12}, {0, 14, 1}},
1319                    {{89, 12}, {1, 0, 8}},
1320                    {{90, 12}, {1, 5, 2}},
1321                    {{91, 12}, {1, 6, 2}},
1322                    {{92, 12}, {1, 17, 1}},
1323                    {{93, 12}, {1, 18, 1}},
1324                    {{94, 12}, {1, 19, 1}},
1325                    {{95, 12}, {1, 20, 1}}
1326            }
1327    };
1328    
1329    /* constants taken from momusys/vm_common/inlcude/max_level.h */
1330    uint8_t const max_level[2][2][64] = {
1331            {
1332                    /* intra = 0, last = 0 */
1333                    {
1334                            12, 6, 4, 3, 3, 3, 3, 2,
1335                            2, 2, 2, 1, 1, 1, 1, 1,
1336                            1, 1, 1, 1, 1, 1, 1, 1,
1337                            1, 1, 1, 0, 0, 0, 0, 0,
1338                            0, 0, 0, 0, 0, 0, 0, 0,
1339                            0, 0, 0, 0, 0, 0, 0, 0,
1340                            0, 0, 0, 0, 0, 0, 0, 0,
1341                            0, 0, 0, 0, 0, 0, 0, 0
1342                    },
1343                    /* intra = 0, last = 1 */
1344                    {
1345                            3, 2, 1, 1, 1, 1, 1, 1,
1346                            1, 1, 1, 1, 1, 1, 1, 1,
1347                            1, 1, 1, 1, 1, 1, 1, 1,
1348                            1, 1, 1, 1, 1, 1, 1, 1,
1349                            1, 1, 1, 1, 1, 1, 1, 1,
1350                            1, 0, 0, 0, 0, 0, 0, 0,
1351                            0, 0, 0, 0, 0, 0, 0, 0,
1352                            0, 0, 0, 0, 0, 0, 0, 0
1353                    }
1354            },
1355            {
1356                    /* intra = 1, last = 0 */
1357                    {
1358                            27, 10, 5, 4, 3, 3, 3, 3,
1359                            2, 2, 1, 1, 1, 1, 1, 0,
1360                            0, 0, 0, 0, 0, 0, 0, 0,
1361                            0, 0, 0, 0, 0, 0, 0, 0,
1362                            0, 0, 0, 0, 0, 0, 0, 0,
1363                            0, 0, 0, 0, 0, 0, 0, 0,
1364                            0, 0, 0, 0, 0, 0, 0, 0,
1365                            0, 0, 0, 0, 0, 0, 0, 0
1366                    },
1367                    /* intra = 1, last = 1 */
1368                    {
1369                            8, 3, 2, 2, 2, 2, 2, 1,
1370                            1, 1, 1, 1, 1, 1, 1, 1,
1371                            1, 1, 1, 1, 1, 0, 0, 0,
1372                            0, 0, 0, 0, 0, 0, 0, 0,
1373                            0, 0, 0, 0, 0, 0, 0, 0,
1374                            0, 0, 0, 0, 0, 0, 0, 0,
1375                            0, 0, 0, 0, 0, 0, 0, 0,
1376                            0, 0, 0, 0, 0, 0, 0, 0
1377                    }
1378            }
1379    };
1380    
1381    uint8_t const max_run[2][2][64] = {
1382            {
1383                    /* intra = 0, last = 0 */
1384                    {
1385                            0, 26, 10, 6, 2, 1, 1, 0,
1386                            0, 0, 0, 0, 0, 0, 0, 0,
1387                            0, 0, 0, 0, 0, 0, 0, 0,
1388                            0, 0, 0, 0, 0, 0, 0, 0,
1389                            0, 0, 0, 0, 0, 0, 0, 0,
1390                            0, 0, 0, 0, 0, 0, 0, 0,
1391                            0, 0, 0, 0, 0, 0, 0, 0,
1392                            0, 0, 0, 0, 0, 0, 0, 0,
1393                    },
1394                    /* intra = 0, last = 1 */
1395                    {
1396                            0, 40, 1, 0, 0, 0, 0, 0,
1397                            0, 0, 0, 0, 0, 0, 0, 0,
1398                            0, 0, 0, 0, 0, 0, 0, 0,
1399                            0, 0, 0, 0, 0, 0, 0, 0,
1400                            0, 0, 0, 0, 0, 0, 0, 0,
1401                            0, 0, 0, 0, 0, 0, 0, 0,
1402                            0, 0, 0, 0, 0, 0, 0, 0,
1403                            0, 0, 0, 0, 0, 0, 0, 0,
1404                    }
1405            },
1406            {
1407                    /* intra = 1, last = 0 */
1408                    {
1409                            0, 14, 9, 7, 3, 2, 1, 1,
1410                            1, 1, 1, 0, 0, 0, 0, 0,
1411                            0, 0, 0, 0, 0, 0, 0, 0,
1412                            0, 0, 0, 0, 0, 0, 0, 0,
1413                            0, 0, 0, 0, 0, 0, 0, 0,
1414                            0, 0, 0, 0, 0, 0, 0, 0,
1415                            0, 0, 0, 0, 0, 0, 0, 0,
1416                            0, 0, 0, 0, 0, 0, 0, 0,
1417                    },
1418                    /* intra = 1, last = 1 */
1419                    {
1420                            0, 20, 6, 1, 0, 0, 0, 0,
1421                            0, 0, 0, 0, 0, 0, 0, 0,
1422                            0, 0, 0, 0, 0, 0, 0, 0,
1423                            0, 0, 0, 0, 0, 0, 0, 0,
1424                            0, 0, 0, 0, 0, 0, 0, 0,
1425                            0, 0, 0, 0, 0, 0, 0, 0,
1426                            0, 0, 0, 0, 0, 0, 0, 0,
1427                            0, 0, 0, 0, 0, 0, 0, 0,
1428                    }
1429            }
1430    };
1431    
1432    /******************************************************************
1433     * encoder tables                                                 *
1434     ******************************************************************/
1435    
1436    VLC sprite_trajectory_code[32768];
1437    
1438    VLC sprite_trajectory_len[15] = {
1439            { 0x00 , 2},
1440            { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
1441            { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7E, 7}, { 0xFE, 8},
1442            { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
1443    
1444    
1445    /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
1446       the sign bit must be added afterwards. */
1447    
1448    /* MCBPC Indexing by cbpc in first two bits, mode in last two.
1449     CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
1450     Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
1451    
1452    VLC mcbpc_intra_tab[15] = {
1453            {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
1454            {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
1455            {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
1456            {0x00, 0}, {0x03, 3}, {0x03, 6}
1457    };
1458    
1459    /* MCBPC inter.
1460       Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
1461    
1462    VLC mcbpc_inter_tab[29] = {
1463            {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
1464            {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
1465            {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
1466            {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
1467    };
1468    
1469    const VLC xvid_cbpy_tab[16] = {
1470            {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
1471            {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
1472    };
1473    
1474    const VLC dcy_tab[511] = {
1475            {0x100, 15}, {0x101, 15}, {0x102, 15}, {0x103, 15},
1476            {0x104, 15}, {0x105, 15}, {0x106, 15}, {0x107, 15},
1477            {0x108, 15}, {0x109, 15}, {0x10a, 15}, {0x10b, 15},
1478            {0x10c, 15}, {0x10d, 15}, {0x10e, 15}, {0x10f, 15},
1479            {0x110, 15}, {0x111, 15}, {0x112, 15}, {0x113, 15},
1480            {0x114, 15}, {0x115, 15}, {0x116, 15}, {0x117, 15},
1481            {0x118, 15}, {0x119, 15}, {0x11a, 15}, {0x11b, 15},
1482            {0x11c, 15}, {0x11d, 15}, {0x11e, 15}, {0x11f, 15},
1483            {0x120, 15}, {0x121, 15}, {0x122, 15}, {0x123, 15},
1484            {0x124, 15}, {0x125, 15}, {0x126, 15}, {0x127, 15},
1485            {0x128, 15}, {0x129, 15}, {0x12a, 15}, {0x12b, 15},
1486            {0x12c, 15}, {0x12d, 15}, {0x12e, 15}, {0x12f, 15},
1487            {0x130, 15}, {0x131, 15}, {0x132, 15}, {0x133, 15},
1488            {0x134, 15}, {0x135, 15}, {0x136, 15}, {0x137, 15},
1489            {0x138, 15}, {0x139, 15}, {0x13a, 15}, {0x13b, 15},
1490            {0x13c, 15}, {0x13d, 15}, {0x13e, 15}, {0x13f, 15},
1491            {0x140, 15}, {0x141, 15}, {0x142, 15}, {0x143, 15},
1492            {0x144, 15}, {0x145, 15}, {0x146, 15}, {0x147, 15},
1493            {0x148, 15}, {0x149, 15}, {0x14a, 15}, {0x14b, 15},
1494            {0x14c, 15}, {0x14d, 15}, {0x14e, 15}, {0x14f, 15},
1495            {0x150, 15}, {0x151, 15}, {0x152, 15}, {0x153, 15},
1496            {0x154, 15}, {0x155, 15}, {0x156, 15}, {0x157, 15},
1497            {0x158, 15}, {0x159, 15}, {0x15a, 15}, {0x15b, 15},
1498            {0x15c, 15}, {0x15d, 15}, {0x15e, 15}, {0x15f, 15},
1499            {0x160, 15}, {0x161, 15}, {0x162, 15}, {0x163, 15},
1500            {0x164, 15}, {0x165, 15}, {0x166, 15}, {0x167, 15},
1501            {0x168, 15}, {0x169, 15}, {0x16a, 15}, {0x16b, 15},
1502            {0x16c, 15}, {0x16d, 15}, {0x16e, 15}, {0x16f, 15},
1503            {0x170, 15}, {0x171, 15}, {0x172, 15}, {0x173, 15},
1504            {0x174, 15}, {0x175, 15}, {0x176, 15}, {0x177, 15},
1505            {0x178, 15}, {0x179, 15}, {0x17a, 15}, {0x17b, 15},
1506            {0x17c, 15}, {0x17d, 15}, {0x17e, 15}, {0x17f, 15},
1507            {0x80, 13}, {0x81, 13}, {0x82, 13}, {0x83, 13},
1508            {0x84, 13}, {0x85, 13}, {0x86, 13}, {0x87, 13},
1509            {0x88, 13}, {0x89, 13}, {0x8a, 13}, {0x8b, 13},
1510            {0x8c, 13}, {0x8d, 13}, {0x8e, 13}, {0x8f, 13},
1511            {0x90, 13}, {0x91, 13}, {0x92, 13}, {0x93, 13},
1512            {0x94, 13}, {0x95, 13}, {0x96, 13}, {0x97, 13},
1513            {0x98, 13}, {0x99, 13}, {0x9a, 13}, {0x9b, 13},
1514            {0x9c, 13}, {0x9d, 13}, {0x9e, 13}, {0x9f, 13},
1515            {0xa0, 13}, {0xa1, 13}, {0xa2, 13}, {0xa3, 13},
1516            {0xa4, 13}, {0xa5, 13}, {0xa6, 13}, {0xa7, 13},
1517            {0xa8, 13}, {0xa9, 13}, {0xaa, 13}, {0xab, 13},
1518            {0xac, 13}, {0xad, 13}, {0xae, 13}, {0xaf, 13},
1519            {0xb0, 13}, {0xb1, 13}, {0xb2, 13}, {0xb3, 13},
1520            {0xb4, 13}, {0xb5, 13}, {0xb6, 13}, {0xb7, 13},
1521            {0xb8, 13}, {0xb9, 13}, {0xba, 13}, {0xbb, 13},
1522            {0xbc, 13}, {0xbd, 13}, {0xbe, 13}, {0xbf, 13},
1523            {0x40, 11}, {0x41, 11}, {0x42, 11}, {0x43, 11},
1524            {0x44, 11}, {0x45, 11}, {0x46, 11}, {0x47, 11},
1525            {0x48, 11}, {0x49, 11}, {0x4a, 11}, {0x4b, 11},
1526            {0x4c, 11}, {0x4d, 11}, {0x4e, 11}, {0x4f, 11},
1527            {0x50, 11}, {0x51, 11}, {0x52, 11}, {0x53, 11},
1528            {0x54, 11}, {0x55, 11}, {0x56, 11}, {0x57, 11},
1529            {0x58, 11}, {0x59, 11}, {0x5a, 11}, {0x5b, 11},
1530            {0x5c, 11}, {0x5d, 11}, {0x5e, 11}, {0x5f, 11},
1531            {0x20, 9}, {0x21, 9}, {0x22, 9}, {0x23, 9},
1532            {0x24, 9}, {0x25, 9}, {0x26, 9}, {0x27, 9},
1533            {0x28, 9}, {0x29, 9}, {0x2a, 9}, {0x2b, 9},
1534            {0x2c, 9}, {0x2d, 9}, {0x2e, 9}, {0x2f, 9},
1535            {0x10, 7}, {0x11, 7}, {0x12, 7}, {0x13, 7},
1536            {0x14, 7}, {0x15, 7}, {0x16, 7}, {0x17, 7},
1537            {0x10, 6}, {0x11, 6}, {0x12, 6}, {0x13, 6},
1538            {0x08, 4}, {0x09, 4}, {0x06, 3}, {0x03, 3},
1539            {0x07, 3}, {0x0a, 4}, {0x0b, 4}, {0x14, 6},
1540            {0x15, 6}, {0x16, 6}, {0x17, 6}, {0x18, 7},
1541            {0x19, 7}, {0x1a, 7}, {0x1b, 7}, {0x1c, 7},
1542            {0x1d, 7}, {0x1e, 7}, {0x1f, 7}, {0x30, 9},
1543            {0x31, 9}, {0x32, 9}, {0x33, 9}, {0x34, 9},
1544            {0x35, 9}, {0x36, 9}, {0x37, 9}, {0x38, 9},
1545            {0x39, 9}, {0x3a, 9}, {0x3b, 9}, {0x3c, 9},
1546            {0x3d, 9}, {0x3e, 9}, {0x3f, 9}, {0x60, 11},
1547            {0x61, 11}, {0x62, 11}, {0x63, 11}, {0x64, 11},
1548            {0x65, 11}, {0x66, 11}, {0x67, 11}, {0x68, 11},
1549            {0x69, 11}, {0x6a, 11}, {0x6b, 11}, {0x6c, 11},
1550            {0x6d, 11}, {0x6e, 11}, {0x6f, 11}, {0x70, 11},
1551            {0x71, 11}, {0x72, 11}, {0x73, 11}, {0x74, 11},
1552            {0x75, 11}, {0x76, 11}, {0x77, 11}, {0x78, 11},
1553            {0x79, 11}, {0x7a, 11}, {0x7b, 11}, {0x7c, 11},
1554            {0x7d, 11}, {0x7e, 11}, {0x7f, 11}, {0xc0, 13},
1555            {0xc1, 13}, {0xc2, 13}, {0xc3, 13}, {0xc4, 13},
1556            {0xc5, 13}, {0xc6, 13}, {0xc7, 13}, {0xc8, 13},
1557            {0xc9, 13}, {0xca, 13}, {0xcb, 13}, {0xcc, 13},
1558            {0xcd, 13}, {0xce, 13}, {0xcf, 13}, {0xd0, 13},
1559            {0xd1, 13}, {0xd2, 13}, {0xd3, 13}, {0xd4, 13},
1560            {0xd5, 13}, {0xd6, 13}, {0xd7, 13}, {0xd8, 13},
1561            {0xd9, 13}, {0xda, 13}, {0xdb, 13}, {0xdc, 13},
1562            {0xdd, 13}, {0xde, 13}, {0xdf, 13}, {0xe0, 13},
1563            {0xe1, 13}, {0xe2, 13}, {0xe3, 13}, {0xe4, 13},
1564            {0xe5, 13}, {0xe6, 13}, {0xe7, 13}, {0xe8, 13},
1565            {0xe9, 13}, {0xea, 13}, {0xeb, 13}, {0xec, 13},
1566            {0xed, 13}, {0xee, 13}, {0xef, 13}, {0xf0, 13},
1567            {0xf1, 13}, {0xf2, 13}, {0xf3, 13}, {0xf4, 13},
1568            {0xf5, 13}, {0xf6, 13}, {0xf7, 13}, {0xf8, 13},
1569            {0xf9, 13}, {0xfa, 13}, {0xfb, 13}, {0xfc, 13},
1570            {0xfd, 13}, {0xfe, 13}, {0xff, 13}, {0x180, 15},
1571            {0x181, 15}, {0x182, 15}, {0x183, 15}, {0x184, 15},
1572            {0x185, 15}, {0x186, 15}, {0x187, 15}, {0x188, 15},
1573            {0x189, 15}, {0x18a, 15}, {0x18b, 15}, {0x18c, 15},
1574            {0x18d, 15}, {0x18e, 15}, {0x18f, 15}, {0x190, 15},
1575            {0x191, 15}, {0x192, 15}, {0x193, 15}, {0x194, 15},
1576            {0x195, 15}, {0x196, 15}, {0x197, 15}, {0x198, 15},
1577            {0x199, 15}, {0x19a, 15}, {0x19b, 15}, {0x19c, 15},
1578            {0x19d, 15}, {0x19e, 15}, {0x19f, 15}, {0x1a0, 15},
1579            {0x1a1, 15}, {0x1a2, 15}, {0x1a3, 15}, {0x1a4, 15},
1580            {0x1a5, 15}, {0x1a6, 15}, {0x1a7, 15}, {0x1a8, 15},
1581            {0x1a9, 15}, {0x1aa, 15}, {0x1ab, 15}, {0x1ac, 15},
1582            {0x1ad, 15}, {0x1ae, 15}, {0x1af, 15}, {0x1b0, 15},
1583            {0x1b1, 15}, {0x1b2, 15}, {0x1b3, 15}, {0x1b4, 15},
1584            {0x1b5, 15}, {0x1b6, 15}, {0x1b7, 15}, {0x1b8, 15},
1585            {0x1b9, 15}, {0x1ba, 15}, {0x1bb, 15}, {0x1bc, 15},
1586            {0x1bd, 15}, {0x1be, 15}, {0x1bf, 15}, {0x1c0, 15},
1587            {0x1c1, 15}, {0x1c2, 15}, {0x1c3, 15}, {0x1c4, 15},
1588            {0x1c5, 15}, {0x1c6, 15}, {0x1c7, 15}, {0x1c8, 15},
1589            {0x1c9, 15}, {0x1ca, 15}, {0x1cb, 15}, {0x1cc, 15},
1590            {0x1cd, 15}, {0x1ce, 15}, {0x1cf, 15}, {0x1d0, 15},
1591            {0x1d1, 15}, {0x1d2, 15}, {0x1d3, 15}, {0x1d4, 15},
1592            {0x1d5, 15}, {0x1d6, 15}, {0x1d7, 15}, {0x1d8, 15},
1593            {0x1d9, 15}, {0x1da, 15}, {0x1db, 15}, {0x1dc, 15},
1594            {0x1dd, 15}, {0x1de, 15}, {0x1df, 15}, {0x1e0, 15},
1595            {0x1e1, 15}, {0x1e2, 15}, {0x1e3, 15}, {0x1e4, 15},
1596            {0x1e5, 15}, {0x1e6, 15}, {0x1e7, 15}, {0x1e8, 15},
1597            {0x1e9, 15}, {0x1ea, 15}, {0x1eb, 15}, {0x1ec, 15},
1598            {0x1ed, 15}, {0x1ee, 15}, {0x1ef, 15}, {0x1f0, 15},
1599            {0x1f1, 15}, {0x1f2, 15}, {0x1f3, 15}, {0x1f4, 15},
1600            {0x1f5, 15}, {0x1f6, 15}, {0x1f7, 15}, {0x1f8, 15},
1601            {0x1f9, 15}, {0x1fa, 15}, {0x1fb, 15}, {0x1fc, 15},
1602            {0x1fd, 15}, {0x1fe, 15}, {0x1ff, 15},
1603    };
1604    
1605    const VLC dcc_tab[511] = {
1606            {0x100, 16}, {0x101, 16}, {0x102, 16}, {0x103, 16},
1607            {0x104, 16}, {0x105, 16}, {0x106, 16}, {0x107, 16},
1608            {0x108, 16}, {0x109, 16}, {0x10a, 16}, {0x10b, 16},
1609            {0x10c, 16}, {0x10d, 16}, {0x10e, 16}, {0x10f, 16},
1610            {0x110, 16}, {0x111, 16}, {0x112, 16}, {0x113, 16},
1611            {0x114, 16}, {0x115, 16}, {0x116, 16}, {0x117, 16},
1612            {0x118, 16}, {0x119, 16}, {0x11a, 16}, {0x11b, 16},
1613            {0x11c, 16}, {0x11d, 16}, {0x11e, 16}, {0x11f, 16},
1614            {0x120, 16}, {0x121, 16}, {0x122, 16}, {0x123, 16},
1615            {0x124, 16}, {0x125, 16}, {0x126, 16}, {0x127, 16},
1616            {0x128, 16}, {0x129, 16}, {0x12a, 16}, {0x12b, 16},
1617            {0x12c, 16}, {0x12d, 16}, {0x12e, 16}, {0x12f, 16},
1618            {0x130, 16}, {0x131, 16}, {0x132, 16}, {0x133, 16},
1619            {0x134, 16}, {0x135, 16}, {0x136, 16}, {0x137, 16},
1620            {0x138, 16}, {0x139, 16}, {0x13a, 16}, {0x13b, 16},
1621            {0x13c, 16}, {0x13d, 16}, {0x13e, 16}, {0x13f, 16},
1622            {0x140, 16}, {0x141, 16}, {0x142, 16}, {0x143, 16},
1623            {0x144, 16}, {0x145, 16}, {0x146, 16}, {0x147, 16},
1624            {0x148, 16}, {0x149, 16}, {0x14a, 16}, {0x14b, 16},
1625            {0x14c, 16}, {0x14d, 16}, {0x14e, 16}, {0x14f, 16},
1626            {0x150, 16}, {0x151, 16}, {0x152, 16}, {0x153, 16},
1627            {0x154, 16}, {0x155, 16}, {0x156, 16}, {0x157, 16},
1628            {0x158, 16}, {0x159, 16}, {0x15a, 16}, {0x15b, 16},
1629            {0x15c, 16}, {0x15d, 16}, {0x15e, 16}, {0x15f, 16},
1630            {0x160, 16}, {0x161, 16}, {0x162, 16}, {0x163, 16},
1631            {0x164, 16}, {0x165, 16}, {0x166, 16}, {0x167, 16},
1632            {0x168, 16}, {0x169, 16}, {0x16a, 16}, {0x16b, 16},
1633            {0x16c, 16}, {0x16d, 16}, {0x16e, 16}, {0x16f, 16},
1634            {0x170, 16}, {0x171, 16}, {0x172, 16}, {0x173, 16},
1635            {0x174, 16}, {0x175, 16}, {0x176, 16}, {0x177, 16},
1636            {0x178, 16}, {0x179, 16}, {0x17a, 16}, {0x17b, 16},
1637            {0x17c, 16}, {0x17d, 16}, {0x17e, 16}, {0x17f, 16},
1638            {0x80, 14}, {0x81, 14}, {0x82, 14}, {0x83, 14},
1639            {0x84, 14}, {0x85, 14}, {0x86, 14}, {0x87, 14},
1640            {0x88, 14}, {0x89, 14}, {0x8a, 14}, {0x8b, 14},
1641            {0x8c, 14}, {0x8d, 14}, {0x8e, 14}, {0x8f, 14},
1642            {0x90, 14}, {0x91, 14}, {0x92, 14}, {0x93, 14},
1643            {0x94, 14}, {0x95, 14}, {0x96, 14}, {0x97, 14},
1644            {0x98, 14}, {0x99, 14}, {0x9a, 14}, {0x9b, 14},
1645            {0x9c, 14}, {0x9d, 14}, {0x9e, 14}, {0x9f, 14},
1646            {0xa0, 14}, {0xa1, 14}, {0xa2, 14}, {0xa3, 14},
1647            {0xa4, 14}, {0xa5, 14}, {0xa6, 14}, {0xa7, 14},
1648            {0xa8, 14}, {0xa9, 14}, {0xaa, 14}, {0xab, 14},
1649            {0xac, 14}, {0xad, 14}, {0xae, 14}, {0xaf, 14},
1650            {0xb0, 14}, {0xb1, 14}, {0xb2, 14}, {0xb3, 14},
1651            {0xb4, 14}, {0xb5, 14}, {0xb6, 14}, {0xb7, 14},
1652            {0xb8, 14}, {0xb9, 14}, {0xba, 14}, {0xbb, 14},
1653            {0xbc, 14}, {0xbd, 14}, {0xbe, 14}, {0xbf, 14},
1654            {0x40, 12}, {0x41, 12}, {0x42, 12}, {0x43, 12},
1655            {0x44, 12}, {0x45, 12}, {0x46, 12}, {0x47, 12},
1656            {0x48, 12}, {0x49, 12}, {0x4a, 12}, {0x4b, 12},
1657            {0x4c, 12}, {0x4d, 12}, {0x4e, 12}, {0x4f, 12},
1658            {0x50, 12}, {0x51, 12}, {0x52, 12}, {0x53, 12},
1659            {0x54, 12}, {0x55, 12}, {0x56, 12}, {0x57, 12},
1660            {0x58, 12}, {0x59, 12}, {0x5a, 12}, {0x5b, 12},
1661            {0x5c, 12}, {0x5d, 12}, {0x5e, 12}, {0x5f, 12},
1662            {0x20, 10}, {0x21, 10}, {0x22, 10}, {0x23, 10},
1663            {0x24, 10}, {0x25, 10}, {0x26, 10}, {0x27, 10},
1664            {0x28, 10}, {0x29, 10}, {0x2a, 10}, {0x2b, 10},
1665            {0x2c, 10}, {0x2d, 10}, {0x2e, 10}, {0x2f, 10},
1666            {0x10, 8}, {0x11, 8}, {0x12, 8}, {0x13, 8},
1667            {0x14, 8}, {0x15, 8}, {0x16, 8}, {0x17, 8},
1668            {0x08, 6}, {0x09, 6}, {0x0a, 6}, {0x0b, 6},
1669            {0x04, 4}, {0x05, 4}, {0x04, 3}, {0x03, 2},
1670            {0x05, 3}, {0x06, 4}, {0x07, 4}, {0x0c, 6},
1671            {0x0d, 6}, {0x0e, 6}, {0x0f, 6}, {0x18, 8},
1672            {0x19, 8}, {0x1a, 8}, {0x1b, 8}, {0x1c, 8},
1673            {0x1d, 8}, {0x1e, 8}, {0x1f, 8}, {0x30, 10},
1674            {0x31, 10}, {0x32, 10}, {0x33, 10}, {0x34, 10},
1675            {0x35, 10}, {0x36, 10}, {0x37, 10}, {0x38, 10},
1676            {0x39, 10}, {0x3a, 10}, {0x3b, 10}, {0x3c, 10},
1677            {0x3d, 10}, {0x3e, 10}, {0x3f, 10}, {0x60, 12},
1678            {0x61, 12}, {0x62, 12}, {0x63, 12}, {0x64, 12},
1679            {0x65, 12}, {0x66, 12}, {0x67, 12}, {0x68, 12},
1680            {0x69, 12}, {0x6a, 12}, {0x6b, 12}, {0x6c, 12},
1681            {0x6d, 12}, {0x6e, 12}, {0x6f, 12}, {0x70, 12},
1682            {0x71, 12}, {0x72, 12}, {0x73, 12}, {0x74, 12},
1683            {0x75, 12}, {0x76, 12}, {0x77, 12}, {0x78, 12},
1684            {0x79, 12}, {0x7a, 12}, {0x7b, 12}, {0x7c, 12},
1685            {0x7d, 12}, {0x7e, 12}, {0x7f, 12}, {0xc0, 14},
1686            {0xc1, 14}, {0xc2, 14}, {0xc3, 14}, {0xc4, 14},
1687            {0xc5, 14}, {0xc6, 14}, {0xc7, 14}, {0xc8, 14},
1688            {0xc9, 14}, {0xca, 14}, {0xcb, 14}, {0xcc, 14},
1689            {0xcd, 14}, {0xce, 14}, {0xcf, 14}, {0xd0, 14},
1690            {0xd1, 14}, {0xd2, 14}, {0xd3, 14}, {0xd4, 14},
1691            {0xd5, 14}, {0xd6, 14}, {0xd7, 14}, {0xd8, 14},
1692            {0xd9, 14}, {0xda, 14}, {0xdb, 14}, {0xdc, 14},
1693            {0xdd, 14}, {0xde, 14}, {0xdf, 14}, {0xe0, 14},
1694            {0xe1, 14}, {0xe2, 14}, {0xe3, 14}, {0xe4, 14},
1695            {0xe5, 14}, {0xe6, 14}, {0xe7, 14}, {0xe8, 14},
1696            {0xe9, 14}, {0xea, 14}, {0xeb, 14}, {0xec, 14},
1697            {0xed, 14}, {0xee, 14}, {0xef, 14}, {0xf0, 14},
1698            {0xf1, 14}, {0xf2, 14}, {0xf3, 14}, {0xf4, 14},
1699            {0xf5, 14}, {0xf6, 14}, {0xf7, 14}, {0xf8, 14},
1700            {0xf9, 14}, {0xfa, 14}, {0xfb, 14}, {0xfc, 14},
1701            {0xfd, 14}, {0xfe, 14}, {0xff, 14}, {0x180, 16},
1702            {0x181, 16}, {0x182, 16}, {0x183, 16}, {0x184, 16},
1703            {0x185, 16}, {0x186, 16}, {0x187, 16}, {0x188, 16},
1704            {0x189, 16}, {0x18a, 16}, {0x18b, 16}, {0x18c, 16},
1705            {0x18d, 16}, {0x18e, 16}, {0x18f, 16}, {0x190, 16},
1706            {0x191, 16}, {0x192, 16}, {0x193, 16}, {0x194, 16},
1707            {0x195, 16}, {0x196, 16}, {0x197, 16}, {0x198, 16},
1708            {0x199, 16}, {0x19a, 16}, {0x19b, 16}, {0x19c, 16},
1709            {0x19d, 16}, {0x19e, 16}, {0x19f, 16}, {0x1a0, 16},
1710            {0x1a1, 16}, {0x1a2, 16}, {0x1a3, 16}, {0x1a4, 16},
1711            {0x1a5, 16}, {0x1a6, 16}, {0x1a7, 16}, {0x1a8, 16},
1712            {0x1a9, 16}, {0x1aa, 16}, {0x1ab, 16}, {0x1ac, 16},
1713            {0x1ad, 16}, {0x1ae, 16}, {0x1af, 16}, {0x1b0, 16},
1714            {0x1b1, 16}, {0x1b2, 16}, {0x1b3, 16}, {0x1b4, 16},
1715            {0x1b5, 16}, {0x1b6, 16}, {0x1b7, 16}, {0x1b8, 16},
1716            {0x1b9, 16}, {0x1ba, 16}, {0x1bb, 16}, {0x1bc, 16},
1717            {0x1bd, 16}, {0x1be, 16}, {0x1bf, 16}, {0x1c0, 16},
1718            {0x1c1, 16}, {0x1c2, 16}, {0x1c3, 16}, {0x1c4, 16},
1719            {0x1c5, 16}, {0x1c6, 16}, {0x1c7, 16}, {0x1c8, 16},
1720            {0x1c9, 16}, {0x1ca, 16}, {0x1cb, 16}, {0x1cc, 16},
1721            {0x1cd, 16}, {0x1ce, 16}, {0x1cf, 16}, {0x1d0, 16},
1722            {0x1d1, 16}, {0x1d2, 16}, {0x1d3, 16}, {0x1d4, 16},
1723            {0x1d5, 16}, {0x1d6, 16}, {0x1d7, 16}, {0x1d8, 16},
1724            {0x1d9, 16}, {0x1da, 16}, {0x1db, 16}, {0x1dc, 16},
1725            {0x1dd, 16}, {0x1de, 16}, {0x1df, 16}, {0x1e0, 16},
1726            {0x1e1, 16}, {0x1e2, 16}, {0x1e3, 16}, {0x1e4, 16},
1727            {0x1e5, 16}, {0x1e6, 16}, {0x1e7, 16}, {0x1e8, 16},
1728            {0x1e9, 16}, {0x1ea, 16}, {0x1eb, 16}, {0x1ec, 16},
1729            {0x1ed, 16}, {0x1ee, 16}, {0x1ef, 16}, {0x1f0, 16},
1730            {0x1f1, 16}, {0x1f2, 16}, {0x1f3, 16}, {0x1f4, 16},
1731            {0x1f5, 16}, {0x1f6, 16}, {0x1f7, 16}, {0x1f8, 16},
1732            {0x1f9, 16}, {0x1fa, 16}, {0x1fb, 16}, {0x1fc, 16},
1733            {0x1fd, 16}, {0x1fe, 16}, {0x1ff, 16},
1734    };
1735    
1736    
1737    const VLC mb_motion_table[65] = {
1738            {0x05, 13}, {0x07, 13}, {0x05, 12}, {0x07, 12},
1739            {0x09, 12}, {0x0b, 12}, {0x0d, 12}, {0x0f, 12},
1740            {0x09, 11}, {0x0b, 11}, {0x0d, 11}, {0x0f, 11},
1741            {0x11, 11}, {0x13, 11}, {0x15, 11}, {0x17, 11},
1742            {0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11},
1743            {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10},
1744            {0x17, 10}, {0x07, 8}, {0x09, 8}, {0x0b, 8},
1745            {0x07, 7}, {0x03, 5}, {0x03, 4}, {0x03, 3},
1746            {0x01, 1}, {0x02, 3}, {0x02, 4}, {0x02, 5},
1747            {0x06, 7}, {0x0a, 8}, {0x08, 8}, {0x06, 8},
1748            {0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11},
1749            {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11},
1750            {0x18, 11}, {0x16, 11}, {0x14, 11}, {0x12, 11},
1751            {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},
1752            {0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12},
1753            {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},
1754            {0x04, 13}
1755    };
1756    
1757    
1758    /******************************************************************
1759     * decoder tables                                                 *
1760     ******************************************************************/
1761    
1762    VLC const mcbpc_intra_table[64] = {
1763            {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4},  {4, 4},  {4, 4},  {4, 4},
1764            {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
1765            {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},
1766            {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3},
1767            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1768            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1769            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1770            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1}
1771    };
1772    
1773    VLC const mcbpc_inter_table[257] = {
1774            {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},
1775            {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},
1776            {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
1777            {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
1778            {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
1779            {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6},
1780            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1781            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1782            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1783            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1784            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1785            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1786            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1787            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1788            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1789            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1790            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1791            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1792            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1793            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1794            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1795            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1796            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1797            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1798            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1799            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1800            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1801            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1802            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1803            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1804            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1805            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1806            {0, 1}
1807    };
1808    
1809    VLC const cbpy_table[64] = {
1810            {-1, 0}, {-1, 0}, {6, 6},  {9, 6},  {8, 5},  {8, 5},  {4, 5},  {4, 5},
1811            {2, 5},  {2, 5},  {1, 5},  {1, 5},  {0, 4},  {0, 4},  {0, 4},  {0, 4},
1812            {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
1813            {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4},  {5, 4},  {5, 4},  {5, 4},
1814            {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4},  {3, 4},  {3, 4},  {3, 4},
1815            {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4},  {7, 4},  {7, 4},  {7, 4},
1816            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
1817            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}
1818    };
1819    
1820    VLC const TMNMVtab0[] = {
1821            {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},
1822            {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}
1823    };
1824    
1825    VLC const TMNMVtab1[] = {
1826            {12, 10}, {-12, 10}, {11, 10}, {-11, 10},
1827            {10, 9}, {10, 9}, {-10, 9}, {-10, 9},
1828            {9, 9}, {9, 9}, {-9, 9}, {-9, 9},
1829            {8, 9}, {8, 9}, {-8, 9}, {-8, 9},
1830            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1831            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1832            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1833            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1834            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1835            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1836            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
1837            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
1838            {5, 7}, {5, 7}, {5, 7}, {5, 7},
1839            {5, 7}, {5, 7}, {5, 7}, {5, 7},
1840            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
1841            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
1842            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1843            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1844            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1845            {4, 6}, {4, 6}, {4, 6}, {4, 6},
1846            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1847            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1848            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
1849            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}
1850    };
1851    
1852    VLC const TMNMVtab2[] = {
1853            {32, 12}, {-32, 12}, {31, 12}, {-31, 12},
1854            {30, 11}, {30, 11}, {-30, 11}, {-30, 11},
1855            {29, 11}, {29, 11}, {-29, 11}, {-29, 11},
1856            {28, 11}, {28, 11}, {-28, 11}, {-28, 11},
1857            {27, 11}, {27, 11}, {-27, 11}, {-27, 11},
1858            {26, 11}, {26, 11}, {-26, 11}, {-26, 11},
1859            {25, 11}, {25, 11}, {-25, 11}, {-25, 11},
1860            {24, 10}, {24, 10}, {24, 10}, {24, 10},
1861            {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10},
1862            {23, 10}, {23, 10}, {23, 10}, {23, 10},
1863            {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10},
1864            {22, 10}, {22, 10}, {22, 10}, {22, 10},
1865            {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10},
1866            {21, 10}, {21, 10}, {21, 10}, {21, 10},
1867            {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10},
1868            {20, 10}, {20, 10}, {20, 10}, {20, 10},
1869            {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10},
1870            {19, 10}, {19, 10}, {19, 10}, {19, 10},
1871            {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10},
1872            {18, 10}, {18, 10}, {18, 10}, {18, 10},
1873            {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10},
1874            {17, 10}, {17, 10}, {17, 10}, {17, 10},
1875            {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10},
1876            {16, 10}, {16, 10}, {16, 10}, {16, 10},
1877            {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10},
1878            {15, 10}, {15, 10}, {15, 10}, {15, 10},
1879            {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10},
1880            {14, 10}, {14, 10}, {14, 10}, {14, 10},
1881            {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10},
1882            {13, 10}, {13, 10}, {13, 10}, {13, 10},
1883            {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}
1884    };
1885    
1886    short const dc_threshold[] = {
1887            21514, 26984,  8307, 28531, 29798, 24951, 25970, 26912,
1888             8307, 25956, 26994, 25974,  8292, 29286, 28015, 29728,
1889            25960, 18208, 21838, 18208, 19536, 22560, 26998,  8260,
1890            28515, 25956,  8291, 25640, 30309, 27749, 11817, 22794,
1891            30063,  8306, 28531, 29798, 24951, 25970, 25632, 29545,
1892            29300, 25193, 29813, 29295, 26656, 29537, 29728,  8303,
1893            26983, 25974, 24864, 25443, 29541,  8307, 28532, 26912,
1894            29556, 29472, 30063, 25458,  8293, 28515, 25956,  2606
1895    };
1896    
1897    VLC const dc_lum_tab[] = {
1898            {0, 0}, {4, 3}, {3, 3}, {0, 3},
1899            {2, 2}, {2, 2}, {1, 2}, {1, 2},
1900    };

Legend:
Removed from v.451  
changed lines
  Added in v.1537

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