Mercurial > mplayer.hg
annotate libmpeg2/slice.c @ 12973:093afb92e4d5
LIVE.COM autodetection
author | wight |
---|---|
date | Mon, 09 Aug 2004 08:21:42 +0000 |
parents | cda4ad0d3e70 |
children | 34df725814e8 |
rev | line source |
---|---|
1 | 1 /* |
2 * slice.c | |
12932 | 3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> |
4 * Copyright (C) 2003 Peter Gubanov <peter@elecard.net.ru> | |
9852 | 5 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> |
1 | 6 * |
7 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. | |
9852 | 8 * See http://libmpeg2.sourceforge.net/ for updates. |
1 | 9 * |
10 * mpeg2dec is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * mpeg2dec is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 | |
25 #include "config.h" | |
26 | |
27 #include <inttypes.h> | |
28 | |
9852 | 29 #include "mpeg2.h" |
12932 | 30 #include "attributes.h" |
1 | 31 #include "mpeg2_internal.h" |
32 | |
9852 | 33 extern mpeg2_mc_t mpeg2_mc; |
34 extern void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride); | |
35 extern void (* mpeg2_idct_add) (int last, int16_t * block, | |
36 uint8_t * dest, int stride); | |
37 extern void (* mpeg2_cpu_state_save) (cpu_state_t * state); | |
38 extern void (* mpeg2_cpu_state_restore) (cpu_state_t * state); | |
2756
b4d0cc1fd14b
workaround for MBC/MBR difference (wrong libavcodec-mplayer version pair)
arpi
parents:
142
diff
changeset
|
39 |
1 | 40 #include "vlc.h" |
41 | |
12932 | 42 static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) |
1 | 43 { |
9852 | 44 #define bit_buf (decoder->bitstream_buf) |
45 #define bits (decoder->bitstream_bits) | |
46 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 47 int macroblock_modes; |
9852 | 48 const MBtab * tab; |
1 | 49 |
9852 | 50 switch (decoder->coding_type) { |
1 | 51 case I_TYPE: |
52 | |
53 tab = MB_I + UBITS (bit_buf, 1); | |
54 DUMPBITS (bit_buf, bits, tab->len); | |
55 macroblock_modes = tab->modes; | |
56 | |
9852 | 57 if ((! (decoder->frame_pred_frame_dct)) && |
58 (decoder->picture_structure == FRAME_PICTURE)) { | |
1 | 59 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; |
60 DUMPBITS (bit_buf, bits, 1); | |
61 } | |
62 | |
63 return macroblock_modes; | |
64 | |
65 case P_TYPE: | |
66 | |
67 tab = MB_P + UBITS (bit_buf, 5); | |
68 DUMPBITS (bit_buf, bits, tab->len); | |
69 macroblock_modes = tab->modes; | |
70 | |
9852 | 71 if (decoder->picture_structure != FRAME_PICTURE) { |
1 | 72 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { |
12932 | 73 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
1 | 74 DUMPBITS (bit_buf, bits, 2); |
75 } | |
12932 | 76 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; |
9852 | 77 } else if (decoder->frame_pred_frame_dct) { |
1 | 78 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) |
12932 | 79 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; |
80 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | |
1 | 81 } else { |
82 if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { | |
12932 | 83 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
1 | 84 DUMPBITS (bit_buf, bits, 2); |
85 } | |
86 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { | |
87 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | |
88 DUMPBITS (bit_buf, bits, 1); | |
89 } | |
12932 | 90 return macroblock_modes | MACROBLOCK_MOTION_FORWARD; |
1 | 91 } |
92 | |
93 case B_TYPE: | |
94 | |
95 tab = MB_B + UBITS (bit_buf, 6); | |
96 DUMPBITS (bit_buf, bits, tab->len); | |
97 macroblock_modes = tab->modes; | |
98 | |
9852 | 99 if (decoder->picture_structure != FRAME_PICTURE) { |
1 | 100 if (! (macroblock_modes & MACROBLOCK_INTRA)) { |
12932 | 101 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
1 | 102 DUMPBITS (bit_buf, bits, 2); |
103 } | |
104 return macroblock_modes; | |
9852 | 105 } else if (decoder->frame_pred_frame_dct) { |
36 | 106 /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ |
12932 | 107 macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; |
1 | 108 return macroblock_modes; |
109 } else { | |
110 if (macroblock_modes & MACROBLOCK_INTRA) | |
111 goto intra; | |
12932 | 112 macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
1 | 113 DUMPBITS (bit_buf, bits, 2); |
114 if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { | |
115 intra: | |
116 macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | |
117 DUMPBITS (bit_buf, bits, 1); | |
118 } | |
119 return macroblock_modes; | |
120 } | |
121 | |
122 case D_TYPE: | |
123 | |
124 DUMPBITS (bit_buf, bits, 1); | |
125 return MACROBLOCK_INTRA; | |
126 | |
127 default: | |
128 return 0; | |
129 } | |
130 #undef bit_buf | |
131 #undef bits | |
132 #undef bit_ptr | |
133 } | |
134 | |
12932 | 135 static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder) |
1 | 136 { |
9852 | 137 #define bit_buf (decoder->bitstream_buf) |
138 #define bits (decoder->bitstream_bits) | |
139 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 140 |
141 int quantizer_scale_code; | |
142 | |
143 quantizer_scale_code = UBITS (bit_buf, 5); | |
144 DUMPBITS (bit_buf, bits, 5); | |
145 | |
12932 | 146 decoder->quantizer_matrix[0] = |
147 decoder->quantizer_prescale[0][quantizer_scale_code]; | |
148 decoder->quantizer_matrix[1] = | |
149 decoder->quantizer_prescale[1][quantizer_scale_code]; | |
150 decoder->quantizer_matrix[2] = | |
151 decoder->chroma_quantizer[0][quantizer_scale_code]; | |
152 decoder->quantizer_matrix[3] = | |
153 decoder->chroma_quantizer[1][quantizer_scale_code]; | |
1 | 154 #undef bit_buf |
155 #undef bits | |
156 #undef bit_ptr | |
157 } | |
158 | |
12932 | 159 static inline int get_motion_delta (mpeg2_decoder_t * const decoder, |
9852 | 160 const int f_code) |
1 | 161 { |
9852 | 162 #define bit_buf (decoder->bitstream_buf) |
163 #define bits (decoder->bitstream_bits) | |
164 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 165 |
166 int delta; | |
167 int sign; | |
9852 | 168 const MVtab * tab; |
1 | 169 |
170 if (bit_buf & 0x80000000) { | |
171 DUMPBITS (bit_buf, bits, 1); | |
172 return 0; | |
173 } else if (bit_buf >= 0x0c000000) { | |
174 | |
175 tab = MV_4 + UBITS (bit_buf, 4); | |
176 delta = (tab->delta << f_code) + 1; | |
177 bits += tab->len + f_code + 1; | |
178 bit_buf <<= tab->len; | |
179 | |
180 sign = SBITS (bit_buf, 1); | |
181 bit_buf <<= 1; | |
182 | |
183 if (f_code) | |
184 delta += UBITS (bit_buf, f_code); | |
185 bit_buf <<= f_code; | |
186 | |
187 return (delta ^ sign) - sign; | |
188 | |
189 } else { | |
190 | |
191 tab = MV_10 + UBITS (bit_buf, 10); | |
192 delta = (tab->delta << f_code) + 1; | |
193 bits += tab->len + 1; | |
194 bit_buf <<= tab->len; | |
195 | |
196 sign = SBITS (bit_buf, 1); | |
197 bit_buf <<= 1; | |
198 | |
199 if (f_code) { | |
200 NEEDBITS (bit_buf, bits, bit_ptr); | |
201 delta += UBITS (bit_buf, f_code); | |
202 DUMPBITS (bit_buf, bits, f_code); | |
203 } | |
204 | |
205 return (delta ^ sign) - sign; | |
206 | |
207 } | |
208 #undef bit_buf | |
209 #undef bits | |
210 #undef bit_ptr | |
211 } | |
212 | |
9852 | 213 static inline int bound_motion_vector (const int vector, const int f_code) |
1 | 214 { |
9852 | 215 return ((int32_t)vector << (27 - f_code)) >> (27 - f_code); |
1 | 216 } |
217 | |
12932 | 218 static inline int get_dmv (mpeg2_decoder_t * const decoder) |
1 | 219 { |
9852 | 220 #define bit_buf (decoder->bitstream_buf) |
221 #define bits (decoder->bitstream_bits) | |
222 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 223 |
9852 | 224 const DMVtab * tab; |
1 | 225 |
226 tab = DMV_2 + UBITS (bit_buf, 2); | |
227 DUMPBITS (bit_buf, bits, tab->len); | |
228 return tab->dmv; | |
229 #undef bit_buf | |
230 #undef bits | |
231 #undef bit_ptr | |
232 } | |
233 | |
12932 | 234 static inline int get_coded_block_pattern (mpeg2_decoder_t * const decoder) |
1 | 235 { |
9852 | 236 #define bit_buf (decoder->bitstream_buf) |
237 #define bits (decoder->bitstream_bits) | |
238 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 239 |
9852 | 240 const CBPtab * tab; |
1 | 241 |
242 NEEDBITS (bit_buf, bits, bit_ptr); | |
243 | |
244 if (bit_buf >= 0x20000000) { | |
245 | |
9852 | 246 tab = CBP_7 + (UBITS (bit_buf, 7) - 16); |
1 | 247 DUMPBITS (bit_buf, bits, tab->len); |
248 return tab->cbp; | |
249 | |
250 } else { | |
251 | |
252 tab = CBP_9 + UBITS (bit_buf, 9); | |
253 DUMPBITS (bit_buf, bits, tab->len); | |
254 return tab->cbp; | |
255 } | |
256 | |
257 #undef bit_buf | |
258 #undef bits | |
259 #undef bit_ptr | |
260 } | |
261 | |
12932 | 262 static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder) |
1 | 263 { |
9852 | 264 #define bit_buf (decoder->bitstream_buf) |
265 #define bits (decoder->bitstream_bits) | |
266 #define bit_ptr (decoder->bitstream_ptr) | |
267 const DCtab * tab; | |
1 | 268 int size; |
269 int dc_diff; | |
270 | |
271 if (bit_buf < 0xf8000000) { | |
272 tab = DC_lum_5 + UBITS (bit_buf, 5); | |
273 size = tab->size; | |
274 if (size) { | |
275 bits += tab->len + size; | |
276 bit_buf <<= tab->len; | |
277 dc_diff = | |
278 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | |
279 bit_buf <<= size; | |
12932 | 280 return dc_diff << decoder->intra_dc_precision; |
1 | 281 } else { |
282 DUMPBITS (bit_buf, bits, 3); | |
283 return 0; | |
284 } | |
285 } else { | |
9852 | 286 tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); |
1 | 287 size = tab->size; |
288 DUMPBITS (bit_buf, bits, tab->len); | |
289 NEEDBITS (bit_buf, bits, bit_ptr); | |
290 dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | |
291 DUMPBITS (bit_buf, bits, size); | |
12932 | 292 return dc_diff << decoder->intra_dc_precision; |
1 | 293 } |
294 #undef bit_buf | |
295 #undef bits | |
296 #undef bit_ptr | |
297 } | |
298 | |
12932 | 299 static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder) |
1 | 300 { |
9852 | 301 #define bit_buf (decoder->bitstream_buf) |
302 #define bits (decoder->bitstream_bits) | |
303 #define bit_ptr (decoder->bitstream_ptr) | |
304 const DCtab * tab; | |
1 | 305 int size; |
306 int dc_diff; | |
307 | |
308 if (bit_buf < 0xf8000000) { | |
309 tab = DC_chrom_5 + UBITS (bit_buf, 5); | |
310 size = tab->size; | |
311 if (size) { | |
312 bits += tab->len + size; | |
313 bit_buf <<= tab->len; | |
314 dc_diff = | |
315 UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | |
316 bit_buf <<= size; | |
12932 | 317 return dc_diff << decoder->intra_dc_precision; |
1 | 318 } else { |
319 DUMPBITS (bit_buf, bits, 2); | |
320 return 0; | |
321 } | |
322 } else { | |
9852 | 323 tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); |
1 | 324 size = tab->size; |
325 DUMPBITS (bit_buf, bits, tab->len + 1); | |
326 NEEDBITS (bit_buf, bits, bit_ptr); | |
327 dc_diff = UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | |
328 DUMPBITS (bit_buf, bits, size); | |
12932 | 329 return dc_diff << decoder->intra_dc_precision; |
1 | 330 } |
331 #undef bit_buf | |
332 #undef bits | |
333 #undef bit_ptr | |
334 } | |
335 | |
12932 | 336 #define SATURATE(val) \ |
337 do { \ | |
338 val <<= 4; \ | |
339 if (unlikely (val != (int16_t) val)) \ | |
340 val = (SBITS (val, 1) ^ 2047) << 4; \ | |
1 | 341 } while (0) |
342 | |
12932 | 343 static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, |
344 const uint16_t * const quant_matrix) | |
1 | 345 { |
346 int i; | |
347 int j; | |
348 int val; | |
12932 | 349 const uint8_t * const scan = decoder->scan; |
1 | 350 int mismatch; |
9852 | 351 const DCTtab * tab; |
1 | 352 uint32_t bit_buf; |
353 int bits; | |
9852 | 354 const uint8_t * bit_ptr; |
12932 | 355 int16_t * const dest = decoder->DCTblock; |
1 | 356 |
357 i = 0; | |
358 mismatch = ~dest[0]; | |
359 | |
9852 | 360 bit_buf = decoder->bitstream_buf; |
361 bits = decoder->bitstream_bits; | |
362 bit_ptr = decoder->bitstream_ptr; | |
1 | 363 |
364 NEEDBITS (bit_buf, bits, bit_ptr); | |
365 | |
366 while (1) { | |
367 if (bit_buf >= 0x28000000) { | |
368 | |
9852 | 369 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 370 |
371 i += tab->run; | |
372 if (i >= 64) | |
36 | 373 break; /* end of block */ |
1 | 374 |
375 normal_code: | |
376 j = scan[i]; | |
377 bit_buf <<= tab->len; | |
378 bits += tab->len + 1; | |
12932 | 379 val = (tab->level * quant_matrix[j]) >> 4; |
1 | 380 |
36 | 381 /* if (bitstream_get (1)) val = -val; */ |
1 | 382 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); |
383 | |
384 SATURATE (val); | |
385 dest[j] = val; | |
386 mismatch ^= val; | |
387 | |
388 bit_buf <<= 1; | |
389 NEEDBITS (bit_buf, bits, bit_ptr); | |
390 | |
391 continue; | |
392 | |
393 } else if (bit_buf >= 0x04000000) { | |
394 | |
9852 | 395 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
1 | 396 |
397 i += tab->run; | |
398 if (i < 64) | |
399 goto normal_code; | |
400 | |
36 | 401 /* escape code */ |
1 | 402 |
403 i += UBITS (bit_buf << 6, 6) - 64; | |
404 if (i >= 64) | |
36 | 405 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 406 |
407 j = scan[i]; | |
408 | |
409 DUMPBITS (bit_buf, bits, 12); | |
410 NEEDBITS (bit_buf, bits, bit_ptr); | |
12932 | 411 val = (SBITS (bit_buf, 12) * quant_matrix[j]) / 16; |
1 | 412 |
413 SATURATE (val); | |
414 dest[j] = val; | |
415 mismatch ^= val; | |
416 | |
417 DUMPBITS (bit_buf, bits, 12); | |
418 NEEDBITS (bit_buf, bits, bit_ptr); | |
419 | |
420 continue; | |
421 | |
422 } else if (bit_buf >= 0x02000000) { | |
9852 | 423 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
1 | 424 i += tab->run; |
425 if (i < 64) | |
426 goto normal_code; | |
427 } else if (bit_buf >= 0x00800000) { | |
9852 | 428 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
1 | 429 i += tab->run; |
430 if (i < 64) | |
431 goto normal_code; | |
432 } else if (bit_buf >= 0x00200000) { | |
9852 | 433 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
1 | 434 i += tab->run; |
435 if (i < 64) | |
436 goto normal_code; | |
437 } else { | |
438 tab = DCT_16 + UBITS (bit_buf, 16); | |
439 bit_buf <<= 16; | |
440 GETWORD (bit_buf, bits + 16, bit_ptr); | |
441 i += tab->run; | |
442 if (i < 64) | |
443 goto normal_code; | |
444 } | |
36 | 445 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 446 } |
12932 | 447 dest[63] ^= mismatch & 16; |
36 | 448 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
9852 | 449 decoder->bitstream_buf = bit_buf; |
450 decoder->bitstream_bits = bits; | |
451 decoder->bitstream_ptr = bit_ptr; | |
1 | 452 } |
453 | |
12932 | 454 static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, |
455 const uint16_t * const quant_matrix) | |
1 | 456 { |
457 int i; | |
458 int j; | |
459 int val; | |
12932 | 460 const uint8_t * const scan = decoder->scan; |
1 | 461 int mismatch; |
9852 | 462 const DCTtab * tab; |
1 | 463 uint32_t bit_buf; |
464 int bits; | |
9852 | 465 const uint8_t * bit_ptr; |
12932 | 466 int16_t * const dest = decoder->DCTblock; |
1 | 467 |
468 i = 0; | |
469 mismatch = ~dest[0]; | |
470 | |
9852 | 471 bit_buf = decoder->bitstream_buf; |
472 bits = decoder->bitstream_bits; | |
473 bit_ptr = decoder->bitstream_ptr; | |
1 | 474 |
475 NEEDBITS (bit_buf, bits, bit_ptr); | |
476 | |
477 while (1) { | |
478 if (bit_buf >= 0x04000000) { | |
479 | |
9852 | 480 tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); |
1 | 481 |
482 i += tab->run; | |
483 if (i < 64) { | |
484 | |
485 normal_code: | |
486 j = scan[i]; | |
487 bit_buf <<= tab->len; | |
488 bits += tab->len + 1; | |
12932 | 489 val = (tab->level * quant_matrix[j]) >> 4; |
1 | 490 |
36 | 491 /* if (bitstream_get (1)) val = -val; */ |
1 | 492 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); |
493 | |
494 SATURATE (val); | |
495 dest[j] = val; | |
496 mismatch ^= val; | |
497 | |
498 bit_buf <<= 1; | |
499 NEEDBITS (bit_buf, bits, bit_ptr); | |
500 | |
501 continue; | |
502 | |
503 } else { | |
504 | |
36 | 505 /* end of block. I commented out this code because if we */ |
506 /* dont exit here we will still exit at the later test :) */ | |
1 | 507 |
36 | 508 /* if (i >= 128) break; */ /* end of block */ |
1 | 509 |
36 | 510 /* escape code */ |
1 | 511 |
512 i += UBITS (bit_buf << 6, 6) - 64; | |
513 if (i >= 64) | |
36 | 514 break; /* illegal, check against buffer overflow */ |
1 | 515 |
516 j = scan[i]; | |
517 | |
518 DUMPBITS (bit_buf, bits, 12); | |
519 NEEDBITS (bit_buf, bits, bit_ptr); | |
12932 | 520 val = (SBITS (bit_buf, 12) * quant_matrix[j]) / 16; |
1 | 521 |
522 SATURATE (val); | |
523 dest[j] = val; | |
524 mismatch ^= val; | |
525 | |
526 DUMPBITS (bit_buf, bits, 12); | |
527 NEEDBITS (bit_buf, bits, bit_ptr); | |
528 | |
529 continue; | |
530 | |
531 } | |
532 } else if (bit_buf >= 0x02000000) { | |
9852 | 533 tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); |
1 | 534 i += tab->run; |
535 if (i < 64) | |
536 goto normal_code; | |
537 } else if (bit_buf >= 0x00800000) { | |
9852 | 538 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
1 | 539 i += tab->run; |
540 if (i < 64) | |
541 goto normal_code; | |
542 } else if (bit_buf >= 0x00200000) { | |
9852 | 543 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
1 | 544 i += tab->run; |
545 if (i < 64) | |
546 goto normal_code; | |
547 } else { | |
548 tab = DCT_16 + UBITS (bit_buf, 16); | |
549 bit_buf <<= 16; | |
550 GETWORD (bit_buf, bits + 16, bit_ptr); | |
551 i += tab->run; | |
552 if (i < 64) | |
553 goto normal_code; | |
554 } | |
36 | 555 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 556 } |
12932 | 557 dest[63] ^= mismatch & 16; |
36 | 558 DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ |
9852 | 559 decoder->bitstream_buf = bit_buf; |
560 decoder->bitstream_bits = bits; | |
561 decoder->bitstream_ptr = bit_ptr; | |
1 | 562 } |
563 | |
12932 | 564 static int get_non_intra_block (mpeg2_decoder_t * const decoder, |
565 const uint16_t * const quant_matrix) | |
1 | 566 { |
567 int i; | |
568 int j; | |
569 int val; | |
12932 | 570 const uint8_t * const scan = decoder->scan; |
1 | 571 int mismatch; |
9852 | 572 const DCTtab * tab; |
1 | 573 uint32_t bit_buf; |
574 int bits; | |
9852 | 575 const uint8_t * bit_ptr; |
12932 | 576 int16_t * const dest = decoder->DCTblock; |
1 | 577 |
578 i = -1; | |
12932 | 579 mismatch = -1; |
1 | 580 |
9852 | 581 bit_buf = decoder->bitstream_buf; |
582 bits = decoder->bitstream_bits; | |
583 bit_ptr = decoder->bitstream_ptr; | |
1 | 584 |
585 NEEDBITS (bit_buf, bits, bit_ptr); | |
586 if (bit_buf >= 0x28000000) { | |
9852 | 587 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 588 goto entry_1; |
589 } else | |
590 goto entry_2; | |
591 | |
592 while (1) { | |
593 if (bit_buf >= 0x28000000) { | |
594 | |
9852 | 595 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 596 |
597 entry_1: | |
598 i += tab->run; | |
599 if (i >= 64) | |
36 | 600 break; /* end of block */ |
1 | 601 |
602 normal_code: | |
603 j = scan[i]; | |
604 bit_buf <<= tab->len; | |
605 bits += tab->len + 1; | |
12932 | 606 val = ((2 * tab->level + 1) * quant_matrix[j]) >> 5; |
1 | 607 |
36 | 608 /* if (bitstream_get (1)) val = -val; */ |
1 | 609 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); |
610 | |
611 SATURATE (val); | |
612 dest[j] = val; | |
613 mismatch ^= val; | |
614 | |
615 bit_buf <<= 1; | |
616 NEEDBITS (bit_buf, bits, bit_ptr); | |
617 | |
618 continue; | |
619 | |
620 } | |
621 | |
622 entry_2: | |
623 if (bit_buf >= 0x04000000) { | |
624 | |
9852 | 625 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
1 | 626 |
627 i += tab->run; | |
628 if (i < 64) | |
629 goto normal_code; | |
630 | |
36 | 631 /* escape code */ |
1 | 632 |
633 i += UBITS (bit_buf << 6, 6) - 64; | |
634 if (i >= 64) | |
36 | 635 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 636 |
637 j = scan[i]; | |
638 | |
639 DUMPBITS (bit_buf, bits, 12); | |
640 NEEDBITS (bit_buf, bits, bit_ptr); | |
641 val = 2 * (SBITS (bit_buf, 12) + SBITS (bit_buf, 1)) + 1; | |
12932 | 642 val = (val * quant_matrix[j]) / 32; |
1 | 643 |
644 SATURATE (val); | |
645 dest[j] = val; | |
646 mismatch ^= val; | |
647 | |
648 DUMPBITS (bit_buf, bits, 12); | |
649 NEEDBITS (bit_buf, bits, bit_ptr); | |
650 | |
651 continue; | |
652 | |
653 } else if (bit_buf >= 0x02000000) { | |
9852 | 654 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
1 | 655 i += tab->run; |
656 if (i < 64) | |
657 goto normal_code; | |
658 } else if (bit_buf >= 0x00800000) { | |
9852 | 659 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
1 | 660 i += tab->run; |
661 if (i < 64) | |
662 goto normal_code; | |
663 } else if (bit_buf >= 0x00200000) { | |
9852 | 664 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
1 | 665 i += tab->run; |
666 if (i < 64) | |
667 goto normal_code; | |
668 } else { | |
669 tab = DCT_16 + UBITS (bit_buf, 16); | |
670 bit_buf <<= 16; | |
671 GETWORD (bit_buf, bits + 16, bit_ptr); | |
672 i += tab->run; | |
673 if (i < 64) | |
674 goto normal_code; | |
675 } | |
36 | 676 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 677 } |
12932 | 678 dest[63] ^= mismatch & 16; |
36 | 679 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
9852 | 680 decoder->bitstream_buf = bit_buf; |
681 decoder->bitstream_bits = bits; | |
682 decoder->bitstream_ptr = bit_ptr; | |
683 return i; | |
1 | 684 } |
685 | |
12932 | 686 static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) |
1 | 687 { |
688 int i; | |
689 int j; | |
690 int val; | |
12932 | 691 const uint8_t * const scan = decoder->scan; |
692 const uint16_t * const quant_matrix = decoder->quantizer_matrix[0]; | |
9852 | 693 const DCTtab * tab; |
1 | 694 uint32_t bit_buf; |
695 int bits; | |
9852 | 696 const uint8_t * bit_ptr; |
12932 | 697 int16_t * const dest = decoder->DCTblock; |
1 | 698 |
699 i = 0; | |
700 | |
9852 | 701 bit_buf = decoder->bitstream_buf; |
702 bits = decoder->bitstream_bits; | |
703 bit_ptr = decoder->bitstream_ptr; | |
1 | 704 |
705 NEEDBITS (bit_buf, bits, bit_ptr); | |
706 | |
707 while (1) { | |
708 if (bit_buf >= 0x28000000) { | |
709 | |
9852 | 710 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 711 |
712 i += tab->run; | |
713 if (i >= 64) | |
36 | 714 break; /* end of block */ |
1 | 715 |
716 normal_code: | |
717 j = scan[i]; | |
718 bit_buf <<= tab->len; | |
719 bits += tab->len + 1; | |
12932 | 720 val = (tab->level * quant_matrix[j]) >> 4; |
1 | 721 |
36 | 722 /* oddification */ |
1 | 723 val = (val - 1) | 1; |
724 | |
36 | 725 /* if (bitstream_get (1)) val = -val; */ |
1 | 726 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); |
727 | |
728 SATURATE (val); | |
729 dest[j] = val; | |
730 | |
731 bit_buf <<= 1; | |
732 NEEDBITS (bit_buf, bits, bit_ptr); | |
733 | |
734 continue; | |
735 | |
736 } else if (bit_buf >= 0x04000000) { | |
737 | |
9852 | 738 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
1 | 739 |
740 i += tab->run; | |
741 if (i < 64) | |
742 goto normal_code; | |
743 | |
36 | 744 /* escape code */ |
1 | 745 |
746 i += UBITS (bit_buf << 6, 6) - 64; | |
747 if (i >= 64) | |
36 | 748 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 749 |
750 j = scan[i]; | |
751 | |
752 DUMPBITS (bit_buf, bits, 12); | |
753 NEEDBITS (bit_buf, bits, bit_ptr); | |
754 val = SBITS (bit_buf, 8); | |
755 if (! (val & 0x7f)) { | |
756 DUMPBITS (bit_buf, bits, 8); | |
757 val = UBITS (bit_buf, 8) + 2 * val; | |
758 } | |
12932 | 759 val = (val * quant_matrix[j]) / 16; |
1 | 760 |
36 | 761 /* oddification */ |
1 | 762 val = (val + ~SBITS (val, 1)) | 1; |
763 | |
764 SATURATE (val); | |
765 dest[j] = val; | |
766 | |
767 DUMPBITS (bit_buf, bits, 8); | |
768 NEEDBITS (bit_buf, bits, bit_ptr); | |
769 | |
770 continue; | |
771 | |
772 } else if (bit_buf >= 0x02000000) { | |
9852 | 773 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
1 | 774 i += tab->run; |
775 if (i < 64) | |
776 goto normal_code; | |
777 } else if (bit_buf >= 0x00800000) { | |
9852 | 778 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
1 | 779 i += tab->run; |
780 if (i < 64) | |
781 goto normal_code; | |
782 } else if (bit_buf >= 0x00200000) { | |
9852 | 783 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
1 | 784 i += tab->run; |
785 if (i < 64) | |
786 goto normal_code; | |
787 } else { | |
788 tab = DCT_16 + UBITS (bit_buf, 16); | |
789 bit_buf <<= 16; | |
790 GETWORD (bit_buf, bits + 16, bit_ptr); | |
791 i += tab->run; | |
792 if (i < 64) | |
793 goto normal_code; | |
794 } | |
36 | 795 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 796 } |
36 | 797 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
9852 | 798 decoder->bitstream_buf = bit_buf; |
799 decoder->bitstream_bits = bits; | |
800 decoder->bitstream_ptr = bit_ptr; | |
1 | 801 } |
802 | |
12932 | 803 static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) |
1 | 804 { |
805 int i; | |
806 int j; | |
807 int val; | |
12932 | 808 const uint8_t * const scan = decoder->scan; |
809 const uint16_t * const quant_matrix = decoder->quantizer_matrix[1]; | |
9852 | 810 const DCTtab * tab; |
1 | 811 uint32_t bit_buf; |
812 int bits; | |
9852 | 813 const uint8_t * bit_ptr; |
12932 | 814 int16_t * const dest = decoder->DCTblock; |
1 | 815 |
816 i = -1; | |
817 | |
9852 | 818 bit_buf = decoder->bitstream_buf; |
819 bits = decoder->bitstream_bits; | |
820 bit_ptr = decoder->bitstream_ptr; | |
1 | 821 |
822 NEEDBITS (bit_buf, bits, bit_ptr); | |
823 if (bit_buf >= 0x28000000) { | |
9852 | 824 tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 825 goto entry_1; |
826 } else | |
827 goto entry_2; | |
828 | |
829 while (1) { | |
830 if (bit_buf >= 0x28000000) { | |
831 | |
9852 | 832 tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
1 | 833 |
834 entry_1: | |
835 i += tab->run; | |
836 if (i >= 64) | |
36 | 837 break; /* end of block */ |
1 | 838 |
839 normal_code: | |
840 j = scan[i]; | |
841 bit_buf <<= tab->len; | |
842 bits += tab->len + 1; | |
12932 | 843 val = ((2 * tab->level + 1) * quant_matrix[j]) >> 5; |
1 | 844 |
36 | 845 /* oddification */ |
1 | 846 val = (val - 1) | 1; |
847 | |
36 | 848 /* if (bitstream_get (1)) val = -val; */ |
1 | 849 val = (val ^ SBITS (bit_buf, 1)) - SBITS (bit_buf, 1); |
850 | |
851 SATURATE (val); | |
852 dest[j] = val; | |
853 | |
854 bit_buf <<= 1; | |
855 NEEDBITS (bit_buf, bits, bit_ptr); | |
856 | |
857 continue; | |
858 | |
859 } | |
860 | |
861 entry_2: | |
862 if (bit_buf >= 0x04000000) { | |
863 | |
9852 | 864 tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
1 | 865 |
866 i += tab->run; | |
867 if (i < 64) | |
868 goto normal_code; | |
869 | |
36 | 870 /* escape code */ |
1 | 871 |
872 i += UBITS (bit_buf << 6, 6) - 64; | |
873 if (i >= 64) | |
36 | 874 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 875 |
876 j = scan[i]; | |
877 | |
878 DUMPBITS (bit_buf, bits, 12); | |
879 NEEDBITS (bit_buf, bits, bit_ptr); | |
880 val = SBITS (bit_buf, 8); | |
881 if (! (val & 0x7f)) { | |
882 DUMPBITS (bit_buf, bits, 8); | |
883 val = UBITS (bit_buf, 8) + 2 * val; | |
884 } | |
885 val = 2 * (val + SBITS (val, 1)) + 1; | |
12932 | 886 val = (val * quant_matrix[j]) / 32; |
1 | 887 |
36 | 888 /* oddification */ |
1 | 889 val = (val + ~SBITS (val, 1)) | 1; |
890 | |
891 SATURATE (val); | |
892 dest[j] = val; | |
893 | |
894 DUMPBITS (bit_buf, bits, 8); | |
895 NEEDBITS (bit_buf, bits, bit_ptr); | |
896 | |
897 continue; | |
898 | |
899 } else if (bit_buf >= 0x02000000) { | |
9852 | 900 tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
1 | 901 i += tab->run; |
902 if (i < 64) | |
903 goto normal_code; | |
904 } else if (bit_buf >= 0x00800000) { | |
9852 | 905 tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
1 | 906 i += tab->run; |
907 if (i < 64) | |
908 goto normal_code; | |
909 } else if (bit_buf >= 0x00200000) { | |
9852 | 910 tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
1 | 911 i += tab->run; |
912 if (i < 64) | |
913 goto normal_code; | |
914 } else { | |
915 tab = DCT_16 + UBITS (bit_buf, 16); | |
916 bit_buf <<= 16; | |
917 GETWORD (bit_buf, bits + 16, bit_ptr); | |
918 i += tab->run; | |
919 if (i < 64) | |
920 goto normal_code; | |
921 } | |
36 | 922 break; /* illegal, check needed to avoid buffer overflow */ |
1 | 923 } |
36 | 924 DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
9852 | 925 decoder->bitstream_buf = bit_buf; |
926 decoder->bitstream_bits = bits; | |
927 decoder->bitstream_ptr = bit_ptr; | |
928 return i; | |
1 | 929 } |
930 | |
12932 | 931 static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder, |
932 const int cc, | |
9852 | 933 uint8_t * const dest, const int stride) |
1 | 934 { |
9852 | 935 #define bit_buf (decoder->bitstream_buf) |
936 #define bits (decoder->bitstream_bits) | |
937 #define bit_ptr (decoder->bitstream_ptr) | |
1 | 938 NEEDBITS (bit_buf, bits, bit_ptr); |
36 | 939 /* Get the intra DC coefficient and inverse quantize it */ |
1 | 940 if (cc == 0) |
12932 | 941 decoder->DCTblock[0] = |
942 decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder); | |
1 | 943 else |
12932 | 944 decoder->DCTblock[0] = |
945 decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder); | |
1 | 946 |
9852 | 947 if (decoder->mpeg1) { |
948 if (decoder->coding_type != D_TYPE) | |
949 get_mpeg1_intra_block (decoder); | |
950 } else if (decoder->intra_vlc_format) | |
12932 | 951 get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); |
1 | 952 else |
12932 | 953 get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); |
9852 | 954 mpeg2_idct_copy (decoder->DCTblock, dest, stride); |
1 | 955 #undef bit_buf |
956 #undef bits | |
957 #undef bit_ptr | |
958 } | |
959 | |
12932 | 960 static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder, |
961 const int cc, | |
9852 | 962 uint8_t * const dest, const int stride) |
1 | 963 { |
9852 | 964 int last; |
965 | |
966 if (decoder->mpeg1) | |
967 last = get_mpeg1_non_intra_block (decoder); | |
1 | 968 else |
12932 | 969 last = get_non_intra_block (decoder, |
970 decoder->quantizer_matrix[cc ? 3 : 1]); | |
9852 | 971 mpeg2_idct_add (last, decoder->DCTblock, dest, stride); |
1 | 972 } |
973 | |
12932 | 974 #define MOTION_420(table,ref,motion_x,motion_y,size,y) \ |
9852 | 975 pos_x = 2 * decoder->offset + motion_x; \ |
976 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | |
12932 | 977 if (unlikely (pos_x > decoder->limit_x)) { \ |
978 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
979 motion_x = pos_x - 2 * decoder->offset; \ | |
980 } \ | |
981 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | |
982 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | |
983 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | |
984 } \ | |
9852 | 985 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
986 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | |
987 ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \ | |
988 decoder->stride, size); \ | |
989 motion_x /= 2; motion_y /= 2; \ | |
990 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | |
991 offset = (((decoder->offset + motion_x) >> 1) + \ | |
992 ((((decoder->v_offset + motion_y) >> 1) + y/2) * \ | |
993 decoder->uv_stride)); \ | |
994 table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \ | |
995 (decoder->offset >> 1), ref[1] + offset, \ | |
996 decoder->uv_stride, size/2); \ | |
997 table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \ | |
998 (decoder->offset >> 1), ref[2] + offset, \ | |
999 decoder->uv_stride, size/2) | |
49 | 1000 |
12932 | 1001 #define MOTION_FIELD_420(table,ref,motion_x,motion_y,dest_field,op,src_field) \ |
9852 | 1002 pos_x = 2 * decoder->offset + motion_x; \ |
1003 pos_y = decoder->v_offset + motion_y; \ | |
12932 | 1004 if (unlikely (pos_x > decoder->limit_x)) { \ |
1005 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1006 motion_x = pos_x - 2 * decoder->offset; \ | |
1007 } \ | |
1008 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1009 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1010 motion_y = pos_y - decoder->v_offset; \ | |
1011 } \ | |
9852 | 1012 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1013 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | |
1014 decoder->offset, \ | |
1015 (ref[0] + (pos_x >> 1) + \ | |
1016 ((pos_y op) + src_field) * decoder->stride), \ | |
1017 2 * decoder->stride, 8); \ | |
1018 motion_x /= 2; motion_y /= 2; \ | |
1019 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | |
1020 offset = (((decoder->offset + motion_x) >> 1) + \ | |
1021 (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \ | |
1022 decoder->uv_stride)); \ | |
1023 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | |
1024 (decoder->offset >> 1), ref[1] + offset, \ | |
1025 2 * decoder->uv_stride, 4); \ | |
1026 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | |
1027 (decoder->offset >> 1), ref[2] + offset, \ | |
1028 2 * decoder->uv_stride, 4) | |
1 | 1029 |
12932 | 1030 #define MOTION_DMV_420(table,ref,motion_x,motion_y) \ |
1031 pos_x = 2 * decoder->offset + motion_x; \ | |
1032 pos_y = decoder->v_offset + motion_y; \ | |
1033 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1034 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1035 motion_x = pos_x - 2 * decoder->offset; \ | |
1036 } \ | |
1037 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1038 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1039 motion_y = pos_y - decoder->v_offset; \ | |
1040 } \ | |
1041 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1042 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | |
1043 table[xy_half] (decoder->dest[0] + decoder->offset, \ | |
1044 ref[0] + offset, 2 * decoder->stride, 8); \ | |
1045 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | |
1046 ref[0] + decoder->stride + offset, \ | |
1047 2 * decoder->stride, 8); \ | |
1048 motion_x /= 2; motion_y /= 2; \ | |
1049 xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | |
1050 offset = (((decoder->offset + motion_x) >> 1) + \ | |
1051 (((decoder->v_offset >> 1) + (motion_y & ~1)) * \ | |
1052 decoder->uv_stride)); \ | |
1053 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | |
1054 ref[1] + offset, 2 * decoder->uv_stride, 4); \ | |
1055 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | |
1056 (decoder->offset >> 1), \ | |
1057 ref[1] + decoder->uv_stride + offset, \ | |
1058 2 * decoder->uv_stride, 4); \ | |
1059 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | |
1060 ref[2] + offset, 2 * decoder->uv_stride, 4); \ | |
1061 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | |
1062 (decoder->offset >> 1), \ | |
1063 ref[2] + decoder->uv_stride + offset, \ | |
1064 2 * decoder->uv_stride, 4) | |
1065 | |
1066 #define MOTION_ZERO_420(table,ref) \ | |
1067 table[0] (decoder->dest[0] + decoder->offset, \ | |
1068 (ref[0] + decoder->offset + \ | |
1069 decoder->v_offset * decoder->stride), decoder->stride, 16); \ | |
1070 offset = ((decoder->offset >> 1) + \ | |
1071 (decoder->v_offset >> 1) * decoder->uv_stride); \ | |
1072 table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | |
1073 ref[1] + offset, decoder->uv_stride, 8); \ | |
1074 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | |
1075 ref[2] + offset, decoder->uv_stride, 8) | |
1076 | |
1077 #define MOTION_422(table,ref,motion_x,motion_y,size,y) \ | |
1078 pos_x = 2 * decoder->offset + motion_x; \ | |
1079 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | |
1080 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1081 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1082 motion_x = pos_x - 2 * decoder->offset; \ | |
1083 } \ | |
1084 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | |
1085 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | |
1086 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | |
1087 } \ | |
1088 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1089 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | |
1090 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | |
1091 ref[0] + offset, decoder->stride, size); \ | |
1092 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | |
1093 motion_x /= 2; \ | |
1094 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | |
1095 table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \ | |
1096 (decoder->offset >> 1), ref[1] + offset, \ | |
1097 decoder->uv_stride, size); \ | |
1098 table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \ | |
1099 (decoder->offset >> 1), ref[2] + offset, \ | |
1100 decoder->uv_stride, size) | |
1101 | |
1102 #define MOTION_FIELD_422(table,ref,motion_x,motion_y,dest_field,op,src_field) \ | |
1103 pos_x = 2 * decoder->offset + motion_x; \ | |
1104 pos_y = decoder->v_offset + motion_y; \ | |
1105 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1106 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1107 motion_x = pos_x - 2 * decoder->offset; \ | |
1108 } \ | |
1109 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1110 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1111 motion_y = pos_y - decoder->v_offset; \ | |
1112 } \ | |
1113 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1114 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | |
1115 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | |
1116 decoder->offset, ref[0] + offset, \ | |
1117 2 * decoder->stride, 8); \ | |
1118 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | |
1119 motion_x /= 2; \ | |
1120 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | |
1121 table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | |
1122 (decoder->offset >> 1), ref[1] + offset, \ | |
1123 2 * decoder->uv_stride, 8); \ | |
1124 table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | |
1125 (decoder->offset >> 1), ref[2] + offset, \ | |
1126 2 * decoder->uv_stride, 8) | |
1127 | |
1128 #define MOTION_DMV_422(table,ref,motion_x,motion_y) \ | |
1129 pos_x = 2 * decoder->offset + motion_x; \ | |
1130 pos_y = decoder->v_offset + motion_y; \ | |
1131 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1132 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1133 motion_x = pos_x - 2 * decoder->offset; \ | |
1134 } \ | |
1135 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1136 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1137 motion_y = pos_y - decoder->v_offset; \ | |
1138 } \ | |
1139 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1140 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | |
1141 table[xy_half] (decoder->dest[0] + decoder->offset, \ | |
1142 ref[0] + offset, 2 * decoder->stride, 8); \ | |
1143 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | |
1144 ref[0] + decoder->stride + offset, \ | |
1145 2 * decoder->stride, 8); \ | |
1146 offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | |
1147 motion_x /= 2; \ | |
1148 xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | |
1149 table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | |
1150 ref[1] + offset, 2 * decoder->uv_stride, 8); \ | |
1151 table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | |
1152 (decoder->offset >> 1), \ | |
1153 ref[1] + decoder->uv_stride + offset, \ | |
1154 2 * decoder->uv_stride, 8); \ | |
1155 table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | |
1156 ref[2] + offset, 2 * decoder->uv_stride, 8); \ | |
1157 table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | |
1158 (decoder->offset >> 1), \ | |
1159 ref[2] + decoder->uv_stride + offset, \ | |
1160 2 * decoder->uv_stride, 8) | |
1161 | |
1162 #define MOTION_ZERO_422(table,ref) \ | |
1163 offset = decoder->offset + decoder->v_offset * decoder->stride; \ | |
1164 table[0] (decoder->dest[0] + decoder->offset, \ | |
1165 ref[0] + offset, decoder->stride, 16); \ | |
1166 offset >>= 1; \ | |
1167 table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | |
1168 ref[1] + offset, decoder->uv_stride, 16); \ | |
1169 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | |
1170 ref[2] + offset, decoder->uv_stride, 16) | |
1171 | |
1172 #define MOTION_444(table,ref,motion_x,motion_y,size,y) \ | |
1173 pos_x = 2 * decoder->offset + motion_x; \ | |
1174 pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | |
1175 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1176 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1177 motion_x = pos_x - 2 * decoder->offset; \ | |
1178 } \ | |
1179 if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | |
1180 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | |
1181 motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | |
1182 } \ | |
1183 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1184 offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | |
1185 table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | |
1186 ref[0] + offset, decoder->stride, size); \ | |
1187 table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \ | |
1188 ref[1] + offset, decoder->stride, size); \ | |
1189 table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \ | |
1190 ref[2] + offset, decoder->stride, size) | |
1191 | |
1192 #define MOTION_FIELD_444(table,ref,motion_x,motion_y,dest_field,op,src_field) \ | |
1193 pos_x = 2 * decoder->offset + motion_x; \ | |
1194 pos_y = decoder->v_offset + motion_y; \ | |
1195 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1196 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1197 motion_x = pos_x - 2 * decoder->offset; \ | |
1198 } \ | |
1199 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1200 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1201 motion_y = pos_y - decoder->v_offset; \ | |
1202 } \ | |
1203 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1204 offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | |
1205 table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | |
1206 decoder->offset, ref[0] + offset, \ | |
1207 2 * decoder->stride, 8); \ | |
1208 table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \ | |
1209 decoder->offset, ref[1] + offset, \ | |
1210 2 * decoder->stride, 8); \ | |
1211 table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \ | |
1212 decoder->offset, ref[2] + offset, \ | |
1213 2 * decoder->stride, 8) | |
1214 | |
1215 #define MOTION_DMV_444(table,ref,motion_x,motion_y) \ | |
1216 pos_x = 2 * decoder->offset + motion_x; \ | |
1217 pos_y = decoder->v_offset + motion_y; \ | |
1218 if (unlikely (pos_x > decoder->limit_x)) { \ | |
1219 pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | |
1220 motion_x = pos_x - 2 * decoder->offset; \ | |
1221 } \ | |
1222 if (unlikely (pos_y > decoder->limit_y)) { \ | |
1223 pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | |
1224 motion_y = pos_y - decoder->v_offset; \ | |
1225 } \ | |
1226 xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | |
1227 offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | |
1228 table[xy_half] (decoder->dest[0] + decoder->offset, \ | |
1229 ref[0] + offset, 2 * decoder->stride, 8); \ | |
1230 table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | |
1231 ref[0] + decoder->stride + offset, \ | |
1232 2 * decoder->stride, 8); \ | |
1233 table[xy_half] (decoder->dest[1] + decoder->offset, \ | |
1234 ref[1] + offset, 2 * decoder->stride, 8); \ | |
1235 table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \ | |
1236 ref[1] + decoder->stride + offset, \ | |
1237 2 * decoder->stride, 8); \ | |
1238 table[xy_half] (decoder->dest[2] + decoder->offset, \ | |
1239 ref[2] + offset, 2 * decoder->stride, 8); \ | |
1240 table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \ | |
1241 ref[2] + decoder->stride + offset, \ | |
1242 2 * decoder->stride, 8) | |
1243 | |
1244 #define MOTION_ZERO_444(table,ref) \ | |
1245 offset = decoder->offset + decoder->v_offset * decoder->stride; \ | |
1246 table[0] (decoder->dest[0] + decoder->offset, \ | |
1247 ref[0] + offset, decoder->stride, 16); \ | |
1248 table[4] (decoder->dest[1] + decoder->offset, \ | |
1249 ref[1] + offset, decoder->stride, 16); \ | |
1250 table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | |
1251 ref[2] + offset, decoder->stride, 16) | |
1252 | |
9852 | 1253 #define bit_buf (decoder->bitstream_buf) |
1254 #define bits (decoder->bitstream_bits) | |
1255 #define bit_ptr (decoder->bitstream_ptr) | |
12932 | 1256 |
1257 static void motion_mp1 (mpeg2_decoder_t * const decoder, | |
1258 motion_t * const motion, | |
1259 mpeg2_mc_fct * const * const table) | |
1260 { | |
1 | 1261 int motion_x, motion_y; |
9852 | 1262 unsigned int pos_x, pos_y, xy_half, offset; |
1 | 1263 |
1264 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 1265 motion_x = (motion->pmv[0][0] + |
1266 (get_motion_delta (decoder, | |
1267 motion->f_code[0]) << motion->f_code[1])); | |
1268 motion_x = bound_motion_vector (motion_x, | |
1269 motion->f_code[0] + motion->f_code[1]); | |
1 | 1270 motion->pmv[0][0] = motion_x; |
1271 | |
1272 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 1273 motion_y = (motion->pmv[0][1] + |
1274 (get_motion_delta (decoder, | |
1275 motion->f_code[0]) << motion->f_code[1])); | |
1276 motion_y = bound_motion_vector (motion_y, | |
1277 motion->f_code[0] + motion->f_code[1]); | |
1 | 1278 motion->pmv[0][1] = motion_y; |
1279 | |
12932 | 1280 MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0); |
1 | 1281 } |
1282 | |
12932 | 1283 #define MOTION_FUNCTIONS(FORMAT,MOTION,MOTION_FIELD,MOTION_DMV,MOTION_ZERO) \ |
1284 \ | |
1285 static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1286 motion_t * const motion, \ | |
1287 mpeg2_mc_fct * const * const table) \ | |
1288 { \ | |
1289 int motion_x, motion_y; \ | |
1290 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1291 \ | |
1292 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1293 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1294 motion->f_code[0]); \ | |
1295 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1296 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | |
1297 \ | |
1298 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1299 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | |
1300 motion->f_code[1]); \ | |
1301 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | |
1302 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | |
1303 \ | |
1304 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | |
1305 } \ | |
1306 \ | |
1307 static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1308 motion_t * const motion, \ | |
1309 mpeg2_mc_fct * const * const table) \ | |
1310 { \ | |
1311 int motion_x, motion_y, field; \ | |
1312 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1313 \ | |
1314 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1315 field = UBITS (bit_buf, 1); \ | |
1316 DUMPBITS (bit_buf, bits, 1); \ | |
1317 \ | |
1318 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1319 motion->f_code[0]); \ | |
1320 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1321 motion->pmv[0][0] = motion_x; \ | |
1322 \ | |
1323 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1324 motion_y = ((motion->pmv[0][1] >> 1) + \ | |
1325 get_motion_delta (decoder, motion->f_code[1])); \ | |
1326 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | |
1327 motion->pmv[0][1] = motion_y << 1; \ | |
1328 \ | |
1329 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \ | |
1330 \ | |
1331 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1332 field = UBITS (bit_buf, 1); \ | |
1333 DUMPBITS (bit_buf, bits, 1); \ | |
1334 \ | |
1335 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | |
1336 motion->f_code[0]); \ | |
1337 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1338 motion->pmv[1][0] = motion_x; \ | |
1339 \ | |
1340 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1341 motion_y = ((motion->pmv[1][1] >> 1) + \ | |
1342 get_motion_delta (decoder, motion->f_code[1])); \ | |
1343 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | |
1344 motion->pmv[1][1] = motion_y << 1; \ | |
1345 \ | |
1346 MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \ | |
1347 } \ | |
1348 \ | |
1349 static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1350 motion_t * const motion, \ | |
1351 mpeg2_mc_fct * const * const table) \ | |
1352 { \ | |
1353 int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \ | |
1354 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1355 \ | |
1356 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1357 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1358 motion->f_code[0]); \ | |
1359 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1360 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | |
1361 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1362 dmv_x = get_dmv (decoder); \ | |
1363 \ | |
1364 motion_y = ((motion->pmv[0][1] >> 1) + \ | |
1365 get_motion_delta (decoder, motion->f_code[1])); \ | |
1366 /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | |
1367 motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \ | |
1368 dmv_y = get_dmv (decoder); \ | |
1369 \ | |
1370 m = decoder->top_field_first ? 1 : 3; \ | |
1371 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | |
1372 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \ | |
1373 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \ | |
1374 \ | |
1375 m = decoder->top_field_first ? 3 : 1; \ | |
1376 other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | |
1377 other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \ | |
1378 MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\ | |
1379 \ | |
1380 MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \ | |
1381 } \ | |
1382 \ | |
1383 static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1384 motion_t * const motion, \ | |
1385 mpeg2_mc_fct * const * const table) \ | |
1386 { \ | |
1387 int motion_x, motion_y; \ | |
1388 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1389 \ | |
1390 motion_x = motion->pmv[0][0]; \ | |
1391 motion_y = motion->pmv[0][1]; \ | |
1392 \ | |
1393 MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | |
1394 } \ | |
1395 \ | |
1396 static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1397 motion_t * const motion, \ | |
1398 mpeg2_mc_fct * const * const table) \ | |
1399 { \ | |
1400 unsigned int offset; \ | |
1401 \ | |
1402 motion->pmv[0][0] = motion->pmv[0][1] = 0; \ | |
1403 motion->pmv[1][0] = motion->pmv[1][1] = 0; \ | |
1404 \ | |
1405 MOTION_ZERO (table, motion->ref[0]); \ | |
1406 } \ | |
1407 \ | |
1408 static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1409 motion_t * const motion, \ | |
1410 mpeg2_mc_fct * const * const table) \ | |
1411 { \ | |
1412 int motion_x, motion_y; \ | |
1413 uint8_t ** ref_field; \ | |
1414 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1415 \ | |
1416 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1417 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | |
1418 DUMPBITS (bit_buf, bits, 1); \ | |
1419 \ | |
1420 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1421 motion->f_code[0]); \ | |
1422 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1423 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | |
1424 \ | |
1425 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1426 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | |
1427 motion->f_code[1]); \ | |
1428 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | |
1429 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | |
1430 \ | |
1431 MOTION (table, ref_field, motion_x, motion_y, 16, 0); \ | |
1432 } \ | |
1433 \ | |
1434 static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1435 motion_t * const motion, \ | |
1436 mpeg2_mc_fct * const * const table) \ | |
1437 { \ | |
1438 int motion_x, motion_y; \ | |
1439 uint8_t ** ref_field; \ | |
1440 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1441 \ | |
1442 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1443 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | |
1444 DUMPBITS (bit_buf, bits, 1); \ | |
1445 \ | |
1446 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1447 motion->f_code[0]); \ | |
1448 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1449 motion->pmv[0][0] = motion_x; \ | |
1450 \ | |
1451 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1452 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | |
1453 motion->f_code[1]); \ | |
1454 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | |
1455 motion->pmv[0][1] = motion_y; \ | |
1456 \ | |
1457 MOTION (table, ref_field, motion_x, motion_y, 8, 0); \ | |
1458 \ | |
1459 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1460 ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | |
1461 DUMPBITS (bit_buf, bits, 1); \ | |
1462 \ | |
1463 motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | |
1464 motion->f_code[0]); \ | |
1465 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1466 motion->pmv[1][0] = motion_x; \ | |
1467 \ | |
1468 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1469 motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \ | |
1470 motion->f_code[1]); \ | |
1471 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | |
1472 motion->pmv[1][1] = motion_y; \ | |
1473 \ | |
1474 MOTION (table, ref_field, motion_x, motion_y, 8, 8); \ | |
1475 } \ | |
1476 \ | |
1477 static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | |
1478 motion_t * const motion, \ | |
1479 mpeg2_mc_fct * const * const table) \ | |
1480 { \ | |
1481 int motion_x, motion_y, other_x, other_y; \ | |
1482 unsigned int pos_x, pos_y, xy_half, offset; \ | |
1483 \ | |
1484 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1485 motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | |
1486 motion->f_code[0]); \ | |
1487 motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | |
1488 motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | |
1489 NEEDBITS (bit_buf, bits, bit_ptr); \ | |
1490 other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \ | |
1491 \ | |
1492 motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | |
1493 motion->f_code[1]); \ | |
1494 motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | |
1495 motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | |
1496 other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \ | |
1497 decoder->dmv_offset); \ | |
1498 \ | |
1499 MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \ | |
1500 MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \ | |
1501 } \ | |
9852 | 1502 |
12932 | 1503 MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420, |
1504 MOTION_ZERO_420) | |
1505 MOTION_FUNCTIONS (422, MOTION_422, MOTION_FIELD_422, MOTION_DMV_422, | |
1506 MOTION_ZERO_422) | |
1507 MOTION_FUNCTIONS (444, MOTION_444, MOTION_FIELD_444, MOTION_DMV_444, | |
1508 MOTION_ZERO_444) | |
1 | 1509 |
36 | 1510 /* like motion_frame, but parsing without actual motion compensation */ |
12932 | 1511 static void motion_fr_conceal (mpeg2_decoder_t * const decoder) |
1 | 1512 { |
1513 int tmp; | |
1514 | |
1515 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 1516 tmp = (decoder->f_motion.pmv[0][0] + |
1517 get_motion_delta (decoder, decoder->f_motion.f_code[0])); | |
1518 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); | |
1519 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp; | |
1 | 1520 |
1521 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 1522 tmp = (decoder->f_motion.pmv[0][1] + |
1523 get_motion_delta (decoder, decoder->f_motion.f_code[1])); | |
1524 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); | |
1525 decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp; | |
1 | 1526 |
36 | 1527 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ |
1 | 1528 } |
1529 | |
12932 | 1530 static void motion_fi_conceal (mpeg2_decoder_t * const decoder) |
1 | 1531 { |
1532 int tmp; | |
1533 | |
1534 NEEDBITS (bit_buf, bits, bit_ptr); | |
36 | 1535 DUMPBITS (bit_buf, bits, 1); /* remove field_select */ |
1 | 1536 |
9852 | 1537 tmp = (decoder->f_motion.pmv[0][0] + |
1538 get_motion_delta (decoder, decoder->f_motion.f_code[0])); | |
1539 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); | |
1540 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp; | |
1 | 1541 |
1542 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 1543 tmp = (decoder->f_motion.pmv[0][1] + |
1544 get_motion_delta (decoder, decoder->f_motion.f_code[1])); | |
1545 tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); | |
1546 decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp; | |
1 | 1547 |
36 | 1548 DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ |
12932 | 1549 } |
1550 | |
1 | 1551 #undef bit_buf |
1552 #undef bits | |
1553 #undef bit_ptr | |
1554 | |
9852 | 1555 #define MOTION_CALL(routine,direction) \ |
1556 do { \ | |
1557 if ((direction) & MACROBLOCK_MOTION_FORWARD) \ | |
1558 routine (decoder, &(decoder->f_motion), mpeg2_mc.put); \ | |
1559 if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ | |
1560 routine (decoder, &(decoder->b_motion), \ | |
1561 ((direction) & MACROBLOCK_MOTION_FORWARD ? \ | |
1562 mpeg2_mc.avg : mpeg2_mc.put)); \ | |
1 | 1563 } while (0) |
1564 | |
9852 | 1565 #define NEXT_MACROBLOCK \ |
36 | 1566 do { \ |
12935 | 1567 if(decoder->quant_store) \ |
1568 decoder->quant_store[decoder->quant_stride*(decoder->v_offset>>4) \ | |
1569 +(decoder->offset>>4)] = decoder->quantizer_scale; \ | |
9852 | 1570 decoder->offset += 16; \ |
1571 if (decoder->offset == decoder->width) { \ | |
36 | 1572 do { /* just so we can use the break statement */ \ |
9852 | 1573 if (decoder->convert) { \ |
12932 | 1574 decoder->convert (decoder->convert_id, decoder->dest, \ |
9852 | 1575 decoder->v_offset); \ |
1576 if (decoder->coding_type == B_TYPE) \ | |
36 | 1577 break; \ |
1578 } \ | |
12932 | 1579 decoder->dest[0] += decoder->slice_stride; \ |
1580 decoder->dest[1] += decoder->slice_uv_stride; \ | |
1581 decoder->dest[2] += decoder->slice_uv_stride; \ | |
36 | 1582 } while (0); \ |
9852 | 1583 decoder->v_offset += 16; \ |
1584 if (decoder->v_offset > decoder->limit_y) { \ | |
1585 if (mpeg2_cpu_state_restore) \ | |
1586 mpeg2_cpu_state_restore (&cpu_state); \ | |
1587 return; \ | |
1588 } \ | |
1589 decoder->offset = 0; \ | |
36 | 1590 } \ |
1 | 1591 } while (0) |
1592 | |
12932 | 1593 void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3], |
9852 | 1594 uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]) |
1 | 1595 { |
9852 | 1596 int offset, stride, height, bottom_field; |
1597 | |
12932 | 1598 stride = decoder->stride_frame; |
9852 | 1599 bottom_field = (decoder->picture_structure == BOTTOM_FIELD); |
1600 offset = bottom_field ? stride : 0; | |
1601 height = decoder->height; | |
1 | 1602 |
9852 | 1603 decoder->picture_dest[0] = current_fbuf[0] + offset; |
1604 decoder->picture_dest[1] = current_fbuf[1] + (offset >> 1); | |
1605 decoder->picture_dest[2] = current_fbuf[2] + (offset >> 1); | |
1606 | |
1607 decoder->f_motion.ref[0][0] = forward_fbuf[0] + offset; | |
1608 decoder->f_motion.ref[0][1] = forward_fbuf[1] + (offset >> 1); | |
1609 decoder->f_motion.ref[0][2] = forward_fbuf[2] + (offset >> 1); | |
1610 | |
1611 decoder->b_motion.ref[0][0] = backward_fbuf[0] + offset; | |
1612 decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1); | |
1613 decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1); | |
1 | 1614 |
9852 | 1615 if (decoder->picture_structure != FRAME_PICTURE) { |
1616 decoder->dmv_offset = bottom_field ? 1 : -1; | |
1617 decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field]; | |
1618 decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field]; | |
1619 decoder->b_motion.ref2[0] = decoder->b_motion.ref[bottom_field]; | |
1620 decoder->b_motion.ref2[1] = decoder->b_motion.ref[!bottom_field]; | |
1621 offset = stride - offset; | |
1622 | |
1623 if (decoder->second_field && (decoder->coding_type != B_TYPE)) | |
1624 forward_fbuf = current_fbuf; | |
49 | 1625 |
9852 | 1626 decoder->f_motion.ref[1][0] = forward_fbuf[0] + offset; |
1627 decoder->f_motion.ref[1][1] = forward_fbuf[1] + (offset >> 1); | |
1628 decoder->f_motion.ref[1][2] = forward_fbuf[2] + (offset >> 1); | |
49 | 1629 |
9852 | 1630 decoder->b_motion.ref[1][0] = backward_fbuf[0] + offset; |
1631 decoder->b_motion.ref[1][1] = backward_fbuf[1] + (offset >> 1); | |
1632 decoder->b_motion.ref[1][2] = backward_fbuf[2] + (offset >> 1); | |
1633 | |
1634 stride <<= 1; | |
1635 height >>= 1; | |
1 | 1636 } |
1637 | |
9852 | 1638 decoder->stride = stride; |
1639 decoder->uv_stride = stride >> 1; | |
12932 | 1640 decoder->slice_stride = 16 * stride; |
1641 decoder->slice_uv_stride = | |
1642 decoder->slice_stride >> (2 - decoder->chroma_format); | |
9852 | 1643 decoder->limit_x = 2 * decoder->width - 32; |
1644 decoder->limit_y_16 = 2 * height - 32; | |
1645 decoder->limit_y_8 = 2 * height - 16; | |
1646 decoder->limit_y = height - 16; | |
12932 | 1647 |
1648 if (decoder->mpeg1) { | |
1649 decoder->motion_parser[0] = motion_zero_420; | |
1650 decoder->motion_parser[MC_FRAME] = motion_mp1; | |
1651 decoder->motion_parser[4] = motion_reuse_420; | |
1652 } else if (decoder->picture_structure == FRAME_PICTURE) { | |
1653 if (decoder->chroma_format == 0) { | |
1654 decoder->motion_parser[0] = motion_zero_420; | |
1655 decoder->motion_parser[MC_FIELD] = motion_fr_field_420; | |
1656 decoder->motion_parser[MC_FRAME] = motion_fr_frame_420; | |
1657 decoder->motion_parser[MC_DMV] = motion_fr_dmv_420; | |
1658 decoder->motion_parser[4] = motion_reuse_420; | |
1659 } else if (decoder->chroma_format == 1) { | |
1660 decoder->motion_parser[0] = motion_zero_422; | |
1661 decoder->motion_parser[MC_FIELD] = motion_fr_field_422; | |
1662 decoder->motion_parser[MC_FRAME] = motion_fr_frame_422; | |
1663 decoder->motion_parser[MC_DMV] = motion_fr_dmv_422; | |
1664 decoder->motion_parser[4] = motion_reuse_422; | |
1665 } else { | |
1666 decoder->motion_parser[0] = motion_zero_444; | |
1667 decoder->motion_parser[MC_FIELD] = motion_fr_field_444; | |
1668 decoder->motion_parser[MC_FRAME] = motion_fr_frame_444; | |
1669 decoder->motion_parser[MC_DMV] = motion_fr_dmv_444; | |
1670 decoder->motion_parser[4] = motion_reuse_444; | |
1671 } | |
1672 } else { | |
1673 if (decoder->chroma_format == 0) { | |
1674 decoder->motion_parser[0] = motion_zero_420; | |
1675 decoder->motion_parser[MC_FIELD] = motion_fi_field_420; | |
1676 decoder->motion_parser[MC_16X8] = motion_fi_16x8_420; | |
1677 decoder->motion_parser[MC_DMV] = motion_fi_dmv_420; | |
1678 decoder->motion_parser[4] = motion_reuse_420; | |
1679 } else if (decoder->chroma_format == 1) { | |
1680 decoder->motion_parser[0] = motion_zero_422; | |
1681 decoder->motion_parser[MC_FIELD] = motion_fi_field_422; | |
1682 decoder->motion_parser[MC_16X8] = motion_fi_16x8_422; | |
1683 decoder->motion_parser[MC_DMV] = motion_fi_dmv_422; | |
1684 decoder->motion_parser[4] = motion_reuse_422; | |
1685 } else { | |
1686 decoder->motion_parser[0] = motion_zero_444; | |
1687 decoder->motion_parser[MC_FIELD] = motion_fi_field_444; | |
1688 decoder->motion_parser[MC_16X8] = motion_fi_16x8_444; | |
1689 decoder->motion_parser[MC_DMV] = motion_fi_dmv_444; | |
1690 decoder->motion_parser[4] = motion_reuse_444; | |
1691 } | |
1692 } | |
9852 | 1693 } |
49 | 1694 |
12932 | 1695 static inline int slice_init (mpeg2_decoder_t * const decoder, int code) |
9852 | 1696 { |
1697 #define bit_buf (decoder->bitstream_buf) | |
1698 #define bits (decoder->bitstream_bits) | |
1699 #define bit_ptr (decoder->bitstream_ptr) | |
1700 int offset; | |
1701 const MBAtab * mba; | |
49 | 1702 |
9852 | 1703 decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = |
12932 | 1704 decoder->dc_dct_pred[2] = 16384; |
1 | 1705 |
9852 | 1706 decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; |
1707 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; | |
1708 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | |
1709 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | |
1 | 1710 |
9852 | 1711 if (decoder->vertical_position_extension) { |
1712 code += UBITS (bit_buf, 3) << 7; | |
1713 DUMPBITS (bit_buf, bits, 3); | |
1 | 1714 } |
9852 | 1715 decoder->v_offset = (code - 1) * 16; |
1716 offset = 0; | |
1717 if (!(decoder->convert) || decoder->coding_type != B_TYPE) | |
12932 | 1718 offset = (code - 1) * decoder->slice_stride; |
1 | 1719 |
12932 | 1720 decoder->dest[0] = decoder->picture_dest[0] + offset; |
1721 offset >>= (2 - decoder->chroma_format); | |
9852 | 1722 decoder->dest[1] = decoder->picture_dest[1] + offset; |
1723 decoder->dest[2] = decoder->picture_dest[2] + offset; | |
1 | 1724 |
12932 | 1725 get_quantizer_scale (decoder); |
1 | 1726 |
36 | 1727 /* ignore intra_slice and all the extra data */ |
1 | 1728 while (bit_buf & 0x80000000) { |
1729 DUMPBITS (bit_buf, bits, 9); | |
1730 NEEDBITS (bit_buf, bits, bit_ptr); | |
1731 } | |
9852 | 1732 |
1733 /* decode initial macroblock address increment */ | |
1734 offset = 0; | |
1735 while (1) { | |
1736 if (bit_buf >= 0x08000000) { | |
1737 mba = MBA_5 + (UBITS (bit_buf, 6) - 2); | |
1738 break; | |
1739 } else if (bit_buf >= 0x01800000) { | |
1740 mba = MBA_11 + (UBITS (bit_buf, 12) - 24); | |
1741 break; | |
1742 } else switch (UBITS (bit_buf, 12)) { | |
1743 case 8: /* macroblock_escape */ | |
1744 offset += 33; | |
1745 DUMPBITS (bit_buf, bits, 11); | |
1746 NEEDBITS (bit_buf, bits, bit_ptr); | |
1747 continue; | |
1748 case 15: /* macroblock_stuffing (MPEG1 only) */ | |
1749 bit_buf &= 0xfffff; | |
1750 DUMPBITS (bit_buf, bits, 11); | |
1751 NEEDBITS (bit_buf, bits, bit_ptr); | |
1752 continue; | |
1753 default: /* error */ | |
1754 return 1; | |
1755 } | |
1756 } | |
1757 DUMPBITS (bit_buf, bits, mba->len + 1); | |
1758 decoder->offset = (offset + mba->mba) << 4; | |
1 | 1759 |
9852 | 1760 while (decoder->offset - decoder->width >= 0) { |
1761 decoder->offset -= decoder->width; | |
1762 if (!(decoder->convert) || decoder->coding_type != B_TYPE) { | |
12932 | 1763 decoder->dest[0] += decoder->slice_stride; |
1764 decoder->dest[1] += decoder->slice_uv_stride; | |
1765 decoder->dest[2] += decoder->slice_uv_stride; | |
9852 | 1766 } |
1767 decoder->v_offset += 16; | |
1768 } | |
1769 if (decoder->v_offset > decoder->limit_y) | |
1770 return 1; | |
1771 | |
1772 return 0; | |
1773 #undef bit_buf | |
1774 #undef bits | |
1775 #undef bit_ptr | |
1776 } | |
1777 | |
12932 | 1778 void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, |
9852 | 1779 const uint8_t * const buffer) |
1780 { | |
1781 #define bit_buf (decoder->bitstream_buf) | |
1782 #define bits (decoder->bitstream_bits) | |
1783 #define bit_ptr (decoder->bitstream_ptr) | |
1784 cpu_state_t cpu_state; | |
1785 | |
1786 bitstream_init (decoder, buffer); | |
1787 | |
1788 if (slice_init (decoder, code)) | |
1789 return; | |
1790 | |
1791 if (mpeg2_cpu_state_save) | |
1792 mpeg2_cpu_state_save (&cpu_state); | |
1 | 1793 |
1794 while (1) { | |
9852 | 1795 int macroblock_modes; |
1796 int mba_inc; | |
1797 const MBAtab * mba; | |
1798 | |
1 | 1799 NEEDBITS (bit_buf, bits, bit_ptr); |
1800 | |
9852 | 1801 macroblock_modes = get_macroblock_modes (decoder); |
1 | 1802 |
36 | 1803 /* maybe integrate MACROBLOCK_QUANT test into get_macroblock_modes ? */ |
1 | 1804 if (macroblock_modes & MACROBLOCK_QUANT) |
12932 | 1805 get_quantizer_scale (decoder); |
1 | 1806 |
1807 if (macroblock_modes & MACROBLOCK_INTRA) { | |
1808 | |
1809 int DCT_offset, DCT_stride; | |
9852 | 1810 int offset; |
1811 uint8_t * dest_y; | |
1 | 1812 |
9852 | 1813 if (decoder->concealment_motion_vectors) { |
1814 if (decoder->picture_structure == FRAME_PICTURE) | |
1815 motion_fr_conceal (decoder); | |
1 | 1816 else |
9852 | 1817 motion_fi_conceal (decoder); |
1 | 1818 } else { |
9852 | 1819 decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; |
1820 decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; | |
1821 decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | |
1822 decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | |
1 | 1823 } |
1824 | |
1825 if (macroblock_modes & DCT_TYPE_INTERLACED) { | |
9852 | 1826 DCT_offset = decoder->stride; |
1827 DCT_stride = decoder->stride * 2; | |
1 | 1828 } else { |
9852 | 1829 DCT_offset = decoder->stride * 8; |
1830 DCT_stride = decoder->stride; | |
1 | 1831 } |
1832 | |
9852 | 1833 offset = decoder->offset; |
1834 dest_y = decoder->dest[0] + offset; | |
1835 slice_intra_DCT (decoder, 0, dest_y, DCT_stride); | |
1836 slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride); | |
1837 slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride); | |
1838 slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride); | |
12932 | 1839 if (likely (decoder->chroma_format == 0)) { |
1840 slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1), | |
1841 decoder->uv_stride); | |
1842 slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1), | |
1843 decoder->uv_stride); | |
1844 if (decoder->coding_type == D_TYPE) { | |
1845 NEEDBITS (bit_buf, bits, bit_ptr); | |
1846 DUMPBITS (bit_buf, bits, 1); | |
1847 } | |
1848 } else if (likely (decoder->chroma_format == 1)) { | |
1849 uint8_t * dest_u = decoder->dest[1] + (offset >> 1); | |
1850 uint8_t * dest_v = decoder->dest[2] + (offset >> 1); | |
1851 DCT_stride >>= 1; | |
1852 DCT_offset >>= 1; | |
1853 slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | |
1854 slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | |
1855 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | |
1856 slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); | |
1857 } else { | |
1858 uint8_t * dest_u = decoder->dest[1] + offset; | |
1859 uint8_t * dest_v = decoder->dest[2] + offset; | |
1860 slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | |
1861 slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | |
1862 slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | |
1863 slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); | |
1864 slice_intra_DCT (decoder, 1, dest_u + 8, DCT_stride); | |
1865 slice_intra_DCT (decoder, 2, dest_v + 8, DCT_stride); | |
1866 slice_intra_DCT (decoder, 1, dest_u + DCT_offset + 8, | |
1867 DCT_stride); | |
1868 slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8, | |
1869 DCT_stride); | |
1 | 1870 } |
1871 } else { | |
1872 | |
12932 | 1873 motion_parser_t * parser; |
1 | 1874 |
12932 | 1875 parser = |
1876 decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT]; | |
1877 MOTION_CALL (parser, macroblock_modes); | |
1 | 1878 |
1879 if (macroblock_modes & MACROBLOCK_PATTERN) { | |
1880 int coded_block_pattern; | |
1881 int DCT_offset, DCT_stride; | |
1882 | |
1883 if (macroblock_modes & DCT_TYPE_INTERLACED) { | |
9852 | 1884 DCT_offset = decoder->stride; |
1885 DCT_stride = decoder->stride * 2; | |
1 | 1886 } else { |
9852 | 1887 DCT_offset = decoder->stride * 8; |
1888 DCT_stride = decoder->stride; | |
1 | 1889 } |
1890 | |
9852 | 1891 coded_block_pattern = get_coded_block_pattern (decoder); |
1 | 1892 |
12932 | 1893 if (likely (decoder->chroma_format == 0)) { |
1894 int offset = decoder->offset; | |
1895 uint8_t * dest_y = decoder->dest[0] + offset; | |
1896 if (coded_block_pattern & 1) | |
1897 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | |
1898 if (coded_block_pattern & 2) | |
1899 slice_non_intra_DCT (decoder, 0, dest_y + 8, | |
1900 DCT_stride); | |
1901 if (coded_block_pattern & 4) | |
1902 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | |
1903 DCT_stride); | |
1904 if (coded_block_pattern & 8) | |
1905 slice_non_intra_DCT (decoder, 0, | |
1906 dest_y + DCT_offset + 8, | |
1907 DCT_stride); | |
1908 if (coded_block_pattern & 16) | |
1909 slice_non_intra_DCT (decoder, 1, | |
1910 decoder->dest[1] + (offset >> 1), | |
1911 decoder->uv_stride); | |
1912 if (coded_block_pattern & 32) | |
1913 slice_non_intra_DCT (decoder, 2, | |
1914 decoder->dest[2] + (offset >> 1), | |
1915 decoder->uv_stride); | |
1916 } else if (likely (decoder->chroma_format == 1)) { | |
1917 int offset; | |
1918 uint8_t * dest_y; | |
1919 | |
1920 coded_block_pattern |= bit_buf & (3 << 30); | |
1921 DUMPBITS (bit_buf, bits, 2); | |
1922 | |
1923 offset = decoder->offset; | |
1924 dest_y = decoder->dest[0] + offset; | |
1925 if (coded_block_pattern & 1) | |
1926 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | |
1927 if (coded_block_pattern & 2) | |
1928 slice_non_intra_DCT (decoder, 0, dest_y + 8, | |
1929 DCT_stride); | |
1930 if (coded_block_pattern & 4) | |
1931 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | |
1932 DCT_stride); | |
1933 if (coded_block_pattern & 8) | |
1934 slice_non_intra_DCT (decoder, 0, | |
1935 dest_y + DCT_offset + 8, | |
1936 DCT_stride); | |
1937 | |
1938 DCT_stride >>= 1; | |
1939 DCT_offset = (DCT_offset + offset) >> 1; | |
1940 if (coded_block_pattern & 16) | |
1941 slice_non_intra_DCT (decoder, 1, | |
1942 decoder->dest[1] + (offset >> 1), | |
1943 DCT_stride); | |
1944 if (coded_block_pattern & 32) | |
1945 slice_non_intra_DCT (decoder, 2, | |
1946 decoder->dest[2] + (offset >> 1), | |
1947 DCT_stride); | |
1948 if (coded_block_pattern & (2 << 30)) | |
1949 slice_non_intra_DCT (decoder, 1, | |
1950 decoder->dest[1] + DCT_offset, | |
1951 DCT_stride); | |
1952 if (coded_block_pattern & (1 << 30)) | |
1953 slice_non_intra_DCT (decoder, 2, | |
1954 decoder->dest[2] + DCT_offset, | |
1955 DCT_stride); | |
1956 } else { | |
1957 int offset; | |
1958 uint8_t * dest_y, * dest_u, * dest_v; | |
1959 | |
1960 coded_block_pattern |= bit_buf & (63 << 26); | |
1961 DUMPBITS (bit_buf, bits, 6); | |
1962 | |
1963 offset = decoder->offset; | |
1964 dest_y = decoder->dest[0] + offset; | |
1965 dest_u = decoder->dest[1] + offset; | |
1966 dest_v = decoder->dest[2] + offset; | |
1967 | |
1968 if (coded_block_pattern & 1) | |
1969 slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | |
1970 if (coded_block_pattern & 2) | |
1971 slice_non_intra_DCT (decoder, 0, dest_y + 8, | |
1972 DCT_stride); | |
1973 if (coded_block_pattern & 4) | |
1974 slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | |
1975 DCT_stride); | |
1976 if (coded_block_pattern & 8) | |
1977 slice_non_intra_DCT (decoder, 0, | |
1978 dest_y + DCT_offset + 8, | |
1979 DCT_stride); | |
1980 | |
1981 if (coded_block_pattern & 16) | |
1982 slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride); | |
1983 if (coded_block_pattern & 32) | |
1984 slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride); | |
1985 if (coded_block_pattern & (32 << 26)) | |
1986 slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset, | |
1987 DCT_stride); | |
1988 if (coded_block_pattern & (16 << 26)) | |
1989 slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset, | |
1990 DCT_stride); | |
1991 if (coded_block_pattern & (8 << 26)) | |
1992 slice_non_intra_DCT (decoder, 1, dest_u + 8, | |
1993 DCT_stride); | |
1994 if (coded_block_pattern & (4 << 26)) | |
1995 slice_non_intra_DCT (decoder, 2, dest_v + 8, | |
1996 DCT_stride); | |
1997 if (coded_block_pattern & (2 << 26)) | |
1998 slice_non_intra_DCT (decoder, 1, | |
1999 dest_u + DCT_offset + 8, | |
2000 DCT_stride); | |
2001 if (coded_block_pattern & (1 << 26)) | |
2002 slice_non_intra_DCT (decoder, 2, | |
2003 dest_v + DCT_offset + 8, | |
2004 DCT_stride); | |
2005 } | |
1 | 2006 } |
2007 | |
9852 | 2008 decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = |
12932 | 2009 decoder->dc_dct_pred[2] = 16384; |
1 | 2010 } |
2011 | |
9852 | 2012 NEXT_MACROBLOCK; |
1 | 2013 |
2014 NEEDBITS (bit_buf, bits, bit_ptr); | |
9852 | 2015 mba_inc = 0; |
2016 while (1) { | |
2017 if (bit_buf >= 0x10000000) { | |
2018 mba = MBA_5 + (UBITS (bit_buf, 5) - 2); | |
2019 break; | |
2020 } else if (bit_buf >= 0x03000000) { | |
2021 mba = MBA_11 + (UBITS (bit_buf, 11) - 24); | |
2022 break; | |
2023 } else switch (UBITS (bit_buf, 11)) { | |
2024 case 8: /* macroblock_escape */ | |
2025 mba_inc += 33; | |
2026 /* pass through */ | |
2027 case 15: /* macroblock_stuffing (MPEG1 only) */ | |
2028 DUMPBITS (bit_buf, bits, 11); | |
2029 NEEDBITS (bit_buf, bits, bit_ptr); | |
142 | 2030 continue; |
9852 | 2031 default: /* end of slice, or error */ |
2032 if (mpeg2_cpu_state_restore) | |
2033 mpeg2_cpu_state_restore (&cpu_state); | |
2034 return; | |
2035 } | |
2036 } | |
2037 DUMPBITS (bit_buf, bits, mba->len); | |
2038 mba_inc += mba->mba; | |
1 | 2039 |
9852 | 2040 if (mba_inc) { |
2041 decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = | |
12932 | 2042 decoder->dc_dct_pred[2] = 16384; |
1 | 2043 |
9852 | 2044 if (decoder->coding_type == P_TYPE) { |
1 | 2045 do { |
12932 | 2046 MOTION_CALL (decoder->motion_parser[0], |
2047 MACROBLOCK_MOTION_FORWARD); | |
9852 | 2048 NEXT_MACROBLOCK; |
1 | 2049 } while (--mba_inc); |
2050 } else { | |
2051 do { | |
12932 | 2052 MOTION_CALL (decoder->motion_parser[4], macroblock_modes); |
9852 | 2053 NEXT_MACROBLOCK; |
1 | 2054 } while (--mba_inc); |
2055 } | |
2056 } | |
2057 } | |
2058 #undef bit_buf | |
2059 #undef bits | |
2060 #undef bit_ptr | |
2061 } |