]> git.sesse.net Git - vlc/blob - modules/stream_out/transrate/putvlc.h
* modules/stream_out/transrate: New transrating module, based on GPL
[vlc] / modules / stream_out / transrate / putvlc.h
1 // put blk
2
3 /* type definitions for variable length code table entries */
4
5 typedef struct
6 {
7   unsigned char code; /* right justified */
8   char len;
9 } VLCtable;
10
11 /* for codes longer than 8 bits (excluding leading zeroes) */
12 typedef struct
13 {
14   unsigned short code; /* right justified */
15   char len;
16 } sVLCtable;
17
18
19 /* Table B-2, B-3, B-4 variable length codes for macroblock_type
20  *
21  * indexed by [macroblock_type]
22  */
23
24 const static VLCtable mbtypetab[3][32]=
25 {
26  /* I */
27  {
28   {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
29   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
30   {0,0}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
31   {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
32  },
33  /* P */
34  {
35   {0,0}, {3,5}, {1,2}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
36   {1,3}, {0,0}, {1,1}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
37   {0,0}, {1,6}, {1,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0},
38   {0,0}, {0,0}, {2,5}, {0,0}, {0,0}, {0,0}, {0,0}, {0,0}
39  },
40  /* B */
41  {
42   {0,0}, {3,5}, {0,0}, {0,0}, {2,3}, {0,0}, {3,3}, {0,0},
43   {2,4}, {0,0}, {3,4}, {0,0}, {2,2}, {0,0}, {3,2}, {0,0},
44   {0,0}, {1,6}, {0,0}, {0,0}, {0,0}, {0,0}, {2,6}, {0,0},
45   {0,0}, {0,0}, {3,6}, {0,0}, {0,0}, {0,0}, {2,5}, {0,0}
46  }
47 };
48
49
50 /* Table B-5 ... B-8 variable length codes for macroblock_type in
51  *  scalable sequences
52  *
53  * not implemented
54  */
55
56 /* Table B-9, variable length codes for coded_block_pattern
57  *
58  * indexed by [coded_block_pattern]
59  */
60
61 const static VLCtable cbptable[64]=
62 {
63   {0x01,9}, {0x0b,5}, {0x09,5}, {0x0d,6}, 
64   {0x0d,4}, {0x17,7}, {0x13,7}, {0x1f,8}, 
65   {0x0c,4}, {0x16,7}, {0x12,7}, {0x1e,8}, 
66   {0x13,5}, {0x1b,8}, {0x17,8}, {0x13,8}, 
67   {0x0b,4}, {0x15,7}, {0x11,7}, {0x1d,8}, 
68   {0x11,5}, {0x19,8}, {0x15,8}, {0x11,8}, 
69   {0x0f,6}, {0x0f,8}, {0x0d,8}, {0x03,9}, 
70   {0x0f,5}, {0x0b,8}, {0x07,8}, {0x07,9}, 
71   {0x0a,4}, {0x14,7}, {0x10,7}, {0x1c,8}, 
72   {0x0e,6}, {0x0e,8}, {0x0c,8}, {0x02,9}, 
73   {0x10,5}, {0x18,8}, {0x14,8}, {0x10,8}, 
74   {0x0e,5}, {0x0a,8}, {0x06,8}, {0x06,9}, 
75   {0x12,5}, {0x1a,8}, {0x16,8}, {0x12,8}, 
76   {0x0d,5}, {0x09,8}, {0x05,8}, {0x05,9}, 
77   {0x0c,5}, {0x08,8}, {0x04,8}, {0x04,9},
78   {0x07,3}, {0x0a,5}, {0x08,5}, {0x0c,6}
79 };
80
81
82
83 /* Table B-14, DCT coefficients table zero
84  *
85  * indexed by [run][level-1]
86  * split into two tables (dct_code_tab1, dct_code_tab2) to reduce size
87  * 'first DCT coefficient' condition and 'End of Block' are treated elsewhere
88  * codes do not include s (sign bit)
89  */
90
91 const static VLCtable dct_code_tab1[2][40]=
92 {
93  /* run = 0, level = 1...40 */
94  {
95   {0x03, 2}, {0x04, 4}, {0x05, 5}, {0x06, 7},
96   {0x26, 8}, {0x21, 8}, {0x0a,10}, {0x1d,12},
97   {0x18,12}, {0x13,12}, {0x10,12}, {0x1a,13},
98   {0x19,13}, {0x18,13}, {0x17,13}, {0x1f,14},
99   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
100   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
101   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
102   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
103   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
104   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
105  },
106  /* run = 1, level = 1...18 */
107  {
108   {0x03, 3}, {0x06, 6}, {0x25, 8}, {0x0c,10},
109   {0x1b,12}, {0x16,13}, {0x15,13}, {0x1f,15},
110   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
111   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
112   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
113   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
114   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
115   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
116   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
117   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
118  }
119 };
120
121 const static VLCtable dct_code_tab2[30][5]=
122 {
123   /* run = 2...31, level = 1...5 */
124   {{0x05, 4}, {0x04, 7}, {0x0b,10}, {0x14,12}, {0x14,13}},
125   {{0x07, 5}, {0x24, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
126   {{0x06, 5}, {0x0f,10}, {0x12,12}, {0x00, 0}, {0x00, 0}},
127   {{0x07, 6}, {0x09,10}, {0x12,13}, {0x00, 0}, {0x00, 0}},
128   {{0x05, 6}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
129   {{0x04, 6}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
130   {{0x07, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
131   {{0x05, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
132   {{0x27, 8}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
133   {{0x23, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
134   {{0x22, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
135   {{0x20, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
136   {{0x0e,10}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
137   {{0x0d,10}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
138   {{0x08,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
139   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
140   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
141   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
142   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
143   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
144   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
145   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
146   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
147   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
148   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
149   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
150   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
151   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
152   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
153   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
154 };
155
156
157 /* Table B-15, DCT coefficients table one
158  *
159  * indexed by [run][level-1]
160  * split into two tables (dct_code_tab1a, dct_code_tab2a) to reduce size
161  * 'End of Block' is treated elsewhere
162  * codes do not include s (sign bit)
163  */
164
165 const static VLCtable dct_code_tab1a[2][40]=
166 {
167  /* run = 0, level = 1...40 */
168  {
169   {0x02, 2}, {0x06, 3}, {0x07, 4}, {0x1c, 5},
170   {0x1d, 5}, {0x05, 6}, {0x04, 6}, {0x7b, 7},
171   {0x7c, 7}, {0x23, 8}, {0x22, 8}, {0xfa, 8},
172   {0xfb, 8}, {0xfe, 8}, {0xff, 8}, {0x1f,14},
173   {0x1e,14}, {0x1d,14}, {0x1c,14}, {0x1b,14},
174   {0x1a,14}, {0x19,14}, {0x18,14}, {0x17,14},
175   {0x16,14}, {0x15,14}, {0x14,14}, {0x13,14},
176   {0x12,14}, {0x11,14}, {0x10,14}, {0x18,15},
177   {0x17,15}, {0x16,15}, {0x15,15}, {0x14,15},
178   {0x13,15}, {0x12,15}, {0x11,15}, {0x10,15}
179  },
180  /* run = 1, level = 1...18 */
181  {
182   {0x02, 3}, {0x06, 5}, {0x79, 7}, {0x27, 8},
183   {0x20, 8}, {0x16,13}, {0x15,13}, {0x1f,15},
184   {0x1e,15}, {0x1d,15}, {0x1c,15}, {0x1b,15},
185   {0x1a,15}, {0x19,15}, {0x13,16}, {0x12,16},
186   {0x11,16}, {0x10,16}, {0x00, 0}, {0x00, 0},
187   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
188   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
189   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
190   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0},
191   {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}
192  }
193 };
194
195 const static VLCtable dct_code_tab2a[30][5]=
196 {
197   /* run = 2...31, level = 1...5 */
198   {{0x05, 5}, {0x07, 7}, {0xfc, 8}, {0x0c,10}, {0x14,13}},
199   {{0x07, 5}, {0x26, 8}, {0x1c,12}, {0x13,13}, {0x00, 0}},
200   {{0x06, 6}, {0xfd, 8}, {0x12,12}, {0x00, 0}, {0x00, 0}},
201   {{0x07, 6}, {0x04, 9}, {0x12,13}, {0x00, 0}, {0x00, 0}},
202   {{0x06, 7}, {0x1e,12}, {0x14,16}, {0x00, 0}, {0x00, 0}},
203   {{0x04, 7}, {0x15,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
204   {{0x05, 7}, {0x11,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
205   {{0x78, 7}, {0x11,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
206   {{0x7a, 7}, {0x10,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
207   {{0x21, 8}, {0x1a,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
208   {{0x25, 8}, {0x19,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
209   {{0x24, 8}, {0x18,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
210   {{0x05, 9}, {0x17,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
211   {{0x07, 9}, {0x16,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
212   {{0x0d,10}, {0x15,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
213   {{0x1f,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
214   {{0x1a,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
215   {{0x19,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
216   {{0x17,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
217   {{0x16,12}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
218   {{0x1f,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
219   {{0x1e,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
220   {{0x1d,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
221   {{0x1c,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
222   {{0x1b,13}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
223   {{0x1f,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
224   {{0x1e,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
225   {{0x1d,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
226   {{0x1c,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}},
227   {{0x1b,16}, {0x00, 0}, {0x00, 0}, {0x00, 0}, {0x00, 0}}
228 };