[cvs] / xvidcore / src / bitstream / vlc_codes.h Repository:
ViewVC logotype

Diff of /xvidcore/src/bitstream/vlc_codes.h

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

revision 1.6.2.3, Thu Jan 16 21:16:04 2003 UTC revision 1.7, Sun Sep 8 13:44:11 2002 UTC
# Line 1  Line 1 
1    /*****************************************************************************
2     *
3     *  XVID MPEG-4 VIDEO CODEC
4     *  - Vector Length Coding tables -
5     *
6     *  Copyright(C) 2002 Michael Militzer
7     *
8     *
9     *  This program is an implementation of a part of one or more MPEG-4
10     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
11     *  to use this software module in hardware or software products are
12     *  advised that its use may infringe existing patents or copyrights, and
13     *  any such use would be at such party's own risk.  The original
14     *  developer of this software module and his/her company, and subsequent
15     *  editors and their companies, will have no liability for use of this
16     *  software or modifications or derivatives thereof.
17     *
18     *  This program is free software; you can redistribute it and/or modify
19     *  it under the terms of the GNU General Public License as published by
20     *  the Free Software Foundation; either version 2 of the License, or
21     *  (at your option) any later version.
22     *
23     *  This program is distributed in the hope that it will be useful,
24     *  but WITHOUT ANY WARRANTY; without even the implied warranty of
25     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26     *  GNU General Public License for more details.
27     *
28     *  You should have received a copy of the GNU General Public License
29     *  along with this program; if not, write to the Free Software
30     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
31     *
32     * $Id$
33     *
34     ****************************************************************************/
35    
36  #ifndef _VLC_CODES_H_  #ifndef _VLC_CODES_H_
37  #define _VLC_CODES_H_  #define _VLC_CODES_H_
38    
# Line 5  Line 40 
40  #include "mbcoding.h"  #include "mbcoding.h"
41    
42  #define VLC_ERROR       (-1)  #define VLC_ERROR       (-1)
43    #define ESCAPE 7167
44    
45  #define ESCAPE  3  /*****************************************************************************
46  #define ESCAPE1 6   * The Vector Length Coding structure
47  #define ESCAPE2 14   ****************************************************************************/
 #define ESCAPE3 15  
48    
49  typedef struct  typedef struct
50  {  {
51          uint32_t code;          uint32_t code;
52          uint8_t len;          int8_t len;
53  }  }
54  VLC;  VLC;
55    
56  typedef struct  static VLC *DCT3D[2];
 {  
         uint8_t last;  
         uint8_t run;  
         int8_t level;  
 }  
 EVENT;  
   
 typedef struct  
 {  
         uint8_t len;  
         EVENT event;  
 }  
 REVERSE_EVENT;  
   
 typedef struct  
 {  
         VLC vlc;  
         EVENT event;  
 }  
 VLC_TABLE;  
57    
58    
59  /******************************************************************  /*****************************************************************************
60   * common tables between encoder/decoder                          *   * common tables between encoder/decoder
61   ******************************************************************/   ****************************************************************************/
62    
63  static VLC_TABLE const coeff_tab[2][102] =  /* constants taken from momusys/vm_common/inlcude/max_level.h */
64  {  static char max_level[4][64] = {
65          /* intra = 0 */          /* intra, last = 0 */
66          {          {
67                  {{ 2,  2}, {0, 0, 1}},           27, 10, 5, 4, 3, 3, 3, 3,
68                  {{15,  4}, {0, 0, 2}},           2, 2, 1, 1, 1, 1, 1, 0,
69                  {{21,  6}, {0, 0, 3}},           0, 0, 0, 0, 0, 0, 0, 0,
70                  {{23,  7}, {0, 0, 4}},           0, 0, 0, 0, 0, 0, 0, 0,
71                  {{31,  8}, {0, 0, 5}},           0, 0, 0, 0, 0, 0, 0, 0,
72                  {{37,  9}, {0, 0, 6}},           0, 0, 0, 0, 0, 0, 0, 0,
73                  {{36,  9}, {0, 0, 7}},           0, 0, 0, 0, 0, 0, 0, 0,
74                  {{33, 10}, {0, 0, 8}},           0, 0, 0, 0, 0, 0, 0, 0
                 {{32, 10}, {0, 0, 9}},  
                 {{ 7, 11}, {0, 0, 10}},  
                 {{ 6, 11}, {0, 0, 11}},  
                 {{32, 11}, {0, 0, 12}},  
                 {{ 6,  3}, {0, 1, 1}},  
                 {{20,  6}, {0, 1, 2}},  
                 {{30,  8}, {0, 1, 3}},  
                 {{15, 10}, {0, 1, 4}},  
                 {{33, 11}, {0, 1, 5}},  
                 {{80, 12}, {0, 1, 6}},  
                 {{14,  4}, {0, 2, 1}},  
                 {{29,  8}, {0, 2, 2}},  
                 {{14, 10}, {0, 2, 3}},  
                 {{81, 12}, {0, 2, 4}},  
                 {{13,  5}, {0, 3, 1}},  
                 {{35,  9}, {0, 3, 2}},  
                 {{13, 10}, {0, 3, 3}},  
                 {{12,  5}, {0, 4, 1}},  
                 {{34,  9}, {0, 4, 2}},  
                 {{82, 12}, {0, 4, 3}},  
                 {{11,  5}, {0, 5, 1}},  
                 {{12, 10}, {0, 5, 2}},  
                 {{83, 12}, {0, 5, 3}},  
                 {{19,  6}, {0, 6, 1}},  
                 {{11, 10}, {0, 6, 2}},  
                 {{84, 12}, {0, 6, 3}},  
                 {{18,  6}, {0, 7, 1}},  
                 {{10, 10}, {0, 7, 2}},  
                 {{17,  6}, {0, 8, 1}},  
                 {{ 9, 10}, {0, 8, 2}},  
                 {{16,  6}, {0, 9, 1}},  
                 {{ 8, 10}, {0, 9, 2}},  
                 {{22,  7}, {0, 10, 1}},  
                 {{85, 12}, {0, 10, 2}},  
                 {{21,  7}, {0, 11, 1}},  
                 {{20,  7}, {0, 12, 1}},  
                 {{28,  8}, {0, 13, 1}},  
                 {{27,  8}, {0, 14, 1}},  
                 {{33,  9}, {0, 15, 1}},  
                 {{32,  9}, {0, 16, 1}},  
                 {{31,  9}, {0, 17, 1}},  
                 {{30,  9}, {0, 18, 1}},  
                 {{29,  9}, {0, 19, 1}},  
                 {{28,  9}, {0, 20, 1}},  
                 {{27,  9}, {0, 21, 1}},  
                 {{26,  9}, {0, 22, 1}},  
                 {{34, 11}, {0, 23, 1}},  
                 {{35, 11}, {0, 24, 1}},  
                 {{86, 12}, {0, 25, 1}},  
                 {{87, 12}, {0, 26, 1}},  
                 {{ 7,  4}, {1, 0, 1}},  
                 {{25,  9}, {1, 0, 2}},  
                 {{ 5, 11}, {1, 0, 3}},  
                 {{15,  6}, {1, 1, 1}},  
                 {{ 4, 11}, {1, 1, 2}},  
                 {{14,  6}, {1, 2, 1}},  
                 {{13,  6}, {1, 3, 1}},  
                 {{12,  6}, {1, 4, 1}},  
                 {{19,  7}, {1, 5, 1}},  
                 {{18,  7}, {1, 6, 1}},  
                 {{17,  7}, {1, 7, 1}},  
                 {{16,  7}, {1, 8, 1}},  
                 {{26,  8}, {1, 9, 1}},  
                 {{25,  8}, {1, 10, 1}},  
                 {{24,  8}, {1, 11, 1}},  
                 {{23,  8}, {1, 12, 1}},  
                 {{22,  8}, {1, 13, 1}},  
                 {{21,  8}, {1, 14, 1}},  
                 {{20,  8}, {1, 15, 1}},  
                 {{19,  8}, {1, 16, 1}},  
                 {{24,  9}, {1, 17, 1}},  
                 {{23,  9}, {1, 18, 1}},  
                 {{22,  9}, {1, 19, 1}},  
                 {{21,  9}, {1, 20, 1}},  
                 {{20,  9}, {1, 21, 1}},  
                 {{19,  9}, {1, 22, 1}},  
                 {{18,  9}, {1, 23, 1}},  
                 {{17,  9}, {1, 24, 1}},  
                 {{ 7, 10}, {1, 25, 1}},  
                 {{ 6, 10}, {1, 26, 1}},  
                 {{ 5, 10}, {1, 27, 1}},  
                 {{ 4, 10}, {1, 28, 1}},  
                 {{36, 11}, {1, 29, 1}},  
                 {{37, 11}, {1, 30, 1}},  
                 {{38, 11}, {1, 31, 1}},  
                 {{39, 11}, {1, 32, 1}},  
                 {{88, 12}, {1, 33, 1}},  
                 {{89, 12}, {1, 34, 1}},  
                 {{90, 12}, {1, 35, 1}},  
                 {{91, 12}, {1, 36, 1}},  
                 {{92, 12}, {1, 37, 1}},  
                 {{93, 12}, {1, 38, 1}},  
                 {{94, 12}, {1, 39, 1}},  
                 {{95, 12}, {1, 40, 1}}  
75          },          },
         /* intra = 1 */  
         {  
                 {{ 2,  2}, {0, 0, 1}},  
                 {{15,  4}, {0, 0, 3}},  
                 {{21,  6}, {0, 0, 6}},  
                 {{23,  7}, {0, 0, 9}},  
                 {{31,  8}, {0, 0, 10}},  
                 {{37,  9}, {0, 0, 13}},  
                 {{36,  9}, {0, 0, 14}},  
                 {{33, 10}, {0, 0, 17}},  
                 {{32, 10}, {0, 0, 18}},  
                 {{ 7, 11}, {0, 0, 21}},  
                 {{ 6, 11}, {0, 0, 22}},  
                 {{32, 11}, {0, 0, 23}},  
                 {{ 6,  3}, {0, 0, 2}},  
                 {{20,  6}, {0, 1, 2}},  
                 {{30,  8}, {0, 0, 11}},  
                 {{15, 10}, {0, 0, 19}},  
                 {{33, 11}, {0, 0, 24}},  
                 {{80, 12}, {0, 0, 25}},  
                 {{14,  4}, {0, 1, 1}},  
                 {{29,  8}, {0, 0, 12}},  
                 {{14, 10}, {0, 0, 20}},  
                 {{81, 12}, {0, 0, 26}},  
                 {{13,  5}, {0, 0, 4}},  
                 {{35,  9}, {0, 0, 15}},  
                 {{13, 10}, {0, 1, 7}},  
                 {{12,  5}, {0, 0, 5}},  
                 {{34,  9}, {0, 4, 2}},  
                 {{82, 12}, {0, 0, 27}},  
                 {{11,  5}, {0, 2, 1}},  
                 {{12, 10}, {0, 2, 4}},  
                 {{83, 12}, {0, 1, 9}},  
                 {{19,  6}, {0, 0, 7}},  
                 {{11, 10}, {0, 3, 4}},  
                 {{84, 12}, {0, 6, 3}},  
                 {{18,  6}, {0, 0, 8}},  
                 {{10, 10}, {0, 4, 3}},  
                 {{17,  6}, {0, 3, 1}},  
                 {{ 9, 10}, {0, 8, 2}},  
                 {{16,  6}, {0, 4, 1}},  
                 {{ 8, 10}, {0, 5, 3}},  
                 {{22,  7}, {0, 1, 3}},  
                 {{85, 12}, {0, 1, 10}},  
                 {{21,  7}, {0, 2, 2}},  
                 {{20,  7}, {0, 7, 1}},  
                 {{28,  8}, {0, 1, 4}},  
                 {{27,  8}, {0, 3, 2}},  
                 {{33,  9}, {0, 0, 16}},  
                 {{32,  9}, {0, 1, 5}},  
                 {{31,  9}, {0, 1, 6}},  
                 {{30,  9}, {0, 2, 3}},  
                 {{29,  9}, {0, 3, 3}},  
                 {{28,  9}, {0, 5, 2}},  
                 {{27,  9}, {0, 6, 2}},  
                 {{26,  9}, {0, 7, 2}},  
                 {{34, 11}, {0, 1, 8}},  
                 {{35, 11}, {0, 9, 2}},  
                 {{86, 12}, {0, 2, 5}},  
                 {{87, 12}, {0, 7, 3}},  
                 {{ 7,  4}, {1, 0, 1}},  
                 {{25,  9}, {0, 11, 1}},  
                 {{ 5, 11}, {1, 0, 6}},  
                 {{15,  6}, {1, 1, 1}},  
                 {{ 4, 11}, {1, 0, 7}},  
                 {{14,  6}, {1, 2, 1}},  
                 {{13,  6}, {0, 5, 1}},  
                 {{12,  6}, {1, 0, 2}},  
                 {{19,  7}, {1, 5, 1}},  
                 {{18,  7}, {0, 6, 1}},  
                 {{17,  7}, {1, 3, 1}},  
                 {{16,  7}, {1, 4, 1}},  
                 {{26,  8}, {1, 9, 1}},  
                 {{25,  8}, {0, 8, 1}},  
                 {{24,  8}, {0, 9, 1}},  
                 {{23,  8}, {0, 10, 1}},  
                 {{22,  8}, {1, 0, 3}},  
                 {{21,  8}, {1, 6, 1}},  
                 {{20,  8}, {1, 7, 1}},  
                 {{19,  8}, {1, 8, 1}},  
                 {{24,  9}, {0, 12, 1}},  
                 {{23,  9}, {1, 0, 4}},  
                 {{22,  9}, {1, 1, 2}},  
                 {{21,  9}, {1, 10, 1}},  
                 {{20,  9}, {1, 11, 1}},  
                 {{19,  9}, {1, 12, 1}},  
                 {{18,  9}, {1, 13, 1}},  
                 {{17,  9}, {1, 14, 1}},  
                 {{ 7, 10}, {0, 13, 1}},  
                 {{ 6, 10}, {1, 0, 5}},  
                 {{ 5, 10}, {1, 1, 3}},  
                 {{ 4, 10}, {1, 2, 2}},  
                 {{36, 11}, {1, 3, 2}},  
                 {{37, 11}, {1, 4, 2}},  
                 {{38, 11}, {1, 15, 1}},  
                 {{39, 11}, {1, 16, 1}},  
                 {{88, 12}, {0, 14, 1}},  
                 {{89, 12}, {1, 0, 8}},  
                 {{90, 12}, {1, 5, 2}},  
                 {{91, 12}, {1, 6, 2}},  
                 {{92, 12}, {1, 17, 1}},  
                 {{93, 12}, {1, 18, 1}},  
                 {{94, 12}, {1, 19, 1}},  
                 {{95, 12}, {1, 20, 1}}  
         }  
 };  
76    
77  /* constants taken from momusys/vm_common/inlcude/max_level.h */          /* intra, last = 1 */
 static uint8_t const max_level[2][2][64] = {  
78          {          {
79                  /* intra = 0, last = 0 */           8, 3, 2, 2, 2, 2, 2, 1,
80             1, 1, 1, 1, 1, 1, 1, 1,
81             1, 1, 1, 1, 1, 0, 0, 0,
82             0, 0, 0, 0, 0, 0, 0, 0,
83             0, 0, 0, 0, 0, 0, 0, 0,
84             0, 0, 0, 0, 0, 0, 0, 0,
85             0, 0, 0, 0, 0, 0, 0, 0,
86             0, 0, 0, 0, 0, 0, 0, 0
87             },
88    
89            /* inter, last = 0 */
90                  {                  {
91                          12, 6, 4, 3, 3, 3, 3, 2,                          12, 6, 4, 3, 3, 3, 3, 2,
92                          2, 2, 2, 1, 1, 1, 1, 1,                          2, 2, 2, 1, 1, 1, 1, 1,
# Line 273  Line 97 
97                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
98                          0, 0, 0, 0, 0, 0, 0, 0                          0, 0, 0, 0, 0, 0, 0, 0
99                  },                  },
100                  /* intra = 0, last = 1 */  
101            /* inter, last = 1 */
102                  {                  {
103                          3, 2, 1, 1, 1, 1, 1, 1,                          3, 2, 1, 1, 1, 1, 1, 1,
104                          1, 1, 1, 1, 1, 1, 1, 1,                          1, 1, 1, 1, 1, 1, 1, 1,
# Line 284  Line 109 
109                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
110                          0, 0, 0, 0, 0, 0, 0, 0                          0, 0, 0, 0, 0, 0, 0, 0
111                  }                  }
112          },  };
113          {  
114                  /* intra = 1, last = 0 */  static char max_run[4][256] = {
115            /* intra, last = 0 */
116                  {                  {
117                          27, 10, 5, 4, 3, 3, 3, 3,           0, 14, 9, 7, 3, 2, 1, 1,
118                          2, 2, 1, 1, 1, 1, 1, 0,           1, 1, 1, 0, 0, 0, 0, 0,
119             0, 0, 0, 0, 0, 0, 0, 0,
120             0, 0, 0, 0, 0, 0, 0, 0,
121             0, 0, 0, 0, 0, 0, 0, 0,
122             0, 0, 0, 0, 0, 0, 0, 0,
123             0, 0, 0, 0, 0, 0, 0, 0,
124             0, 0, 0, 0, 0, 0, 0, 0,
125             0, 0, 0, 0, 0, 0, 0, 0,
126             0, 0, 0, 0, 0, 0, 0, 0,
127             0, 0, 0, 0, 0, 0, 0, 0,
128             0, 0, 0, 0, 0, 0, 0, 0,
129             0, 0, 0, 0, 0, 0, 0, 0,
130             0, 0, 0, 0, 0, 0, 0, 0,
131             0, 0, 0, 0, 0, 0, 0, 0,
132             0, 0, 0, 0, 0, 0, 0, 0,
133             0, 0, 0, 0, 0, 0, 0, 0,
134             0, 0, 0, 0, 0, 0, 0, 0,
135             0, 0, 0, 0, 0, 0, 0, 0,
136             0, 0, 0, 0, 0, 0, 0, 0,
137             0, 0, 0, 0, 0, 0, 0, 0,
138             0, 0, 0, 0, 0, 0, 0, 0,
139             0, 0, 0, 0, 0, 0, 0, 0,
140             0, 0, 0, 0, 0, 0, 0, 0,
141             0, 0, 0, 0, 0, 0, 0, 0,
142             0, 0, 0, 0, 0, 0, 0, 0,
143                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
144                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
145                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
# Line 297  Line 147 
147                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
148                          0, 0, 0, 0, 0, 0, 0, 0                          0, 0, 0, 0, 0, 0, 0, 0
149                  },                  },
150                  /* intra = 1, last = 1 */  
151            /* intra, last = 1 */
152                  {                  {
153                          8, 3, 2, 2, 2, 2, 2, 1,           0, 20, 6, 1, 0, 0, 0, 0,
154                          1, 1, 1, 1, 1, 1, 1, 1,           0, 0, 0, 0, 0, 0, 0, 0,
155                          1, 1, 1, 1, 1, 0, 0, 0,           0, 0, 0, 0, 0, 0, 0, 0,
156             0, 0, 0, 0, 0, 0, 0, 0,
157             0, 0, 0, 0, 0, 0, 0, 0,
158             0, 0, 0, 0, 0, 0, 0, 0,
159             0, 0, 0, 0, 0, 0, 0, 0,
160             0, 0, 0, 0, 0, 0, 0, 0,
161             0, 0, 0, 0, 0, 0, 0, 0,
162             0, 0, 0, 0, 0, 0, 0, 0,
163             0, 0, 0, 0, 0, 0, 0, 0,
164             0, 0, 0, 0, 0, 0, 0, 0,
165             0, 0, 0, 0, 0, 0, 0, 0,
166             0, 0, 0, 0, 0, 0, 0, 0,
167             0, 0, 0, 0, 0, 0, 0, 0,
168             0, 0, 0, 0, 0, 0, 0, 0,
169             0, 0, 0, 0, 0, 0, 0, 0,
170             0, 0, 0, 0, 0, 0, 0, 0,
171             0, 0, 0, 0, 0, 0, 0, 0,
172             0, 0, 0, 0, 0, 0, 0, 0,
173             0, 0, 0, 0, 0, 0, 0, 0,
174             0, 0, 0, 0, 0, 0, 0, 0,
175             0, 0, 0, 0, 0, 0, 0, 0,
176             0, 0, 0, 0, 0, 0, 0, 0,
177             0, 0, 0, 0, 0, 0, 0, 0,
178             0, 0, 0, 0, 0, 0, 0, 0,
179             0, 0, 0, 0, 0, 0, 0, 0,
180                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
181                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
182                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
183                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
184                          0, 0, 0, 0, 0, 0, 0, 0                          0, 0, 0, 0, 0, 0, 0, 0
185                  }           },
         }  
 };  
186    
187  static uint8_t const max_run[2][2][64] = {          /* inter, last = 0 */
         {  
                 /* intra = 0, last = 0 */  
188                  {                  {
189                          0, 26, 10, 6, 2, 1, 1, 0,                          0, 26, 10, 6, 2, 1, 1, 0,
190                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
# Line 323  Line 194 
194                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
195                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
196                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
197             0, 0, 0, 0, 0, 0, 0, 0,
198             0, 0, 0, 0, 0, 0, 0, 0,
199             0, 0, 0, 0, 0, 0, 0, 0,
200             0, 0, 0, 0, 0, 0, 0, 0,
201             0, 0, 0, 0, 0, 0, 0, 0,
202             0, 0, 0, 0, 0, 0, 0, 0,
203             0, 0, 0, 0, 0, 0, 0, 0,
204             0, 0, 0, 0, 0, 0, 0, 0,
205             0, 0, 0, 0, 0, 0, 0, 0,
206             0, 0, 0, 0, 0, 0, 0, 0,
207             0, 0, 0, 0, 0, 0, 0, 0,
208             0, 0, 0, 0, 0, 0, 0, 0,
209             0, 0, 0, 0, 0, 0, 0, 0,
210             0, 0, 0, 0, 0, 0, 0, 0,
211             0, 0, 0, 0, 0, 0, 0, 0,
212             0, 0, 0, 0, 0, 0, 0, 0,
213             0, 0, 0, 0, 0, 0, 0, 0,
214             0, 0, 0, 0, 0, 0, 0, 0,
215             0, 0, 0, 0, 0, 0, 0, 0,
216             0, 0, 0, 0, 0, 0, 0, 0,
217             0, 0, 0, 0, 0, 0, 0, 0,
218             0, 0, 0, 0, 0, 0, 0, 0,
219             0, 0, 0, 0, 0, 0, 0, 0,
220             0, 0, 0, 0, 0, 0, 0, 0
221                  },                  },
222                  /* intra = 0, last = 1 */  
223            /* inter, last = 1 */
224                  {                  {
225                          0, 40, 1, 0, 0, 0, 0, 0,                          0, 40, 1, 0, 0, 0, 0, 0,
226                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
# Line 334  Line 230 
230                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
231                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
232                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
                 }  
         },  
         {  
                 /* intra = 1, last = 0 */  
                 {  
                         0, 14, 9, 7, 3, 2, 1, 1,  
                         1, 1, 1, 0, 0, 0, 0, 0,  
233                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
234                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
235                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
236                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
237                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
238                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
                 },  
                 /* intra = 1, last = 1 */  
                 {  
                         0, 20, 6, 1, 0, 0, 0, 0,  
239                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
240                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
241                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
# Line 358  Line 243 
243                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
244                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
245                          0, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0, 0,
246                  }           0, 0, 0, 0, 0, 0, 0, 0,
247             0, 0, 0, 0, 0, 0, 0, 0,
248             0, 0, 0, 0, 0, 0, 0, 0,
249             0, 0, 0, 0, 0, 0, 0, 0,
250             0, 0, 0, 0, 0, 0, 0, 0,
251             0, 0, 0, 0, 0, 0, 0, 0,
252             0, 0, 0, 0, 0, 0, 0, 0,
253             0, 0, 0, 0, 0, 0, 0, 0,
254             0, 0, 0, 0, 0, 0, 0, 0,
255             0, 0, 0, 0, 0, 0, 0, 0,
256             0, 0, 0, 0, 0, 0, 0, 0
257          }          }
258  };  };
259    
260    
261  /******************************************************************  /******************************************************************
262   * encoder tables                                                 *   * encoder tables                                                 *
263   ******************************************************************/   ******************************************************************/
264    
265  static VLC sprite_trajectory_code[32768];  /* DCT coefficients. Four tables, two for last = 0, two for last = 1.
266       the sign bit must be added afterwards. */
267    
268  static VLC sprite_trajectory_len[15] = {  /* first part of coeffs for last = 0. Indexed by [run][level-1] */
         { 0x00 , 2},  
         { 0x02 , 3}, { 0x03, 3}, { 0x04, 3}, { 0x05, 3}, { 0x06, 3},  
         { 0x0E , 4}, { 0x1E, 5}, { 0x3E, 6}, { 0x7F, 7}, { 0xFE, 8},  
         { 0x1FE, 9}, {0x3FE,10}, {0x7FE,11}, {0xFFE,12} };  
269    
270    static VLC coeff_tab0[2][12] = {
271            /* run = 0  */
272            {
273                    {0x02, 2},  {0x0f, 4},  {0x15, 6},  {0x17, 7},
274                    {0x1f, 8},  {0x25, 9},  {0x24, 9},  {0x21, 10},
275                    {0x20, 10}, {0x07, 11}, {0x06, 11}, {0x20, 11}
276            },
277    
278            /* run = 1 */
279            {
280                    {0x06, 3},  {0x14, 6},  {0x1e, 8}, {0x0f, 10},
281                    {0x21, 11}, {0x50, 12}, {0x00, 0}, {0x00, 0},
282                    {0x00, 0},  {0x00, 0},  {0x00, 0}, {0x00, 0}
283            }
284    };
285    
286    /* rest of coeffs for last = 0. indexing by [run-2][level-1] */
287    
288    static VLC coeff_tab1[25][4] = {
289            /* First row is run=2, then each row is run 2 + index */
290            {{0x0e, 4}, {0x1d, 8}, {0x0e, 10}, {0x51, 12}},
291            {{0x0d, 5}, {0x23, 9},  {0x0d, 10}, {0x00, 0}},
292            {{0x0c, 5}, {0x22, 9},  {0x52, 12}, {0x00, 0}},
293            {{0x0b, 5}, {0x0c, 10}, {0x53, 12}, {0x00, 0}},
294            {{0x13, 6}, {0x0b, 10}, {0x54, 12}, {0x00, 0}},
295            {{0x12, 6}, {0x0a, 10}, {0x00, 0},  {0x00, 0}},
296            {{0x11, 6}, {0x09, 10}, {0x00, 0},  {0x00, 0}},
297            {{0x10, 6}, {0x08, 10}, {0x00, 0},  {0x00, 0}},
298            {{0x16, 7}, {0x55, 12}, {0x00, 0},  {0x00, 0}},
299            {{0x15, 7}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
300            {{0x14, 7}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
301            {{0x1c, 8}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
302            {{0x1b, 8}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
303            {{0x21, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
304            {{0x20, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
305            {{0x1f, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
306            {{0x1e, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
307            {{0x1d, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
308            {{0x1c, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
309            {{0x1b, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
310            {{0x1a, 9}, {0x00, 0},  {0x00, 0},  {0x00, 0}},
311            {{0x22, 11}, {0x00, 0}, {0x00, 0},  {0x00, 0}},
312            {{0x23, 11}, {0x00, 0}, {0x00, 0},  {0x00, 0}},
313            {{0x56, 12}, {0x00, 0}, {0x00, 0},  {0x00, 0}},
314            {{0x57, 12}, {0x00, 0}, {0x00, 0},  {0x00, 0}}
315    
316    };
317    
318    /* first coeffs of last = 1. indexing by [run][level-1] */
319    
320    static VLC coeff_tab2[2][3] = {
321            /*  run = 0 */
322            {{0x07, 4}, {0x19, 9},  {0x05, 11}},
323            /* run = 1 */
324            {{0x0f, 6}, {0x04, 11}, {0x00, 0}}
325    };
326    
327    /* rest of coeffs for last = 1. indexing by [run-2] */
328    
329    static VLC coeff_tab3[40][1] = {
330            {{0x0e, 6}},  {{0x0d, 6}},  {{0x0c, 6}},  {{0x13, 7}},
331            {{0x12, 7}},  {{0x11, 7}},  {{0x10, 7}},  {{0x1a, 8}},
332            {{0x19, 8}},  {{0x18, 8}},  {{0x17, 8}},  {{0x16, 8}},
333            {{0x15, 8}},  {{0x14, 8}},  {{0x13, 8}},  {{0x18, 9}},
334            {{0x17, 9}},  {{0x16, 9}},  {{0x15, 9}},  {{0x14, 9}},
335            {{0x13, 9}},  {{0x12, 9}},  {{0x11, 9}},  {{0x07, 10}},
336            {{0x06, 10}}, {{0x05, 10}}, {{0x04, 10}}, {{0x24, 11}},
337            {{0x25, 11}}, {{0x26, 11}}, {{0x27, 11}}, {{0x58, 12}},
338            {{0x59, 12}}, {{0x5a, 12}}, {{0x5b, 12}}, {{0x5c, 12}},
339            {{0x5d, 12}}, {{0x5e, 12}}, {{0x5f, 12}}, {{0x00, 0}}
340    };
341    
342    /*
343     * New tables for Intra luminance coefficients. Same codewords,
344     * different meaning
345     */
346    
347    /* Coeffs for last = 0, run = 0. Indexed by [level-1] */
348    
349    static VLC coeff_tab4[27] = {
350            /* run = 0 */
351            {0x02, 2},  {0x06, 3},  {0x0f, 4},
352            {0x0d, 5},  {0x0c, 5},  {0x15, 6},
353            {0x13, 6},  {0x12, 6},  {0x17, 7},
354            {0x1f, 8},  {0x1e, 8},  {0x1d, 8},
355            {0x25, 9},  {0x24, 9},  {0x23, 9},
356            {0x21, 9},      {0x21, 10}, {0x20, 10},
357            {0x0f, 10}, {0x0e, 10}, {0x07, 11},
358            {0x06, 11}, {0x20, 11}, {0x21, 11},
359            {0x50, 12}, {0x51, 12}, {0x52, 12}
360    };
361    
362    /* Coeffs for last = 0, run = 1. Indexed by [level-1] */
363    
364    static VLC coeff_tab5[10] = {
365            {0x0e, 4}, {0x14, 6},  {0x16, 7},  {0x1c, 8},  {0x20, 9},
366            {0x1f, 9}, {0x0d, 10}, {0x22, 11}, {0x53, 12}, {0x55, 12}
367    };
368    
369    /* Coeffs for last = 0, run = 2 -> 9. Indexed by [run-2][level-1] */
370    
371    static VLC coeff_tab6[8][5] = {
372            /* run = 2 */
373            {{0x0b, 5}, {0x15, 7}, {0x1e, 9}, {0x0c, 10}, {0x56, 12}},
374    
375            /* run = 3 */
376            {{0x11, 6}, {0x1b, 8}, {0x1d, 9}, {0x0b, 10}, {0x00, 0}},
377    
378            /* run = 4 */
379            {{0x10, 6}, {0x22, 9}, {0x0a, 10}, {0x00, 0}, {0x00, 0}},
380    
381            /* run = 5 */
382            {{0x0d, 6}, {0x1c, 9}, {0x08, 10}, {0x00, 0}, {0x00, 0}},
383    
384            /* run = 6 */
385            {{0x12, 7}, {0x1b, 9}, {0x54, 12}, {0x00, 0}, {0x00, 0}},
386    
387            /* run = 7 */
388            {{0x14, 7}, {0x1a, 9}, {0x57, 12}, {0x00, 0}, {0x00, 0}},
389    
390            /* run = 8 */
391            {{0x19, 8}, {0x09, 10}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
392    
393            /* run = 9 */
394            {{0x18, 8}, {0x23, 11}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
395    };
396    
397    /* Coeffs for last = 0, run = 10 -> 14. Indexed by [run-10] */
398    
399    static VLC coeff_tab7[5][1] = {
400            {{0x17, 8}},
401            {{0x19, 9}},
402            {{0x18, 9}},
403            {{0x07, 10}},
404            {{0x58, 12}}
405    };
406    
407    /* Coeffs for last = 1, run = 0. Indexed by [level-1] */
408    
409    static VLC coeff_tab8[8] = {
410            {0x07, 4},  {0x0c, 6},  {0x16, 8},  {0x17, 9},
411            {0x06, 10}, {0x05, 11}, {0x04, 11}, {0x59, 12}
412    };
413    
414    /* Coeffs for last = 1, run = 1 -> 6. Indexed by [run-1][level-1] */
415    
416    static VLC coeff_tab9[6][3] = {
417            /* run = 1 */
418            {{0x0f, 6}, {0x16, 9}, {0x05, 10}},
419    
420            /* run = 2 */
421            {{0x0e, 6}, {0x04, 10}, {0x00, 0}},
422    
423            /* run = 3 */
424            {{0x11, 7}, {0x24, 11}, {0x00, 0}},
425    
426            /* run = 4 */
427            {{0x10, 7}, {0x25, 11}, {0x00, 0}},
428    
429            /* run = 5 */
430            {{0x13, 7}, {0x5a, 12}, {0x00, 0}},
431    
432            /* run = 6 */
433            {{0x15, 8}, {0x5b, 12}, {0x00, 0}}
434    };
435    
436    /* Coeffs for last = 1, run = 7 -> 20. Indexed by [run-7] */
437    
438    static VLC coeff_tab10[14][1] = {
439            {{0x14, 8}},
440            {{0x13, 8}},
441            {{0x1a, 8}},
442            {{0x15, 9}},
443            {{0x14, 9}},
444            {{0x13, 9}},
445            {{0x12, 9}},
446            {{0x11, 9}},
447            {{0x26, 11}},
448            {{0x27, 11}},
449            {{0x5c, 12}},
450            {{0x5d, 12}},
451            {{0x5e, 12}},
452            {{0x5f, 12}}
453    };
454    
 /* DCT coefficients. Four tables, two for last = 0, two for last = 1.  
    the sign bit must be added afterwards. */  
455    
456  /* MCBPC Indexing by cbpc in first two bits, mode in last two.  static VLC *coeff_intra_last0[15] = {
457   CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.          coeff_tab4,
458   Example: cbpc = 01 and mode = 4 gives index = 0110 = 6. */          coeff_tab5,
459            coeff_tab6[0],
460            coeff_tab6[1],
461            coeff_tab6[2],
462            coeff_tab6[3],
463            coeff_tab6[4],
464            coeff_tab6[5],
465            coeff_tab6[6],
466            coeff_tab6[7],
467            coeff_tab7[0],
468            coeff_tab7[1],
469            coeff_tab7[2],
470            coeff_tab7[3],
471            coeff_tab7[4]
472    };
473    
474    static VLC *coeff_intra_last1[21] = {
475            coeff_tab8,
476            coeff_tab9[0],
477            coeff_tab9[1],
478            coeff_tab9[2],
479            coeff_tab9[3],
480            coeff_tab9[4],
481            coeff_tab9[5],
482            coeff_tab10[0],
483            coeff_tab10[1],
484            coeff_tab10[2],
485            coeff_tab10[3],
486            coeff_tab10[4],
487            coeff_tab10[5],
488            coeff_tab10[6],
489            coeff_tab10[7],
490            coeff_tab10[8],
491            coeff_tab10[9],
492            coeff_tab10[10],
493            coeff_tab10[11],
494            coeff_tab10[12],
495            coeff_tab10[13],
496    };
497    
498    static VLC *coeff_inter_last0[27] = {
499            coeff_tab0[0],
500            coeff_tab0[1],
501            coeff_tab1[0],
502            coeff_tab1[1],
503            coeff_tab1[2],
504            coeff_tab1[3],
505            coeff_tab1[4],
506            coeff_tab1[5],
507            coeff_tab1[6],
508            coeff_tab1[7],
509            coeff_tab1[8],
510            coeff_tab1[9],
511            coeff_tab1[10],
512            coeff_tab1[11],
513            coeff_tab1[12],
514            coeff_tab1[13],
515            coeff_tab1[14],
516            coeff_tab1[15],
517            coeff_tab1[16],
518            coeff_tab1[17],
519            coeff_tab1[18],
520            coeff_tab1[19],
521            coeff_tab1[20],
522            coeff_tab1[21],
523            coeff_tab1[22],
524            coeff_tab1[23],
525            coeff_tab1[24],
526    };
527    
528    static VLC *coeff_inter_last1[42] = {
529            coeff_tab2[0],
530            coeff_tab2[1],
531            coeff_tab3[0],
532            coeff_tab3[1],
533            coeff_tab3[2],
534            coeff_tab3[3],
535            coeff_tab3[4],
536            coeff_tab3[5],
537            coeff_tab3[6],
538            coeff_tab3[7],
539            coeff_tab3[8],
540            coeff_tab3[9],
541            coeff_tab3[10],
542            coeff_tab3[11],
543            coeff_tab3[12],
544            coeff_tab3[13],
545            coeff_tab3[14],
546            coeff_tab3[15],
547            coeff_tab3[16],
548            coeff_tab3[17],
549            coeff_tab3[18],
550            coeff_tab3[19],
551            coeff_tab3[20],
552            coeff_tab3[21],
553            coeff_tab3[22],
554            coeff_tab3[23],
555            coeff_tab3[24],
556            coeff_tab3[25],
557            coeff_tab3[26],
558            coeff_tab3[27],
559            coeff_tab3[28],
560            coeff_tab3[29],
561            coeff_tab3[30],
562            coeff_tab3[31],
563            coeff_tab3[32],
564            coeff_tab3[33],
565            coeff_tab3[34],
566            coeff_tab3[35],
567            coeff_tab3[36],
568            coeff_tab3[37],
569            coeff_tab3[38],
570            coeff_tab3[39],
571    };
572    
573    static VLC **coeff_vlc[4] = {
574            coeff_intra_last0,
575            coeff_intra_last1,
576            coeff_inter_last0,
577            coeff_inter_last1,
578    };
579    
580    /*
581     * MCBPC Indexing by cbpc in first two bits, mode in last two.
582     * CBPC as in table 4/H.263, MB type (mode): 3 = 01, 4 = 10.
583     * Example: cbpc = 01 and mode = 4 gives index = 0110 = 6.
584     */
585    
586  static VLC mcbpc_intra_tab[15] = {  static VLC mcbpc_intra_tab[15] = {
587          {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},          {0x01, 9}, {0x01, 1}, {0x01, 4}, {0x00, 0},
# Line 692  Line 893 
893   * decoder tables                                                 *   * decoder tables                                                 *
894   ******************************************************************/   ******************************************************************/
895    
896  static VLC const mcbpc_intra_table[64] = {  static const VLC mcbpc_intra_table[64] = {
897          {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4},  {4, 4},  {4, 4},  {4, 4},          {-1, 0}, {20, 6}, {36, 6}, {52, 6}, {4, 4},  {4, 4},  {4, 4},  {4, 4},
898          {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},          {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3}, {19, 3},
899          {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},          {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3}, {35, 3},
# Line 703  Line 904 
904          {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1}          {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1},  {3, 1}
905  };  };
906    
907  static VLC const mcbpc_inter_table[257] = {  
908    static const VLC mcbpc_inter_table[257] = {
909          {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},          {VLC_ERROR, 0}, {255, 9}, {52, 9}, {36, 9}, {20, 9}, {49, 9}, {35, 8}, {35, 8},
910          {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},          {19, 8}, {19, 8}, {50, 8}, {50, 8}, {51, 7}, {51, 7}, {51, 7}, {51, 7},
911          {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},          {34, 7}, {34, 7}, {34, 7}, {34, 7}, {18, 7}, {18, 7}, {18, 7}, {18, 7},
# Line 739  Line 941 
941          {0, 1}          {0, 1}
942  };  };
943    
944  static VLC const cbpy_table[64] = {  static const VLC cbpy_table[64] = {
945          {-1, 0}, {-1, 0}, {6, 6},  {9, 6},  {8, 5},  {8, 5},  {4, 5},  {4, 5},          {-1, 0}, {-1, 0}, {6, 6},  {9, 6},  {8, 5},  {8, 5},  {4, 5},  {4, 5},
946          {2, 5},  {2, 5},  {1, 5},  {1, 5},  {0, 4},  {0, 4},  {0, 4},  {0, 4},          {2, 5},  {2, 5},  {1, 5},  {1, 5},  {0, 4},  {0, 4},  {0, 4},  {0, 4},
947          {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},          {12, 4}, {12, 4}, {12, 4}, {12, 4}, {10, 4}, {10, 4}, {10, 4}, {10, 4},
# Line 750  Line 952 
952          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}          {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}, {15, 2}
953  };  };
954    
955  static VLC const TMNMVtab0[] = {  
956    VLC TMNMVtab0[] = {
957          {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},          {3, 4}, {-3, 4}, {2, 3}, {2, 3}, {-2, 3}, {-2, 3}, {1, 2},
958          {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}          {1, 2}, {1, 2}, {1, 2}, {-1, 2}, {-1, 2}, {-1, 2}, {-1, 2}
959  };  };
960    
961  static VLC const TMNMVtab1[] = {  VLC TMNMVtab1[] = {
962          {12, 10}, {-12, 10}, {11, 10}, {-11, 10},          {12, 10}, {-12, 10}, {11, 10}, {-11, 10},
963          {10, 9}, {10, 9}, {-10, 9}, {-10, 9},          {10, 9}, {10, 9}, {-10, 9}, {-10, 9},
964          {9, 9}, {9, 9}, {-9, 9}, {-9, 9},          {9, 9}, {9, 9}, {-9, 9}, {-9, 9},
# Line 782  Line 985 
985          {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}          {-4, 6}, {-4, 6}, {-4, 6}, {-4, 6}
986  };  };
987    
988  static VLC const TMNMVtab2[] = {  VLC TMNMVtab2[] = {
989          {32, 12}, {-32, 12}, {31, 12}, {-31, 12},          {32, 12}, {-32, 12}, {31, 12}, {-31, 12},
990          {30, 11}, {30, 11}, {-30, 11}, {-30, 11},          {30, 11}, {30, 11}, {-30, 11}, {-30, 11},
991          {29, 11}, {29, 11}, {-29, 11}, {-29, 11},          {29, 11}, {29, 11}, {-29, 11}, {-29, 11},
# Line 816  Line 1019 
1019          {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}          {-13, 10}, {-13, 10}, {-13, 10}, {-13, 10}
1020  };  };
1021    
1022  static short const dc_threshold[] = {  
1023          21514, 26984,  8307, 28531, 29798, 24951, 25970, 26912,  VLC DCT3Dtab0[] = {
1024           8307, 25956, 26994, 25974,  8292, 29286, 28015, 29728,          {4225, 7}, {4209, 7}, {4193, 7}, {4177, 7}, {193, 7}, {177, 7},
1025          25960, 18208, 21838, 18208, 19536, 22560, 26998,  8260,          {161, 7}, {4, 7}, {4161, 6}, {4161, 6}, {4145, 6}, {4145, 6},
1026          28515, 25956,  8291, 25640, 30309, 27749, 11817, 22794,          {4129, 6}, {4129, 6}, {4113, 6}, {4113, 6}, {145, 6}, {145, 6},
1027          30063,  8306, 28531, 29798, 24951, 25970, 25632, 29545,          {129, 6}, {129, 6}, {113, 6}, {113, 6}, {97, 6}, {97, 6},
1028          29300, 25193, 29813, 29295, 26656, 29537, 29728,  8303,          {18, 6}, {18, 6}, {3, 6}, {3, 6}, {81, 5}, {81, 5},
1029          26983, 25974, 24864, 25443, 29541,  8307, 28532, 26912,          {81, 5}, {81, 5}, {65, 5}, {65, 5}, {65, 5}, {65, 5},
1030          29556, 29472, 30063, 25458,  8293, 28515, 25956,  2606          {49, 5}, {49, 5}, {49, 5}, {49, 5}, {4097, 4}, {4097, 4},
1031            {4097, 4}, {4097, 4}, {4097, 4}, {4097, 4}, {4097, 4}, {4097, 4},
1032            {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
1033            {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
1034            {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
1035            {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
1036            {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2}, {1, 2},
1037            {1, 2}, {1, 2}, {17, 3}, {17, 3}, {17, 3}, {17, 3},
1038            {17, 3}, {17, 3}, {17, 3}, {17, 3}, {17, 3}, {17, 3},
1039            {17, 3}, {17, 3}, {17, 3}, {17, 3}, {17, 3}, {17, 3},
1040            {33, 4}, {33, 4}, {33, 4}, {33, 4}, {33, 4}, {33, 4},
1041            {33, 4}, {33, 4}, {2, 4}, {2, 4}, {2, 4}, {2, 4},
1042            {2, 4}, {2, 4}, {2, 4}, {2, 4}
1043    };
1044    
1045    
1046    VLC DCT3Dtab1[] = {
1047            {9, 10}, {8, 10}, {4481, 9}, {4481, 9}, {4465, 9}, {4465, 9},
1048            {4449, 9}, {4449, 9}, {4433, 9}, {4433, 9}, {4417, 9}, {4417, 9},
1049            {4401, 9}, {4401, 9}, {4385, 9}, {4385, 9}, {4369, 9}, {4369, 9},
1050            {4098, 9}, {4098, 9}, {353, 9}, {353, 9}, {337, 9}, {337, 9},
1051            {321, 9}, {321, 9}, {305, 9}, {305, 9}, {289, 9}, {289, 9},
1052            {273, 9}, {273, 9}, {257, 9}, {257, 9}, {241, 9}, {241, 9},
1053            {66, 9}, {66, 9}, {50, 9}, {50, 9}, {7, 9}, {7, 9},
1054            {6, 9}, {6, 9}, {4353, 8}, {4353, 8}, {4353, 8}, {4353, 8},
1055            {4337, 8}, {4337, 8}, {4337, 8}, {4337, 8}, {4321, 8}, {4321, 8},
1056            {4321, 8}, {4321, 8}, {4305, 8}, {4305, 8}, {4305, 8}, {4305, 8},
1057            {4289, 8}, {4289, 8}, {4289, 8}, {4289, 8}, {4273, 8}, {4273, 8},
1058            {4273, 8}, {4273, 8}, {4257, 8}, {4257, 8}, {4257, 8}, {4257, 8},
1059            {4241, 8}, {4241, 8}, {4241, 8}, {4241, 8}, {225, 8}, {225, 8},
1060            {225, 8}, {225, 8}, {209, 8}, {209, 8}, {209, 8}, {209, 8},
1061            {34, 8}, {34, 8}, {34, 8}, {34, 8}, {19, 8}, {19, 8},
1062            {19, 8}, {19, 8}, {5, 8}, {5, 8}, {5, 8}, {5, 8}
1063  };  };
1064    
1065  static VLC const dc_lum_tab[] = {  VLC DCT3Dtab2[] = {
1066            {4114, 11}, {4114, 11}, {4099, 11}, {4099, 11}, {11, 11}, {11, 11},
1067            {10, 11}, {10, 11}, {4545, 10}, {4545, 10}, {4545, 10}, {4545, 10},
1068            {4529, 10}, {4529, 10}, {4529, 10}, {4529, 10}, {4513, 10}, {4513, 10},
1069            {4513, 10}, {4513, 10}, {4497, 10}, {4497, 10}, {4497, 10}, {4497, 10},
1070            {146, 10}, {146, 10}, {146, 10}, {146, 10}, {130, 10}, {130, 10},
1071            {130, 10}, {130, 10}, {114, 10}, {114, 10}, {114, 10}, {114, 10},
1072            {98, 10}, {98, 10}, {98, 10}, {98, 10}, {82, 10}, {82, 10},
1073            {82, 10}, {82, 10}, {51, 10}, {51, 10}, {51, 10}, {51, 10},
1074            {35, 10}, {35, 10}, {35, 10}, {35, 10}, {20, 10}, {20, 10},
1075            {20, 10}, {20, 10}, {12, 11}, {12, 11}, {21, 11}, {21, 11},
1076            {369, 11}, {369, 11}, {385, 11}, {385, 11}, {4561, 11}, {4561, 11},
1077            {4577, 11}, {4577, 11}, {4593, 11}, {4593, 11}, {4609, 11}, {4609, 11},
1078            {22, 12}, {36, 12}, {67, 12}, {83, 12}, {99, 12}, {162, 12},
1079            {401, 12}, {417, 12}, {4625, 12}, {4641, 12}, {4657, 12}, {4673, 12},
1080            {4689, 12}, {4705, 12}, {4721, 12}, {4737, 12}, {7167, 7},
1081            {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7},
1082            {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7},
1083            {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7},
1084            {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7},
1085            {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7}, {7167, 7},
1086            {7167, 7}
1087    };
1088    
1089    
1090    /* New tables for Intra luminance blocks */
1091    
1092    VLC DCT3Dtab3[] = {
1093            {0x10401, 7}, {0x10301, 7}, {0x00601, 7}, {0x10501, 7},
1094            {0x00701, 7}, {0x00202, 7}, {0x00103, 7}, {0x00009, 7},
1095            {0x10002, 6}, {0x10002, 6}, {0x00501, 6}, {0x00501, 6},
1096            {0x10201, 6}, {0x10201, 6}, {0x10101, 6}, {0x10101, 6},
1097            {0x00401, 6}, {0x00401, 6}, {0x00301, 6}, {0x00301, 6},
1098            {0x00008, 6}, {0x00008, 6}, {0x00007, 6}, {0x00007, 6},
1099            {0x00102, 6}, {0x00102, 6}, {0x00006, 6}, {0x00006, 6},
1100            {0x00201, 5}, {0x00201, 5}, {0x00201, 5}, {0x00201, 5},
1101            {0x00005, 5}, {0x00005, 5}, {0x00005, 5}, {0x00005, 5},
1102            {0x00004, 5}, {0x00004, 5}, {0x00004, 5}, {0x00004, 5},
1103            {0x10001, 4}, {0x10001, 4}, {0x10001, 4}, {0x10001, 4},
1104            {0x10001, 4}, {0x10001, 4}, {0x10001, 4}, {0x10001, 4},
1105            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1106            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1107            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1108            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1109            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1110            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1111            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1112            {0x00001, 2}, {0x00001, 2}, {0x00001, 2}, {0x00001, 2},
1113            {0x00002, 3}, {0x00002, 3}, {0x00002, 3}, {0x00002, 3},
1114            {0x00002, 3}, {0x00002, 3}, {0x00002, 3}, {0x00002, 3},
1115            {0x00002, 3}, {0x00002, 3}, {0x00002, 3}, {0x00002, 3},
1116            {0x00002, 3}, {0x00002, 3}, {0x00002, 3}, {0x00002, 3},
1117            {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},
1118            {0x00101, 4}, {0x00101, 4}, {0x00101, 4}, {0x00101, 4},
1119            {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4},
1120            {0x00003, 4}, {0x00003, 4}, {0x00003, 4}, {0x00003, 4}
1121    };
1122    
1123    
1124    VLC DCT3Dtab4[] = {
1125            {0x00012, 10}, {0x00011, 10}, {0x10e01, 9}, {0x10e01, 9},
1126            {0x10d01, 9}, {0x10d01, 9}, {0x10c01, 9}, {0x10c01, 9},
1127            {0x10b01, 9}, {0x10b01, 9}, {0x10a01, 9}, {0x10a01, 9},
1128            {0x10102, 9}, {0x10102, 9}, {0x10004, 9}, {0x10004, 9},
1129            {0x00c01, 9}, {0x00c01, 9}, {0x00b01, 9}, {0x00b01, 9},
1130            {0x00702, 9}, {0x00702, 9}, {0x00602, 9}, {0x00602, 9},
1131            {0x00502, 9}, {0x00502, 9}, {0x00303, 9}, {0x00303, 9},
1132            {0x00203, 9}, {0x00203, 9}, {0x00106, 9}, {0x00106, 9},
1133            {0x00105, 9}, {0x00105, 9}, {0x00010, 9}, {0x00010, 9},
1134            {0x00402, 9}, {0x00402, 9}, {0x0000f, 9}, {0x0000f, 9},
1135            {0x0000e, 9}, {0x0000e, 9}, {0x0000d, 9}, {0x0000d, 9},
1136            {0x10801, 8}, {0x10801, 8}, {0x10801, 8}, {0x10801, 8},
1137            {0x10701, 8}, {0x10701, 8}, {0x10701, 8}, {0x10701, 8},
1138            {0x10601, 8}, {0x10601, 8}, {0x10601, 8}, {0x10601, 8},
1139            {0x10003, 8}, {0x10003, 8}, {0x10003, 8}, {0x10003, 8},
1140            {0x00a01, 8}, {0x00a01, 8}, {0x00a01, 8}, {0x00a01, 8},
1141            {0x00901, 8}, {0x00901, 8}, {0x00901, 8}, {0x00901, 8},
1142            {0x00801, 8}, {0x00801, 8}, {0x00801, 8}, {0x00801, 8},
1143            {0x10901, 8}, {0x10901, 8}, {0x10901, 8}, {0x10901, 8},
1144            {0x00302, 8}, {0x00302, 8}, {0x00302, 8}, {0x00302, 8},
1145            {0x00104, 8}, {0x00104, 8}, {0x00104, 8}, {0x00104, 8},
1146            {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8}, {0x0000c, 8},
1147            {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8}, {0x0000b, 8},
1148            {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}, {0x0000a, 8}
1149    };
1150    
1151    VLC DCT3Dtab5[] = {
1152            {0x10007, 11}, {0x10007, 11}, {0x10006, 11}, {0x10006, 11},
1153            {0x00016, 11}, {0x00016, 11}, {0x00015, 11}, {0x00015, 11},
1154            {0x10202, 10}, {0x10202, 10}, {0x10202, 10}, {0x10202, 10},
1155            {0x10103, 10}, {0x10103, 10}, {0x10103, 10}, {0x10103, 10},
1156            {0x10005, 10}, {0x10005, 10}, {0x10005, 10}, {0x10005, 10},
1157            {0x00d01, 10}, {0x00d01, 10}, {0x00d01, 10}, {0x00d01, 10},
1158            {0x00503, 10}, {0x00503, 10}, {0x00503, 10}, {0x00503, 10},
1159            {0x00802, 10}, {0x00802, 10}, {0x00802, 10}, {0x00802, 10},
1160            {0x00403, 10}, {0x00403, 10}, {0x00403, 10}, {0x00403, 10},
1161            {0x00304, 10}, {0x00304, 10}, {0x00304, 10}, {0x00304, 10},
1162            {0x00204, 10}, {0x00204, 10}, {0x00204, 10}, {0x00204, 10},
1163            {0x00107, 10}, {0x00107, 10}, {0x00107, 10}, {0x00107, 10},
1164            {0x00014, 10}, {0x00014, 10}, {0x00014, 10}, {0x00014, 10},
1165            {0x00013, 10}, {0x00013, 10}, {0x00013, 10}, {0x00013, 10},
1166            {0x00017, 11}, {0x00017, 11}, {0x00018, 11}, {0x00018, 11},
1167            {0x00108, 11}, {0x00108, 11}, {0x00902, 11}, {0x00902, 11},
1168            {0x10302, 11}, {0x10302, 11}, {0x10402, 11}, {0x10402, 11},
1169            {0x10f01, 11}, {0x10f01, 11}, {0x11001, 11}, {0x11001, 11},
1170            {0x00019, 12}, {0x0001a, 12}, {0x0001b, 12}, {0x00109, 12},
1171            {0x00603, 12}, {0x0010a, 12}, {0x00205, 12}, {0x00703, 12},
1172            {0x00e01, 12}, {0x10008, 12}, {0x10502, 12}, {0x10602, 12},
1173            {0x11101, 12}, {0x11201, 12}, {0x11301, 12}, {0x11401, 12},
1174            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1175            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1176            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1177            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1178            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1179            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1180            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7},
1181            {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}, {0x01bff, 7}
1182    };
1183    
1184    VLC ERRtab[] = {
1185            {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1186            {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1187            {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1188            {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0},
1189            {VLC_ERROR, 0}, {VLC_ERROR, 0}, {VLC_ERROR, 0}
1190    };
1191    
1192    static const VLC dc_lum_tab[] = {
1193          {0, 0}, {4, 3}, {3, 3}, {0, 3},          {0, 0}, {4, 3}, {3, 3}, {0, 3},
1194          {2, 2}, {2, 2}, {1, 2}, {1, 2},          {2, 2}, {2, 2}, {1, 2}, {1, 2},
1195  };  };
1196    
1197    static __inline int
1198    get_coeff(Bitstream * bs,
1199                      int *run,
1200                      int *last,
1201                      int intra,
1202                      int short_video_header)
1203    {
1204    
1205            uint32_t mode;
1206            const VLC *tab;
1207            int32_t level;
1208    
1209            if (short_video_header)         // inter-VLCs will be used for both intra and inter blocks
1210                    intra = 0;
1211    
1212            tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1213    
1214            if (tab->code == -1)
1215                    goto error;
1216    
1217            BitstreamSkip(bs, tab->len);
1218    
1219            if (tab->code != ESCAPE) {
1220                    if (!intra) {
1221                            *run = (tab->code >> 4) & 255;
1222                            level = tab->code & 15;
1223                            *last = (tab->code >> 12) & 1;
1224                    } else {
1225                            *run = (tab->code >> 8) & 255;
1226                            level = tab->code & 255;
1227                            *last = (tab->code >> 16) & 1;
1228                    }
1229                    return BitstreamGetBit(bs) ? -level : level;
1230            }
1231    
1232            if (short_video_header) {
1233                    // escape mode 4 - H.263 type, only used if short_video_header = 1
1234                    *last = BitstreamGetBit(bs);
1235                    *run = BitstreamGetBits(bs, 6);
1236                    level = BitstreamGetBits(bs, 8);
1237    
1238                    if (level == 0 || level == 128)
1239                            DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
1240    
1241                    return (level >= 128 ? -(256 - level) : level);
1242            }
1243    
1244            mode = BitstreamShowBits(bs, 2);
1245    
1246            if (mode < 3) {
1247                    BitstreamSkip(bs, (mode == 2) ? 2 : 1);
1248    
1249                    tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
1250                    if (tab->code == -1)
1251                            goto error;
1252    
1253                    BitstreamSkip(bs, tab->len);
1254    
1255                    if (!intra) {
1256                            *run = (tab->code >> 4) & 255;
1257                            level = tab->code & 15;
1258                            *last = (tab->code >> 12) & 1;
1259                    } else {
1260                            *run = (tab->code >> 8) & 255;
1261                            level = tab->code & 255;
1262                            *last = (tab->code >> 16) & 1;
1263                    }
1264    
1265                    if (mode < 2)                   // first escape mode, level is offset
1266                            level += max_level[*last + (!intra << 1)][*run];        // need to add back the max level
1267                    else if (mode == 2)             // second escape mode, run is offset
1268                            *run += max_run[*last + (!intra << 1)][level] + 1;
1269    
1270                    return BitstreamGetBit(bs) ? -level : level;
1271            }
1272            // third escape mode - fixed length codes
1273            BitstreamSkip(bs, 2);
1274            *last = BitstreamGetBits(bs, 1);
1275            *run = BitstreamGetBits(bs, 6);
1276            BitstreamSkip(bs, 1);           // marker
1277            level = BitstreamGetBits(bs, 12);
1278            BitstreamSkip(bs, 1);           // marker
1279    
1280            return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
1281    
1282      error:
1283            *run = VLC_ERROR;
1284            return 0;
1285    
1286    }
1287    
1288  #endif /* _VLC_CODES_H */  #endif /* _VLC_CODES_H */

Legend:
Removed from v.1.6.2.3  
changed lines
  Added in v.1.7

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