comparison libmpeg2/slice.c @ 36:846535ace7a2

libmpeg2-0.2.0 merge
author arpi_esp
date Sun, 04 Mar 2001 21:01:54 +0000
parents 3b5f5d1c5041
children 0d76b2b962ad
comparison
equal deleted inserted replaced
35:25f148e9890a 36:846535ace7a2
1 /* 1 /*
2 * slice.c 2 * slice.c
3 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 3 * Copyright (C) 1999-2001 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4 * 4 *
5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. 5 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
6 * 6 *
7 * mpeg2dec is free software; you can redistribute it and/or modify 7 * mpeg2dec is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
22 #include "config.h" 22 #include "config.h"
23 23
24 #include <string.h> 24 #include <string.h>
25 #include <inttypes.h> 25 #include <inttypes.h>
26 26
27 #include "video_out.h"
27 #include "mpeg2_internal.h" 28 #include "mpeg2_internal.h"
28 #include "attributes.h" 29 #include "attributes.h"
29 30
30 extern mc_functions_t mc_functions; 31 extern mc_functions_t mc_functions;
31 extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride); 32 extern void (* idct_block_copy) (int16_t * block, uint8_t * dest, int stride);
32 extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride); 33 extern void (* idct_block_add) (int16_t * block, uint8_t * dest, int stride);
33
34 static int16_t DCTblock[64] ATTR_ALIGN(16);
35 34
36 #include "vlc.h" 35 #include "vlc.h"
37 36
38 static int non_linear_quantizer_scale [] = { 37 static int non_linear_quantizer_scale [] = {
39 0, 1, 2, 3, 4, 5, 6, 7, 38 0, 1, 2, 3, 4, 5, 6, 7,
40 8, 10, 12, 14, 16, 18, 20, 22, 39 8, 10, 12, 14, 16, 18, 20, 22,
41 24, 28, 32, 36, 40, 44, 48, 52, 40 24, 28, 32, 36, 40, 44, 48, 52,
42 56, 64, 72, 80, 88, 96, 104, 112 41 56, 64, 72, 80, 88, 96, 104, 112
43 }; 42 };
44 43
45 static inline int get_macroblock_modes (slice_t * slice, int picture_structure, 44 static inline int get_macroblock_modes (picture_t * picture)
46 int picture_coding_type, 45 {
47 int frame_pred_frame_dct) 46 #define bit_buf (picture->bitstream_buf)
48 { 47 #define bits (picture->bitstream_bits)
49 #define bit_buf (slice->bitstream_buf) 48 #define bit_ptr (picture->bitstream_ptr)
50 #define bits (slice->bitstream_bits)
51 #define bit_ptr (slice->bitstream_ptr)
52 int macroblock_modes; 49 int macroblock_modes;
53 MBtab * tab; 50 MBtab * tab;
54 51
55 switch (picture_coding_type) { 52 switch (picture->picture_coding_type) {
56 case I_TYPE: 53 case I_TYPE:
57 54
58 tab = MB_I + UBITS (bit_buf, 1); 55 tab = MB_I + UBITS (bit_buf, 1);
59 DUMPBITS (bit_buf, bits, tab->len); 56 DUMPBITS (bit_buf, bits, tab->len);
60 macroblock_modes = tab->modes; 57 macroblock_modes = tab->modes;
61 58
62 if ((! frame_pred_frame_dct) && (picture_structure == FRAME_PICTURE)) { 59 if ((! (picture->frame_pred_frame_dct)) &&
60 (picture->picture_structure == FRAME_PICTURE)) {
63 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; 61 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
64 DUMPBITS (bit_buf, bits, 1); 62 DUMPBITS (bit_buf, bits, 1);
65 } 63 }
66 64
67 return macroblock_modes; 65 return macroblock_modes;
70 68
71 tab = MB_P + UBITS (bit_buf, 5); 69 tab = MB_P + UBITS (bit_buf, 5);
72 DUMPBITS (bit_buf, bits, tab->len); 70 DUMPBITS (bit_buf, bits, tab->len);
73 macroblock_modes = tab->modes; 71 macroblock_modes = tab->modes;
74 72
75 if (picture_structure != FRAME_PICTURE) { 73 if (picture->picture_structure != FRAME_PICTURE) {
76 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { 74 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
77 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; 75 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
78 DUMPBITS (bit_buf, bits, 2); 76 DUMPBITS (bit_buf, bits, 2);
79 } 77 }
80 return macroblock_modes; 78 return macroblock_modes;
81 } else if (frame_pred_frame_dct) { 79 } else if (picture->frame_pred_frame_dct) {
82 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) 80 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
83 macroblock_modes |= MC_FRAME; 81 macroblock_modes |= MC_FRAME;
84 return macroblock_modes; 82 return macroblock_modes;
85 } else { 83 } else {
86 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { 84 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
98 96
99 tab = MB_B + UBITS (bit_buf, 6); 97 tab = MB_B + UBITS (bit_buf, 6);
100 DUMPBITS (bit_buf, bits, tab->len); 98 DUMPBITS (bit_buf, bits, tab->len);
101 macroblock_modes = tab->modes; 99 macroblock_modes = tab->modes;
102 100
103 if (picture_structure != FRAME_PICTURE) { 101 if (picture->picture_structure != FRAME_PICTURE) {
104 if (! (macroblock_modes & MACROBLOCK_INTRA)) { 102 if (! (macroblock_modes & MACROBLOCK_INTRA)) {
105 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE; 103 macroblock_modes |= UBITS (bit_buf, 2) * MOTION_TYPE_BASE;
106 DUMPBITS (bit_buf, bits, 2); 104 DUMPBITS (bit_buf, bits, 2);
107 } 105 }
108 return macroblock_modes; 106 return macroblock_modes;
109 } else if (frame_pred_frame_dct) { 107 } else if (picture->frame_pred_frame_dct) {
110 //if (! (macroblock_modes & MACROBLOCK_INTRA)) 108 /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */
111 macroblock_modes |= MC_FRAME; 109 macroblock_modes |= MC_FRAME;
112 return macroblock_modes; 110 return macroblock_modes;
113 } else { 111 } else {
114 if (macroblock_modes & MACROBLOCK_INTRA) 112 if (macroblock_modes & MACROBLOCK_INTRA)
115 goto intra; 113 goto intra;
134 #undef bit_buf 132 #undef bit_buf
135 #undef bits 133 #undef bits
136 #undef bit_ptr 134 #undef bit_ptr
137 } 135 }
138 136
139 static inline int get_quantizer_scale (slice_t * slice, int q_scale_type) 137 static inline int get_quantizer_scale (picture_t * picture)
140 { 138 {
141 #define bit_buf (slice->bitstream_buf) 139 #define bit_buf (picture->bitstream_buf)
142 #define bits (slice->bitstream_bits) 140 #define bits (picture->bitstream_bits)
143 #define bit_ptr (slice->bitstream_ptr) 141 #define bit_ptr (picture->bitstream_ptr)
144 142
145 int quantizer_scale_code; 143 int quantizer_scale_code;
146 144
147 quantizer_scale_code = UBITS (bit_buf, 5); 145 quantizer_scale_code = UBITS (bit_buf, 5);
148 DUMPBITS (bit_buf, bits, 5); 146 DUMPBITS (bit_buf, bits, 5);
149 147
150 if (q_scale_type) 148 if (picture->q_scale_type)
151 return non_linear_quantizer_scale [quantizer_scale_code]; 149 return non_linear_quantizer_scale [quantizer_scale_code];
152 else 150 else
153 return quantizer_scale_code << 1; 151 return quantizer_scale_code << 1;
154 #undef bit_buf 152 #undef bit_buf
155 #undef bits 153 #undef bits
156 #undef bit_ptr 154 #undef bit_ptr
157 } 155 }
158 156
159 static inline int get_motion_delta (slice_t * slice, int f_code) 157 static inline int get_motion_delta (picture_t * picture, int f_code)
160 { 158 {
161 #define bit_buf (slice->bitstream_buf) 159 #define bit_buf (picture->bitstream_buf)
162 #define bits (slice->bitstream_bits) 160 #define bits (picture->bitstream_bits)
163 #define bit_ptr (slice->bitstream_ptr) 161 #define bit_ptr (picture->bitstream_ptr)
164 162
165 int delta; 163 int delta;
166 int sign; 164 int sign;
167 MVtab * tab; 165 MVtab * tab;
168 166
224 #else 222 #else
225 return (vector << (27 - f_code)) >> (27 - f_code); 223 return (vector << (27 - f_code)) >> (27 - f_code);
226 #endif 224 #endif
227 } 225 }
228 226
229 static inline int get_dmv (slice_t * slice) 227 static inline int get_dmv (picture_t * picture)
230 { 228 {
231 #define bit_buf (slice->bitstream_buf) 229 #define bit_buf (picture->bitstream_buf)
232 #define bits (slice->bitstream_bits) 230 #define bits (picture->bitstream_bits)
233 #define bit_ptr (slice->bitstream_ptr) 231 #define bit_ptr (picture->bitstream_ptr)
234 232
235 DMVtab * tab; 233 DMVtab * tab;
236 234
237 tab = DMV_2 + UBITS (bit_buf, 2); 235 tab = DMV_2 + UBITS (bit_buf, 2);
238 DUMPBITS (bit_buf, bits, tab->len); 236 DUMPBITS (bit_buf, bits, tab->len);
240 #undef bit_buf 238 #undef bit_buf
241 #undef bits 239 #undef bits
242 #undef bit_ptr 240 #undef bit_ptr
243 } 241 }
244 242
245 static inline int get_coded_block_pattern (slice_t * slice) 243 static inline int get_coded_block_pattern (picture_t * picture)
246 { 244 {
247 #define bit_buf (slice->bitstream_buf) 245 #define bit_buf (picture->bitstream_buf)
248 #define bits (slice->bitstream_bits) 246 #define bits (picture->bitstream_bits)
249 #define bit_ptr (slice->bitstream_ptr) 247 #define bit_ptr (picture->bitstream_ptr)
250 248
251 CBPtab * tab; 249 CBPtab * tab;
252 250
253 NEEDBITS (bit_buf, bits, bit_ptr); 251 NEEDBITS (bit_buf, bits, bit_ptr);
254 252
268 #undef bit_buf 266 #undef bit_buf
269 #undef bits 267 #undef bits
270 #undef bit_ptr 268 #undef bit_ptr
271 } 269 }
272 270
273 static inline int get_luma_dc_dct_diff (slice_t * slice) 271 static inline int get_luma_dc_dct_diff (picture_t * picture)
274 { 272 {
275 #define bit_buf (slice->bitstream_buf) 273 #define bit_buf (picture->bitstream_buf)
276 #define bits (slice->bitstream_bits) 274 #define bits (picture->bitstream_bits)
277 #define bit_ptr (slice->bitstream_ptr) 275 #define bit_ptr (picture->bitstream_ptr)
278 DCtab * tab; 276 DCtab * tab;
279 int size; 277 int size;
280 int dc_diff; 278 int dc_diff;
281 279
282 if (bit_buf < 0xf8000000) { 280 if (bit_buf < 0xf8000000) {
305 #undef bit_buf 303 #undef bit_buf
306 #undef bits 304 #undef bits
307 #undef bit_ptr 305 #undef bit_ptr
308 } 306 }
309 307
310 static inline int get_chroma_dc_dct_diff (slice_t * slice) 308 static inline int get_chroma_dc_dct_diff (picture_t * picture)
311 { 309 {
312 #define bit_buf (slice->bitstream_buf) 310 #define bit_buf (picture->bitstream_buf)
313 #define bits (slice->bitstream_bits) 311 #define bits (picture->bitstream_bits)
314 #define bit_ptr (slice->bitstream_ptr) 312 #define bit_ptr (picture->bitstream_ptr)
315 DCtab * tab; 313 DCtab * tab;
316 int size; 314 int size;
317 int dc_diff; 315 int dc_diff;
318 316
319 if (bit_buf < 0xf8000000) { 317 if (bit_buf < 0xf8000000) {
342 #undef bit_buf 340 #undef bit_buf
343 #undef bits 341 #undef bits
344 #undef bit_ptr 342 #undef bit_ptr
345 } 343 }
346 344
347 #define SATURATE(val) \ 345 #define SATURATE(val) \
348 do { \ 346 do { \
349 if (val > 2047) \ 347 if ((uint32_t)(val + 2048) > 4095) \
350 val = 2047; \ 348 val = (val > 0) ? 2047 : -2048; \
351 else if (val < -2048) \
352 val = -2048; \
353 } while (0) 349 } while (0)
354 350
355 static void get_intra_block_B14 (picture_t * picture, slice_t * slice, 351 static void get_intra_block_B14 (picture_t * picture)
356 int16_t * dest)
357 { 352 {
358 int i; 353 int i;
359 int j; 354 int j;
360 int val; 355 int val;
361 uint8_t * scan = picture->scan; 356 uint8_t * scan = picture->scan;
362 uint8_t * quant_matrix = picture->intra_quantizer_matrix; 357 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
363 int quantizer_scale = slice->quantizer_scale; 358 int quantizer_scale = picture->quantizer_scale;
364 int mismatch; 359 int mismatch;
365 DCTtab * tab; 360 DCTtab * tab;
366 uint32_t bit_buf; 361 uint32_t bit_buf;
367 int bits; 362 int bits;
368 uint8_t * bit_ptr; 363 uint8_t * bit_ptr;
369 364 int16_t * dest;
365
366 dest = picture->DCTblock;
370 i = 0; 367 i = 0;
371 mismatch = ~dest[0]; 368 mismatch = ~dest[0];
372 369
373 bit_buf = slice->bitstream_buf; 370 bit_buf = picture->bitstream_buf;
374 bits = slice->bitstream_bits; 371 bits = picture->bitstream_bits;
375 bit_ptr = slice->bitstream_ptr; 372 bit_ptr = picture->bitstream_ptr;
376 373
377 NEEDBITS (bit_buf, bits, bit_ptr); 374 NEEDBITS (bit_buf, bits, bit_ptr);
378 375
379 while (1) { 376 while (1) {
380 if (bit_buf >= 0x28000000) { 377 if (bit_buf >= 0x28000000) {
381 378
382 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5); 379 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
383 380
384 i += tab->run; 381 i += tab->run;
385 if (i >= 64) 382 if (i >= 64)
386 break; // end of block 383 break; /* end of block */
387 384
388 normal_code: 385 normal_code:
389 j = scan[i]; 386 j = scan[i];
390 bit_buf <<= tab->len; 387 bit_buf <<= tab->len;
391 bits += tab->len + 1; 388 bits += tab->len + 1;
392 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; 389 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
393 390
394 // if (bitstream_get (1)) val = -val; 391 /* if (bitstream_get (1)) val = -val; */
395 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); 392 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
396 393
397 SATURATE (val); 394 SATURATE (val);
398 dest[j] = val; 395 dest[j] = val;
399 mismatch ^= val; 396 mismatch ^= val;
409 406
410 i += tab->run; 407 i += tab->run;
411 if (i < 64) 408 if (i < 64)
412 goto normal_code; 409 goto normal_code;
413 410
414 // escape code 411 /* escape code */
415 412
416 i += UBITS (bit_buf << 6, 6) - 64; 413 i += UBITS (bit_buf << 6, 6) - 64;
417 if (i >= 64) 414 if (i >= 64)
418 break; // illegal, but check needed to avoid buffer overflow 415 break; /* illegal, check needed to avoid buffer overflow */
419 416
420 j = scan[i]; 417 j = scan[i];
421 418
422 DUMPBITS (bit_buf, bits, 12); 419 DUMPBITS (bit_buf, bits, 12);
423 NEEDBITS (bit_buf, bits, bit_ptr); 420 NEEDBITS (bit_buf, bits, bit_ptr);
454 GETWORD (bit_buf, bits + 16, bit_ptr); 451 GETWORD (bit_buf, bits + 16, bit_ptr);
455 i += tab->run; 452 i += tab->run;
456 if (i < 64) 453 if (i < 64)
457 goto normal_code; 454 goto normal_code;
458 } 455 }
459 break; // illegal, but check needed to avoid buffer overflow 456 break; /* illegal, check needed to avoid buffer overflow */
460 } 457 }
461 dest[63] ^= mismatch & 1; 458 dest[63] ^= mismatch & 1;
462 DUMPBITS (bit_buf, bits, 2); // dump end of block code 459 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
463 slice->bitstream_buf = bit_buf; 460 picture->bitstream_buf = bit_buf;
464 slice->bitstream_bits = bits; 461 picture->bitstream_bits = bits;
465 slice->bitstream_ptr = bit_ptr; 462 picture->bitstream_ptr = bit_ptr;
466 } 463 }
467 464
468 static void get_intra_block_B15 (picture_t * picture, slice_t * slice, 465 static void get_intra_block_B15 (picture_t * picture)
469 int16_t * dest)
470 { 466 {
471 int i; 467 int i;
472 int j; 468 int j;
473 int val; 469 int val;
474 uint8_t * scan = picture->scan; 470 uint8_t * scan = picture->scan;
475 uint8_t * quant_matrix = picture->intra_quantizer_matrix; 471 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
476 int quantizer_scale = slice->quantizer_scale; 472 int quantizer_scale = picture->quantizer_scale;
477 int mismatch; 473 int mismatch;
478 DCTtab * tab; 474 DCTtab * tab;
479 uint32_t bit_buf; 475 uint32_t bit_buf;
480 int bits; 476 int bits;
481 uint8_t * bit_ptr; 477 uint8_t * bit_ptr;
482 478 int16_t * dest;
479
480 dest = picture->DCTblock;
483 i = 0; 481 i = 0;
484 mismatch = ~dest[0]; 482 mismatch = ~dest[0];
485 483
486 bit_buf = slice->bitstream_buf; 484 bit_buf = picture->bitstream_buf;
487 bits = slice->bitstream_bits; 485 bits = picture->bitstream_bits;
488 bit_ptr = slice->bitstream_ptr; 486 bit_ptr = picture->bitstream_ptr;
489 487
490 NEEDBITS (bit_buf, bits, bit_ptr); 488 NEEDBITS (bit_buf, bits, bit_ptr);
491 489
492 while (1) { 490 while (1) {
493 if (bit_buf >= 0x04000000) { 491 if (bit_buf >= 0x04000000) {
501 j = scan[i]; 499 j = scan[i];
502 bit_buf <<= tab->len; 500 bit_buf <<= tab->len;
503 bits += tab->len + 1; 501 bits += tab->len + 1;
504 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; 502 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
505 503
506 // if (bitstream_get (1)) val = -val; 504 /* if (bitstream_get (1)) val = -val; */
507 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); 505 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
508 506
509 SATURATE (val); 507 SATURATE (val);
510 dest[j] = val; 508 dest[j] = val;
511 mismatch ^= val; 509 mismatch ^= val;
515 513
516 continue; 514 continue;
517 515
518 } else { 516 } else {
519 517
520 // end of block. I commented out this code because if we 518 /* end of block. I commented out this code because if we */
521 // dont exit here we will still exit at the later test :) 519 /* dont exit here we will still exit at the later test :) */
522 520
523 //if (i >= 128) break; // end of block 521 /* if (i >= 128) break; */ /* end of block */
524 522
525 // escape code 523 /* escape code */
526 524
527 i += UBITS (bit_buf << 6, 6) - 64; 525 i += UBITS (bit_buf << 6, 6) - 64;
528 if (i >= 64) 526 if (i >= 64)
529 break; // illegal, but check against buffer overflow 527 break; /* illegal, check against buffer overflow */
530 528
531 j = scan[i]; 529 j = scan[i];
532 530
533 DUMPBITS (bit_buf, bits, 12); 531 DUMPBITS (bit_buf, bits, 12);
534 NEEDBITS (bit_buf, bits, bit_ptr); 532 NEEDBITS (bit_buf, bits, bit_ptr);
566 GETWORD (bit_buf, bits + 16, bit_ptr); 564 GETWORD (bit_buf, bits + 16, bit_ptr);
567 i += tab->run; 565 i += tab->run;
568 if (i < 64) 566 if (i < 64)
569 goto normal_code; 567 goto normal_code;
570 } 568 }
571 break; // illegal, but check needed to avoid buffer overflow 569 break; /* illegal, check needed to avoid buffer overflow */
572 } 570 }
573 dest[63] ^= mismatch & 1; 571 dest[63] ^= mismatch & 1;
574 DUMPBITS (bit_buf, bits, 4); // dump end of block code 572 DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
575 slice->bitstream_buf = bit_buf; 573 picture->bitstream_buf = bit_buf;
576 slice->bitstream_bits = bits; 574 picture->bitstream_bits = bits;
577 slice->bitstream_ptr = bit_ptr; 575 picture->bitstream_ptr = bit_ptr;
578 } 576 }
579 577
580 static void get_non_intra_block (picture_t * picture, slice_t * slice, 578 static void get_non_intra_block (picture_t * picture)
581 int16_t * dest)
582 { 579 {
583 int i; 580 int i;
584 int j; 581 int j;
585 int val; 582 int val;
586 uint8_t * scan = picture->scan; 583 uint8_t * scan = picture->scan;
587 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix; 584 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
588 int quantizer_scale = slice->quantizer_scale; 585 int quantizer_scale = picture->quantizer_scale;
589 int mismatch; 586 int mismatch;
590 DCTtab * tab; 587 DCTtab * tab;
591 uint32_t bit_buf; 588 uint32_t bit_buf;
592 int bits; 589 int bits;
593 uint8_t * bit_ptr; 590 uint8_t * bit_ptr;
591 int16_t * dest;
594 592
595 i = -1; 593 i = -1;
596 mismatch = 1; 594 mismatch = 1;
597 595 dest = picture->DCTblock;
598 bit_buf = slice->bitstream_buf; 596
599 bits = slice->bitstream_bits; 597 bit_buf = picture->bitstream_buf;
600 bit_ptr = slice->bitstream_ptr; 598 bits = picture->bitstream_bits;
599 bit_ptr = picture->bitstream_ptr;
601 600
602 NEEDBITS (bit_buf, bits, bit_ptr); 601 NEEDBITS (bit_buf, bits, bit_ptr);
603 if (bit_buf >= 0x28000000) { 602 if (bit_buf >= 0x28000000) {
604 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5); 603 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
605 goto entry_1; 604 goto entry_1;
612 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5); 611 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
613 612
614 entry_1: 613 entry_1:
615 i += tab->run; 614 i += tab->run;
616 if (i >= 64) 615 if (i >= 64)
617 break; // end of block 616 break; /* end of block */
618 617
619 normal_code: 618 normal_code:
620 j = scan[i]; 619 j = scan[i];
621 bit_buf <<= tab->len; 620 bit_buf <<= tab->len;
622 bits += tab->len + 1; 621 bits += tab->len + 1;
623 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; 622 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
624 623
625 // if (bitstream_get (1)) val = -val; 624 /* if (bitstream_get (1)) val = -val; */
626 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); 625 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
627 626
628 SATURATE (val); 627 SATURATE (val);
629 dest[j] = val; 628 dest[j] = val;
630 mismatch ^= val; 629 mismatch ^= val;
643 642
644 i += tab->run; 643 i += tab->run;
645 if (i < 64) 644 if (i < 64)
646 goto normal_code; 645 goto normal_code;
647 646
648 // escape code 647 /* escape code */
649 648
650 i += UBITS (bit_buf << 6, 6) - 64; 649 i += UBITS (bit_buf << 6, 6) - 64;
651 if (i >= 64) 650 if (i >= 64)
652 break; // illegal, but check needed to avoid buffer overflow 651 break; /* illegal, check needed to avoid buffer overflow */
653 652
654 j = scan[i]; 653 j = scan[i];
655 654
656 DUMPBITS (bit_buf, bits, 12); 655 DUMPBITS (bit_buf, bits, 12);
657 NEEDBITS (bit_buf, bits, bit_ptr); 656 NEEDBITS (bit_buf, bits, bit_ptr);
688 GETWORD (bit_buf, bits + 16, bit_ptr); 687 GETWORD (bit_buf, bits + 16, bit_ptr);
689 i += tab->run; 688 i += tab->run;
690 if (i < 64) 689 if (i < 64)
691 goto normal_code; 690 goto normal_code;
692 } 691 }
693 break; // illegal, but check needed to avoid buffer overflow 692 break; /* illegal, check needed to avoid buffer overflow */
694 } 693 }
695 dest[63] ^= mismatch & 1; 694 dest[63] ^= mismatch & 1;
696 DUMPBITS (bit_buf, bits, 2); // dump end of block code 695 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
697 slice->bitstream_buf = bit_buf; 696 picture->bitstream_buf = bit_buf;
698 slice->bitstream_bits = bits; 697 picture->bitstream_bits = bits;
699 slice->bitstream_ptr = bit_ptr; 698 picture->bitstream_ptr = bit_ptr;
700 } 699 }
701 700
702 static void get_mpeg1_intra_block (picture_t * picture, slice_t * slice, 701 static void get_mpeg1_intra_block (picture_t * picture)
703 int16_t * dest)
704 { 702 {
705 int i; 703 int i;
706 int j; 704 int j;
707 int val; 705 int val;
708 uint8_t * scan = picture->scan; 706 uint8_t * scan = picture->scan;
709 uint8_t * quant_matrix = picture->intra_quantizer_matrix; 707 uint8_t * quant_matrix = picture->intra_quantizer_matrix;
710 int quantizer_scale = slice->quantizer_scale; 708 int quantizer_scale = picture->quantizer_scale;
711 DCTtab * tab; 709 DCTtab * tab;
712 uint32_t bit_buf; 710 uint32_t bit_buf;
713 int bits; 711 int bits;
714 uint8_t * bit_ptr; 712 uint8_t * bit_ptr;
713 int16_t * dest;
715 714
716 i = 0; 715 i = 0;
717 716 dest = picture->DCTblock;
718 bit_buf = slice->bitstream_buf; 717
719 bits = slice->bitstream_bits; 718 bit_buf = picture->bitstream_buf;
720 bit_ptr = slice->bitstream_ptr; 719 bits = picture->bitstream_bits;
720 bit_ptr = picture->bitstream_ptr;
721 721
722 NEEDBITS (bit_buf, bits, bit_ptr); 722 NEEDBITS (bit_buf, bits, bit_ptr);
723 723
724 while (1) { 724 while (1) {
725 if (bit_buf >= 0x28000000) { 725 if (bit_buf >= 0x28000000) {
726 726
727 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5); 727 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
728 728
729 i += tab->run; 729 i += tab->run;
730 if (i >= 64) 730 if (i >= 64)
731 break; // end of block 731 break; /* end of block */
732 732
733 normal_code: 733 normal_code:
734 j = scan[i]; 734 j = scan[i];
735 bit_buf <<= tab->len; 735 bit_buf <<= tab->len;
736 bits += tab->len + 1; 736 bits += tab->len + 1;
737 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4; 737 val = (tab->level * quantizer_scale * quant_matrix[j]) >> 4;
738 738
739 // oddification 739 /* oddification */
740 val = (val - 1) | 1; 740 val = (val - 1) | 1;
741 741
742 // if (bitstream_get (1)) val = -val; 742 /* if (bitstream_get (1)) val = -val; */
743 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); 743 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
744 744
745 SATURATE (val); 745 SATURATE (val);
746 dest[j] = val; 746 dest[j] = val;
747 747
756 756
757 i += tab->run; 757 i += tab->run;
758 if (i < 64) 758 if (i < 64)
759 goto normal_code; 759 goto normal_code;
760 760
761 // escape code 761 /* escape code */
762 762
763 i += UBITS (bit_buf << 6, 6) - 64; 763 i += UBITS (bit_buf << 6, 6) - 64;
764 if (i >= 64) 764 if (i >= 64)
765 break; // illegal, but check needed to avoid buffer overflow 765 break; /* illegal, check needed to avoid buffer overflow */
766 766
767 j = scan[i]; 767 j = scan[i];
768 768
769 DUMPBITS (bit_buf, bits, 12); 769 DUMPBITS (bit_buf, bits, 12);
770 NEEDBITS (bit_buf, bits, bit_ptr); 770 NEEDBITS (bit_buf, bits, bit_ptr);
773 DUMPBITS (bit_buf, bits, 8); 773 DUMPBITS (bit_buf, bits, 8);
774 val = UBITS (bit_buf, 8) + 2 * val; 774 val = UBITS (bit_buf, 8) + 2 * val;
775 } 775 }
776 val = (val * quantizer_scale * quant_matrix[j]) / 16; 776 val = (val * quantizer_scale * quant_matrix[j]) / 16;
777 777
778 // oddification 778 /* oddification */
779 val = (val + ~SBITS (val, 1)) | 1; 779 val = (val + ~SBITS (val, 1)) | 1;
780 780
781 SATURATE (val); 781 SATURATE (val);
782 dest[j] = val; 782 dest[j] = val;
783 783
807 GETWORD (bit_buf, bits + 16, bit_ptr); 807 GETWORD (bit_buf, bits + 16, bit_ptr);
808 i += tab->run; 808 i += tab->run;
809 if (i < 64) 809 if (i < 64)
810 goto normal_code; 810 goto normal_code;
811 } 811 }
812 break; // illegal, but check needed to avoid buffer overflow 812 break; /* illegal, check needed to avoid buffer overflow */
813 } 813 }
814 DUMPBITS (bit_buf, bits, 2); // dump end of block code 814 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
815 slice->bitstream_buf = bit_buf; 815 picture->bitstream_buf = bit_buf;
816 slice->bitstream_bits = bits; 816 picture->bitstream_bits = bits;
817 slice->bitstream_ptr = bit_ptr; 817 picture->bitstream_ptr = bit_ptr;
818 } 818 }
819 819
820 static void get_mpeg1_non_intra_block (picture_t * picture, slice_t * slice, 820 static void get_mpeg1_non_intra_block (picture_t * picture)
821 int16_t * dest)
822 { 821 {
823 int i; 822 int i;
824 int j; 823 int j;
825 int val; 824 int val;
826 uint8_t * scan = picture->scan; 825 uint8_t * scan = picture->scan;
827 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix; 826 uint8_t * quant_matrix = picture->non_intra_quantizer_matrix;
828 int quantizer_scale = slice->quantizer_scale; 827 int quantizer_scale = picture->quantizer_scale;
829 DCTtab * tab; 828 DCTtab * tab;
830 uint32_t bit_buf; 829 uint32_t bit_buf;
831 int bits; 830 int bits;
832 uint8_t * bit_ptr; 831 uint8_t * bit_ptr;
832 int16_t * dest;
833 833
834 i = -1; 834 i = -1;
835 835 dest = picture->DCTblock;
836 bit_buf = slice->bitstream_buf; 836
837 bits = slice->bitstream_bits; 837 bit_buf = picture->bitstream_buf;
838 bit_ptr = slice->bitstream_ptr; 838 bits = picture->bitstream_bits;
839 bit_ptr = picture->bitstream_ptr;
839 840
840 NEEDBITS (bit_buf, bits, bit_ptr); 841 NEEDBITS (bit_buf, bits, bit_ptr);
841 if (bit_buf >= 0x28000000) { 842 if (bit_buf >= 0x28000000) {
842 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5); 843 tab = DCT_B14DC_5 - 5 + UBITS (bit_buf, 5);
843 goto entry_1; 844 goto entry_1;
850 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5); 851 tab = DCT_B14AC_5 - 5 + UBITS (bit_buf, 5);
851 852
852 entry_1: 853 entry_1:
853 i += tab->run; 854 i += tab->run;
854 if (i >= 64) 855 if (i >= 64)
855 break; // end of block 856 break; /* end of block */
856 857
857 normal_code: 858 normal_code:
858 j = scan[i]; 859 j = scan[i];
859 bit_buf <<= tab->len; 860 bit_buf <<= tab->len;
860 bits += tab->len + 1; 861 bits += tab->len + 1;
861 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5; 862 val = ((2*tab->level+1) * quantizer_scale * quant_matrix[j]) >> 5;
862 863
863 // oddification 864 /* oddification */
864 val = (val - 1) | 1; 865 val = (val - 1) | 1;
865 866
866 // if (bitstream_get (1)) val = -val; 867 /* if (bitstream_get (1)) val = -val; */
867 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); 868 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1);
868 869
869 SATURATE (val); 870 SATURATE (val);
870 dest[j] = val; 871 dest[j] = val;
871 872
883 884
884 i += tab->run; 885 i += tab->run;
885 if (i < 64) 886 if (i < 64)
886 goto normal_code; 887 goto normal_code;
887 888
888 // escape code 889 /* escape code */
889 890
890 i += UBITS (bit_buf << 6, 6) - 64; 891 i += UBITS (bit_buf << 6, 6) - 64;
891 if (i >= 64) 892 if (i >= 64)
892 break; // illegal, but check needed to avoid buffer overflow 893 break; /* illegal, check needed to avoid buffer overflow */
893 894
894 j = scan[i]; 895 j = scan[i];
895 896
896 DUMPBITS (bit_buf, bits, 12); 897 DUMPBITS (bit_buf, bits, 12);
897 NEEDBITS (bit_buf, bits, bit_ptr); 898 NEEDBITS (bit_buf, bits, bit_ptr);
901 val = UBITS (bit_buf, 8) + 2 * val; 902 val = UBITS (bit_buf, 8) + 2 * val;
902 } 903 }
903 val = 2 * (val + SBITS (val, 1)) + 1; 904 val = 2 * (val + SBITS (val, 1)) + 1;
904 val = (val * quantizer_scale * quant_matrix[j]) / 32; 905 val = (val * quantizer_scale * quant_matrix[j]) / 32;
905 906
906 // oddification 907 /* oddification */
907 val = (val + ~SBITS (val, 1)) | 1; 908 val = (val + ~SBITS (val, 1)) | 1;
908 909
909 SATURATE (val); 910 SATURATE (val);
910 dest[j] = val; 911 dest[j] = val;
911 912
935 GETWORD (bit_buf, bits + 16, bit_ptr); 936 GETWORD (bit_buf, bits + 16, bit_ptr);
936 i += tab->run; 937 i += tab->run;
937 if (i < 64) 938 if (i < 64)
938 goto normal_code; 939 goto normal_code;
939 } 940 }
940 break; // illegal, but check needed to avoid buffer overflow 941 break; /* illegal, check needed to avoid buffer overflow */
941 } 942 }
942 DUMPBITS (bit_buf, bits, 2); // dump end of block code 943 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
943 slice->bitstream_buf = bit_buf; 944 picture->bitstream_buf = bit_buf;
944 slice->bitstream_bits = bits; 945 picture->bitstream_bits = bits;
945 slice->bitstream_ptr = bit_ptr; 946 picture->bitstream_ptr = bit_ptr;
946 } 947 }
947 948
948 static inline int get_macroblock_address_increment (slice_t * slice) 949 static inline int get_macroblock_address_increment (picture_t * picture)
949 { 950 {
950 #define bit_buf (slice->bitstream_buf) 951 #define bit_buf (picture->bitstream_buf)
951 #define bits (slice->bitstream_bits) 952 #define bits (picture->bitstream_bits)
952 #define bit_ptr (slice->bitstream_ptr) 953 #define bit_ptr (picture->bitstream_ptr)
953 954
954 MBAtab * tab; 955 MBAtab * tab;
955 int mba; 956 int mba;
956 957
957 mba = 0; 958 mba = 0;
964 } else if (bit_buf >= 0x03000000) { 965 } else if (bit_buf >= 0x03000000) {
965 tab = MBA_11 - 24 + UBITS (bit_buf, 11); 966 tab = MBA_11 - 24 + UBITS (bit_buf, 11);
966 DUMPBITS (bit_buf, bits, tab->len); 967 DUMPBITS (bit_buf, bits, tab->len);
967 return mba + tab->mba; 968 return mba + tab->mba;
968 } else switch (UBITS (bit_buf, 11)) { 969 } else switch (UBITS (bit_buf, 11)) {
969 case 8: // macroblock_escape 970 case 8: /* macroblock_escape */
970 mba += 33; 971 mba += 33;
971 // no break here on purpose 972 /* no break here on purpose */
972 case 15: // macroblock_stuffing (MPEG1 only) 973 case 15: /* macroblock_stuffing (MPEG1 only) */
973 DUMPBITS (bit_buf, bits, 11); 974 DUMPBITS (bit_buf, bits, 11);
974 NEEDBITS (bit_buf, bits, bit_ptr); 975 NEEDBITS (bit_buf, bits, bit_ptr);
975 break; 976 break;
976 default: // end of slice, or error 977 default: /* end of slice, or error */
977 return 0; 978 return 0;
978 } 979 }
979 } 980 }
980 981
981 #undef bit_buf 982 #undef bit_buf
982 #undef bits 983 #undef bits
983 #undef bit_ptr 984 #undef bit_ptr
984 } 985 }
985 986
986 static inline void slice_intra_DCT (picture_t * picture, slice_t * slice, 987 static inline void slice_intra_DCT (picture_t * picture, int cc,
987 int cc, uint8_t * dest, int stride) 988 uint8_t * dest, int stride)
988 { 989 {
989 #define bit_buf (slice->bitstream_buf) 990 #define bit_buf (picture->bitstream_buf)
990 #define bits (slice->bitstream_bits) 991 #define bits (picture->bitstream_bits)
991 #define bit_ptr (slice->bitstream_ptr) 992 #define bit_ptr (picture->bitstream_ptr)
992 NEEDBITS (bit_buf, bits, bit_ptr); 993 NEEDBITS (bit_buf, bits, bit_ptr);
993 //Get the intra DC coefficient and inverse quantize it 994 /* Get the intra DC coefficient and inverse quantize it */
994 if (cc == 0) 995 if (cc == 0)
995 slice->dc_dct_pred[0] += get_luma_dc_dct_diff (slice); 996 picture->dc_dct_pred[0] += get_luma_dc_dct_diff (picture);
996 else 997 else
997 slice->dc_dct_pred[cc] += get_chroma_dc_dct_diff (slice); 998 picture->dc_dct_pred[cc] += get_chroma_dc_dct_diff (picture);
998 DCTblock[0] = slice->dc_dct_pred[cc] << (3 - picture->intra_dc_precision); 999 picture->DCTblock[0] =
1000 picture->dc_dct_pred[cc] << (3 - picture->intra_dc_precision);
1001 memset (picture->DCTblock + 1, 0, 63 * sizeof (int16_t));
999 1002
1000 if (picture->mpeg1) { 1003 if (picture->mpeg1) {
1001 if (picture->picture_coding_type != D_TYPE) 1004 if (picture->picture_coding_type != D_TYPE)
1002 get_mpeg1_intra_block (picture, slice, DCTblock); 1005 get_mpeg1_intra_block (picture);
1003 } else if (picture->intra_vlc_format) 1006 } else if (picture->intra_vlc_format)
1004 get_intra_block_B15 (picture, slice, DCTblock); 1007 get_intra_block_B15 (picture);
1005 else 1008 else
1006 get_intra_block_B14 (picture, slice, DCTblock); 1009 get_intra_block_B14 (picture);
1007 idct_block_copy (DCTblock, dest, stride); 1010 idct_block_copy (picture->DCTblock, dest, stride);
1008 memset (DCTblock, 0, sizeof (DCTblock)); 1011 #undef bit_buf
1009 #undef bit_buf 1012 #undef bits
1010 #undef bits 1013 #undef bit_ptr
1011 #undef bit_ptr 1014 }
1012 } 1015
1013 1016 static inline void slice_non_intra_DCT (picture_t * picture, uint8_t * dest,
1014 static inline void slice_non_intra_DCT (picture_t * picture, slice_t * slice, 1017 int stride)
1015 uint8_t * dest, int stride) 1018 {
1016 { 1019 memset (picture->DCTblock, 0, 64 * sizeof (int16_t));
1017 if (picture->mpeg1) 1020 if (picture->mpeg1)
1018 get_mpeg1_non_intra_block (picture, slice, DCTblock); 1021 get_mpeg1_non_intra_block (picture);
1019 else 1022 else
1020 get_non_intra_block (picture, slice, DCTblock); 1023 get_non_intra_block (picture);
1021 idct_block_add (DCTblock, dest, stride); 1024 idct_block_add (picture->DCTblock, dest, stride);
1022 memset (DCTblock, 0, sizeof (DCTblock));
1023 } 1025 }
1024 1026
1025 static inline void motion_block (void (** table) (uint8_t *, uint8_t *, 1027 static inline void motion_block (void (** table) (uint8_t *, uint8_t *,
1026 int32_t, int32_t), 1028 int32_t, int32_t),
1027 int x_pred, int y_pred, 1029 int x_pred, int y_pred,
1056 table[4+xy_half] (dest[1] + dest_offset, src1, stride, height); 1058 table[4+xy_half] (dest[1] + dest_offset, src1, stride, height);
1057 table[4+xy_half] (dest[2] + dest_offset, src2, stride, height); 1059 table[4+xy_half] (dest[2] + dest_offset, src2, stride, height);
1058 } 1060 }
1059 1061
1060 1062
1061 static void motion_mp1 (slice_t * slice, motion_t * motion, 1063 static void motion_mp1 (picture_t * picture, motion_t * motion,
1062 uint8_t * dest[3], int offset, int width, 1064 uint8_t * dest[3], int offset, int stride,
1063 void (** table) (uint8_t *, uint8_t *, int, int)) 1065 void (** table) (uint8_t *, uint8_t *, int, int))
1064 { 1066 {
1065 #define bit_buf (slice->bitstream_buf) 1067 #define bit_buf (picture->bitstream_buf)
1066 #define bits (slice->bitstream_bits) 1068 #define bits (picture->bitstream_bits)
1067 #define bit_ptr (slice->bitstream_ptr) 1069 #define bit_ptr (picture->bitstream_ptr)
1068 int motion_x, motion_y; 1070 int motion_x, motion_y;
1069 1071
1070 NEEDBITS (bit_buf, bits, bit_ptr); 1072 NEEDBITS (bit_buf, bits, bit_ptr);
1071 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1073 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1074 motion->f_code[0]);
1072 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1075 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1073 motion->pmv[0][0] = motion_x; 1076 motion->pmv[0][0] = motion_x;
1074 1077
1075 NEEDBITS (bit_buf, bits, bit_ptr); 1078 NEEDBITS (bit_buf, bits, bit_ptr);
1076 motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[0]); 1079 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1080 motion->f_code[0]);
1077 motion_y = bound_motion_vector (motion_y, motion->f_code[0]); 1081 motion_y = bound_motion_vector (motion_y, motion->f_code[0]);
1078 motion->pmv[0][1] = motion_y; 1082 motion->pmv[0][1] = motion_y;
1079 1083
1080 if (motion->f_code[1]) { 1084 if (motion->f_code[1]) {
1081 motion_x <<= 1; 1085 motion_x <<= 1;
1082 motion_y <<= 1; 1086 motion_y <<= 1;
1083 } 1087 }
1084 1088
1085 motion_block (table, motion_x, motion_y, dest, offset, 1089 motion_block (table, motion_x, motion_y, dest, offset,
1086 motion->ref[0], offset, width, 16, 0); 1090 motion->ref[0], offset, stride, 16, 0);
1087 #undef bit_buf 1091 #undef bit_buf
1088 #undef bits 1092 #undef bits
1089 #undef bit_ptr 1093 #undef bit_ptr
1090 } 1094 }
1091 1095
1092 static void motion_mp1_reuse (slice_t * slice, motion_t * motion, 1096 static void motion_mp1_reuse (picture_t * picture, motion_t * motion,
1093 uint8_t * dest[3], int offset, int width, 1097 uint8_t * dest[3], int offset, int stride,
1094 void (** table) (uint8_t *, uint8_t *, int, int)) 1098 void (** table) (uint8_t *, uint8_t *, int, int))
1095 { 1099 {
1096 int motion_x, motion_y; 1100 int motion_x, motion_y;
1097 1101
1098 motion_x = motion->pmv[0][0]; 1102 motion_x = motion->pmv[0][0];
1102 motion_x <<= 1; 1106 motion_x <<= 1;
1103 motion_y <<= 1; 1107 motion_y <<= 1;
1104 } 1108 }
1105 1109
1106 motion_block (table, motion_x, motion_y, dest, offset, 1110 motion_block (table, motion_x, motion_y, dest, offset,
1107 motion->ref[0], offset, width, 16, 0); 1111 motion->ref[0], offset, stride, 16, 0);
1108 } 1112 }
1109 1113
1110 static void motion_fr_frame (slice_t * slice, motion_t * motion, 1114 static void motion_fr_frame (picture_t * picture, motion_t * motion,
1111 uint8_t * dest[3], int offset, int width, 1115 uint8_t * dest[3], int offset, int stride,
1112 void (** table) (uint8_t *, uint8_t *, int, int)) 1116 void (** table) (uint8_t *, uint8_t *, int, int))
1113 { 1117 {
1114 #define bit_buf (slice->bitstream_buf) 1118 #define bit_buf (picture->bitstream_buf)
1115 #define bits (slice->bitstream_bits) 1119 #define bits (picture->bitstream_bits)
1116 #define bit_ptr (slice->bitstream_ptr) 1120 #define bit_ptr (picture->bitstream_ptr)
1117 int motion_x, motion_y; 1121 int motion_x, motion_y;
1118 1122
1119 NEEDBITS (bit_buf, bits, bit_ptr); 1123 NEEDBITS (bit_buf, bits, bit_ptr);
1120 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1124 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1125 motion->f_code[0]);
1121 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1126 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1122 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; 1127 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
1123 1128
1124 NEEDBITS (bit_buf, bits, bit_ptr); 1129 NEEDBITS (bit_buf, bits, bit_ptr);
1125 motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1130 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1131 motion->f_code[1]);
1126 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1132 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1127 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1133 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1128 1134
1129 motion_block (table, motion_x, motion_y, dest, offset, 1135 motion_block (table, motion_x, motion_y, dest, offset,
1130 motion->ref[0], offset, width, 16, 0); 1136 motion->ref[0], offset, stride, 16, 0);
1131 #undef bit_buf 1137 #undef bit_buf
1132 #undef bits 1138 #undef bits
1133 #undef bit_ptr 1139 #undef bit_ptr
1134 } 1140 }
1135 1141
1136 static void motion_fr_field (slice_t * slice, motion_t * motion, 1142 static void motion_fr_field (picture_t * picture, motion_t * motion,
1137 uint8_t * dest[3], int offset, int width, 1143 uint8_t * dest[3], int offset, int stride,
1138 void (** table) (uint8_t *, uint8_t *, int, int)) 1144 void (** table) (uint8_t *, uint8_t *, int, int))
1139 { 1145 {
1140 #define bit_buf (slice->bitstream_buf) 1146 #define bit_buf (picture->bitstream_buf)
1141 #define bits (slice->bitstream_bits) 1147 #define bits (picture->bitstream_bits)
1142 #define bit_ptr (slice->bitstream_ptr) 1148 #define bit_ptr (picture->bitstream_ptr)
1143 int motion_x, motion_y; 1149 int motion_x, motion_y;
1144 int field_select; 1150 int field_select;
1145 1151
1146 NEEDBITS (bit_buf, bits, bit_ptr); 1152 NEEDBITS (bit_buf, bits, bit_ptr);
1147 field_select = SBITS (bit_buf, 1); 1153 field_select = SBITS (bit_buf, 1);
1148 DUMPBITS (bit_buf, bits, 1); 1154 DUMPBITS (bit_buf, bits, 1);
1149 1155
1150 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1156 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1157 motion->f_code[0]);
1151 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1158 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1152 motion->pmv[0][0] = motion_x; 1159 motion->pmv[0][0] = motion_x;
1153 1160
1154 NEEDBITS (bit_buf, bits, bit_ptr); 1161 NEEDBITS (bit_buf, bits, bit_ptr);
1155 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, 1162 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
1156 motion->f_code[1]); 1163 motion->f_code[1]);
1157 //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1164 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
1158 motion->pmv[0][1] = motion_y << 1; 1165 motion->pmv[0][1] = motion_y << 1;
1159 1166
1160 motion_block (table, motion_x, motion_y, dest, offset, 1167 motion_block (table, motion_x, motion_y, dest, offset,
1161 motion->ref[0], offset + (field_select & width), 1168 motion->ref[0], offset + (field_select & stride),
1162 width * 2, 8, 0); 1169 stride * 2, 8, 0);
1163 1170
1164 NEEDBITS (bit_buf, bits, bit_ptr); 1171 NEEDBITS (bit_buf, bits, bit_ptr);
1165 field_select = SBITS (bit_buf, 1); 1172 field_select = SBITS (bit_buf, 1);
1166 DUMPBITS (bit_buf, bits, 1); 1173 DUMPBITS (bit_buf, bits, 1);
1167 1174
1168 motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]); 1175 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
1176 motion->f_code[0]);
1169 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1177 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1170 motion->pmv[1][0] = motion_x; 1178 motion->pmv[1][0] = motion_x;
1171 1179
1172 NEEDBITS (bit_buf, bits, bit_ptr); 1180 NEEDBITS (bit_buf, bits, bit_ptr);
1173 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (slice, 1181 motion_y = (motion->pmv[1][1] >> 1) + get_motion_delta (picture,
1174 motion->f_code[1]); 1182 motion->f_code[1]);
1175 //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1183 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
1176 motion->pmv[1][1] = motion_y << 1; 1184 motion->pmv[1][1] = motion_y << 1;
1177 1185
1178 motion_block (table, motion_x, motion_y, dest, offset + width, 1186 motion_block (table, motion_x, motion_y, dest, offset + stride,
1179 motion->ref[0], offset + (field_select & width), 1187 motion->ref[0], offset + (field_select & stride),
1180 width * 2, 8, 0); 1188 stride * 2, 8, 0);
1181 #undef bit_buf 1189 #undef bit_buf
1182 #undef bits 1190 #undef bits
1183 #undef bit_ptr 1191 #undef bit_ptr
1184 } 1192 }
1185 1193
1186 static int motion_dmv_top_field_first; 1194 static void motion_fr_dmv (picture_t * picture, motion_t * motion,
1187 static void motion_fr_dmv (slice_t * slice, motion_t * motion, 1195 uint8_t * dest[3], int offset, int stride,
1188 uint8_t * dest[3], int offset, int width,
1189 void (** table) (uint8_t *, uint8_t *, int, int)) 1196 void (** table) (uint8_t *, uint8_t *, int, int))
1190 { 1197 {
1191 #define bit_buf (slice->bitstream_buf) 1198 #define bit_buf (picture->bitstream_buf)
1192 #define bits (slice->bitstream_bits) 1199 #define bits (picture->bitstream_bits)
1193 #define bit_ptr (slice->bitstream_ptr) 1200 #define bit_ptr (picture->bitstream_ptr)
1194 int motion_x, motion_y; 1201 int motion_x, motion_y;
1195 int dmv_x, dmv_y; 1202 int dmv_x, dmv_y;
1196 int m; 1203 int m;
1197 int other_x, other_y; 1204 int other_x, other_y;
1198 1205
1199 NEEDBITS (bit_buf, bits, bit_ptr); 1206 NEEDBITS (bit_buf, bits, bit_ptr);
1200 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1207 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1208 motion->f_code[0]);
1201 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1209 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1202 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; 1210 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
1203 1211
1204 NEEDBITS (bit_buf, bits, bit_ptr); 1212 NEEDBITS (bit_buf, bits, bit_ptr);
1205 dmv_x = get_dmv (slice); 1213 dmv_x = get_dmv (picture);
1206 1214
1207 NEEDBITS (bit_buf, bits, bit_ptr); 1215 NEEDBITS (bit_buf, bits, bit_ptr);
1208 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (slice, 1216 motion_y = (motion->pmv[0][1] >> 1) + get_motion_delta (picture,
1209 motion->f_code[1]); 1217 motion->f_code[1]);
1210 //motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1218 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */
1211 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; 1219 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1;
1212 1220
1213 NEEDBITS (bit_buf, bits, bit_ptr); 1221 NEEDBITS (bit_buf, bits, bit_ptr);
1214 dmv_y = get_dmv (slice); 1222 dmv_y = get_dmv (picture);
1215 1223
1216 motion_block (mc_functions.put, motion_x, motion_y, dest, offset, 1224 motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
1217 motion->ref[0], offset, width * 2, 8, 0); 1225 motion->ref[0], offset, stride * 2, 8, 0);
1218 1226
1219 m = motion_dmv_top_field_first ? 1 : 3; 1227 m = picture->top_field_first ? 1 : 3;
1220 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; 1228 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
1221 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; 1229 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1;
1222 motion_block (mc_functions.avg, other_x, other_y, dest, offset, 1230 motion_block (mc_functions.avg, other_x, other_y, dest, offset,
1223 motion->ref[0], offset + width, width * 2, 8, 0); 1231 motion->ref[0], offset + stride, stride * 2, 8, 0);
1224 1232
1225 motion_block (mc_functions.put, motion_x, motion_y, dest, offset + width, 1233 motion_block (mc_functions.put, motion_x, motion_y, dest, offset + stride,
1226 motion->ref[0], offset + width, width * 2, 8, 0); 1234 motion->ref[0], offset + stride, stride * 2, 8, 0);
1227 1235
1228 m = motion_dmv_top_field_first ? 3 : 1; 1236 m = picture->top_field_first ? 3 : 1;
1229 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; 1237 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x;
1230 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; 1238 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1;
1231 motion_block (mc_functions.avg, other_x, other_y, dest, offset + width, 1239 motion_block (mc_functions.avg, other_x, other_y, dest, offset + stride,
1232 motion->ref[0], offset, width * 2, 8, 0); 1240 motion->ref[0], offset, stride * 2, 8, 0);
1233 #undef bit_buf 1241 #undef bit_buf
1234 #undef bits 1242 #undef bits
1235 #undef bit_ptr 1243 #undef bit_ptr
1236 } 1244 }
1237 1245
1238 // like motion_frame, but reuse previous motion vectors 1246 /* like motion_frame, but reuse previous motion vectors */
1239 static void motion_fr_reuse (slice_t * slice, motion_t * motion, 1247 static void motion_fr_reuse (picture_t * picture, motion_t * motion,
1240 uint8_t * dest[3], int offset, int width, 1248 uint8_t * dest[3], int offset, int stride,
1241 void (** table) (uint8_t *, uint8_t *, int, int)) 1249 void (** table) (uint8_t *, uint8_t *, int, int))
1242 { 1250 {
1243 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, 1251 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
1244 motion->ref[0], offset, width, 16, 0); 1252 motion->ref[0], offset, stride, 16, 0);
1245 } 1253 }
1246 1254
1247 // like motion_frame, but use null motion vectors 1255 /* like motion_frame, but use null motion vectors */
1248 static void motion_fr_zero (slice_t * slice, motion_t * motion, 1256 static void motion_fr_zero (picture_t * picture, motion_t * motion,
1249 uint8_t * dest[3], int offset, int width, 1257 uint8_t * dest[3], int offset, int stride,
1250 void (** table) (uint8_t *, uint8_t *, int, int)) 1258 void (** table) (uint8_t *, uint8_t *, int, int))
1251 { 1259 {
1252 motion_block (table, 0, 0, dest, offset, 1260 motion_block (table, 0, 0, dest, offset,
1253 motion->ref[0], offset, width, 16, 0); 1261 motion->ref[0], offset, stride, 16, 0);
1254 } 1262 }
1255 1263
1256 // like motion_frame, but parsing without actual motion compensation 1264 /* like motion_frame, but parsing without actual motion compensation */
1257 static void motion_fr_conceal (slice_t * slice, motion_t * motion) 1265 static void motion_fr_conceal (picture_t * picture)
1258 { 1266 {
1259 #define bit_buf (slice->bitstream_buf) 1267 #define bit_buf (picture->bitstream_buf)
1260 #define bits (slice->bitstream_bits) 1268 #define bits (picture->bitstream_bits)
1261 #define bit_ptr (slice->bitstream_ptr) 1269 #define bit_ptr (picture->bitstream_ptr)
1262 int tmp; 1270 int tmp;
1263 1271
1264 NEEDBITS (bit_buf, bits, bit_ptr); 1272 NEEDBITS (bit_buf, bits, bit_ptr);
1265 tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1273 tmp = (picture->f_motion.pmv[0][0] +
1266 tmp = bound_motion_vector (tmp, motion->f_code[0]); 1274 get_motion_delta (picture, picture->f_motion.f_code[0]));
1267 motion->pmv[1][0] = motion->pmv[0][0] = tmp; 1275 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
1268 1276 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
1269 NEEDBITS (bit_buf, bits, bit_ptr); 1277
1270 tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1278 NEEDBITS (bit_buf, bits, bit_ptr);
1271 tmp = bound_motion_vector (tmp, motion->f_code[1]); 1279 tmp = (picture->f_motion.pmv[0][1] +
1272 motion->pmv[1][1] = motion->pmv[0][1] = tmp; 1280 get_motion_delta (picture, picture->f_motion.f_code[1]));
1273 1281 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
1274 DUMPBITS (bit_buf, bits, 1); // remove marker_bit 1282 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
1275 #undef bit_buf 1283
1276 #undef bits 1284 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
1277 #undef bit_ptr 1285 #undef bit_buf
1278 } 1286 #undef bits
1279 1287 #undef bit_ptr
1280 static void motion_fi_field (slice_t * slice, motion_t * motion, 1288 }
1281 uint8_t * dest[3], int offset, int width, 1289
1290 static void motion_fi_field (picture_t * picture, motion_t * motion,
1291 uint8_t * dest[3], int offset, int stride,
1282 void (** table) (uint8_t *, uint8_t *, int, int)) 1292 void (** table) (uint8_t *, uint8_t *, int, int))
1283 { 1293 {
1284 #define bit_buf (slice->bitstream_buf) 1294 #define bit_buf (picture->bitstream_buf)
1285 #define bits (slice->bitstream_bits) 1295 #define bits (picture->bitstream_bits)
1286 #define bit_ptr (slice->bitstream_ptr) 1296 #define bit_ptr (picture->bitstream_ptr)
1287 int motion_x, motion_y; 1297 int motion_x, motion_y;
1288 int field_select; 1298 int field_select;
1289 1299
1290 NEEDBITS (bit_buf, bits, bit_ptr); 1300 NEEDBITS (bit_buf, bits, bit_ptr);
1291 field_select = UBITS (bit_buf, 1); 1301 field_select = UBITS (bit_buf, 1);
1292 DUMPBITS (bit_buf, bits, 1); 1302 DUMPBITS (bit_buf, bits, 1);
1293 1303
1294 NEEDBITS (bit_buf, bits, bit_ptr); 1304 NEEDBITS (bit_buf, bits, bit_ptr);
1295 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1305 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1306 motion->f_code[0]);
1296 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1307 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1297 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; 1308 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
1298 1309
1299 NEEDBITS (bit_buf, bits, bit_ptr); 1310 NEEDBITS (bit_buf, bits, bit_ptr);
1300 motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1311 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1312 motion->f_code[1]);
1301 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1313 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1302 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1314 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1303 1315
1304 motion_block (table, motion_x, motion_y, dest, offset, 1316 motion_block (table, motion_x, motion_y, dest, offset,
1305 motion->ref[field_select], offset, width, 16, 0); 1317 motion->ref[field_select], offset, stride, 16, 0);
1306 #undef bit_buf 1318 #undef bit_buf
1307 #undef bits 1319 #undef bits
1308 #undef bit_ptr 1320 #undef bit_ptr
1309 } 1321 }
1310 1322
1311 static void motion_fi_16x8 (slice_t * slice, motion_t * motion, 1323 static void motion_fi_16x8 (picture_t * picture, motion_t * motion,
1312 uint8_t * dest[3], int offset, int width, 1324 uint8_t * dest[3], int offset, int stride,
1313 void (** table) (uint8_t *, uint8_t *, int, int)) 1325 void (** table) (uint8_t *, uint8_t *, int, int))
1314 { 1326 {
1315 #define bit_buf (slice->bitstream_buf) 1327 #define bit_buf (picture->bitstream_buf)
1316 #define bits (slice->bitstream_bits) 1328 #define bits (picture->bitstream_bits)
1317 #define bit_ptr (slice->bitstream_ptr) 1329 #define bit_ptr (picture->bitstream_ptr)
1318 int motion_x, motion_y; 1330 int motion_x, motion_y;
1319 int field_select; 1331 int field_select;
1320 1332
1321 NEEDBITS (bit_buf, bits, bit_ptr); 1333 NEEDBITS (bit_buf, bits, bit_ptr);
1322 field_select = UBITS (bit_buf, 1); 1334 field_select = UBITS (bit_buf, 1);
1323 DUMPBITS (bit_buf, bits, 1); 1335 DUMPBITS (bit_buf, bits, 1);
1324 1336
1325 NEEDBITS (bit_buf, bits, bit_ptr); 1337 NEEDBITS (bit_buf, bits, bit_ptr);
1326 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1338 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1339 motion->f_code[0]);
1327 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1340 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1328 motion->pmv[0][0] = motion_x; 1341 motion->pmv[0][0] = motion_x;
1329 1342
1330 NEEDBITS (bit_buf, bits, bit_ptr); 1343 NEEDBITS (bit_buf, bits, bit_ptr);
1331 motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1344 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1345 motion->f_code[1]);
1332 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1346 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1333 motion->pmv[0][1] = motion_y; 1347 motion->pmv[0][1] = motion_y;
1334 1348
1335 motion_block (table, motion_x, motion_y, dest, offset, 1349 motion_block (table, motion_x, motion_y, dest, offset,
1336 motion->ref[field_select], offset, width, 8, 0); 1350 motion->ref[field_select], offset, stride, 8, 0);
1337 1351
1338 NEEDBITS (bit_buf, bits, bit_ptr); 1352 NEEDBITS (bit_buf, bits, bit_ptr);
1339 field_select = UBITS (bit_buf, 1); 1353 field_select = UBITS (bit_buf, 1);
1340 DUMPBITS (bit_buf, bits, 1); 1354 DUMPBITS (bit_buf, bits, 1);
1341 1355
1342 NEEDBITS (bit_buf, bits, bit_ptr); 1356 NEEDBITS (bit_buf, bits, bit_ptr);
1343 motion_x = motion->pmv[1][0] + get_motion_delta (slice, motion->f_code[0]); 1357 motion_x = motion->pmv[1][0] + get_motion_delta (picture,
1358 motion->f_code[0]);
1344 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1359 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1345 motion->pmv[1][0] = motion_x; 1360 motion->pmv[1][0] = motion_x;
1346 1361
1347 NEEDBITS (bit_buf, bits, bit_ptr); 1362 NEEDBITS (bit_buf, bits, bit_ptr);
1348 motion_y = motion->pmv[1][1] + get_motion_delta (slice, motion->f_code[1]); 1363 motion_y = motion->pmv[1][1] + get_motion_delta (picture,
1364 motion->f_code[1]);
1349 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1365 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1350 motion->pmv[1][1] = motion_y; 1366 motion->pmv[1][1] = motion_y;
1351 1367
1352 motion_block (table, motion_x, motion_y, dest, offset, 1368 motion_block (table, motion_x, motion_y, dest, offset,
1353 motion->ref[field_select], offset, width, 8, 1); 1369 motion->ref[field_select], offset, stride, 8, 1);
1354 #undef bit_buf 1370 #undef bit_buf
1355 #undef bits 1371 #undef bits
1356 #undef bit_ptr 1372 #undef bit_ptr
1357 } 1373 }
1358 1374
1359 static int current_field = 0; 1375 static void motion_fi_dmv (picture_t * picture, motion_t * motion,
1360 static void motion_fi_dmv (slice_t * slice, motion_t * motion, 1376 uint8_t * dest[3], int offset, int stride,
1361 uint8_t * dest[3], int offset, int width,
1362 void (** table) (uint8_t *, uint8_t *, int, int)) 1377 void (** table) (uint8_t *, uint8_t *, int, int))
1363 { 1378 {
1364 #define bit_buf (slice->bitstream_buf) 1379 #define bit_buf (picture->bitstream_buf)
1365 #define bits (slice->bitstream_bits) 1380 #define bits (picture->bitstream_bits)
1366 #define bit_ptr (slice->bitstream_ptr) 1381 #define bit_ptr (picture->bitstream_ptr)
1367 int motion_x, motion_y; 1382 int motion_x, motion_y;
1368 int dmv_x, dmv_y; 1383 int dmv_x, dmv_y;
1369 1384
1370 NEEDBITS (bit_buf, bits, bit_ptr); 1385 NEEDBITS (bit_buf, bits, bit_ptr);
1371 motion_x = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1386 motion_x = motion->pmv[0][0] + get_motion_delta (picture,
1387 motion->f_code[0]);
1372 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); 1388 motion_x = bound_motion_vector (motion_x, motion->f_code[0]);
1373 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; 1389 motion->pmv[1][0] = motion->pmv[0][0] = motion_x;
1374 1390
1375 NEEDBITS (bit_buf, bits, bit_ptr); 1391 NEEDBITS (bit_buf, bits, bit_ptr);
1376 dmv_x = get_dmv (slice); 1392 dmv_x = get_dmv (picture);
1377 1393
1378 NEEDBITS (bit_buf, bits, bit_ptr); 1394 NEEDBITS (bit_buf, bits, bit_ptr);
1379 motion_y = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1395 motion_y = motion->pmv[0][1] + get_motion_delta (picture,
1396 motion->f_code[1]);
1380 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); 1397 motion_y = bound_motion_vector (motion_y, motion->f_code[1]);
1381 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; 1398 motion->pmv[1][1] = motion->pmv[0][1] = motion_y;
1382 1399
1383 NEEDBITS (bit_buf, bits, bit_ptr); 1400 NEEDBITS (bit_buf, bits, bit_ptr);
1384 dmv_y = get_dmv (slice); 1401 dmv_y = get_dmv (picture);
1385 1402
1386 motion_block (mc_functions.put, motion_x, motion_y, dest, offset, 1403 motion_block (mc_functions.put, motion_x, motion_y, dest, offset,
1387 motion->ref[current_field], offset, width, 16, 0); 1404 motion->ref[picture->current_field], offset, stride, 16, 0);
1388 1405
1389 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x; 1406 motion_x = ((motion_x + (motion_x > 0)) >> 1) + dmv_x;
1390 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y + 1407 motion_y = ((motion_y + (motion_y > 0)) >> 1) + dmv_y +
1391 2 * current_field - 1; 1408 2 * picture->current_field - 1;
1392 motion_block (mc_functions.avg, motion_x, motion_y, dest, offset, 1409 motion_block (mc_functions.avg, motion_x, motion_y, dest, offset,
1393 motion->ref[!current_field], offset, width, 16, 0); 1410 motion->ref[!picture->current_field], offset, stride, 16, 0);
1394 #undef bit_buf 1411 #undef bit_buf
1395 #undef bits 1412 #undef bits
1396 #undef bit_ptr 1413 #undef bit_ptr
1397 } 1414 }
1398 1415
1399 static void motion_fi_reuse (slice_t * slice, motion_t * motion, 1416 static void motion_fi_reuse (picture_t * picture, motion_t * motion,
1400 uint8_t * dest[3], int offset, int width, 1417 uint8_t * dest[3], int offset, int stride,
1401 void (** table) (uint8_t *, uint8_t *, int, int)) 1418 void (** table) (uint8_t *, uint8_t *, int, int))
1402 { 1419 {
1403 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset, 1420 motion_block (table, motion->pmv[0][0], motion->pmv[0][1], dest, offset,
1404 motion->ref[current_field], offset, width, 16, 0); 1421 motion->ref[picture->current_field], offset, stride, 16, 0);
1405 } 1422 }
1406 1423
1407 static void motion_fi_zero (slice_t * slice, motion_t * motion, 1424 static void motion_fi_zero (picture_t * picture, motion_t * motion,
1408 uint8_t * dest[3], int offset, int width, 1425 uint8_t * dest[3], int offset, int stride,
1409 void (** table) (uint8_t *, uint8_t *, int, int)) 1426 void (** table) (uint8_t *, uint8_t *, int, int))
1410 { 1427 {
1411 motion_block (table, 0, 0, dest, offset, 1428 motion_block (table, 0, 0, dest, offset,
1412 motion->ref[current_field], offset, width, 16, 0); 1429 motion->ref[picture->current_field], offset, stride, 16, 0);
1413 } 1430 }
1414 1431
1415 static void motion_fi_conceal (slice_t * slice, motion_t * motion) 1432 static void motion_fi_conceal (picture_t * picture)
1416 { 1433 {
1417 #define bit_buf (slice->bitstream_buf) 1434 #define bit_buf (picture->bitstream_buf)
1418 #define bits (slice->bitstream_bits) 1435 #define bits (picture->bitstream_bits)
1419 #define bit_ptr (slice->bitstream_ptr) 1436 #define bit_ptr (picture->bitstream_ptr)
1420 int tmp; 1437 int tmp;
1421 1438
1422 NEEDBITS (bit_buf, bits, bit_ptr); 1439 NEEDBITS (bit_buf, bits, bit_ptr);
1423 DUMPBITS (bit_buf, bits, 1); // remove field_select 1440 DUMPBITS (bit_buf, bits, 1); /* remove field_select */
1424 1441
1425 NEEDBITS (bit_buf, bits, bit_ptr); 1442 NEEDBITS (bit_buf, bits, bit_ptr);
1426 tmp = motion->pmv[0][0] + get_motion_delta (slice, motion->f_code[0]); 1443 tmp = (picture->f_motion.pmv[0][0] +
1427 tmp = bound_motion_vector (tmp, motion->f_code[0]); 1444 get_motion_delta (picture, picture->f_motion.f_code[0]));
1428 motion->pmv[1][0] = motion->pmv[0][0] = tmp; 1445 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[0]);
1429 1446 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[0][0] = tmp;
1430 NEEDBITS (bit_buf, bits, bit_ptr); 1447
1431 tmp = motion->pmv[0][1] + get_motion_delta (slice, motion->f_code[1]); 1448 NEEDBITS (bit_buf, bits, bit_ptr);
1432 tmp = bound_motion_vector (tmp, motion->f_code[1]); 1449 tmp = (picture->f_motion.pmv[0][1] +
1433 motion->pmv[1][1] = motion->pmv[0][1] = tmp; 1450 get_motion_delta (picture, picture->f_motion.f_code[1]));
1434 1451 tmp = bound_motion_vector (tmp, picture->f_motion.f_code[1]);
1435 DUMPBITS (bit_buf, bits, 1); // remove marker_bit 1452 picture->f_motion.pmv[1][1] = picture->f_motion.pmv[0][1] = tmp;
1436 #undef bit_buf 1453
1437 #undef bits 1454 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
1438 #undef bit_ptr 1455 #undef bit_buf
1439 } 1456 #undef bits
1440 1457 #undef bit_ptr
1441 #define MOTION(routine,direction,slice,dest,offset,stride) \ 1458 }
1459
1460 #define MOTION(routine,direction) \
1442 do { \ 1461 do { \
1443 if ((direction) & MACROBLOCK_MOTION_FORWARD) \ 1462 if ((direction) & MACROBLOCK_MOTION_FORWARD) \
1444 routine (&slice, &((slice).f_motion), dest, offset, stride, \ 1463 routine (picture, &(picture->f_motion), dest, offset, stride, \
1445 mc_functions.put); \ 1464 mc_functions.put); \
1446 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ 1465 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
1447 routine (&slice, &((slice).b_motion), dest, offset, stride, \ 1466 routine (picture, &(picture->b_motion), dest, offset, stride, \
1448 ((direction) & MACROBLOCK_MOTION_FORWARD ? \ 1467 ((direction) & MACROBLOCK_MOTION_FORWARD ? \
1449 mc_functions.avg : mc_functions.put)); \ 1468 mc_functions.avg : mc_functions.put)); \
1450 } while (0) 1469 } while (0)
1451 1470
1452 #define CHECK_DISPLAY \ 1471 #define CHECK_DISPLAY \
1453 do { \ 1472 do { \
1454 if (offset == width) { \ 1473 if (offset == picture->coded_picture_width) { \
1455 slice.f_motion.ref[0][0] += 16 * offset; \ 1474 picture->f_motion.ref[0][0] += 16 * stride; \
1456 slice.f_motion.ref[0][1] += 4 * offset; \ 1475 picture->f_motion.ref[0][1] += 4 * stride; \
1457 slice.f_motion.ref[0][2] += 4 * offset; \ 1476 picture->f_motion.ref[0][2] += 4 * stride; \
1458 slice.b_motion.ref[0][0] += 16 * offset; \ 1477 picture->b_motion.ref[0][0] += 16 * stride; \
1459 slice.b_motion.ref[0][1] += 4 * offset; \ 1478 picture->b_motion.ref[0][1] += 4 * stride; \
1460 slice.b_motion.ref[0][2] += 4 * offset; \ 1479 picture->b_motion.ref[0][2] += 4 * stride; \
1461 dest[0] += 16 * offset; \ 1480 do { /* just so we can use the break statement */ \
1462 dest[1] += 4 * offset; \ 1481 if (picture->current_frame->copy) { \
1463 dest[2] += 4 * offset; \ 1482 picture->current_frame->copy (picture->current_frame, \
1464 offset = 0; ++ypos; \ 1483 dest); \
1465 } \ 1484 if (picture->picture_coding_type == B_TYPE) \
1485 break; \
1486 } \
1487 dest[0] += 16 * stride; \
1488 dest[1] += 4 * stride; \
1489 dest[2] += 4 * stride; \
1490 } while (0); \
1491 offset = 0; \
1492 } \
1466 } while (0) 1493 } while (0)
1467 1494
1468 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer) 1495 int slice_process (picture_t * picture, uint8_t code, uint8_t * buffer)
1469 { 1496 {
1470 #define bit_buf (slice.bitstream_buf) 1497 #define bit_buf (picture->bitstream_buf)
1471 #define bits (slice.bitstream_bits) 1498 #define bits (picture->bitstream_bits)
1472 #define bit_ptr (slice.bitstream_ptr) 1499 #define bit_ptr (picture->bitstream_ptr)
1473 slice_t slice;
1474 int macroblock_modes; 1500 int macroblock_modes;
1475 int width; 1501 int stride;
1476 int ypos=code-1;
1477 uint8_t * dest[3]; 1502 uint8_t * dest[3];
1478 int offset; 1503 int offset;
1479 uint8_t ** forward_ref[2]; 1504 uint8_t ** forward_ref[2];
1480 1505
1481 width = picture->coded_picture_width; 1506 stride = picture->coded_picture_width;
1482 offset = ypos * width * 4; 1507 offset = (code - 1) * stride * 4;
1483 1508
1484 forward_ref[0] = picture->forward_reference_frame; 1509 forward_ref[0] = picture->forward_reference_frame->base;
1485 if (picture->picture_structure != FRAME_PICTURE) { 1510 if (picture->picture_structure != FRAME_PICTURE) {
1486 offset <<= 1; 1511 offset <<= 1;
1487 forward_ref[1] = picture->forward_reference_frame; 1512 forward_ref[1] = picture->forward_reference_frame->base;
1488 current_field = (picture->picture_structure == BOTTOM_FIELD); 1513 picture->current_field = (picture->picture_structure == BOTTOM_FIELD);
1489 if ((picture->second_field) && 1514 if ((picture->second_field) &&
1490 (picture->picture_coding_type != B_TYPE)) 1515 (picture->picture_coding_type != B_TYPE))
1491 forward_ref[picture->picture_structure == TOP_FIELD] = 1516 forward_ref[picture->picture_structure == TOP_FIELD] =
1492 picture->current_frame; 1517 picture->current_frame->base;
1493 slice.f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + width; 1518 picture->f_motion.ref[1][0] = forward_ref[1][0] + offset * 4 + stride;
1494 slice.f_motion.ref[1][1] = forward_ref[1][1] + offset + (width >> 1); 1519 picture->f_motion.ref[1][1] =
1495 slice.f_motion.ref[1][2] = forward_ref[1][2] + offset + (width >> 1); 1520 forward_ref[1][1] + offset + (stride >> 1);
1496 slice.b_motion.ref[1][0] = 1521 picture->f_motion.ref[1][2] =
1497 picture->backward_reference_frame[0] + offset * 4 + width; 1522 forward_ref[1][2] + offset + (stride >> 1);
1498 slice.b_motion.ref[1][1] = 1523 picture->b_motion.ref[1][0] =
1499 picture->backward_reference_frame[1] + offset + (width >> 1); 1524 picture->backward_reference_frame->base[0] + offset * 4 + stride;
1500 slice.b_motion.ref[1][2] = 1525 picture->b_motion.ref[1][1] =
1501 picture->backward_reference_frame[2] + offset + (width >> 1); 1526 (picture->backward_reference_frame->base[1] +
1527 offset + (stride >> 1));
1528 picture->b_motion.ref[1][2] =
1529 (picture->backward_reference_frame->base[2] +
1530 offset + (stride >> 1));
1502 } 1531 }
1503 1532
1504 slice.f_motion.ref[0][0] = forward_ref[0][0] + offset * 4; 1533 picture->f_motion.ref[0][0] = forward_ref[0][0] + offset * 4;
1505 slice.f_motion.ref[0][1] = forward_ref[0][1] + offset; 1534 picture->f_motion.ref[0][1] = forward_ref[0][1] + offset;
1506 slice.f_motion.ref[0][2] = forward_ref[0][2] + offset; 1535 picture->f_motion.ref[0][2] = forward_ref[0][2] + offset;
1507 slice.f_motion.f_code[0] = picture->f_code[0][0]; 1536 picture->f_motion.f_code[0] = picture->f_code[0][0];
1508 slice.f_motion.f_code[1] = picture->f_code[0][1]; 1537 picture->f_motion.f_code[1] = picture->f_code[0][1];
1509 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1538 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
1510 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1539 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
1511 slice.b_motion.ref[0][0] = 1540 picture->b_motion.ref[0][0] =
1512 picture->backward_reference_frame[0] + offset * 4; 1541 picture->backward_reference_frame->base[0] + offset * 4;
1513 slice.b_motion.ref[0][1] = 1542 picture->b_motion.ref[0][1] =
1514 picture->backward_reference_frame[1] + offset; 1543 picture->backward_reference_frame->base[1] + offset;
1515 slice.b_motion.ref[0][2] = 1544 picture->b_motion.ref[0][2] =
1516 picture->backward_reference_frame[2] + offset; 1545 picture->backward_reference_frame->base[2] + offset;
1517 slice.b_motion.f_code[0] = picture->f_code[1][0]; 1546 picture->b_motion.f_code[0] = picture->f_code[1][0];
1518 slice.b_motion.f_code[1] = picture->f_code[1][1]; 1547 picture->b_motion.f_code[1] = picture->f_code[1][1];
1519 slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0; 1548 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
1520 slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0; 1549 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
1521 1550
1522 if ((! HACK_MODE) && (!picture->mpeg1) && 1551 if ((picture->current_frame->copy) &&
1523 (picture->picture_coding_type == B_TYPE)) 1552 (picture->picture_coding_type == B_TYPE))
1524 offset = 0; 1553 offset = 0;
1525 1554
1526 dest[0] = picture->current_frame[0] + offset * 4; 1555 dest[0] = picture->current_frame->base[0] + offset * 4;
1527 dest[1] = picture->current_frame[1] + offset; 1556 dest[1] = picture->current_frame->base[1] + offset;
1528 dest[2] = picture->current_frame[2] + offset; 1557 dest[2] = picture->current_frame->base[2] + offset;
1529 1558
1530 switch (picture->picture_structure) { 1559 switch (picture->picture_structure) {
1531 case BOTTOM_FIELD: 1560 case BOTTOM_FIELD:
1532 dest[0] += width; 1561 dest[0] += stride;
1533 dest[1] += width >> 1; 1562 dest[1] += stride >> 1;
1534 dest[2] += width >> 1; 1563 dest[2] += stride >> 1;
1535 // follow thru 1564 /* follow thru */
1536 case TOP_FIELD: 1565 case TOP_FIELD:
1537 width <<= 1; 1566 stride <<= 1;
1538 } 1567 }
1539 1568
1540 //reset intra dc predictor 1569 /* reset intra dc predictor */
1541 slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= 1570 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
1542 1<< (picture->intra_dc_precision + 7) ; 1571 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision + 7);
1543 1572
1544 bitstream_init (&slice, buffer); 1573 bitstream_init (picture, buffer);
1545 1574
1546 slice.quantizer_scale = get_quantizer_scale (&slice, 1575 picture->quantizer_scale = get_quantizer_scale (picture);
1547 picture->q_scale_type); 1576
1548 1577 /* ignore intra_slice and all the extra data */
1549 //Ignore intra_slice and all the extra data
1550 while (bit_buf & 0x80000000) { 1578 while (bit_buf & 0x80000000) {
1551 DUMPBITS (bit_buf, bits, 9); 1579 DUMPBITS (bit_buf, bits, 9);
1552 NEEDBITS (bit_buf, bits, bit_ptr); 1580 NEEDBITS (bit_buf, bits, bit_ptr);
1553 } 1581 }
1554 DUMPBITS (bit_buf, bits, 1); 1582 DUMPBITS (bit_buf, bits, 1);
1555 1583
1556 NEEDBITS (bit_buf, bits, bit_ptr); 1584 NEEDBITS (bit_buf, bits, bit_ptr);
1557 offset = get_macroblock_address_increment (&slice) << 4; 1585 offset = get_macroblock_address_increment (picture) << 4;
1558 1586
1559 while (1) { 1587 while (1) {
1560 NEEDBITS (bit_buf, bits, bit_ptr); 1588 NEEDBITS (bit_buf, bits, bit_ptr);
1561 1589
1562 macroblock_modes = 1590 macroblock_modes = get_macroblock_modes (picture);
1563 get_macroblock_modes (&slice, picture->picture_structure, 1591
1564 picture->picture_coding_type, 1592 /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */
1565 picture->frame_pred_frame_dct);
1566
1567 // maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ?
1568 if (macroblock_modes & MACROBLOCK_QUANT) 1593 if (macroblock_modes & MACROBLOCK_QUANT)
1569 slice.quantizer_scale = 1594 picture->quantizer_scale = get_quantizer_scale (picture);
1570 get_quantizer_scale (&slice, picture->q_scale_type);
1571 1595
1572 if (macroblock_modes & MACROBLOCK_INTRA) { 1596 if (macroblock_modes & MACROBLOCK_INTRA) {
1573 1597
1574 int DCT_offset, DCT_stride; 1598 int DCT_offset, DCT_stride;
1575 1599
1576 if (picture->concealment_motion_vectors) { 1600 if (picture->concealment_motion_vectors) {
1577 if (picture->picture_structure == FRAME_PICTURE) 1601 if (picture->picture_structure == FRAME_PICTURE)
1578 motion_fr_conceal (&slice, &slice.f_motion); 1602 motion_fr_conceal (picture);
1579 else 1603 else
1580 motion_fi_conceal (&slice, &slice.f_motion); 1604 motion_fi_conceal (picture);
1581 } else { 1605 } else {
1582 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1606 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
1583 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1607 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
1584 slice.b_motion.pmv[0][0] = slice.b_motion.pmv[0][1] = 0; 1608 picture->b_motion.pmv[0][0] = picture->b_motion.pmv[0][1] = 0;
1585 slice.b_motion.pmv[1][0] = slice.b_motion.pmv[1][1] = 0; 1609 picture->b_motion.pmv[1][0] = picture->b_motion.pmv[1][1] = 0;
1586 } 1610 }
1587 1611
1588 if (macroblock_modes & DCT_TYPE_INTERLACED) { 1612 if (macroblock_modes & DCT_TYPE_INTERLACED) {
1589 DCT_offset = width; 1613 DCT_offset = stride;
1590 DCT_stride = width * 2; 1614 DCT_stride = stride * 2;
1591 } else { 1615 } else {
1592 DCT_offset = width * 8; 1616 DCT_offset = stride * 8;
1593 DCT_stride = width; 1617 DCT_stride = stride;
1594 } 1618 }
1595 1619
1596 // Decode lum blocks 1620 /* Decode lum blocks */
1597 slice_intra_DCT (picture, &slice, 0, 1621 slice_intra_DCT (picture, 0, dest[0] + offset, DCT_stride);
1598 dest[0] + offset, DCT_stride); 1622 slice_intra_DCT (picture, 0, dest[0] + offset + 8, DCT_stride);
1599 slice_intra_DCT (picture, &slice, 0, 1623 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset,
1600 dest[0] + offset + 8, DCT_stride); 1624 DCT_stride);
1601 slice_intra_DCT (picture, &slice, 0, 1625 slice_intra_DCT (picture, 0, dest[0] + offset + DCT_offset + 8,
1602 dest[0] + offset + DCT_offset, DCT_stride); 1626 DCT_stride);
1603 slice_intra_DCT (picture, &slice, 0, 1627
1604 dest[0] + offset + DCT_offset + 8, DCT_stride); 1628 /* Decode chroma blocks */
1605 1629 slice_intra_DCT (picture, 1, dest[1] + (offset >> 1), stride >> 1);
1606 // Decode chroma blocks 1630 slice_intra_DCT (picture, 2, dest[2] + (offset >> 1), stride >> 1);
1607 slice_intra_DCT (picture, &slice, 1,
1608 dest[1] + (offset>>1), width>>1);
1609 slice_intra_DCT (picture, &slice, 2,
1610 dest[2] + (offset>>1), width>>1);
1611 1631
1612 if (picture->picture_coding_type == D_TYPE) { 1632 if (picture->picture_coding_type == D_TYPE) {
1613 NEEDBITS (bit_buf, bits, bit_ptr); 1633 NEEDBITS (bit_buf, bits, bit_ptr);
1614 DUMPBITS (bit_buf, bits, 1); 1634 DUMPBITS (bit_buf, bits, 1);
1615 } 1635 }
1616 } else { 1636 } else {
1617 1637
1618 if (picture->mpeg1) { 1638 if (picture->mpeg1) {
1619 if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME) 1639 if ((macroblock_modes & MOTION_TYPE_MASK) == MC_FRAME)
1620 MOTION (motion_mp1, macroblock_modes, slice, 1640 MOTION (motion_mp1, macroblock_modes);
1621 dest, offset,width);
1622 else { 1641 else {
1623 // non-intra mb without forward mv in a P picture 1642 /* non-intra mb without forward mv in a P picture */
1624 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1643 picture->f_motion.pmv[0][0] = 0;
1625 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1644 picture->f_motion.pmv[0][1] = 0;
1626 1645 picture->f_motion.pmv[1][0] = 0;
1627 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice, 1646 picture->f_motion.pmv[1][1] = 0;
1628 dest, offset, width); 1647 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
1629 } 1648 }
1630 } else if (picture->picture_structure == FRAME_PICTURE) 1649 } else if (picture->picture_structure == FRAME_PICTURE)
1631 switch (macroblock_modes & MOTION_TYPE_MASK) { 1650 switch (macroblock_modes & MOTION_TYPE_MASK) {
1632 case MC_FRAME: 1651 case MC_FRAME:
1633 MOTION (motion_fr_frame, macroblock_modes, slice, 1652 MOTION (motion_fr_frame, macroblock_modes);
1634 dest, offset, width);
1635 break; 1653 break;
1636 1654
1637 case MC_FIELD: 1655 case MC_FIELD:
1638 MOTION (motion_fr_field, macroblock_modes, slice, 1656 MOTION (motion_fr_field, macroblock_modes);
1639 dest, offset, width);
1640 break; 1657 break;
1641 1658
1642 case MC_DMV: 1659 case MC_DMV:
1643 motion_dmv_top_field_first = picture->top_field_first; 1660 MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD);
1644 MOTION (motion_fr_dmv, MACROBLOCK_MOTION_FORWARD, slice,
1645 dest, offset, width);
1646 break; 1661 break;
1647 1662
1648 case 0: 1663 case 0:
1649 // non-intra mb without forward mv in a P picture 1664 /* non-intra mb without forward mv in a P picture */
1650 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1665 picture->f_motion.pmv[0][0] = 0;
1651 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1666 picture->f_motion.pmv[0][1] = 0;
1652 1667 picture->f_motion.pmv[1][0] = 0;
1653 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, slice, 1668 picture->f_motion.pmv[1][1] = 0;
1654 dest, offset, width); 1669 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
1655 break; 1670 break;
1656 } 1671 }
1657 else 1672 else
1658 switch (macroblock_modes & MOTION_TYPE_MASK) { 1673 switch (macroblock_modes & MOTION_TYPE_MASK) {
1659 case MC_FIELD: 1674 case MC_FIELD:
1660 MOTION (motion_fi_field, macroblock_modes, slice, 1675 MOTION (motion_fi_field, macroblock_modes);
1661 dest, offset, width);
1662 break; 1676 break;
1663 1677
1664 case MC_16X8: 1678 case MC_16X8:
1665 MOTION (motion_fi_16x8, macroblock_modes, slice, 1679 MOTION (motion_fi_16x8, macroblock_modes);
1666 dest, offset, width);
1667 break; 1680 break;
1668 1681
1669 case MC_DMV: 1682 case MC_DMV:
1670 motion_dmv_top_field_first = picture->top_field_first; 1683 MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD);
1671 MOTION (motion_fi_dmv, MACROBLOCK_MOTION_FORWARD, slice,
1672 dest, offset, width);
1673 break; 1684 break;
1674 1685
1675 case 0: 1686 case 0:
1676 // non-intra mb without forward mv in a P picture 1687 /* non-intra mb without forward mv in a P picture */
1677 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1688 picture->f_motion.pmv[0][0] = 0;
1678 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1689 picture->f_motion.pmv[0][1] = 0;
1679 1690 picture->f_motion.pmv[1][0] = 0;
1680 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD, slice, 1691 picture->f_motion.pmv[1][1] = 0;
1681 dest, offset, width); 1692 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
1682 break; 1693 break;
1683 } 1694 }
1684 1695
1685 //6.3.17.4 Coded block pattern 1696 /* 6.3.17.4 Coded block pattern */
1686 if (macroblock_modes & MACROBLOCK_PATTERN) { 1697 if (macroblock_modes & MACROBLOCK_PATTERN) {
1687 int coded_block_pattern; 1698 int coded_block_pattern;
1688 int DCT_offset, DCT_stride; 1699 int DCT_offset, DCT_stride;
1689 1700
1690 if (macroblock_modes & DCT_TYPE_INTERLACED) { 1701 if (macroblock_modes & DCT_TYPE_INTERLACED) {
1691 DCT_offset = width; 1702 DCT_offset = stride;
1692 DCT_stride = width * 2; 1703 DCT_stride = stride * 2;
1693 } else { 1704 } else {
1694 DCT_offset = width * 8; 1705 DCT_offset = stride * 8;
1695 DCT_stride = width; 1706 DCT_stride = stride;
1696 } 1707 }
1697 1708
1698 coded_block_pattern = get_coded_block_pattern (&slice); 1709 coded_block_pattern = get_coded_block_pattern (picture);
1699 1710
1700 // Decode lum blocks 1711 /* Decode lum blocks */
1701 1712
1702 if (coded_block_pattern & 0x20) 1713 if (coded_block_pattern & 0x20)
1703 slice_non_intra_DCT (picture, &slice, 1714 slice_non_intra_DCT (picture, dest[0] + offset,
1704 dest[0] + offset, DCT_stride); 1715 DCT_stride);
1705 if (coded_block_pattern & 0x10) 1716 if (coded_block_pattern & 0x10)
1706 slice_non_intra_DCT (picture, &slice, 1717 slice_non_intra_DCT (picture, dest[0] + offset + 8,
1707 dest[0] + offset + 8, DCT_stride); 1718 DCT_stride);
1708 if (coded_block_pattern & 0x08) 1719 if (coded_block_pattern & 0x08)
1709 slice_non_intra_DCT (picture, &slice, 1720 slice_non_intra_DCT (picture,
1710 dest[0] + offset + DCT_offset, 1721 dest[0] + offset + DCT_offset,
1711 DCT_stride); 1722 DCT_stride);
1712 if (coded_block_pattern & 0x04) 1723 if (coded_block_pattern & 0x04)
1713 slice_non_intra_DCT (picture, &slice, 1724 slice_non_intra_DCT (picture,
1714 dest[0] + offset + DCT_offset + 8, 1725 dest[0] + offset + DCT_offset + 8,
1715 DCT_stride); 1726 DCT_stride);
1716 1727
1717 // Decode chroma blocks 1728 /* Decode chroma blocks */
1718 1729
1719 if (coded_block_pattern & 0x2) 1730 if (coded_block_pattern & 0x2)
1720 slice_non_intra_DCT (picture, &slice, 1731 slice_non_intra_DCT (picture, dest[1] + (offset >> 1),
1721 dest[1] + (offset>>1), width >> 1); 1732 stride >> 1);
1722 if (coded_block_pattern & 0x1) 1733 if (coded_block_pattern & 0x1)
1723 slice_non_intra_DCT (picture, &slice, 1734 slice_non_intra_DCT (picture, dest[2] + (offset >> 1),
1724 dest[2] + (offset>>1), width >> 1); 1735 stride >> 1);
1725 } 1736 }
1726 1737
1727 slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= 1738 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
1728 1 << (picture->intra_dc_precision + 7); 1739 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
1729 } 1740 }
1730
1731 // printf("[%d]",slice.quantizer_scale);
1732 // printf("[%d,%d]",offset>>4,ypos);
1733 quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
1734 1741
1735 offset += 16; 1742 offset += 16;
1736 CHECK_DISPLAY; 1743 CHECK_DISPLAY;
1737 1744
1738 NEEDBITS (bit_buf, bits, bit_ptr); 1745 NEEDBITS (bit_buf, bits, bit_ptr);
1740 if (bit_buf & 0x80000000) { 1747 if (bit_buf & 0x80000000) {
1741 DUMPBITS (bit_buf, bits, 1); 1748 DUMPBITS (bit_buf, bits, 1);
1742 } else { 1749 } else {
1743 int mba_inc; 1750 int mba_inc;
1744 1751
1745 mba_inc = get_macroblock_address_increment (&slice); 1752 mba_inc = get_macroblock_address_increment (picture);
1746 if (!mba_inc) 1753 if (!mba_inc)
1747 break; 1754 break;
1748 1755
1749 //reset intra dc predictor on skipped block 1756 /* reset intra dc predictor on skipped block */
1750 slice.dc_dct_pred[0]=slice.dc_dct_pred[1]=slice.dc_dct_pred[2]= 1757 picture->dc_dct_pred[0] = picture->dc_dct_pred[1] =
1751 1<< (picture->intra_dc_precision + 7); 1758 picture->dc_dct_pred[2] = 1 << (picture->intra_dc_precision+7);
1752 1759
1753 //handling of skipped mb's differs between P_TYPE and B_TYPE 1760 /* handling of skipped mb's differs between P_TYPE and B_TYPE */
1754 //pictures 1761 /* pictures */
1755 if (picture->picture_coding_type == P_TYPE) { 1762 if (picture->picture_coding_type == P_TYPE) {
1756 slice.f_motion.pmv[0][0] = slice.f_motion.pmv[0][1] = 0; 1763 picture->f_motion.pmv[0][0] = picture->f_motion.pmv[0][1] = 0;
1757 slice.f_motion.pmv[1][0] = slice.f_motion.pmv[1][1] = 0; 1764 picture->f_motion.pmv[1][0] = picture->f_motion.pmv[1][1] = 0;
1758 1765
1759 do { 1766 do {
1760 if (picture->picture_structure == FRAME_PICTURE) 1767 if (picture->picture_structure == FRAME_PICTURE)
1761 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD, 1768 MOTION (motion_fr_zero, MACROBLOCK_MOTION_FORWARD);
1762 slice, dest, offset, width);
1763 else 1769 else
1764 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD, 1770 MOTION (motion_fi_zero, MACROBLOCK_MOTION_FORWARD);
1765 slice, dest, offset, width); 1771
1766
1767 quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
1768 // printf("[%d,%d]",offset>>4,ypos);
1769 offset += 16; 1772 offset += 16;
1770 CHECK_DISPLAY; 1773 CHECK_DISPLAY;
1771 } while (--mba_inc); 1774 } while (--mba_inc);
1772 } else { 1775 } else {
1773 do { 1776 do {
1774 if (picture->mpeg1) 1777 if (picture->mpeg1)
1775 MOTION (motion_mp1_reuse, macroblock_modes, 1778 MOTION (motion_mp1_reuse, macroblock_modes);
1776 slice, dest, offset, width);
1777 else if (picture->picture_structure == FRAME_PICTURE) 1779 else if (picture->picture_structure == FRAME_PICTURE)
1778 MOTION (motion_fr_reuse, macroblock_modes, 1780 MOTION (motion_fr_reuse, macroblock_modes);
1779 slice, dest, offset, width);
1780 else 1781 else
1781 MOTION (motion_fi_reuse, macroblock_modes, 1782 MOTION (motion_fi_reuse, macroblock_modes);
1782 slice, dest, offset, width); 1783
1783
1784 quant_store[ypos+1][(offset>>4)+1] = slice.quantizer_scale;
1785 // printf("[%d,%d]",offset>>4,ypos);
1786 offset += 16; 1784 offset += 16;
1787 CHECK_DISPLAY; 1785 CHECK_DISPLAY;
1788 } while (--mba_inc); 1786 } while (--mba_inc);
1789 } 1787 }
1790 } 1788 }