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