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

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

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

revision 1.37, Sun Jan 5 16:54:36 2003 UTC revision 1.44.2.8, Fri May 9 22:02:23 2003 UTC
# Line 1  Line 1 
1  /*****************************************************************************   /******************************************************************************
2   *    *                                                                            *
3   *  XVID MPEG-4 VIDEO CODEC    *  This file is part of XviD, a free MPEG-4 video encoder/decoder            *
4   *  - Macro Block coding functions -    *                                                                            *
5   *    *  XviD is an implementation of a part of one or more MPEG-4 Video tools     *
6   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>    *  as specified in ISO/IEC 14496-2 standard.  Those intending to use this    *
7   *    *  software module in hardware or software products are advised that its     *
8   *  This file is part of XviD, a free MPEG-4 video encoder/decoder    *  use may infringe existing patents or copyrights, and any such use         *
9   *    *  would be at such party's own risk.  The original developer of this        *
10   *  XviD is free software; you can redistribute it and/or modify it    *  software module and his/her company, and subsequent editors and their     *
11   *  under the terms of the GNU General Public License as published by    *  companies, will have no liability for use of this software or             *
12   *  the Free Software Foundation; either version 2 of the License, or    *  modifications or derivatives thereof.                                     *
13   *  (at your option) any later version.    *                                                                            *
14   *    *  XviD is free software; you can redistribute it and/or modify it           *
15   *  This program is distributed in the hope that it will be useful,    *  under the terms of the GNU General Public License as published by         *
16   *  but WITHOUT ANY WARRANTY; without even the implied warranty of    *  the Free Software Foundation; either version 2 of the License, or         *
17   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *  (at your option) any later version.                                       *
18   *  GNU General Public License for more details.    *                                                                            *
19   *    *  XviD is distributed in the hope that it will be useful, but               *
20   *  You should have received a copy of the GNU General Public License    *  WITHOUT ANY WARRANTY; without even the implied warranty of                *
21   *  along with this program; if not, write to the Free Software    *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
22   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    *  GNU General Public License for more details.                              *
23   *    *                                                                            *
24   *  Under section 8 of the GNU General Public License, the copyright    *  You should have received a copy of the GNU General Public License         *
25   *  holders of XVID explicitly forbid distribution in the following    *  along with this program; if not, write to the Free Software               *
26   *  countries:    *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
27   *    *                                                                            *
28   *    - Japan    ******************************************************************************/
29   *    - United States of America  
30   *   /******************************************************************************
31   *  Linking XviD statically or dynamically with other modules is making a    *                                                                            *
32   *  combined work based on XviD.  Thus, the terms and conditions of the    *  mbcoding.c                                                                *
33   *  GNU General Public License cover the whole combination.    *                                                                            *
34   *    *  Copyright (C) 2002 - Michael Militzer <isibaar@xvid.org>                  *
35   *  As a special exception, the copyright holders of XviD give you    *                                                                            *
36   *  permission to link XviD with independent modules that communicate with    *  For more information visit the XviD homepage: http://www.xvid.org         *
37   *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the    *                                                                            *
38   *  license terms of these independent modules, and to copy and distribute    ******************************************************************************/
39   *  the resulting combined work under terms of your choice, provided that  
40   *  every copy of the combined work is accompanied by a complete copy of   /******************************************************************************
41   *  the source code of XviD (the version of XviD used to produce the    *                                                                                                                                                        *
42   *  combined work), being distributed under the terms of the GNU General    *  Revision history:                                                         *
43   *  Public License plus this exception.  An independent module is a module    *                                                                            *
44   *  which is not derived from or based on XviD.    *  28.10.2002 GMC support - gruel                                                                                        *
45   *    *  28.06.2002 added check_resync_marker()                                    *
46   *  Note that people who make modified versions of XviD are not obligated    *  14.04.2002 bframe encoding                                                                                            *
47   *  to grant this special exception for their modified versions; it is    *  08.03.2002 initial version; isibaar                                                           *
48   *  their choice whether to do so.  The GNU General Public License gives    *                                                                                                                                                        *
49   *  permission to release a modified version without this exception; this    ******************************************************************************/
50   *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
  *  
  * $Id$  
  *  
  ****************************************************************************/  
51    
52    #include <stdio.h>
53  #include <stdlib.h>  #include <stdlib.h>
54    #include <string.h>
55    
56  #include "../portab.h"  #include "../portab.h"
57    #include "../global.h"
58  #include "bitstream.h"  #include "bitstream.h"
59  #include "zigzag.h"  #include "zigzag.h"
60  #include "vlc_codes.h"  #include "vlc_codes.h"
# Line 63  Line 62 
62    
63  #include "../utils/mbfunctions.h"  #include "../utils/mbfunctions.h"
64    
65  #define ABS(X) (((X)>0)?(X):-(X))  /* #define BIGLUT */
 #define CLIP(X,A) (X > A) ? (A) : (X)  
   
 /*#define _BIGLUT_*/  
66    
67  #ifdef _BIGLUT_  #ifdef BIGLUT
68  #define LEVELOFFSET 2048  #define LEVELOFFSET 2048
69  #else  #else
70  #define LEVELOFFSET 32  #define LEVELOFFSET 32
71  #endif  #endif
72    
 /*****************************************************************************  
  * Local data  
  ****************************************************************************/  
   
73  static REVERSE_EVENT DCT3D[2][4096];  static REVERSE_EVENT DCT3D[2][4096];
74    
75  #ifdef _BIGLUT_  #ifdef BIGLUT
76  static VLC coeff_VLC[2][2][4096][64];  static VLC coeff_VLC[2][2][4096][64];
77  VLC *intra_table, *inter_table;  VLC *intra_table;
78    static VLC *inter_table;
79  #else  #else
80  static VLC coeff_VLC[2][2][64][64];  static VLC coeff_VLC[2][2][64][64];
81  #endif  #endif
82    
83  /*****************************************************************************  /* not really MB related, but VLCs are only available here */
84   * Vector Length Coding Initialization  void bs_put_spritetrajectory(Bitstream * bs, const int val)
85   ****************************************************************************/  {
86            const int code = sprite_trajectory_code[val+16384].code;
87            const int len = sprite_trajectory_code[val+16384].len;
88            const int code2 = sprite_trajectory_len[len].code;
89            const int len2 = sprite_trajectory_len[len].len;
90    
91    //      printf("GMC=%d Code/Len  = %d / %d ",val, code,len);
92    //      printf("Code2 / Len2 = %d / %d \n",code2,len2);
93    
94            BitstreamPutBits(bs, code2, len2);
95            if (len) BitstreamPutBits(bs, code, len);
96    }
97    
98    int bs_get_spritetrajectory(Bitstream * bs)
99    {
100            int i;
101            for (i = 0; i < 12; i++)
102            {
103                    if (BitstreamShowBits(bs, sprite_trajectory_len[i].len) == sprite_trajectory_len[i].code)
104                    {
105                            BitstreamSkip(bs, sprite_trajectory_len[i].len);
106                            return i;
107                    }
108            }
109            return -1;
110    }
111    
112  void  void
113  init_vlc_tables(void)  init_vlc_tables(void)
114  {  {
115          uint32_t i, j, intra, last, run, offset;          uint32_t i, j, k, intra, last, run,  run_esc, level, level_esc, escape, escape_len, offset;
116          int32_t level;          int32_t l;
         VLC coeff_VLC_temp[2][2][64][64];  
117    
118  #ifdef _BIGLUT_  #ifdef BIGLUT
119          intra_table = coeff_VLC[1];          intra_table = coeff_VLC[1];
120          inter_table = coeff_VLC[0];          inter_table = coeff_VLC[0];
121  #endif  #endif
# Line 112  Line 129 
129                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++)
130                  {                  {
131                          for (run = 0; run < 63 + last; run++)                          for (run = 0; run < 63 + last; run++)
132                                  for (level = 0; level < 32 << intra; level++)                                  for (level = 0; level < (uint32_t)(32 << intra); level++)
133                                  {                                  {
134  #ifdef _BIGLUT_  #ifdef BIGLUT
135                                          offset = LEVELOFFSET;                                          offset = LEVELOFFSET;
136  #else  #else
137                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
138  #endif  #endif
                                         coeff_VLC_temp[intra][last][level][run].len             = 128;  
139                                          coeff_VLC[intra][last][level + offset][run].len = 128;                                          coeff_VLC[intra][last][level + offset][run].len = 128;
140                                  }                                  }
141                  }                  }
# Line 127  Line 143 
143          for (intra = 0; intra < 2; intra++)          for (intra = 0; intra < 2; intra++)
144                  for (i = 0; i < 102; i++)                  for (i = 0; i < 102; i++)
145                  {                  {
146  #ifdef _BIGLUT_  #ifdef BIGLUT
147                          offset = LEVELOFFSET;                          offset = LEVELOFFSET;
148  #else  #else
149                          offset = !intra * LEVELOFFSET;                          offset = !intra * LEVELOFFSET;
150  #endif  #endif
151                          for (j = 0; j < 1 << (12 - coeff_tab[intra][i].vlc.len); j++)                          for (j = 0; j < (uint32_t)(1 << (12 - coeff_tab[intra][i].vlc.len)); j++)
152                          {                          {
153                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len       = coeff_tab[intra][i].vlc.len;
154                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;                                  DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event;
155                          }                          }
156    
                         coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code  
                                 = coeff_tab[intra][i].vlc.code << 1;  
                         coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len  
                                 = coeff_tab[intra][i].vlc.len + 1;  
   
157                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code
158                                  = coeff_tab[intra][i].vlc.code << 1;                                  = coeff_tab[intra][i].vlc.code << 1;
159                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len                          coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len
160                                  = coeff_tab[intra][i].vlc.len + 1;                                  = coeff_tab[intra][i].vlc.len + 1;
161  #ifndef _BIGLUT_  #ifndef BIGLUT
162                          if (!intra)                          if (!intra)
163  #endif  #endif
164                          {                          {
# Line 162  Line 173 
173                  for (last = 0; last < 2; last++)                  for (last = 0; last < 2; last++)
174                          for (run = 0; run < 63 + last; run++)                          for (run = 0; run < 63 + last; run++)
175                          {                          {
176                                  for (level = 1; level < 32 << intra; level++)                                  for (level = 1; level < (uint32_t)(32 << intra); level++)
177                                  {                                  {
178  #ifdef _BIGLUT_                                          if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level])
179                                                continue;
180    
181    #ifdef BIGLUT
182                                          offset = LEVELOFFSET;                                          offset = LEVELOFFSET;
183  #else  #else
184                                          offset = !intra * LEVELOFFSET;                                          offset = !intra * LEVELOFFSET;
185  #endif  #endif
186                                          if ((max_level[intra][last][run]) && (level > max_level[intra][last][run]))                      level_esc = level - max_level[intra][last][run];
187                                                  if (coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len != 128                                          run_esc = run - 1 - max_run[intra][last][level];
188                                                          && coeff_VLC[intra][last][level + offset][run].len == 128)                                          /*use this test to use shorter esc2 codes when possible
189                                            if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]
190                                                    && !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1
191                                                             > coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/
192    
193                                            if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc])
194                                            {
195                                                    escape     = ESCAPE1;
196                                                    escape_len = 7 + 1;
197                                                    run_esc    = run;
198                                            }
199                                            else
200                                                  {                                                  {
201                                                          coeff_VLC[intra][last][level + offset][run].code                                                  if (run_esc <= max_run[intra][last][level] && level <= max_level[intra][last][run_esc])
202                                                                  = (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len)                                                  {
203                                                                  |  coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code;                                                          escape     = ESCAPE2;
204                                                          coeff_VLC[intra][last][level + offset][run].len                                                          escape_len = 7 + 2;
205                                                                  = coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1;                                                          level_esc  = level;
206  #ifndef _BIGLUT_                                                  }
207                                                    else
208                                                    {
209    #ifndef BIGLUT
210                                                          if (!intra)                                                          if (!intra)
211  #endif  #endif
212                                                          {                                                          {
213                                                                    coeff_VLC[intra][last][level + offset][run].code
214                                                                            = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;
215                                                                    coeff_VLC[intra][last][level + offset][run].len = 30;
216                                                                  coeff_VLC[intra][last][offset - level][run].code                                                                  coeff_VLC[intra][last][offset - level][run].code
217                                                                          = (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len)                                                                          = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-(int32_t)level & 0xfff) << 1) | 1;
218                                                                          |  coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code | 1;                                                                  coeff_VLC[intra][last][offset - level][run].len = 30;
                                                                 coeff_VLC[intra][last][offset - level][run].len  
                                                                         = coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1;  
219                                                          }                                                          }
220                                                            continue;
221                                                  }                                                  }
222                                          if (run > max_run[intra][last][level])                                          }
223                                                  if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len != 128  
                                                         && coeff_VLC[intra][last][level + offset][run].len == 128)  
                                                 /*use the lower test instead of the upper to use shorter escape codes when possible :  
                                                 if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2  
                                                         < coeff_VLC[intra][last][level + offset][run].len)*/  
                                                 {  
224                                                          coeff_VLC[intra][last][level + offset][run].code                                                          coeff_VLC[intra][last][level + offset][run].code
225                                                                  = (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len)                                                  = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
226                                                                  |  coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code;                                                  |  coeff_VLC[intra][last][level_esc + offset][run_esc].code;
227                                                          coeff_VLC[intra][last][level + offset][run].len                                                          coeff_VLC[intra][last][level + offset][run].len
228                                                                  = coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2;                                                  = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
229  #ifndef _BIGLUT_  #ifndef BIGLUT
230                                                          if (!intra)                                                          if (!intra)
231  #endif  #endif
232                                                          {                                                          {
233                                                                  coeff_VLC[intra][last][offset - level][run].code                                                                  coeff_VLC[intra][last][offset - level][run].code
234                                                                          = (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len)                                                          = (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len)
235                                                                          |  coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code | 1;                                                          |  coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1;
236                                                                  coeff_VLC[intra][last][offset - level][run].len                                                                  coeff_VLC[intra][last][offset - level][run].len
237                                                                          = coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2;                                                          = coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len;
238                                                          }                                                          }
239                                                  }                                                  }
 #ifndef _BIGLUT_  
                                         if (!intra)  
 #endif  
                                                 if (coeff_VLC[intra][last][level + offset][run].len == 128)  
                                                 {  
                                                         coeff_VLC[intra][last][level + offset][run].code  
                                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1;  
                                                         coeff_VLC[intra][last][level + offset][run].len = 30;  
240    
241                                                          coeff_VLC[intra][last][offset - level][run].code  #ifdef BIGLUT
                                                                 = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1;  
                                                         coeff_VLC[intra][last][offset - level][run].len = 30;  
                                                 }  
                                 }  
 #ifdef _BIGLUT_  
242                                  for (level = 32 << intra; level < 2048; level++)                                  for (level = 32 << intra; level < 2048; level++)
243                                  {                                  {
244                                          coeff_VLC[intra][last][level + offset][run].code                                          coeff_VLC[intra][last][level + offset][run].code
# Line 246  Line 258 
258                                  }                                  }
259  #endif  #endif
260                          }                          }
261    /* init sprite_trajectory tables */
262    /* even if GMC is not specified (it might be used later...) */
263    
264            sprite_trajectory_code[0+16384].code = 0;
265            sprite_trajectory_code[0+16384].len = 0;
266            for (k=0;k<14;k++)
267            {
268                    int limit = (1<<k);
269    
270                    for (l=-(2*limit-1); l <= -limit; l++)
271                    {
272                            sprite_trajectory_code[l+16384].code = (2*limit-1)+l;
273                            sprite_trajectory_code[l+16384].len = k+1;
274  }  }
275    
276  /*****************************************************************************                  for (l=limit; l<= 2*limit-1; l++)
277   * Local inlined functions for MB coding                  {
278   ****************************************************************************/                          sprite_trajectory_code[l+16384].code = l;
279                            sprite_trajectory_code[l+16384].len = k+1;
280                    }
281            }
282    }
283    
284  static __inline void  static __inline void
285  CodeVector(Bitstream * bs,  CodeVector(Bitstream * bs,
# Line 307  Line 336 
336    
337  }  }
338    
339  #ifdef __BIGLUT_  #ifdef BIGLUT
340    
341  static __inline void  static __inline void
342  CodeCoeff(Bitstream * bs,  CodeCoeff(Bitstream * bs,
# Line 347  Line 376 
376    
377  }  }
378    
379    
380    
381    /* returns the number of bits required to encode qcoeff */
382    int
383    CodeCoeff_CalcBits(const int16_t qcoeff[64],
384                      VLC * table,
385                      const uint16_t * zigzag,
386                      uint16_t intra)
387    {
388            int bits = 0;
389            uint32_t j, last;
390            short v;
391            VLC *vlc;
392    
393            j = intra;
394            last = intra;
395    
396            while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
397                    j++;
398    
399            if (j >= 64) return 0;  /* empty block */
400    
401            do {
402                    vlc = table + 64 * 2048 + (v << 6) + j - last;
403                    last = ++j;
404    
405                    /* count zeroes */
406                    while (j < 64 && (v = qcoeff[zigzag[j]]) == 0)
407                            j++;
408    
409                    /* write code */
410                    if (j != 64) {
411                            bits += vlc->len;
412                    } else {
413                            vlc += 64 * 4096;
414                            bits += vlc->len;
415                            break;
416                    }
417            } while (1);
418    
419            return bits;
420    }
421    
422    
423  #else  #else
424    
425  static __inline void  static __inline void
# Line 416  Line 489 
489          i       = 1;          i       = 1;
490          run = 0;          run = 0;
491    
492          while (!(level = qcoeff[zigzag[i++]]))          while (i<64 && !(level = qcoeff[zigzag[i++]]))
493                  run++;                  run++;
494    
495          prev_level = level;          prev_level = level;
# Line 427  Line 500 
500          {          {
501                  if ((level = qcoeff[zigzag[i++]]) != 0)                  if ((level = qcoeff[zigzag[i++]]) != 0)
502                  {                  {
503                          abs_level = ABS(prev_level);                          abs_level = abs(prev_level);
504                          abs_level = abs_level < 64 ? abs_level : 0;                          abs_level = abs_level < 64 ? abs_level : 0;
505                          code      = coeff_VLC[1][0][abs_level][prev_run].code;                          code      = coeff_VLC[1][0][abs_level][prev_run].code;
506                          len               = coeff_VLC[1][0][abs_level][prev_run].len;                          len               = coeff_VLC[1][0][abs_level][prev_run].len;
# Line 447  Line 520 
520                          run++;                          run++;
521          }          }
522    
523          abs_level = ABS(prev_level);          abs_level = abs(prev_level);
524          abs_level = abs_level < 64 ? abs_level : 0;          abs_level = abs_level < 64 ? abs_level : 0;
525          code      = coeff_VLC[1][1][abs_level][prev_run].code;          code      = coeff_VLC[1][1][abs_level][prev_run].code;
526          len               = coeff_VLC[1][1][abs_level][prev_run].len;          len               = coeff_VLC[1][1][abs_level][prev_run].len;
# Line 461  Line 534 
534          BitstreamPutBits(bs, code, len);          BitstreamPutBits(bs, code, len);
535  }  }
536    
537    
538    
539    /* returns the number of bits required to encode qcoeff */
540    
541    int
542    CodeCoeffIntra_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
543    {
544            int bits = 0;
545            uint32_t i, abs_level, run, prev_run, len;
546            int32_t level, prev_level;
547    
548            i       = 1;
549            run = 0;
550    
551            while (i<64 && !(level = qcoeff[zigzag[i++]]))
552                    run++;
553    
554            if (i >= 64) return 0;  /* empty block */
555    
556            prev_level = level;
557            prev_run   = run;
558            run = 0;
559    
560            while (i < 64)
561            {
562                    if ((level = qcoeff[zigzag[i++]]) != 0)
563                    {
564                            abs_level = abs(prev_level);
565                            abs_level = abs_level < 64 ? abs_level : 0;
566                            len               = coeff_VLC[1][0][abs_level][prev_run].len;
567                            bits      += len!=128 ? len : 30;
568    
569                            prev_level = level;
570                            prev_run   = run;
571                            run = 0;
572                    }
573                    else
574                            run++;
575            }
576    
577            abs_level = abs(prev_level);
578            abs_level = abs_level < 64 ? abs_level : 0;
579            len               = coeff_VLC[1][1][abs_level][prev_run].len;
580            bits      += len!=128 ? len : 30;
581    
582            return bits;
583    }
584    
585    int
586    CodeCoeffInter_CalcBits(const int16_t qcoeff[64], const uint16_t * zigzag)
587    {
588            uint32_t i, run, prev_run, len;
589            int32_t level, prev_level, level_shifted;
590            int bits = 0;
591    
592            i       = 0;
593            run = 0;
594    
595            while (!(level = qcoeff[zigzag[i++]]))
596                    run++;
597    
598            prev_level = level;
599            prev_run   = run;
600            run = 0;
601    
602            while (i < 64) {
603                    if ((level = qcoeff[zigzag[i++]]) != 0) {
604                            level_shifted = prev_level + 32;
605                            if (!(level_shifted & -64))
606                                    len      = coeff_VLC[0][0][level_shifted][prev_run].len;
607                            else
608                                    len  = 30;
609    
610                            bits += len;
611                            prev_level = level;
612                            prev_run   = run;
613                            run = 0;
614                    }
615                    else
616                            run++;
617            }
618    
619            level_shifted = prev_level + 32;
620            if (!(level_shifted & -64))
621                    len      = coeff_VLC[0][1][level_shifted][prev_run].len;
622            else
623                    len  = 30;
624            bits += len;
625    
626            return bits;
627    }
628    
629    
630  #endif  #endif
631    
 /*****************************************************************************  
  * Local functions  
  ****************************************************************************/  
632    
633  static void  static int iDQtab[5] = {
634  CodeBlockIntra(const FRAMEINFO * frame,          1, 0, -1 /* no change */, 2, 3
635    };
636    #define DQ_VALUE2INDEX(value)  iDQtab[(value)+2]
637    
638    
639    static __inline void
640    CodeBlockIntra(const FRAMEINFO * const frame,
641                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
642                             int16_t qcoeff[6 * 64],                             int16_t qcoeff[6 * 64],
643                             Bitstream * bs,                             Bitstream * bs,
# Line 479  Line 648 
648    
649          cbpy = pMB->cbp >> 2;          cbpy = pMB->cbp >> 2;
650    
651          /* write mcbpc */          // write mcbpc
652          if (frame->coding_type == I_VOP) {          if (frame->coding_type == I_VOP) {
653                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);                  mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
654                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,                  BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code,
# Line 490  Line 659 
659                                                   mcbpc_inter_tab[mcbpc].len);                                                   mcbpc_inter_tab[mcbpc].len);
660          }          }
661    
662          /* ac prediction flag */          // ac prediction flag
663          if (pMB->acpred_directions[0])          if (pMB->acpred_directions[0])
664                  BitstreamPutBits(bs, 1, 1);                  BitstreamPutBits(bs, 1, 1);
665          else          else
666                  BitstreamPutBits(bs, 0, 1);                  BitstreamPutBits(bs, 0, 1);
667    
668          /* write cbpy */          // write cbpy
669          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);          BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
670    
671          /* write dquant */          // write dquant
672          if (pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA_Q)
673                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
674    
675          /* write interlacing */          // write interlacing
676          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
677                  BitstreamPutBit(bs, pMB->field_dct);                  BitstreamPutBit(bs, pMB->field_dct);
678          }          }
679          /* code block coeffs */          // code block coeffs
680          for (i = 0; i < 6; i++) {          for (i = 0; i < 6; i++) {
681                  if (i < 4)                  if (i < 4)
682                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,                          BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code,
# Line 517  Line 686 
686                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);                                                           dcc_tab[qcoeff[i * 64 + 0] + 255].len);
687    
688                  if (pMB->cbp & (1 << (5 - i))) {                  if (pMB->cbp & (1 << (5 - i))) {
689                            const uint16_t *scan_table =
690                                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
691                                    scan_tables[2] : scan_tables[pMB->acpred_directions[i]];
692    
693                          bits = BitstreamPos(bs);                          bits = BitstreamPos(bs);
694    
695  #ifdef _BIGLUT_  #ifdef BIGLUT
696                          CodeCoeff(bs, &qcoeff[i * 64], intra_table,                          CodeCoeff(bs, &qcoeff[i * 64], intra_table, scan_table, 1);
                                           scan_tables[pMB->acpred_directions[i]], 1);  
697  #else  #else
698                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_tables[pMB->acpred_directions[i]]);                          CodeCoeffIntra(bs, &qcoeff[i * 64], scan_table);
699  #endif  #endif
700    
701                          bits = BitstreamPos(bs) - bits;                          bits = BitstreamPos(bs) - bits;
702                          pStat->iTextBits += bits;                          pStat->iTextBits += bits;
703                  }                  }
# Line 534  Line 707 
707    
708    
709  static void  static void
710  CodeBlockInter(const FRAMEINFO * frame,  CodeBlockInter(const FRAMEINFO * const frame,
711                             const MACROBLOCK * pMB,                             const MACROBLOCK * pMB,
712                             int16_t qcoeff[6 * 64],                             int16_t qcoeff[6 * 64],
713                             Bitstream * bs,                             Bitstream * bs,
# Line 547  Line 720 
720          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);          mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
721          cbpy = 15 - (pMB->cbp >> 2);          cbpy = 15 - (pMB->cbp >> 2);
722    
723          /* write mcbpc */          // write mcbpc
724          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,          BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code,
725                                           mcbpc_inter_tab[mcbpc].len);                                           mcbpc_inter_tab[mcbpc].len);
726    
727          /* write cbpy */          if ( (frame->coding_type == S_VOP) && (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) )
728          BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);                  BitstreamPutBit(bs, pMB->mcsel);                // mcsel: '0'=local motion, '1'=GMC
729    
730            // write cbpy
731            BitstreamPutBits(bs, xvid_cbpy_tab[cbpy].code, xvid_cbpy_tab[cbpy].len);
732    
733          /* write dquant */          // write dquant
734          if (pMB->mode == MODE_INTER_Q)          if (pMB->mode == MODE_INTER_Q)
735                  BitstreamPutBits(bs, pMB->dquant, 2);                  BitstreamPutBits(bs, DQ_VALUE2INDEX(pMB->dquant), 2);
736    
737          /* interlacing */          // interlacing
738          if (frame->global_flags & XVID_INTERLACING) {          if (frame->vol_flags & XVID_VOL_INTERLACING) {
739                  if (pMB->cbp) {                  if (pMB->cbp) {
740                          BitstreamPutBit(bs, pMB->field_dct);                          BitstreamPutBit(bs, pMB->field_dct);
741                          DPRINTF(DPRINTF_DEBUG, "codep: field_dct: %d", pMB->field_dct);                          DPRINTF(DPRINTF_MB,"codep: field_dct: %i", pMB->field_dct);
742                  }                  }
743    
744                  /* if inter block, write field ME flag */                  // if inter block, write field ME flag
745                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {                  if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) {
746                          BitstreamPutBit(bs, pMB->field_pred);                          BitstreamPutBit(bs, pMB->field_pred);
747                          DPRINTF(DPRINTF_DEBUG, "codep: field_pred: %d", pMB->field_pred);                          DPRINTF(DPRINTF_MB,"codep: field_pred: %i", pMB->field_pred);
748    
749                          /* write field prediction references */                          // write field prediction references
750                          if (pMB->field_pred) {                          if (pMB->field_pred) {
751                                  BitstreamPutBit(bs, pMB->field_for_top);                                  BitstreamPutBit(bs, pMB->field_for_top);
752                                  BitstreamPutBit(bs, pMB->field_for_bot);                                  BitstreamPutBit(bs, pMB->field_for_bot);
753                          }                          }
754                  }                  }
755          }          }
756          /* code motion vector(s) */          // code motion vector(s) if motion is local
757            if (!pMB->mcsel)
758          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {          for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) {
759                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat);
760                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);                  CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat);
# Line 585  Line 762 
762    
763          bits = BitstreamPos(bs);          bits = BitstreamPos(bs);
764    
765          /* code block coeffs */          // code block coeffs
766          for (i = 0; i < 6; i++)          for (i = 0; i < 6; i++)
767                  if (pMB->cbp & (1 << (5 - i)))                  if (pMB->cbp & (1 << (5 - i)))
768  #ifdef _BIGLUT_                  {
769                          CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);                          const uint16_t *scan_table =
770                                    frame->vop_flags & XVID_VOP_ALTERNATESCAN ?
771                                    scan_tables[2] : scan_tables[0];
772    
773    #ifdef BIGLUT
774                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_table, 0);
775  #else  #else
776                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);                          CodeCoeffInter(bs, &qcoeff[i * 64], scan_table);
777  #endif  #endif
778                    }
779    
780          bits = BitstreamPos(bs) - bits;          bits = BitstreamPos(bs) - bits;
781          pStat->iTextBits += bits;          pStat->iTextBits += bits;
   
782  }  }
783    
 /*****************************************************************************  
  * Macro Block bitstream encoding functions  
  ****************************************************************************/  
784    
785  void  void
786  MBCoding(const FRAMEINFO * frame,  MBCoding(const FRAMEINFO * const frame,
787                   MACROBLOCK * pMB,                   MACROBLOCK * pMB,
788                   int16_t qcoeff[6 * 64],                   int16_t qcoeff[6 * 64],
789                   Bitstream * bs,                   Bitstream * bs,
790                   Statistics * pStat)                   Statistics * pStat)
791  {  {
792            if (frame->coding_type != I_VOP)
793          if (frame->coding_type == P_VOP) {                          BitstreamPutBit(bs, 0); // not_coded
                         BitstreamPutBit(bs, 0); /* coded */  
         }  
794    
795          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)          if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q)
796                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);                  CodeBlockIntra(frame, pMB, qcoeff, bs, pStat);
# Line 622  Line 799 
799    
800  }  }
801    
802    /*
803    // moved to mbcoding.h so that in can be 'static __inline'
804  void  void
805  MBSkip(Bitstream * bs)  MBSkip(Bitstream * bs)
806  {  {
807          BitstreamPutBit(bs, 1); /* not coded */          BitstreamPutBit(bs, 1); // not coded
         return;  
808  }  }
809    */
810    
811  /*****************************************************************************  /***************************************************************
812   * decoding stuff starts here   * bframe encoding start
813   ****************************************************************************/   ***************************************************************/
814    
815    /*
816            mbtype
817            0       1b              direct(h263)            mvdb
818            1       01b             interpolate mc+q        dbquant, mvdf, mvdb
819            2       001b    backward mc+q           dbquant, mvdb
820            3       0001b   forward mc+q            dbquant, mvdf
821    */
822    
823    static __inline void
824    put_bvop_mbtype(Bitstream * bs,
825                                    int value)
826    {
827            switch (value) {
828                    case MODE_FORWARD:
829                            BitstreamPutBit(bs, 0);
830                    case MODE_BACKWARD:
831                            BitstreamPutBit(bs, 0);
832                    case MODE_INTERPOLATE:
833                            BitstreamPutBit(bs, 0);
834                    case MODE_DIRECT:
835                            BitstreamPutBit(bs, 1);
836                    default:
837                            break;
838            }
839    }
840    
841  /*  /*
842   * For IVOP addbits == 0          dbquant
843   * For PVOP addbits == fcode - 1          -2      10b
844   * For BVOP addbits == max(fcode,bcode) - 1          0       0b
845   * returns true or false          +2      11b
846   */   */
847    
848    static __inline void
849    put_bvop_dbquant(Bitstream * bs,
850                                     int value)
851    {
852            switch (value) {
853            case 0:
854                    BitstreamPutBit(bs, 0);
855                    return;
856    
857            case -2:
858                    BitstreamPutBit(bs, 1);
859                    BitstreamPutBit(bs, 0);
860                    return;
861    
862            case 2:
863                    BitstreamPutBit(bs, 1);
864                    BitstreamPutBit(bs, 1);
865                    return;
866    
867            default:;                                       // invalid
868            }
869    }
870    
871    
872    
873    void
874    MBCodingBVOP(const MACROBLOCK * mb,
875                             const int16_t qcoeff[6 * 64],
876                             const int32_t fcode,
877                             const int32_t bcode,
878                             Bitstream * bs,
879                             Statistics * pStat,
880                             int direction)
881    {
882            int vcode = fcode;
883            unsigned int i;
884    
885    /*      ------------------------------------------------------------------
886                    when a block is skipped it is decoded DIRECT(0,0)
887                    hence is interpolated from forward & backward frames
888            ------------------------------------------------------------------ */
889    
890            if (mb->mode == MODE_DIRECT_NONE_MV) {
891                    BitstreamPutBit(bs, 1); // skipped
892                    return;
893            }
894    
895            BitstreamPutBit(bs, 0);         // not skipped
896    
897            if (mb->cbp == 0) {
898                    BitstreamPutBit(bs, 1); // cbp == 0
899            } else {
900                    BitstreamPutBit(bs, 0); // cbp == xxx
901            }
902    
903            put_bvop_mbtype(bs, mb->mode);
904    
905            if (mb->cbp) {
906                    BitstreamPutBits(bs, mb->cbp, 6);
907            }
908    
909            if (mb->mode != MODE_DIRECT && mb->cbp != 0) {
910                    put_bvop_dbquant(bs, 0);        // todo: mb->dquant = 0
911            }
912    
913            switch (mb->mode) {
914                    case MODE_INTERPOLATE:
915                            CodeVector(bs, mb->pmvs[1].x, vcode, pStat); //forward vector of interpolate mode
916                            CodeVector(bs, mb->pmvs[1].y, vcode, pStat);
917                    case MODE_BACKWARD:
918                            vcode = bcode;
919                    case MODE_FORWARD:
920                            CodeVector(bs, mb->pmvs[0].x, vcode, pStat);
921                            CodeVector(bs, mb->pmvs[0].y, vcode, pStat);
922                            break;
923                    case MODE_DIRECT:
924                            CodeVector(bs, mb->pmvs[3].x, 1, pStat);        // fcode is always 1 for delta vector
925                            CodeVector(bs, mb->pmvs[3].y, 1, pStat);        // prediction is always (0,0)
926                    default: break;
927            }
928    
929            for (i = 0; i < 6; i++) {
930                    if (mb->cbp & (1 << (5 - i))) {
931    #ifdef BIGLUT
932                            CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0);
933    #else
934                            CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]);
935    #endif
936                    }
937            }
938    }
939    
940    
941    
942    /***************************************************************
943     * decoding stuff starts here                                  *
944     ***************************************************************/
945    
946    
947    // for IVOP addbits == 0
948    // for PVOP addbits == fcode - 1
949    // for BVOP addbits == max(fcode,bcode) - 1
950    // returns true or false
951  int  int
952  check_resync_marker(Bitstream * bs, int addbits)  check_resync_marker(Bitstream * bs, int addbits)
953  {  {
# Line 682  Line 989 
989    
990          uint32_t index;          uint32_t index;
991    
992          index = CLIP(BitstreamShowBits(bs, 9), 256);          index = MIN(BitstreamShowBits(bs, 9), 256);
993    
994          BitstreamSkip(bs, mcbpc_inter_table[index].len);          BitstreamSkip(bs, mcbpc_inter_table[index].len);
995    
# Line 708  Line 1015 
1015    
1016  }  }
1017    
1018  int  static __inline int
1019  get_mv_data(Bitstream * bs)  get_mv_data(Bitstream * bs)
1020  {  {
1021    
# Line 754  Line 1061 
1061                  return data;                  return data;
1062    
1063          res = BitstreamGetBits(bs, fcode - 1);          res = BitstreamGetBits(bs, fcode - 1);
1064          mv = ((ABS(data) - 1) * scale_fac) + res + 1;          mv = ((abs(data) - 1) * scale_fac) + res + 1;
1065    
1066          return data < 0 ? -mv : mv;          return data < 0 ? -mv : mv;
1067    
# Line 817  Line 1124 
1124    
1125  }  }
1126    
 /*****************************************************************************  
  * Local inlined function to "decode" written vlc codes  
  ****************************************************************************/  
   
1127  static __inline int  static __inline int
1128  get_coeff(Bitstream * bs,  get_coeff(Bitstream * bs,
1129                    int *run,                    int *run,
# Line 902  Line 1205 
1205          return 0;          return 0;
1206  }  }
1207    
 /*****************************************************************************  
  * MB reading functions  
  ****************************************************************************/  
   
1208  void  void
1209  get_intra_block(Bitstream * bs,  get_intra_block(Bitstream * bs,
1210                                  int16_t * block,                                  int16_t * block,
# Line 914  Line 1213 
1213  {  {
1214    
1215          const uint16_t *scan = scan_tables[direction];          const uint16_t *scan = scan_tables[direction];
1216          int level;          int level, run, last;
         int run;  
         int last;  
1217    
1218          do {          do {
1219                  level = get_coeff(bs, &run, &last, 1, 0);                  level = get_coeff(bs, &run, &last, 1, 0);
1220                  if (run == -1) {                  if (run == -1) {
1221                          DPRINTF(DPRINTF_DEBUG, "fatal: invalid run");                          DPRINTF(DPRINTF_ERROR,"fatal: invalid run");
1222                          break;                          break;
1223                  }                  }
1224                  coeff += run;                  coeff += run;
1225                  block[scan[coeff]] = level;                  block[scan[coeff]] = level;
1226    
1227                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level);
1228                  /*DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); */                  //DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32));
1229    
1230                  if (level < -2047 || level > 2047) {                  if (level < -2047 || level > 2047) {
1231                          DPRINTF(DPRINTF_DEBUG, "warning: intra_overflow: %d", level);                          DPRINTF(DPRINTF_ERROR,"warning: intra_overflow %i", level);
1232                  }                  }
1233                  coeff++;                  coeff++;
1234          } while (!last);          } while (!last);
# Line 940  Line 1237 
1237    
1238  void  void
1239  get_inter_block(Bitstream * bs,  get_inter_block(Bitstream * bs,
1240                                  int16_t * block)                                  int16_t * block,
1241                                    int direction)
1242  {  {
1243    
1244          const uint16_t *scan = scan_tables[0];          const uint16_t *scan = scan_tables[direction];
1245          int p;          int p;
1246          int level;          int level;
1247          int run;          int run;
# Line 961  Line 1259 
1259                  block[scan[p]] = level;                  block[scan[p]] = level;
1260    
1261                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);                  DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level);
1262                    // DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[p], level, BitstreamShowBits(bs, 32));
1263    
1264                  if (level < -2047 || level > 2047) {                  if (level < -2047 || level > 2047) {
1265                          DPRINTF(DPRINTF_DEBUG, "warning: inter_overflow: %d", level);                          DPRINTF(DPRINTF_ERROR,"warning: inter overflow %i", level);
1266                  }                  }
1267                  p++;                  p++;
1268          } while (!last);          } while (!last);
1269    
1270  }  }
1271    
1272    
1273    /*****************************************************************************
1274     * VLC tables and other constant arrays
1275     ****************************************************************************/
1276    
1277    VLC_TABLE const coeff_tab[2][102] =
1278    {
1279            /* intra = 0 */
1280            {
1281                    {{ 2,  2}, {0, 0, 1}},
1282                    {{15,  4}, {0, 0, 2}},
1283                    {{21,  6}, {0, 0, 3}},
1284                    {{23,  7}, {0, 0, 4}},
1285                    {{31,  8}, {0, 0, 5}},
1286                    {{37,  9}, {0, 0, 6}},
1287                    {{36,  9}, {0, 0, 7}},
1288                    {{33, 10}, {0, 0, 8}},
1289                    {{32, 10}, {0, 0, 9}},
1290                    {{ 7, 11}, {0, 0, 10}},
1291                    {{ 6, 11}, {0, 0, 11}},
1292                    {{32, 11}, {0, 0, 12}},
1293                    {{ 6,  3}, {0, 1, 1}},
1294                    {{20,  6}, {0, 1, 2}},
1295                    {{30,  8}, {0, 1, 3}},
1296                    {{15, 10}, {0, 1, 4}},
1297                    {{33, 11}, {0, 1, 5}},
1298                    {{80, 12}, {0, 1, 6}},
1299                    {{14,  4}, {0, 2, 1}},
1300                    {{29,  8}, {0, 2, 2}},
1301                    {{14, 10}, {0, 2, 3}},
1302                    {{81, 12}, {0, 2, 4}},
1303                    {{13,  5}, {0, 3, 1}},
1304                    {{35,  9}, {0, 3, 2}},
1305                    {{13, 10}, {0, 3, 3}},
1306                    {{12,  5}, {0, 4, 1}},
1307                    {{34,  9}, {0, 4, 2}},
1308                    {{82, 12}, {0, 4, 3}},
1309                    {{11,  5}, {0, 5, 1}},
1310                    {{12, 10}, {0, 5, 2}},
1311                    {{83, 12}, {0, 5, 3}},
1312                    {{19,  6}, {0, 6, 1}},
1313                    {{11, 10}, {0, 6, 2}},
1314                    {{84, 12}, {0, 6, 3}},
1315                    {{18,  6}, {0, 7, 1}},
1316                    {{10, 10}, {0, 7, 2}},
1317                    {{17,  6}, {0, 8, 1}},
1318                    {{ 9, 10}, {0, 8, 2}},
1319                    {{16,  6}, {0, 9, 1}},
1320                    {{ 8, 10}, {0, 9, 2}},
1321                    {{22,  7}, {0, 10, 1}},
1322                    {{85, 12}, {0, 10, 2}},
1323                    {{21,  7}, {0, 11, 1}},
1324                    {{20,  7}, {0, 12, 1}},
1325                    {{28,  8}, {0, 13, 1}},
1326                    {{27,  8}, {0, 14, 1}},
1327                    {{33,  9}, {0, 15, 1}},
1328                    {{32,  9}, {0, 16, 1}},
1329                    {{31,  9}, {0, 17, 1}},
1330                    {{30,  9}, {0, 18, 1}},
1331                    {{29,  9}, {0, 19, 1}},
1332                    {{28,  9}, {0, 20, 1}},
1333                    {{27,  9}, {0, 21, 1}},
1334                    {{26,  9}, {0, 22, 1}},
1335                    {{34, 11}, {0, 23, 1}},
1336                    {{35, 11}, {0, 24, 1}},
1337                    {{86, 12}, {0, 25, 1}},
1338                    {{87, 12}, {0, 26, 1}},
1339                    {{ 7,  4}, {1, 0, 1}},
1340                    {{25,  9}, {1, 0, 2}},
1341                    {{ 5, 11}, {1, 0, 3}},
1342                    {{15,  6}, {1, 1, 1}},
1343                    {{ 4, 11}, {1, 1, 2}},
1344                    {{14,  6}, {1, 2, 1}},
1345                    {{13,  6}, {1, 3, 1}},
1346                    {{12,  6}, {1, 4, 1}},
1347                    {{19,  7}, {1, 5, 1}},
1348                    {{18,  7}, {1, 6, 1}},
1349                    {{17,  7}, {1, 7, 1}},
1350                    {{16,  7}, {1, 8, 1}},
1351                    {{26,  8}, {1, 9, 1}},
1352                    {{25,  8}, {1, 10, 1}},
1353                    {{24,  8}, {1, 11, 1}},
1354                    {{23,  8}, {1, 12, 1}},
1355                    {{22,  8}, {1, 13, 1}},
1356                    {{21,  8}, {1, 14, 1}},
1357                    {{20,  8}, {1, 15, 1}},
1358                    {{19,  8}, {1, 16, 1}},
1359                    {{24,  9}, {1, 17, 1}},
1360                    {{23,  9}, {1, 18, 1}},
1361                    {{22,  9}, {1, 19, 1}},
1362                    {{21,  9}, {1, 20, 1}},
1363                    {{20,  9}, {1, 21, 1}},
1364                    {{19,  9}, {1, 22, 1}},
1365                    {{18,  9}, {1, 23, 1}},
1366                    {{17,  9}, {1, 24, 1}},
1367                    {{ 7, 10}, {1, 25, 1}},
1368                    {{ 6, 10}, {1, 26, 1}},
1369                    {{ 5, 10}, {1, 27, 1}},
1370                    {{ 4, 10}, {1, 28, 1}},
1371                    {{36, 11}, {1, 29, 1}},
1372                    {{37, 11}, {1, 30, 1}},
1373                    {{38, 11}, {1, 31, 1}},
1374                    {{39, 11}, {1, 32, 1}},
1375                    {{88, 12}, {1, 33, 1}},
1376                    {{89, 12}, {1, 34, 1}},
1377                    {{90, 12}, {1, 35, 1}},
1378                    {{91, 12}, {1, 36, 1}},
1379                    {{92, 12}, {1, 37, 1}},
1380                    {{93, 12}, {1, 38, 1}},
1381                    {{94, 12}, {1, 39, 1}},
1382                    {{95, 12}, {1, 40, 1}}
1383            },
1384            /* intra = 1 */
1385            {
1386                    {{ 2,  2}, {0, 0, 1}},
1387                    {{15,  4}, {0, 0, 3}},
1388                    {{21,  6}, {0, 0, 6}},
1389                    {{23,  7}, {0, 0, 9}},
1390                    {{31,  8}, {0, 0, 10}},
1391                    {{37,  9}, {0, 0, 13}},
1392                    {{36,  9}, {0, 0, 14}},
1393                    {{33, 10}, {0, 0, 17}},
1394                    {{32, 10}, {0, 0, 18}},
1395                    {{ 7, 11}, {0, 0, 21}},
1396                    {{ 6, 11}, {0, 0, 22}},
1397                    {{32, 11}, {0, 0, 23}},
1398                    {{ 6,  3}, {0, 0, 2}},
1399                    {{20,  6}, {0, 1, 2}},
1400                    {{30,  8}, {0, 0, 11}},
1401                    {{15, 10}, {0, 0, 19}},
1402                    {{33, 11}, {0, 0, 24}},
1403                    {{80, 12}, {0, 0, 25}},
1404                    {{14,  4}, {0, 1, 1}},
1405                    {{29,  8}, {0, 0, 12}},
1406                    {{14, 10}, {0, 0, 20}},
1407                    {{81, 12}, {0, 0, 26}},
1408                    {{13,  5}, {0, 0, 4}},
1409                    {{35,  9}, {0, 0, 15}},
1410                    {{13, 10}, {0, 1, 7}},
1411                    {{12,  5}, {0, 0, 5}},
1412                    {{34,  9}, {0, 4, 2}},
1413                    {{82, 12}, {0, 0, 27}},
1414                    {{11,  5}, {0, 2, 1}},
1415                    {{12, 10}, {0, 2, 4}},
1416                    {{83, 12}, {0, 1, 9}},
1417                    {{19,  6}, {0, 0, 7}},
1418                    {{11, 10}, {0, 3, 4}},
1419                    {{84, 12}, {0, 6, 3}},
1420                    {{18,  6}, {0, 0, 8}},
1421                    {{10, 10}, {0, 4, 3}},
1422                    {{17,  6}, {0, 3, 1}},
1423                    {{ 9, 10}, {0, 8, 2}},
1424                    {{16,  6}, {0, 4, 1}},
1425                    {{ 8, 10}, {0, 5, 3}},
1426                    {{22,  7}, {0, 1, 3}},
1427                    {{85, 12}, {0, 1, 10}},
1428                    {{21,  7}, {0, 2, 2}},
1429                    {{20,  7}, {0, 7, 1}},
1430                    {{28,  8}, {0, 1, 4}},
1431                    {{27,  8}, {0, 3, 2}},
1432                    {{33,  9}, {0, 0, 16}},
1433                    {{32,  9}, {0, 1, 5}},
1434                    {{31,  9}, {0, 1, 6}},
1435                    {{30,  9}, {0, 2, 3}},
1436                    {{29,  9}, {0, 3, 3}},
1437                    {{28,  9}, {0, 5, 2}},
1438                    {{27,  9}, {0, 6, 2}},
1439                    {{26,  9}, {0, 7, 2}},
1440                    {{34, 11}, {0, 1, 8}},
1441                    {{35, 11}, {0, 9, 2}},
1442                    {{86, 12}, {0, 2, 5}},
1443                    {{87, 12}, {0, 7, 3}},
1444                    {{ 7,  4}, {1, 0, 1}},
1445                    {{25,  9}, {0, 11, 1}},
1446                    {{ 5, 11}, {1, 0, 6}},
1447                    {{15,  6}, {1, 1, 1}},
1448                    {{ 4, 11}, {1, 0, 7}},
1449                    {{14,  6}, {1, 2, 1}},
1450                    {{13,  6}, {0, 5, 1}},
1451                    {{12,  6}, {1, 0, 2}},
1452                    {{19,  7}, {1, 5, 1}},
1453                    {{18,  7}, {0, 6, 1}},
1454                    {{17,  7}, {1, 3, 1}},
1455                    {{16,  7}, {1, 4, 1}},
1456                    {{26,  8}, {1, 9, 1}},
1457                    {{25,  8}, {0, 8, 1}},
1458                    {{24,  8}, {0, 9, 1}},
1459                    {{23,  8}, {0, 10, 1}},
1460                    {{22,  8}, {1, 0, 3}},
1461                    {{21,  8}, {1, 6, 1}},
1462                    {{20,  8}, {1, 7, 1}},
1463                    {{19,  8}, {1, 8, 1}},
1464                    {{24,  9}, {0, 12, 1}},
1465                    {{23,  9}, {1, 0, 4}},
1466                    {{22,  9}, {1, 1, 2}},
1467                    {{21,  9}, {1, 10, 1}},
1468                    {{20,  9}, {1, 11, 1}},
1469                    {{19,  9}, {1, 12, 1}},
1470                    {{18,  9}, {1, 13, 1}},
1471                    {{17,  9}, {1, 14, 1}},
1472                    {{ 7, 10}, {0, 13, 1}},
1473                    {{ 6, 10}, {1, 0, 5}},
1474                    {{ 5, 10}, {1, 1, 3}},
1475                    {{ 4, 10}, {1, 2, 2}},
1476                    {{36, 11}, {1, 3, 2}},
1477                    {{37, 11}, {1, 4, 2}},
1478                    {{38, 11}, {1, 15, 1}},
1479                    {{39, 11}, {1, 16, 1}},
1480                    {{88, 12}, {0, 14, 1}},
1481                    {{89, 12}, {1, 0, 8}},
1482                    {{90, 12}, {1, 5, 2}},
1483                    {{91, 12}, {1, 6, 2}},
1484                    {{92, 12}, {1, 17, 1}},
1485                    {{93, 12}, {1, 18, 1}},
1486                    {{94, 12}, {1, 19, 1}},
1487                    {{95, 12}, {1, 20, 1}}
1488            }
1489    };
1490    
1491    /* constants taken from momusys/vm_common/inlcude/max_level.h */
1492    uint8_t const max_level[2][2][64] = {
1493            {
1494                    /* intra = 0, last = 0 */
1495                    {
1496                            12, 6, 4, 3, 3, 3, 3, 2,
1497                            2, 2, 2, 1, 1, 1, 1, 1,
1498                            1, 1, 1, 1, 1, 1, 1, 1,
1499                            1, 1, 1, 0, 0, 0, 0, 0,
1500                            0, 0, 0, 0, 0, 0, 0, 0,
1501                            0, 0, 0, 0, 0, 0, 0, 0,
1502                            0, 0, 0, 0, 0, 0, 0, 0,
1503                            0, 0, 0, 0, 0, 0, 0, 0
1504                    },
1505                    /* intra = 0, last = 1 */
1506                    {
1507                            3, 2, 1, 1, 1, 1, 1, 1,
1508                            1, 1, 1, 1, 1, 1, 1, 1,
1509                            1, 1, 1, 1, 1, 1, 1, 1,
1510                            1, 1, 1, 1, 1, 1, 1, 1,
1511                            1, 1, 1, 1, 1, 1, 1, 1,
1512                            1, 0, 0, 0, 0, 0, 0, 0,
1513                            0, 0, 0, 0, 0, 0, 0, 0,
1514                            0, 0, 0, 0, 0, 0, 0, 0
1515                    }
1516            },
1517            {
1518                    /* intra = 1, last = 0 */
1519                    {
1520                            27, 10, 5, 4, 3, 3, 3, 3,
1521                            2, 2, 1, 1, 1, 1, 1, 0,
1522                            0, 0, 0, 0, 0, 0, 0, 0,
1523                            0, 0, 0, 0, 0, 0, 0, 0,
1524                            0, 0, 0, 0, 0, 0, 0, 0,
1525                            0, 0, 0, 0, 0, 0, 0, 0,
1526                            0, 0, 0, 0, 0, 0, 0, 0,
1527                            0, 0, 0, 0, 0, 0, 0, 0
1528                    },
1529                    /* intra = 1, last = 1 */
1530                    {
1531                            8, 3, 2, 2, 2, 2, 2, 1,
1532                            1, 1, 1, 1, 1, 1, 1, 1,
1533                            1, 1, 1, 1, 1, 0, 0, 0,
1534                            0, 0, 0, 0, 0, 0, 0, 0,
1535                            0, 0, 0, 0, 0, 0, 0, 0,
1536                            0, 0, 0, 0, 0, 0, 0, 0,
1537                            0, 0, 0, 0, 0, 0, 0, 0,
1538                            0, 0, 0, 0, 0, 0, 0, 0
1539                    }
1540            }
1541    };
1542    
1543    uint8_t const max_run[2][2][64] = {
1544            {
1545                    /* intra = 0, last = 0 */
1546                    {
1547                            0, 26, 10, 6, 2, 1, 1, 0,
1548                            0, 0, 0, 0, 0, 0, 0, 0,
1549                            0, 0, 0, 0, 0, 0, 0, 0,
1550                            0, 0, 0, 0, 0, 0, 0, 0,
1551                            0, 0, 0, 0, 0, 0, 0, 0,
1552                            0, 0, 0, 0, 0, 0, 0, 0,
1553                            0, 0, 0, 0, 0, 0, 0, 0,
1554                            0, 0, 0, 0, 0, 0, 0, 0,
1555                    },
1556                    /* intra = 0, last = 1 */
1557                    {
1558                            0, 40, 1, 0, 0, 0, 0, 0,
1559                            0, 0, 0, 0, 0, 0, 0, 0,
1560                            0, 0, 0, 0, 0, 0, 0, 0,
1561                            0, 0, 0, 0, 0, 0, 0, 0,
1562                            0, 0, 0, 0, 0, 0, 0, 0,
1563                            0, 0, 0, 0, 0, 0, 0, 0,
1564                            0, 0, 0, 0, 0, 0, 0, 0,
1565                            0, 0, 0, 0, 0, 0, 0, 0,
1566                    }
1567            },
1568            {
1569                    /* intra = 1, last = 0 */
1570                    {
1571                            0, 14, 9, 7, 3, 2, 1, 1,
1572                            1, 1, 1, 0, 0, 0, 0, 0,
1573                            0, 0, 0, 0, 0, 0, 0, 0,
1574                            0, 0, 0, 0, 0, 0, 0, 0,
1575                            0, 0, 0, 0, 0, 0, 0, 0,
1576                            0, 0, 0, 0, 0, 0, 0, 0,
1577                            0, 0, 0, 0, 0, 0, 0, 0,
1578                            0, 0, 0, 0, 0, 0, 0, 0,
1579                    },
1580                    /* intra = 1, last = 1 */
1581                    {
1582                            0, 20, 6, 1, 0, 0, 0, 0,
1583                            0, 0, 0, 0, 0, 0, 0, 0,
1584                            0, 0, 0, 0, 0, 0, 0, 0,
1585                            0, 0, 0, 0, 0, 0, 0, 0,
1586                            0, 0, 0, 0, 0, 0, 0, 0,
1587                            0, 0, 0, 0, 0, 0, 0, 0,
1588                            0, 0, 0, 0, 0, 0, 0, 0,
1589                            0, 0, 0, 0, 0, 0, 0, 0,
1590                    }
1591            }
1592    };
1593    
1594    /******************************************************************
1595     * encoder tables                                                 *
1596     ******************************************************************/
1597    
1598    VLC sprite_trajectory_code[32768];
1599    
1600    VLC sprite_trajectory_len[15] = {
1601            { 0x00 , 2},
1602            { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},
1603            { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8},
1604            { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };
1605    
1606    
1607    /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
1608       the sign bit must be added afterwards. */
1609    
1610    /* MCBPC Indexing by cbpc in first two bits, mode in last two.
1611     CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
1612     Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */
1613    
1614    VLC mcbpc_intra_tab[15] = {
1615            {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
1616            {0x00, 0}, {0x01, 3}, {0x01, 6}, {0x00, 0},
1617            {0x00, 0}, {0x02, 3}, {0x02, 6}, {0x00, 0},
1618            {0x00, 0}, {0x03, 3}, {0x03, 6}
1619    };
1620    
1621    /* MCBPC inter.
1622       Addressing: 5 bit ccmmm (cc = CBPC, mmm = mode (1-4 binary)) */
1623    
1624    VLC mcbpc_inter_tab[29] = {
1625            {1, 1}, {3, 3}, {2, 3}, {3, 5}, {4, 6}, {1, 9}, {0, 0}, {0, 0},
1626            {3, 4}, {7, 7}, {5, 7}, {4, 8}, {4, 9}, {0, 0}, {0, 0}, {0, 0},
1627            {2, 4}, {6, 7}, {4, 7}, {3, 8}, {3, 9}, {0, 0}, {0, 0}, {0, 0},
1628            {5, 6}, {5, 9}, {5, 8}, {3, 7}, {2, 9}
1629    };
1630    
1631    const VLC xvid_cbpy_tab[16] = {
1632            {3, 4}, {5, 5}, {4, 5}, {9, 4}, {3, 5}, {7, 4}, {2, 6}, {11, 4},
1633            {2, 5}, {3, 6}, {5, 4}, {10, 4}, {4, 4}, {8, 4}, {6, 4}, {3, 2}
1634    };
1635    
1636    const VLC dcy_tab[511] = {
1637            {0x100, 15}, {0x101, 15}, {0x102, 15}, {0x103, 15},
1638            {0x104, 15}, {0x105, 15}, {0x106, 15}, {0x107, 15},
1639            {0x108, 15}, {0x109, 15}, {0x10a, 15}, {0x10b, 15},
1640            {0x10c, 15}, {0x10d, 15}, {0x10e, 15}, {0x10f, 15},
1641            {0x110, 15}, {0x111, 15}, {0x112, 15}, {0x113, 15},
1642            {0x114, 15}, {0x115, 15}, {0x116, 15}, {0x117, 15},
1643            {0x118, 15}, {0x119, 15}, {0x11a, 15}, {0x11b, 15},
1644            {0x11c, 15}, {0x11d, 15}, {0x11e, 15}, {0x11f, 15},
1645            {0x120, 15}, {0x121, 15}, {0x122, 15}, {0x123, 15},
1646            {0x124, 15}, {0x125, 15}, {0x126, 15}, {0x127, 15},
1647            {0x128, 15}, {0x129, 15}, {0x12a, 15}, {0x12b, 15},
1648            {0x12c, 15}, {0x12d, 15}, {0x12e, 15}, {0x12f, 15},
1649            {0x130, 15}, {0x131, 15}, {0x132, 15}, {0x133, 15},
1650            {0x134, 15}, {0x135, 15}, {0x136, 15}, {0x137, 15},
1651            {0x138, 15}, {0x139, 15}, {0x13a, 15}, {0x13b, 15},
1652            {0x13c, 15}, {0x13d, 15}, {0x13e, 15}, {0x13f, 15},
1653            {0x140, 15}, {0x141, 15}, {0x142, 15}, {0x143, 15},
1654            {0x144, 15}, {0x145, 15}, {0x146, 15}, {0x147, 15},
1655            {0x148, 15}, {0x149, 15}, {0x14a, 15}, {0x14b, 15},
1656            {0x14c, 15}, {0x14d, 15}, {0x14e, 15}, {0x14f, 15},
1657            {0x150, 15}, {0x151, 15}, {0x152, 15}, {0x153, 15},
1658            {0x154, 15}, {0x155, 15}, {0x156, 15}, {0x157, 15},
1659            {0x158, 15}, {0x159, 15}, {0x15a, 15}, {0x15b, 15},
1660            {0x15c, 15}, {0x15d, 15}, {0x15e, 15}, {0x15f, 15},
1661            {0x160, 15}, {0x161, 15}, {0x162, 15}, {0x163, 15},
1662            {0x164, 15}, {0x165, 15}, {0x166, 15}, {0x167, 15},
1663            {0x168, 15}, {0x169, 15}, {0x16a, 15}, {0x16b, 15},
1664            {0x16c, 15}, {0x16d, 15}, {0x16e, 15}, {0x16f, 15},
1665            {0x170, 15}, {0x171, 15}, {0x172, 15}, {0x173, 15},
1666            {0x174, 15}, {0x175, 15}, {0x176, 15}, {0x177, 15},
1667            {0x178, 15}, {0x179, 15}, {0x17a, 15}, {0x17b, 15},
1668            {0x17c, 15}, {0x17d, 15}, {0x17e, 15}, {0x17f, 15},
1669            {0x80, 13}, {0x81, 13}, {0x82, 13}, {0x83, 13},
1670            {0x84, 13}, {0x85, 13}, {0x86, 13}, {0x87, 13},
1671            {0x88, 13}, {0x89, 13}, {0x8a, 13}, {0x8b, 13},
1672            {0x8c, 13}, {0x8d, 13}, {0x8e, 13}, {0x8f, 13},
1673            {0x90, 13}, {0x91, 13}, {0x92, 13}, {0x93, 13},
1674            {0x94, 13}, {0x95, 13}, {0x96, 13}, {0x97, 13},
1675            {0x98, 13}, {0x99, 13}, {0x9a, 13}, {0x9b, 13},
1676            {0x9c, 13}, {0x9d, 13}, {0x9e, 13}, {0x9f, 13},
1677            {0xa0, 13}, {0xa1, 13}, {0xa2, 13}, {0xa3, 13},
1678            {0xa4, 13}, {0xa5, 13}, {0xa6, 13}, {0xa7, 13},
1679            {0xa8, 13}, {0xa9, 13}, {0xaa, 13}, {0xab, 13},
1680            {0xac, 13}, {0xad, 13}, {0xae, 13}, {0xaf, 13},
1681            {0xb0, 13}, {0xb1, 13}, {0xb2, 13}, {0xb3, 13},
1682            {0xb4, 13}, {0xb5, 13}, {0xb6, 13}, {0xb7, 13},
1683            {0xb8, 13}, {0xb9, 13}, {0xba, 13}, {0xbb, 13},
1684            {0xbc, 13}, {0xbd, 13}, {0xbe, 13}, {0xbf, 13},
1685            {0x40, 11}, {0x41, 11}, {0x42, 11}, {0x43, 11},
1686            {0x44, 11}, {0x45, 11}, {0x46, 11}, {0x47, 11},
1687            {0x48, 11}, {0x49, 11}, {0x4a, 11}, {0x4b, 11},
1688            {0x4c, 11}, {0x4d, 11}, {0x4e, 11}, {0x4f, 11},
1689            {0x50, 11}, {0x51, 11}, {0x52, 11}, {0x53, 11},
1690            {0x54, 11}, {0x55, 11}, {0x56, 11}, {0x57, 11},
1691            {0x58, 11}, {0x59, 11}, {0x5a, 11}, {0x5b, 11},
1692            {0x5c, 11}, {0x5d, 11}, {0x5e, 11}, {0x5f, 11},
1693            {0x20, 9}, {0x21, 9}, {0x22, 9}, {0x23, 9},
1694            {0x24, 9}, {0x25, 9}, {0x26, 9}, {0x27, 9},
1695            {0x28, 9}, {0x29, 9}, {0x2a, 9}, {0x2b, 9},
1696            {0x2c, 9}, {0x2d, 9}, {0x2e, 9}, {0x2f, 9},
1697            {0x10, 7}, {0x11, 7}, {0x12, 7}, {0x13, 7},
1698            {0x14, 7}, {0x15, 7}, {0x16, 7}, {0x17, 7},
1699            {0x10, 6}, {0x11, 6}, {0x12, 6}, {0x13, 6},
1700            {0x08, 4}, {0x09, 4}, {0x06, 3}, {0x03, 3},
1701            {0x07, 3}, {0x0a, 4}, {0x0b, 4}, {0x14, 6},
1702            {0x15, 6}, {0x16, 6}, {0x17, 6}, {0x18, 7},
1703            {0x19, 7}, {0x1a, 7}, {0x1b, 7}, {0x1c, 7},
1704            {0x1d, 7}, {0x1e, 7}, {0x1f, 7}, {0x30, 9},
1705            {0x31, 9}, {0x32, 9}, {0x33, 9}, {0x34, 9},
1706            {0x35, 9}, {0x36, 9}, {0x37, 9}, {0x38, 9},
1707            {0x39, 9}, {0x3a, 9}, {0x3b, 9}, {0x3c, 9},
1708            {0x3d, 9}, {0x3e, 9}, {0x3f, 9}, {0x60, 11},
1709            {0x61, 11}, {0x62, 11}, {0x63, 11}, {0x64, 11},
1710            {0x65, 11}, {0x66, 11}, {0x67, 11}, {0x68, 11},
1711            {0x69, 11}, {0x6a, 11}, {0x6b, 11}, {0x6c, 11},
1712            {0x6d, 11}, {0x6e, 11}, {0x6f, 11}, {0x70, 11},
1713            {0x71, 11}, {0x72, 11}, {0x73, 11}, {0x74, 11},
1714            {0x75, 11}, {0x76, 11}, {0x77, 11}, {0x78, 11},
1715            {0x79, 11}, {0x7a, 11}, {0x7b, 11}, {0x7c, 11},
1716            {0x7d, 11}, {0x7e, 11}, {0x7f, 11}, {0xc0, 13},
1717            {0xc1, 13}, {0xc2, 13}, {0xc3, 13}, {0xc4, 13},
1718            {0xc5, 13}, {0xc6, 13}, {0xc7, 13}, {0xc8, 13},
1719            {0xc9, 13}, {0xca, 13}, {0xcb, 13}, {0xcc, 13},
1720            {0xcd, 13}, {0xce, 13}, {0xcf, 13}, {0xd0, 13},
1721            {0xd1, 13}, {0xd2, 13}, {0xd3, 13}, {0xd4, 13},
1722            {0xd5, 13}, {0xd6, 13}, {0xd7, 13}, {0xd8, 13},
1723            {0xd9, 13}, {0xda, 13}, {0xdb, 13}, {0xdc, 13},
1724            {0xdd, 13}, {0xde, 13}, {0xdf, 13}, {0xe0, 13},
1725            {0xe1, 13}, {0xe2, 13}, {0xe3, 13}, {0xe4, 13},
1726            {0xe5, 13}, {0xe6, 13}, {0xe7, 13}, {0xe8, 13},
1727            {0xe9, 13}, {0xea, 13}, {0xeb, 13}, {0xec, 13},
1728            {0xed, 13}, {0xee, 13}, {0xef, 13}, {0xf0, 13},
1729            {0xf1, 13}, {0xf2, 13}, {0xf3, 13}, {0xf4, 13},
1730            {0xf5, 13}, {0xf6, 13}, {0xf7, 13}, {0xf8, 13},
1731            {0xf9, 13}, {0xfa, 13}, {0xfb, 13}, {0xfc, 13},
1732            {0xfd, 13}, {0xfe, 13}, {0xff, 13}, {0x180, 15},
1733            {0x181, 15}, {0x182, 15}, {0x183, 15}, {0x184, 15},
1734            {0x185, 15}, {0x186, 15}, {0x187, 15}, {0x188, 15},
1735            {0x189, 15}, {0x18a, 15}, {0x18b, 15}, {0x18c, 15},
1736            {0x18d, 15}, {0x18e, 15}, {0x18f, 15}, {0x190, 15},
1737            {0x191, 15}, {0x192, 15}, {0x193, 15}, {0x194, 15},
1738            {0x195, 15}, {0x196, 15}, {0x197, 15}, {0x198, 15},
1739            {0x199, 15}, {0x19a, 15}, {0x19b, 15}, {0x19c, 15},
1740            {0x19d, 15}, {0x19e, 15}, {0x19f, 15}, {0x1a0, 15},
1741            {0x1a1, 15}, {0x1a2, 15}, {0x1a3, 15}, {0x1a4, 15},
1742            {0x1a5, 15}, {0x1a6, 15}, {0x1a7, 15}, {0x1a8, 15},
1743            {0x1a9, 15}, {0x1aa, 15}, {0x1ab, 15}, {0x1ac, 15},
1744            {0x1ad, 15}, {0x1ae, 15}, {0x1af, 15}, {0x1b0, 15},
1745            {0x1b1, 15}, {0x1b2, 15}, {0x1b3, 15}, {0x1b4, 15},
1746            {0x1b5, 15}, {0x1b6, 15}, {0x1b7, 15}, {0x1b8, 15},
1747            {0x1b9, 15}, {0x1ba, 15}, {0x1bb, 15}, {0x1bc, 15},
1748            {0x1bd, 15}, {0x1be, 15}, {0x1bf, 15}, {0x1c0, 15},
1749            {0x1c1, 15}, {0x1c2, 15}, {0x1c3, 15}, {0x1c4, 15},
1750            {0x1c5, 15}, {0x1c6, 15}, {0x1c7, 15}, {0x1c8, 15},
1751            {0x1c9, 15}, {0x1ca, 15}, {0x1cb, 15}, {0x1cc, 15},
1752            {0x1cd, 15}, {0x1ce, 15}, {0x1cf, 15}, {0x1d0, 15},
1753            {0x1d1, 15}, {0x1d2, 15}, {0x1d3, 15}, {0x1d4, 15},
1754            {0x1d5, 15}, {0x1d6, 15}, {0x1d7, 15}, {0x1d8, 15},
1755            {0x1d9, 15}, {0x1da, 15}, {0x1db, 15}, {0x1dc, 15},
1756            {0x1dd, 15}, {0x1de, 15}, {0x1df, 15}, {0x1e0, 15},
1757            {0x1e1, 15}, {0x1e2, 15}, {0x1e3, 15}, {0x1e4, 15},
1758            {0x1e5, 15}, {0x1e6, 15}, {0x1e7, 15}, {0x1e8, 15},
1759            {0x1e9, 15}, {0x1ea, 15}, {0x1eb, 15}, {0x1ec, 15},
1760            {0x1ed, 15}, {0x1ee, 15}, {0x1ef, 15}, {0x1f0, 15},
1761            {0x1f1, 15}, {0x1f2, 15}, {0x1f3, 15}, {0x1f4, 15},
1762            {0x1f5, 15}, {0x1f6, 15}, {0x1f7, 15}, {0x1f8, 15},
1763            {0x1f9, 15}, {0x1fa, 15}, {0x1fb, 15}, {0x1fc, 15},
1764            {0x1fd, 15}, {0x1fe, 15}, {0x1ff, 15},
1765    };
1766    
1767    const VLC dcc_tab[511] = {
1768            {0x100, 16}, {0x101, 16}, {0x102, 16}, {0x103, 16},
1769            {0x104, 16}, {0x105, 16}, {0x106, 16}, {0x107, 16},
1770            {0x108, 16}, {0x109, 16}, {0x10a, 16}, {0x10b, 16},
1771            {0x10c, 16}, {0x10d, 16}, {0x10e, 16}, {0x10f, 16},
1772            {0x110, 16}, {0x111, 16}, {0x112, 16}, {0x113, 16},
1773            {0x114, 16}, {0x115, 16}, {0x116, 16}, {0x117, 16},
1774            {0x118, 16}, {0x119, 16}, {0x11a, 16}, {0x11b, 16},
1775            {0x11c, 16}, {0x11d, 16}, {0x11e, 16}, {0x11f, 16},
1776            {0x120, 16}, {0x121, 16}, {0x122, 16}, {0x123, 16},
1777            {0x124, 16}, {0x125, 16}, {0x126, 16}, {0x127, 16},
1778            {0x128, 16}, {0x129, 16}, {0x12a, 16}, {0x12b, 16},
1779            {0x12c, 16}, {0x12d, 16}, {0x12e, 16}, {0x12f, 16},
1780            {0x130, 16}, {0x131, 16}, {0x132, 16}, {0x133, 16},
1781            {0x134, 16}, {0x135, 16}, {0x136, 16}, {0x137, 16},
1782            {0x138, 16}, {0x139, 16}, {0x13a, 16}, {0x13b, 16},
1783            {0x13c, 16}, {0x13d, 16}, {0x13e, 16}, {0x13f, 16},
1784            {0x140, 16}, {0x141, 16}, {0x142, 16}, {0x143, 16},
1785            {0x144, 16}, {0x145, 16}, {0x146, 16}, {0x147, 16},
1786            {0x148, 16}, {0x149, 16}, {0x14a, 16}, {0x14b, 16},
1787            {0x14c, 16}, {0x14d, 16}, {0x14e, 16}, {0x14f, 16},
1788            {0x150, 16}, {0x151, 16}, {0x152, 16}, {0x153, 16},
1789            {0x154, 16}, {0x155, 16}, {0x156, 16}, {0x157, 16},
1790            {0x158, 16}, {0x159, 16}, {0x15a, 16}, {0x15b, 16},
1791            {0x15c, 16}, {0x15d, 16}, {0x15e, 16}, {0x15f, 16},
1792            {0x160, 16}, {0x161, 16}, {0x162, 16}, {0x163, 16},
1793            {0x164, 16}, {0x165, 16}, {0x166, 16}, {0x167, 16},
1794            {0x168, 16}, {0x169, 16}, {0x16a, 16}, {0x16b, 16},
1795            {0x16c, 16}, {0x16d, 16}, {0x16e, 16}, {0x16f, 16},
1796            {0x170, 16}, {0x171, 16}, {0x172, 16}, {0x173, 16},
1797            {0x174, 16}, {0x175, 16}, {0x176, 16}, {0x177, 16},
1798            {0x178, 16}, {0x179, 16}, {0x17a, 16}, {0x17b, 16},
1799            {0x17c, 16}, {0x17d, 16}, {0x17e, 16}, {0x17f, 16},
1800            {0x80, 14}, {0x81, 14}, {0x82, 14}, {0x83, 14},
1801            {0x84, 14}, {0x85, 14}, {0x86, 14}, {0x87, 14},
1802            {0x88, 14}, {0x89, 14}, {0x8a, 14}, {0x8b, 14},
1803            {0x8c, 14}, {0x8d, 14}, {0x8e, 14}, {0x8f, 14},
1804            {0x90, 14}, {0x91, 14}, {0x92, 14}, {0x93, 14},
1805            {0x94, 14}, {0x95, 14}, {0x96, 14}, {0x97, 14},
1806            {0x98, 14}, {0x99, 14}, {0x9a, 14}, {0x9b, 14},
1807            {0x9c, 14}, {0x9d, 14}, {0x9e, 14}, {0x9f, 14},
1808            {0xa0, 14}, {0xa1, 14}, {0xa2, 14}, {0xa3, 14},
1809            {0xa4, 14}, {0xa5, 14}, {0xa6, 14}, {0xa7, 14},
1810            {0xa8, 14}, {0xa9, 14}, {0xaa, 14}, {0xab, 14},
1811            {0xac, 14}, {0xad, 14}, {0xae, 14}, {0xaf, 14},
1812            {0xb0, 14}, {0xb1, 14}, {0xb2, 14}, {0xb3, 14},
1813            {0xb4, 14}, {0xb5, 14}, {0xb6, 14}, {0xb7, 14},
1814            {0xb8, 14}, {0xb9, 14}, {0xba, 14}, {0xbb, 14},
1815            {0xbc, 14}, {0xbd, 14}, {0xbe, 14}, {0xbf, 14},
1816            {0x40, 12}, {0x41, 12}, {0x42, 12}, {0x43, 12},
1817            {0x44, 12}, {0x45, 12}, {0x46, 12}, {0x47, 12},
1818            {0x48, 12}, {0x49, 12}, {0x4a, 12}, {0x4b, 12},
1819            {0x4c, 12}, {0x4d, 12}, {0x4e, 12}, {0x4f, 12},
1820            {0x50, 12}, {0x51, 12}, {0x52, 12}, {0x53, 12},
1821            {0x54, 12}, {0x55, 12}, {0x56, 12}, {0x57, 12},
1822            {0x58, 12}, {0x59, 12}, {0x5a, 12}, {0x5b, 12},
1823            {0x5c, 12}, {0x5d, 12}, {0x5e, 12}, {0x5f, 12},
1824            {0x20, 10}, {0x21, 10}, {0x22, 10}, {0x23, 10},
1825            {0x24, 10}, {0x25, 10}, {0x26, 10}, {0x27, 10},
1826            {0x28, 10}, {0x29, 10}, {0x2a, 10}, {0x2b, 10},
1827            {0x2c, 10}, {0x2d, 10}, {0x2e, 10}, {0x2f, 10},
1828            {0x10, 8}, {0x11, 8}, {0x12, 8}, {0x13, 8},
1829            {0x14, 8}, {0x15, 8}, {0x16, 8}, {0x17, 8},
1830            {0x08, 6}, {0x09, 6}, {0x0a, 6}, {0x0b, 6},
1831            {0x04, 4}, {0x05, 4}, {0x04, 3}, {0x03, 2},
1832            {0x05, 3}, {0x06, 4}, {0x07, 4}, {0x0c, 6},
1833            {0x0d, 6}, {0x0e, 6}, {0x0f, 6}, {0x18, 8},
1834            {0x19, 8}, {0x1a, 8}, {0x1b, 8}, {0x1c, 8},
1835            {0x1d, 8}, {0x1e, 8}, {0x1f, 8}, {0x30, 10},
1836            {0x31, 10}, {0x32, 10}, {0x33, 10}, {0x34, 10},
1837            {0x35, 10}, {0x36, 10}, {0x37, 10}, {0x38, 10},
1838            {0x39, 10}, {0x3a, 10}, {0x3b, 10}, {0x3c, 10},
1839            {0x3d, 10}, {0x3e, 10}, {0x3f, 10}, {0x60, 12},
1840            {0x61, 12}, {0x62, 12}, {0x63, 12}, {0x64, 12},
1841            {0x65, 12}, {0x66, 12}, {0x67, 12}, {0x68, 12},
1842            {0x69, 12}, {0x6a, 12}, {0x6b, 12}, {0x6c, 12},
1843            {0x6d, 12}, {0x6e, 12}, {0x6f, 12}, {0x70, 12},
1844            {0x71, 12}, {0x72, 12}, {0x73, 12}, {0x74, 12},
1845            {0x75, 12}, {0x76, 12}, {0x77, 12}, {0x78, 12},
1846            {0x79, 12}, {0x7a, 12}, {0x7b, 12}, {0x7c, 12},
1847            {0x7d, 12}, {0x7e, 12}, {0x7f, 12}, {0xc0, 14},
1848            {0xc1, 14}, {0xc2, 14}, {0xc3, 14}, {0xc4, 14},
1849            {0xc5, 14}, {0xc6, 14}, {0xc7, 14}, {0xc8, 14},
1850            {0xc9, 14}, {0xca, 14}, {0xcb, 14}, {0xcc, 14},
1851            {0xcd, 14}, {0xce, 14}, {0xcf, 14}, {0xd0, 14},
1852            {0xd1, 14}, {0xd2, 14}, {0xd3, 14}, {0xd4, 14},
1853            {0xd5, 14}, {0xd6, 14}, {0xd7, 14}, {0xd8, 14},
1854            {0xd9, 14}, {0xda, 14}, {0xdb, 14}, {0xdc, 14},
1855            {0xdd, 14}, {0xde, 14}, {0xdf, 14}, {0xe0, 14},
1856            {0xe1, 14}, {0xe2, 14}, {0xe3, 14}, {0xe4, 14},
1857            {0xe5, 14}, {0xe6, 14}, {0xe7, 14}, {0xe8, 14},
1858            {0xe9, 14}, {0xea, 14}, {0xeb, 14}, {0xec, 14},
1859            {0xed, 14}, {0xee, 14}, {0xef, 14}, {0xf0, 14},
1860            {0xf1, 14}, {0xf2, 14}, {0xf3, 14}, {0xf4, 14},
1861            {0xf5, 14}, {0xf6, 14}, {0xf7, 14}, {0xf8, 14},
1862            {0xf9, 14}, {0xfa, 14}, {0xfb, 14}, {0xfc, 14},
1863            {0xfd, 14}, {0xfe, 14}, {0xff, 14}, {0x180, 16},
1864            {0x181, 16}, {0x182, 16}, {0x183, 16}, {0x184, 16},
1865            {0x185, 16}, {0x186, 16}, {0x187, 16}, {0x188, 16},
1866            {0x189, 16}, {0x18a, 16}, {0x18b, 16}, {0x18c, 16},
1867            {0x18d, 16}, {0x18e, 16}, {0x18f, 16}, {0x190, 16},
1868            {0x191, 16}, {0x192, 16}, {0x193, 16}, {0x194, 16},
1869            {0x195, 16}, {0x196, 16}, {0x197, 16}, {0x198, 16},
1870            {0x199, 16}, {0x19a, 16}, {0x19b, 16}, {0x19c, 16},
1871            {0x19d, 16}, {0x19e, 16}, {0x19f, 16}, {0x1a0, 16},
1872            {0x1a1, 16}, {0x1a2, 16}, {0x1a3, 16}, {0x1a4, 16},
1873            {0x1a5, 16}, {0x1a6, 16}, {0x1a7, 16}, {0x1a8, 16},
1874            {0x1a9, 16}, {0x1aa, 16}, {0x1ab, 16}, {0x1ac, 16},
1875            {0x1ad, 16}, {0x1ae, 16}, {0x1af, 16}, {0x1b0, 16},
1876            {0x1b1, 16}, {0x1b2, 16}, {0x1b3, 16}, {0x1b4, 16},
1877            {0x1b5, 16}, {0x1b6, 16}, {0x1b7, 16}, {0x1b8, 16},
1878            {0x1b9, 16}, {0x1ba, 16}, {0x1bb, 16}, {0x1bc, 16},
1879            {0x1bd, 16}, {0x1be, 16}, {0x1bf, 16}, {0x1c0, 16},
1880            {0x1c1, 16}, {0x1c2, 16}, {0x1c3, 16}, {0x1c4, 16},
1881            {0x1c5, 16}, {0x1c6, 16}, {0x1c7, 16}, {0x1c8, 16},
1882            {0x1c9, 16}, {0x1ca, 16}, {0x1cb, 16}, {0x1cc, 16},
1883            {0x1cd, 16}, {0x1ce, 16}, {0x1cf, 16}, {0x1d0, 16},
1884            {0x1d1, 16}, {0x1d2, 16}, {0x1d3, 16}, {0x1d4, 16},
1885            {0x1d5, 16}, {0x1d6, 16}, {0x1d7, 16}, {0x1d8, 16},
1886            {0x1d9, 16}, {0x1da, 16}, {0x1db, 16}, {0x1dc, 16},
1887            {0x1dd, 16}, {0x1de, 16}, {0x1df, 16}, {0x1e0, 16},
1888            {0x1e1, 16}, {0x1e2, 16}, {0x1e3, 16}, {0x1e4, 16},
1889            {0x1e5, 16}, {0x1e6, 16}, {0x1e7, 16}, {0x1e8, 16},
1890            {0x1e9, 16}, {0x1ea, 16}, {0x1eb, 16}, {0x1ec, 16},
1891            {0x1ed, 16}, {0x1ee, 16}, {0x1ef, 16}, {0x1f0, 16},
1892            {0x1f1, 16}, {0x1f2, 16}, {0x1f3, 16}, {0x1f4, 16},
1893            {0x1f5, 16}, {0x1f6, 16}, {0x1f7, 16}, {0x1f8, 16},
1894            {0x1f9, 16}, {0x1fa, 16}, {0x1fb, 16}, {0x1fc, 16},
1895            {0x1fd, 16}, {0x1fe, 16}, {0x1ff, 16},
1896    };
1897    
1898    
1899    const VLC mb_motion_table[65] = {
1900            {0x05, 13}, {0x07, 13}, {0x05, 12}, {0x07, 12},
1901            {0x09, 12}, {0x0b, 12}, {0x0d, 12}, {0x0f, 12},
1902            {0x09, 11}, {0x0b, 11}, {0x0d, 11}, {0x0f, 11},
1903            {0x11, 11}, {0x13, 11}, {0x15, 11}, {0x17, 11},
1904            {0x19, 11}, {0x1b, 11}, {0x1d, 11}, {0x1f, 11},
1905            {0x21, 11}, {0x23, 11}, {0x13, 10}, {0x15, 10},
1906            {0x17, 10}, {0x07, 8}, {0x09, 8}, {0x0b, 8},
1907            {0x07, 7}, {0x03, 5}, {0x03, 4}, {0x03, 3},
1908            {0x01, 1}, {0x02, 3}, {0x02, 4}, {0x02, 5},
1909            {0x06, 7}, {0x0a, 8}, {0x08, 8}, {0x06, 8},
1910            {0x16, 10}, {0x14, 10}, {0x12, 10}, {0x22, 11},
1911            {0x20, 11}, {0x1e, 11}, {0x1c, 11}, {0x1a, 11},
1912            {0x18, 11}, {0x16, 11}, {0x14, 11}, {0x12, 11},
1913            {0x10, 11}, {0x0e, 11}, {0x0c, 11}, {0x0a, 11},
1914            {0x08, 11}, {0x0e, 12}, {0x0c, 12}, {0x0a, 12},
1915            {0x08, 12}, {0x06, 12}, {0x04, 12}, {0x06, 13},
1916            {0x04, 13}
1917    };
1918    
1919    
1920    /******************************************************************
1921     * decoder tables                                                 *
1922     ******************************************************************/
1923    
1924    VLC const mcbpc_intra_table[64] = {
1925            {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4},  {4, 4},  {4, 4},  {4, 4},
1926            {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
1927            {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},
1928            {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3}, {51, 3},
1929            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1930            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1931            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},
1932            {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1}
1933    };
1934    
1935    VLC const mcbpc_inter_table[257] = {
1936            {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},
1937            {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},
1938            {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
1939            {33, 7}, {33, 7}, {33, 7}, {33, 7}, {17, 7}, {17, 7}, {17, 7}, {17, 7},
1940            {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6}, {4, 6},
1941            {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6}, {48, 6},
1942            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1943            {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5}, {3, 5},
1944            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1945            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1946            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1947            {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4}, {32, 4},
1948            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1949            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1950            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1951            {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4}, {16, 4},
1952            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1953            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1954            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1955            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1956            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1957            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1958            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1959            {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3}, {2, 3},
1960            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1961            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1962            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1963            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1964            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1965            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1966            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1967            {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
1968            {0, 1}
1969    };
1970    
1971    VLC const cbpy_table[64] = {
1972            {-1, 0}, {-1, 0}, {6, 6},  {9, 6},  {8, 5},  {8, 5},  {4, 5},  {4, 5},
1973            {2, 5},  {2, 5},  {1, 5},  {1, 5},  {0, 4},  {0, 4},  {0, 4},  {0, 4},
1974            {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
1975            {14, 4}, {14, 4}, {14, 4}, {14, 4}, {5, 4},  {5, 4},  {5, 4},  {5, 4},
1976            {13, 4}, {13, 4}, {13, 4}, {13, 4}, {3, 4},  {3, 4},  {3, 4},  {3, 4},
1977            {11, 4}, {11, 4}, {11, 4}, {11, 4}, {7, 4},  {7, 4},  {7, 4},  {7, 4},
1978            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2},
1979            {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}
1980    };
1981    
1982    VLC const TMNMVtab0[] = {
1983            {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},
1984            {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}
1985    };
1986    
1987    VLC const TMNMVtab1[] = {
1988            {12, 10}, {-12, 10}, {11, 10}, {-11, 10},
1989            {10, 9}, {10, 9}, {-10, 9}, {-10, 9},
1990            {9, 9}, {9, 9}, {-9, 9}, {-9, 9},
1991            {8, 9}, {8, 9}, {-8, 9}, {-8, 9},
1992            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1993            {7, 7}, {7, 7}, {7, 7}, {7, 7},
1994            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1995            {-7, 7}, {-7, 7}, {-7, 7}, {-7, 7},
1996            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1997            {6, 7}, {6, 7}, {6, 7}, {6, 7},
1998            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
1999            {-6, 7}, {-6, 7}, {-6, 7}, {-6, 7},
2000            {5, 7}, {5, 7}, {5, 7}, {5, 7},
2001            {5, 7}, {5, 7}, {5, 7}, {5, 7},
2002            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
2003            {-5, 7}, {-5, 7}, {-5, 7}, {-5, 7},
2004            {4, 6}, {4, 6}, {4, 6}, {4, 6},
2005            {4, 6}, {4, 6}, {4, 6}, {4, 6},
2006            {4, 6}, {4, 6}, {4, 6}, {4, 6},
2007            {4, 6}, {4, 6}, {4, 6}, {4, 6},
2008            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
2009            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
2010            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6},
2011            {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}
2012    };
2013    
2014    VLC const TMNMVtab2[] = {
2015            {32, 12}, {-32, 12}, {31, 12}, {-31, 12},
2016            {30, 11}, {30, 11}, {-30, 11}, {-30, 11},
2017            {29, 11}, {29, 11}, {-29, 11}, {-29, 11},
2018            {28, 11}, {28, 11}, {-28, 11}, {-28, 11},
2019            {27, 11}, {27, 11}, {-27, 11}, {-27, 11},
2020            {26, 11}, {26, 11}, {-26, 11}, {-26, 11},
2021            {25, 11}, {25, 11}, {-25, 11}, {-25, 11},
2022            {24, 10}, {24, 10}, {24, 10}, {24, 10},
2023            {-24, 10}, {-24, 10}, {-24, 10}, {-24, 10},
2024            {23, 10}, {23, 10}, {23, 10}, {23, 10},
2025            {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10},
2026            {22, 10}, {22, 10}, {22, 10}, {22, 10},
2027            {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10},
2028            {21, 10}, {21, 10}, {21, 10}, {21, 10},
2029            {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10},
2030            {20, 10}, {20, 10}, {20, 10}, {20, 10},
2031            {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10},
2032            {19, 10}, {19, 10}, {19, 10}, {19, 10},
2033            {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10},
2034            {18, 10}, {18, 10}, {18, 10}, {18, 10},
2035            {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10},
2036            {17, 10}, {17, 10}, {17, 10}, {17, 10},
2037            {-17, 10}, {-17, 10}, {-17, 10}, {-17, 10},
2038            {16, 10}, {16, 10}, {16, 10}, {16, 10},
2039            {-16, 10}, {-16, 10}, {-16, 10}, {-16, 10},
2040            {15, 10}, {15, 10}, {15, 10}, {15, 10},
2041            {-15, 10}, {-15, 10}, {-15, 10}, {-15, 10},
2042            {14, 10}, {14, 10}, {14, 10}, {14, 10},
2043            {-14, 10}, {-14, 10}, {-14, 10}, {-14, 10},
2044            {13, 10}, {13, 10}, {13, 10}, {13, 10},
2045            {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}
2046    };
2047    
2048    short const dc_threshold[] = {
2049            21514, 26984,  8307, 28531, 29798, 24951, 25970, 26912,
2050             8307, 25956, 26994, 25974,  8292, 29286, 28015, 29728,
2051            25960, 18208, 21838, 18208, 19536, 22560, 26998,  8260,
2052            28515, 25956,  8291, 25640, 30309, 27749, 11817, 22794,
2053            30063,  8306, 28531, 29798, 24951, 25970, 25632, 29545,
2054            29300, 25193, 29813, 29295, 26656, 29537, 29728,  8303,
2055            26983, 25974, 24864, 25443, 29541,  8307, 28532, 26912,
2056            29556, 29472, 30063, 25458,  8293, 28515, 25956,  2606
2057    };
2058    
2059    VLC const dc_lum_tab[] = {
2060            {0, 0}, {4, 3}, {3, 3}, {0, 3},
2061            {2, 2}, {2, 2}, {1, 2}, {1, 2},
2062    };

Legend:
Removed from v.1.37  
changed lines
  Added in v.1.44.2.8

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