[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 100 - (view) (download)
Original Path: trunk/xvidcore/src/bitstream/mbcoding.c

1 : Isibaar 100 #include <stdlib.h>
2 : Isibaar 3 #include "../portab.h"
3 :     #include "bitstream.h"
4 :     #include "zigzag.h"
5 :     #include "vlc_codes.h"
6 : Isibaar 100 #include "mbcoding.h"
7 : Isibaar 3
8 :     #include "../utils/mbfunctions.h"
9 :    
10 :     #define ESCAPE 7167
11 :     #define ABS(X) (((X)>0)?(X):-(X))
12 :     #define CLIP(X,A) (X > A) ? (A) : (X)
13 :    
14 : Isibaar 100 VLC DCT3Dintra[4096];
15 :     VLC DCT3Dinter[4096];
16 : Isibaar 3 static VLC *DCT3D[2];
17 :    
18 : Isibaar 100 VLC intra_table[65536];
19 :     VLC inter_table[65536];
20 :    
21 : Isibaar 3 static short clip_table[4096];
22 :    
23 : Isibaar 100 void init_vlc_tables(void)
24 : Isibaar 3 {
25 : edgomez 78
26 : Isibaar 3 int32_t k, l, i, intra, last;
27 :     VLC *vlc[2];
28 :     VLC **coeff_ptr;
29 :     VLC *vlc1, *vlc2;
30 :    
31 :     vlc1 = DCT3Dintra;
32 :     vlc2 = DCT3Dinter;
33 :    
34 : Isibaar 100 vlc[0] = intra_table;
35 :     vlc[1] = inter_table;
36 : Isibaar 3
37 :     // initialize the clipping table
38 :     for(i = -2048; i < 2048; i++) {
39 :     clip_table[i + 2048] = i;
40 :     if(i < -255)
41 :     clip_table[i + 2048] = -255;
42 :     if(i > 255)
43 :     clip_table[i + 2048] = 255;
44 :     }
45 :    
46 : Isibaar 100 // generate encoding vlc lookup tables
47 : Isibaar 3 for(i = 0; i < 4; i++) {
48 :     intra = i % 2;
49 : Isibaar 100 last = i / 2;
50 : Isibaar 3
51 : Isibaar 100 coeff_ptr = coeff_vlc[last + 2 * intra];
52 : Isibaar 3
53 :     for(k = -255; k < 256; k++) { // level
54 : Isibaar 100 int8_t *max_level_ptr = max_level[last + 2 * intra];
55 :     int8_t *max_run_ptr = max_run[last + 2 * intra];
56 : Isibaar 3
57 :     for(l = 0; l < 64; l++) { // run
58 : Isibaar 35 int32_t level = k;
59 :     uint32_t run = l;
60 : Isibaar 100
61 :     if((abs(level) <= max_level_ptr[run]) &&
62 :     (run <= max_run_ptr[abs(level)])) { // level < max_level and run < max_run
63 :    
64 : Isibaar 3 vlc[intra]->code = 0;
65 :     vlc[intra]->len = 0;
66 : Isibaar 100 goto loop_end;
67 :     }
68 :     else {
69 :     if(level > 0) // correct level
70 : Isibaar 3 level -= max_level_ptr[run];
71 :     else
72 :     level += max_level_ptr[run];
73 : Isibaar 35
74 : Isibaar 100 if((abs(level) <= max_level_ptr[run]) &&
75 :     (run <= max_run_ptr[abs(level)])) {
76 : Isibaar 28
77 : Isibaar 100 vlc[intra]->code = 0x06;
78 :     vlc[intra]->len = 8;
79 :     goto loop_end;
80 :     }
81 : Isibaar 3
82 : Isibaar 100 if(level > 0) // still here?
83 :     level += max_level_ptr[run]; // restore level
84 :     else
85 :     level -= max_level_ptr[run];
86 :    
87 :     run -= max_run_ptr[abs(level)] + 1; // and change run
88 :    
89 :     if((abs(level) <= max_level_ptr[run]) &&
90 :     (run <= max_run_ptr[abs(level)])) {
91 :    
92 :     vlc[intra]->code = 0x0e;
93 :     vlc[intra]->len = 9;
94 :     goto loop_end;
95 : Isibaar 3 }
96 : Isibaar 100 run += max_run_ptr[abs(level)] + 1;
97 : Isibaar 3 }
98 : Isibaar 100
99 :     vlc[intra]->code = (uint32_t) ((l << 14) | (0x1e + last) << 20) |
100 :     (1 << 13) | ((k & 0xfff) << 1) | 1;
101 :    
102 :     vlc[intra]->len = 30;
103 : Isibaar 3 vlc[intra]++;
104 : Isibaar 100 continue;
105 :    
106 :     loop_end:
107 :     if(level != 0) {
108 :     vlc[intra]->code = (vlc[intra]->code << (coeff_ptr[run][abs(level) - 1].len + 1)) |
109 :     (coeff_ptr[run][abs(level) - 1].code << 1);
110 :     vlc[intra]->len = (coeff_ptr[run][abs(level) - 1].len + 1) + vlc[intra]->len;
111 :    
112 :     if(level < 0)
113 :     vlc[intra]->code += 1;
114 :     }
115 :    
116 :     vlc[intra]++;
117 : Isibaar 3 }
118 :     }
119 :     }
120 : edgomez 78
121 : Isibaar 3 for(i = 0; i < 4096; i++) {
122 :     if(i >= 512) {
123 :     *vlc1 = DCT3Dtab3[(i >> 5) - 16];
124 :     *vlc2 = DCT3Dtab0[(i >> 5) - 16];
125 :     }
126 :     else if(i >= 128) {
127 :     *vlc1 = DCT3Dtab4[(i >> 2) - 32];
128 :     *vlc2 = DCT3Dtab1[(i >> 2) - 32];
129 :     }
130 :     else if(i >= 8) {
131 :     *vlc1 = DCT3Dtab5[i - 8];
132 :     *vlc2 = DCT3Dtab2[i - 8];
133 :     }
134 :     else {
135 :     *vlc1 = ERRtab[i];
136 :     *vlc2 = ERRtab[i];
137 :     }
138 :    
139 :     vlc1++;
140 :     vlc2++;
141 :     }
142 :     DCT3D[0] = DCT3Dinter;
143 :     DCT3D[1] = DCT3Dintra;
144 :    
145 :     }
146 :    
147 : edgomez 78 static __inline void CodeVector(Bitstream *bs,
148 :     int16_t value,
149 :     int16_t f_code,
150 :     Statistics *pStat)
151 : Isibaar 3 {
152 : edgomez 78
153 : Isibaar 3 const int scale_factor = 1 << (f_code - 1);
154 :     const int cmp = scale_factor << 5;
155 :    
156 :     if(value < (-1 * cmp))
157 :     value += 64 * scale_factor;
158 :    
159 :     if(value > (cmp - 1))
160 :     value -= 64 * scale_factor;
161 :    
162 : edgomez 78 pStat->iMvSum += value * value;
163 :     pStat->iMvCount++;
164 : Isibaar 3
165 : edgomez 78 if (value == 0) {
166 : Isibaar 3 BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len);
167 : edgomez 78 } else {
168 : Isibaar 3 uint16_t length, code, mv_res, sign;
169 :    
170 :     length = 16 << f_code;
171 :     f_code--;
172 :    
173 :     sign = (value < 0);
174 :    
175 :     if(value >= length)
176 :     value -= 2 * length;
177 :     else if(value < -length)
178 :     value += 2 * length;
179 :    
180 :     if(sign)
181 :     value = -value;
182 :    
183 :     value--;
184 :     mv_res = value & ((1 << f_code) - 1);
185 :     code = ((value - mv_res) >> f_code) + 1;
186 :    
187 :     if(sign)
188 :     code = -code;
189 :    
190 :     code += 32;
191 :     BitstreamPutBits(bs, mb_motion_table[code].code, mb_motion_table[code].len);
192 :    
193 :     if(f_code)
194 :     BitstreamPutBits(bs, mv_res, f_code);
195 : edgomez 78 }
196 :    
197 : Isibaar 3 }
198 :    
199 :    
200 : edgomez 78 static __inline void CodeCoeff(Bitstream *bs,
201 :     int16_t qcoeff[64],
202 :     VLC *table,
203 :     const uint16_t *zigzag,
204 :     uint16_t intra)
205 :     {
206 :    
207 : Isibaar 3 uint32_t j, last;
208 :     short v;
209 :     VLC *vlc;
210 :    
211 :     j = intra;
212 :     last = 1 + intra;
213 :    
214 :     while((v = qcoeff[zigzag[j++]]) == 0);
215 :    
216 :     do {
217 :     // count zeroes
218 : Isibaar 100 vlc = table + 64*255 + (clip_table[2048+v] << 6) + j - last;
219 : Isibaar 3 last = j + 1;
220 :     while(j < 64 && (v = qcoeff[zigzag[j++]]) == 0);
221 :    
222 :     // write code
223 :     if(j != 64) {
224 :     BitstreamPutBits(bs, vlc->code, vlc->len);
225 :     } else {
226 :     vlc += 64*511;
227 :     BitstreamPutBits(bs, vlc->code, vlc->len);
228 :     break;
229 :     }
230 :     } while(1);
231 : edgomez 78
232 : Isibaar 3 }
233 :    
234 :    
235 : edgomez 78 static void CodeBlockIntra(const MBParam * pParam,
236 :     const MACROBLOCK *pMB,
237 :     int16_t qcoeff[6*64],
238 :     Bitstream * bs,
239 :     Statistics * pStat)
240 : Isibaar 3 {
241 : edgomez 78
242 : Isibaar 3 uint32_t i, mcbpc, cbpy, bits;
243 :    
244 :     cbpy = pMB->cbp >> 2;
245 :    
246 : edgomez 78 // write mcbpc
247 : Isibaar 28 if(pParam->coding_type == I_VOP) {
248 : edgomez 78 mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2);
249 : Isibaar 28 BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, mcbpc_intra_tab[mcbpc].len);
250 :     }
251 :     else {
252 : edgomez 78 mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
253 : Isibaar 28 BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);
254 :     }
255 : Isibaar 3
256 :     // ac prediction flag
257 :     if(pMB->acpred_directions[0])
258 : edgomez 78 BitstreamPutBits(bs, 1, 1);
259 : Isibaar 3 else
260 : edgomez 78 BitstreamPutBits(bs, 0, 1);
261 : Isibaar 3
262 : edgomez 78 // write cbpy
263 : Isibaar 3 BitstreamPutBits (bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
264 :    
265 :     // write dquant
266 : edgomez 78 if(pMB->mode == MODE_INTRA_Q)
267 : Isibaar 3 BitstreamPutBits(bs, pMB->dquant, 2);
268 :    
269 : h 69 // write interlacing
270 :     if (pParam->global_flags & XVID_INTERLACING)
271 :     {
272 :     BitstreamPutBit(bs, pMB->field_dct);
273 :     }
274 :    
275 : Isibaar 3 // code block coeffs
276 :     for(i = 0; i < 6; i++)
277 :     {
278 :     if(i < 4)
279 : edgomez 78 BitstreamPutBits(bs,
280 :     dcy_tab[qcoeff[i*64 + 0] + 255].code,
281 :     dcy_tab[qcoeff[i*64 + 0] + 255].len);
282 : Isibaar 3 else
283 : edgomez 78 BitstreamPutBits(bs,
284 :     dcc_tab[qcoeff[i*64 + 0] + 255].code,
285 :     dcc_tab[qcoeff[i*64 + 0] + 255].len);
286 : Isibaar 3
287 :     if(pMB->cbp & (1 << (5 - i)))
288 :     {
289 :     bits = BitstreamPos(bs);
290 :    
291 : edgomez 78 CodeCoeff(bs,
292 :     &qcoeff[i*64],
293 :     intra_table,
294 :     scan_tables[pMB->acpred_directions[i]],
295 :     1);
296 : Isibaar 3
297 :     bits = BitstreamPos(bs) - bits;
298 :     pStat->iTextBits += bits;
299 :     }
300 :     }
301 : edgomez 78
302 : Isibaar 3 }
303 :    
304 :    
305 : edgomez 78 static void CodeBlockInter(const MBParam * pParam,
306 :     const MACROBLOCK *pMB,
307 :     int16_t qcoeff[6*64],
308 :     Bitstream * bs,
309 :     Statistics * pStat)
310 : Isibaar 3 {
311 : edgomez 78
312 : Isibaar 3 int32_t i;
313 :     uint32_t bits, mcbpc, cbpy;
314 :    
315 : edgomez 78 mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3);
316 : Isibaar 3 cbpy = 15 - (pMB->cbp >> 2);
317 :    
318 :     // write mcbpc
319 : edgomez 78 BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, mcbpc_inter_tab[mcbpc].len);
320 : Isibaar 3
321 :     // write cbpy
322 :     BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len);
323 :    
324 :     // write dquant
325 : edgomez 78 if(pMB->mode == MODE_INTER_Q)
326 : Isibaar 3 BitstreamPutBits(bs, pMB->dquant, 2);
327 :    
328 : h 69 // interlacing
329 :     if (pParam->global_flags & XVID_INTERLACING)
330 :     {
331 :     BitstreamPutBit(bs, pMB->field_dct);
332 :     DEBUG1("codep: field_dct: ", pMB->field_dct);
333 :    
334 :     // if inter block, write field ME flag
335 :     if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q)
336 :     {
337 :     BitstreamPutBit(bs, pMB->field_pred);
338 :     DEBUG1("codep: field_pred: ", pMB->field_pred);
339 :    
340 :     // write field prediction references
341 :     if (pMB->field_pred)
342 :     {
343 :     BitstreamPutBit(bs, pMB->field_for_top);
344 :     BitstreamPutBit(bs, pMB->field_for_bot);
345 :     }
346 :     }
347 :     }
348 :    
349 : Isibaar 3 // code motion vector(s)
350 :     for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++)
351 :     {
352 :     CodeVector(bs, pMB->pmvs[i].x, pParam->fixed_code, pStat);
353 :     CodeVector(bs, pMB->pmvs[i].y, pParam->fixed_code, pStat);
354 :     }
355 :    
356 :     bits = BitstreamPos(bs);
357 :    
358 :     // code block coeffs
359 :     for(i = 0; i < 6; i++)
360 :     if(pMB->cbp & (1 << (5 - i)))
361 : edgomez 78 CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0);
362 : Isibaar 3
363 :     bits = BitstreamPos(bs) - bits;
364 :     pStat->iTextBits += bits;
365 : edgomez 78
366 : Isibaar 3 }
367 :    
368 :    
369 : edgomez 78 void MBCoding(const MBParam * pParam,
370 :     MACROBLOCK *pMB,
371 :     int16_t qcoeff[6*64],
372 :     Bitstream * bs,
373 :     Statistics * pStat)
374 : Isibaar 3 {
375 : edgomez 78
376 : Isibaar 3 int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q);
377 :    
378 : edgomez 78 if(pParam->coding_type == P_VOP) {
379 : Isibaar 3 if(pMB->cbp == 0 && pMB->mode == MODE_INTER &&
380 : edgomez 78 pMB->mvs[0].x == 0 && pMB->mvs[0].y == 0)
381 : Isibaar 3 {
382 :     BitstreamPutBit(bs, 1); // not_coded
383 :     return;
384 :     }
385 :     else
386 :     BitstreamPutBit(bs, 0); // coded
387 :     }
388 :    
389 :     if(intra)
390 :     CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat);
391 :     else
392 :     CodeBlockInter(pParam, pMB, qcoeff, bs, pStat);
393 : edgomez 78
394 : Isibaar 3 }
395 :    
396 :    
397 :     /***************************************************************
398 : edgomez 15 * decoding stuff starts here *
399 :     ***************************************************************/
400 : Isibaar 3
401 :     int get_mcbpc_intra(Bitstream * bs)
402 :     {
403 : edgomez 78
404 : Isibaar 3 uint32_t index;
405 :    
406 :     while((index = BitstreamShowBits(bs, 9)) == 1)
407 :     BitstreamSkip(bs, 9);
408 :    
409 :     index >>= 3;
410 :    
411 :     BitstreamSkip(bs, mcbpc_intra_table[index].len);
412 : edgomez 78
413 : Isibaar 3 return mcbpc_intra_table[index].code;
414 : edgomez 78
415 : Isibaar 3 }
416 :    
417 :     int get_mcbpc_inter(Bitstream * bs)
418 :     {
419 : edgomez 78
420 : Isibaar 3 uint32_t index;
421 :    
422 :     while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1)
423 :     BitstreamSkip(bs, 9);
424 :    
425 : edgomez 78 BitstreamSkip(bs, mcbpc_inter_table[index].len);
426 :    
427 : Isibaar 3 return mcbpc_inter_table[index].code;
428 : edgomez 78
429 : Isibaar 3 }
430 :    
431 :     int get_cbpy(Bitstream * bs, int intra)
432 :     {
433 : edgomez 78
434 : Isibaar 3 int cbpy;
435 :     uint32_t index = BitstreamShowBits(bs, 6);
436 :    
437 :     BitstreamSkip(bs, cbpy_table[index].len);
438 :     cbpy = cbpy_table[index].code;
439 :    
440 :     if(!intra)
441 :     cbpy = 15 - cbpy;
442 :    
443 :     return cbpy;
444 : edgomez 78
445 : Isibaar 3 }
446 :    
447 :     int get_mv_data(Bitstream * bs)
448 :     {
449 : edgomez 78
450 : Isibaar 3 uint32_t index;
451 :    
452 :     if(BitstreamGetBit(bs))
453 :     return 0;
454 :    
455 :     index = BitstreamShowBits(bs, 12);
456 :    
457 :     if(index >= 512)
458 :     {
459 :     index = (index >> 8) - 2;
460 :     BitstreamSkip(bs, TMNMVtab0[index].len);
461 :     return TMNMVtab0[index].code;
462 :     }
463 :    
464 :     if(index >= 128)
465 :     {
466 :     index = (index >> 2) - 32;
467 :     BitstreamSkip(bs, TMNMVtab1[index].len);
468 :     return TMNMVtab1[index].code;
469 :     }
470 :    
471 :     index -= 4;
472 :    
473 :     BitstreamSkip(bs, TMNMVtab2[index].len);
474 :     return TMNMVtab2[index].code;
475 : edgomez 78
476 : Isibaar 3 }
477 :    
478 :     int get_mv(Bitstream * bs, int fcode)
479 :     {
480 : edgomez 78
481 : Isibaar 3 int data;
482 :     int res;
483 :     int mv;
484 :     int scale_fac = 1 << (fcode - 1);
485 :    
486 :     data = get_mv_data(bs);
487 :    
488 :     if(scale_fac == 1 || data == 0)
489 :     return data;
490 :    
491 :     res = BitstreamGetBits(bs, fcode - 1);
492 :     mv = ((ABS(data) - 1) * scale_fac) + res + 1;
493 :    
494 :     return data < 0 ? -mv : mv;
495 : edgomez 78
496 : Isibaar 3 }
497 :    
498 :     int get_dc_dif(Bitstream * bs, uint32_t dc_size)
499 :     {
500 : edgomez 78
501 : Isibaar 3 int code = BitstreamGetBits(bs, dc_size);
502 :     int msb = code >> (dc_size - 1);
503 :    
504 :     if(msb == 0)
505 :     return (-1 * (code^((1 << dc_size) - 1)));
506 :    
507 :     return code;
508 : edgomez 78
509 : Isibaar 3 }
510 :    
511 :     int get_dc_size_lum(Bitstream * bs)
512 :     {
513 : edgomez 78
514 : Isibaar 3 int code, i;
515 :     code = BitstreamShowBits(bs, 11);
516 :    
517 :     for(i = 11; i > 3; i--) {
518 :     if(code == 1) {
519 :     BitstreamSkip(bs, i);
520 :     return i + 1;
521 :     }
522 :     code >>= 1;
523 :     }
524 :    
525 :     BitstreamSkip(bs, dc_lum_tab[code].len);
526 :     return dc_lum_tab[code].code;
527 : edgomez 78
528 : Isibaar 3 }
529 :    
530 :    
531 :     int get_dc_size_chrom(Bitstream * bs)
532 :     {
533 : edgomez 78
534 : Isibaar 3 uint32_t code, i;
535 :     code = BitstreamShowBits(bs, 12);
536 :    
537 :     for(i = 12; i > 2; i--) {
538 :     if(code == 1) {
539 :     BitstreamSkip(bs, i);
540 :     return i;
541 :     }
542 :     code >>= 1;
543 :     }
544 :    
545 :     return 3 - BitstreamGetBits(bs, 2);
546 : edgomez 78
547 : Isibaar 3 }
548 :    
549 :     int get_coeff(Bitstream * bs, int *run, int *last, int intra, int short_video_header)
550 :     {
551 : edgomez 78
552 :     uint32_t mode;
553 :     const VLC *tab;
554 : Isibaar 3 int32_t level;
555 :    
556 :     if(short_video_header) // inter-VLCs will be used for both intra and inter blocks
557 :     intra = 0;
558 :    
559 :     tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
560 :    
561 :     if(tab->code == -1)
562 :     goto error;
563 :    
564 :     BitstreamSkip(bs, tab->len);
565 :    
566 :     if(tab->code != ESCAPE) {
567 :     if(!intra)
568 :     {
569 :     *run = (tab->code >> 4) & 255;
570 :     level = tab->code & 15;
571 :     *last = (tab->code >> 12) & 1;
572 :     }
573 : edgomez 78 else
574 : Isibaar 3 {
575 :     *run = (tab->code >> 8) & 255;
576 :     level = tab->code & 255;
577 :     *last = (tab->code >> 16) & 1;
578 :     }
579 :     return BitstreamGetBit(bs) ? -level : level;
580 :     }
581 :    
582 :     if(short_video_header)
583 :     {
584 :     // escape mode 4 - H.263 type, only used if short_video_header = 1
585 :     *last = BitstreamGetBit(bs);
586 :     *run = BitstreamGetBits(bs, 6);
587 :     level = BitstreamGetBits(bs, 8);
588 :    
589 :     if (level == 0 || level == 128)
590 :     DEBUG1("Illegal LEVEL for ESCAPE mode 4:", level);
591 :    
592 :     return (level >= 128 ? -(256 - level) : level);
593 :     }
594 :    
595 :     mode = BitstreamShowBits(bs, 2);
596 :    
597 :     if(mode < 3) {
598 :     BitstreamSkip(bs, (mode == 2) ? 2 : 1);
599 :    
600 :     tab = &DCT3D[intra][BitstreamShowBits(bs, 12)];
601 :     if (tab->code == -1)
602 :     goto error;
603 :    
604 :     BitstreamSkip(bs, tab->len);
605 :    
606 :     if (!intra) {
607 :     *run = (tab->code >> 4) & 255;
608 :     level = tab->code & 15;
609 :     *last = (tab->code >> 12) & 1;
610 :     }
611 :     else
612 :     {
613 :     *run = (tab->code >> 8) & 255;
614 :     level = tab->code & 255;
615 :     *last = (tab->code >> 16) & 1;
616 :     }
617 :    
618 :     if(mode < 2) // first escape mode, level is offset
619 :     level += max_level[*last + (!intra<<1)][*run]; // need to add back the max level
620 :     else if(mode == 2) // second escape mode, run is offset
621 :     *run += max_run[*last + (!intra<<1)][level] + 1;
622 :    
623 :     return BitstreamGetBit(bs) ? -level : level;
624 :     }
625 :    
626 :     // third escape mode - fixed length codes
627 :     BitstreamSkip(bs, 2);
628 :     *last = BitstreamGetBits(bs, 1);
629 :     *run = BitstreamGetBits(bs, 6);
630 :     BitstreamSkip(bs, 1); // marker
631 :     level = BitstreamGetBits(bs, 12);
632 :     BitstreamSkip(bs, 1); // marker
633 :    
634 :     return (level & 0x800) ? (level | (-1 ^ 0xfff)) : level;
635 :    
636 : edgomez 78 error:
637 : Isibaar 3 *run = VLC_ERROR;
638 :     return 0;
639 : edgomez 78
640 : Isibaar 3 }
641 :    
642 :    
643 :     void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff)
644 :     {
645 : edgomez 78
646 : Isibaar 3 const uint16_t * scan = scan_tables[ direction ];
647 :     int level;
648 :     int run;
649 :     int last;
650 :    
651 :     do
652 :     {
653 :     level = get_coeff(bs, &run, &last, 1, 0);
654 :     if (run == -1)
655 :     {
656 :     DEBUG("fatal: invalid run");
657 :     break;
658 :     }
659 :     coeff += run;
660 :     block[ scan[coeff] ] = level;
661 :     if (level < -127 || level > 127)
662 :     {
663 :     DEBUG1("warning: intra_overflow", level);
664 :     }
665 :     coeff++;
666 :     } while (!last);
667 : edgomez 78
668 : Isibaar 3 }
669 :    
670 :     void get_inter_block(Bitstream * bs, int16_t * block)
671 :     {
672 : edgomez 78
673 : Isibaar 3 const uint16_t * scan = scan_tables[0];
674 :     int p;
675 :     int level;
676 :     int run;
677 :     int last;
678 :    
679 :     p = 0;
680 :     do
681 :     {
682 :     level = get_coeff(bs, &run, &last, 0, 0);
683 :     if (run == -1)
684 :     {
685 :     DEBUG("fatal: invalid run");
686 :     break;
687 :     }
688 :     p += run;
689 :     block[ scan[p] ] = level;
690 :     if (level < -127 || level > 127)
691 :     {
692 :     DEBUG1("warning: inter_overflow", level);
693 :     }
694 :     p++;
695 :     } while (!last);
696 : edgomez 78
697 : Isibaar 3 }

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