[svn] / branches / dev-api-4 / xvidcore / src / bitstream / mbcoding.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-4/xvidcore/src/bitstream/mbcoding.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1169 - (view) (download)

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

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