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