[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 1003 - (view) (download)

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

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