diff options
Diffstat (limited to 'apps/plugins/mpegplayer/slice.c')
-rw-r--r-- | apps/plugins/mpegplayer/slice.c | 1453 |
1 files changed, 886 insertions, 567 deletions
diff --git a/apps/plugins/mpegplayer/slice.c b/apps/plugins/mpegplayer/slice.c index 7c1c07bf37..a039eb8a25 100644 --- a/apps/plugins/mpegplayer/slice.c +++ b/apps/plugins/mpegplayer/slice.c | |||
@@ -30,11 +30,6 @@ | |||
30 | #include "attributes.h" | 30 | #include "attributes.h" |
31 | #include "mpeg2_internal.h" | 31 | #include "mpeg2_internal.h" |
32 | 32 | ||
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 | |||
38 | #include "vlc.h" | 33 | #include "vlc.h" |
39 | 34 | ||
40 | static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) | 35 | static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) |
@@ -42,18 +37,20 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) | |||
42 | #define bit_buf (decoder->bitstream_buf) | 37 | #define bit_buf (decoder->bitstream_buf) |
43 | #define bits (decoder->bitstream_bits) | 38 | #define bits (decoder->bitstream_bits) |
44 | #define bit_ptr (decoder->bitstream_ptr) | 39 | #define bit_ptr (decoder->bitstream_ptr) |
40 | |||
45 | int macroblock_modes; | 41 | int macroblock_modes; |
46 | const MBtab * tab; | 42 | const MBtab * tab; |
47 | 43 | ||
48 | switch (decoder->coding_type) { | 44 | switch (decoder->coding_type) |
45 | { | ||
49 | case I_TYPE: | 46 | case I_TYPE: |
50 | |||
51 | tab = MB_I + UBITS (bit_buf, 1); | 47 | tab = MB_I + UBITS (bit_buf, 1); |
52 | DUMPBITS (bit_buf, bits, tab->len); | 48 | DUMPBITS (bit_buf, bits, tab->len); |
53 | macroblock_modes = tab->modes; | 49 | macroblock_modes = tab->modes; |
54 | 50 | ||
55 | if ((! (decoder->frame_pred_frame_dct)) && | 51 | if (!(decoder->frame_pred_frame_dct) && |
56 | (decoder->picture_structure == FRAME_PICTURE)) { | 52 | decoder->picture_structure == FRAME_PICTURE) |
53 | { | ||
57 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | 54 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; |
58 | DUMPBITS (bit_buf, bits, 1); | 55 | DUMPBITS (bit_buf, bits, 1); |
59 | } | 56 | } |
@@ -61,55 +58,75 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) | |||
61 | return macroblock_modes; | 58 | return macroblock_modes; |
62 | 59 | ||
63 | case P_TYPE: | 60 | case P_TYPE: |
64 | |||
65 | tab = MB_P + UBITS (bit_buf, 5); | 61 | tab = MB_P + UBITS (bit_buf, 5); |
66 | DUMPBITS (bit_buf, bits, tab->len); | 62 | DUMPBITS (bit_buf, bits, tab->len); |
67 | macroblock_modes = tab->modes; | 63 | macroblock_modes = tab->modes; |
68 | 64 | ||
69 | if (decoder->picture_structure != FRAME_PICTURE) { | 65 | if (decoder->picture_structure != FRAME_PICTURE) |
70 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { | 66 | { |
67 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | ||
68 | { | ||
71 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | 69 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
72 | DUMPBITS (bit_buf, bits, 2); | 70 | DUMPBITS (bit_buf, bits, 2); |
73 | } | 71 | } |
72 | |||
74 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | 73 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; |
75 | } else if (decoder->frame_pred_frame_dct) { | 74 | } |
75 | else if (decoder->frame_pred_frame_dct) | ||
76 | { | ||
76 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | 77 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) |
77 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; | 78 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; |
79 | |||
78 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | 80 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; |
79 | } else { | 81 | } |
80 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) { | 82 | else |
83 | { | ||
84 | if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) | ||
85 | { | ||
81 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | 86 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
82 | DUMPBITS (bit_buf, bits, 2); | 87 | DUMPBITS (bit_buf, bits, 2); |
83 | } | 88 | } |
84 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { | 89 | |
90 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) | ||
91 | { | ||
85 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | 92 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; |
86 | DUMPBITS (bit_buf, bits, 1); | 93 | DUMPBITS (bit_buf, bits, 1); |
87 | } | 94 | } |
95 | |||
88 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; | 96 | return macroblock_modes | MACROBLOCK_MOTION_FORWARD; |
89 | } | 97 | } |
90 | 98 | ||
91 | case B_TYPE: | 99 | case B_TYPE: |
92 | |||
93 | tab = MB_B + UBITS (bit_buf, 6); | 100 | tab = MB_B + UBITS (bit_buf, 6); |
94 | DUMPBITS (bit_buf, bits, tab->len); | 101 | DUMPBITS (bit_buf, bits, tab->len); |
95 | macroblock_modes = tab->modes; | 102 | macroblock_modes = tab->modes; |
96 | 103 | ||
97 | if (decoder->picture_structure != FRAME_PICTURE) { | 104 | if (decoder->picture_structure != FRAME_PICTURE) |
98 | if (! (macroblock_modes & MACROBLOCK_INTRA)) { | 105 | { |
106 | if (! (macroblock_modes & MACROBLOCK_INTRA)) | ||
107 | { | ||
99 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | 108 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
100 | DUMPBITS (bit_buf, bits, 2); | 109 | DUMPBITS (bit_buf, bits, 2); |
101 | } | 110 | } |
111 | |||
102 | return macroblock_modes; | 112 | return macroblock_modes; |
103 | } else if (decoder->frame_pred_frame_dct) { | 113 | } |
114 | else if (decoder->frame_pred_frame_dct) | ||
115 | { | ||
104 | /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ | 116 | /* if (! (macroblock_modes & MACROBLOCK_INTRA)) */ |
105 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; | 117 | macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT; |
106 | return macroblock_modes; | 118 | return macroblock_modes; |
107 | } else { | 119 | } |
120 | else | ||
121 | { | ||
108 | if (macroblock_modes & MACROBLOCK_INTRA) | 122 | if (macroblock_modes & MACROBLOCK_INTRA) |
109 | goto intra; | 123 | goto intra; |
124 | |||
110 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; | 125 | macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT; |
111 | DUMPBITS (bit_buf, bits, 2); | 126 | DUMPBITS (bit_buf, bits, 2); |
112 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) { | 127 | |
128 | if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) | ||
129 | { | ||
113 | intra: | 130 | intra: |
114 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; | 131 | macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED; |
115 | DUMPBITS (bit_buf, bits, 1); | 132 | DUMPBITS (bit_buf, bits, 1); |
@@ -118,7 +135,6 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder) | |||
118 | } | 135 | } |
119 | 136 | ||
120 | case D_TYPE: | 137 | case D_TYPE: |
121 | |||
122 | DUMPBITS (bit_buf, bits, 1); | 138 | DUMPBITS (bit_buf, bits, 1); |
123 | return MACROBLOCK_INTRA; | 139 | return MACROBLOCK_INTRA; |
124 | 140 | ||
@@ -143,10 +159,13 @@ static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder) | |||
143 | 159 | ||
144 | decoder->quantizer_matrix[0] = | 160 | decoder->quantizer_matrix[0] = |
145 | decoder->quantizer_prescale[0][quantizer_scale_code]; | 161 | decoder->quantizer_prescale[0][quantizer_scale_code]; |
162 | |||
146 | decoder->quantizer_matrix[1] = | 163 | decoder->quantizer_matrix[1] = |
147 | decoder->quantizer_prescale[1][quantizer_scale_code]; | 164 | decoder->quantizer_prescale[1][quantizer_scale_code]; |
165 | |||
148 | decoder->quantizer_matrix[2] = | 166 | decoder->quantizer_matrix[2] = |
149 | decoder->chroma_quantizer[0][quantizer_scale_code]; | 167 | decoder->chroma_quantizer[0][quantizer_scale_code]; |
168 | |||
150 | decoder->quantizer_matrix[3] = | 169 | decoder->quantizer_matrix[3] = |
151 | decoder->chroma_quantizer[1][quantizer_scale_code]; | 170 | decoder->chroma_quantizer[1][quantizer_scale_code]; |
152 | #undef bit_buf | 171 | #undef bit_buf |
@@ -165,11 +184,13 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder, | |||
165 | int sign; | 184 | int sign; |
166 | const MVtab * tab; | 185 | const MVtab * tab; |
167 | 186 | ||
168 | if (bit_buf & 0x80000000) { | 187 | if (bit_buf & 0x80000000) |
188 | { | ||
169 | DUMPBITS (bit_buf, bits, 1); | 189 | DUMPBITS (bit_buf, bits, 1); |
170 | return 0; | 190 | return 0; |
171 | } else if (bit_buf >= 0x0c000000) { | 191 | } |
172 | 192 | else if (bit_buf >= 0x0c000000) | |
193 | { | ||
173 | tab = MV_4 + UBITS (bit_buf, 4); | 194 | tab = MV_4 + UBITS (bit_buf, 4); |
174 | delta = (tab->delta << f_code) + 1; | 195 | delta = (tab->delta << f_code) + 1; |
175 | bits += tab->len + f_code + 1; | 196 | bits += tab->len + f_code + 1; |
@@ -183,9 +204,9 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder, | |||
183 | bit_buf <<= f_code; | 204 | bit_buf <<= f_code; |
184 | 205 | ||
185 | return (delta ^ sign) - sign; | 206 | return (delta ^ sign) - sign; |
186 | 207 | } | |
187 | } else { | 208 | else |
188 | 209 | { | |
189 | tab = MV_10 + UBITS (bit_buf, 10); | 210 | tab = MV_10 + UBITS (bit_buf, 10); |
190 | delta = (tab->delta << f_code) + 1; | 211 | delta = (tab->delta << f_code) + 1; |
191 | bits += tab->len + 1; | 212 | bits += tab->len + 1; |
@@ -194,7 +215,8 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder, | |||
194 | sign = SBITS (bit_buf, 1); | 215 | sign = SBITS (bit_buf, 1); |
195 | bit_buf <<= 1; | 216 | bit_buf <<= 1; |
196 | 217 | ||
197 | if (f_code) { | 218 | if (f_code) |
219 | { | ||
198 | NEEDBITS (bit_buf, bits, bit_ptr); | 220 | NEEDBITS (bit_buf, bits, bit_ptr); |
199 | delta += UBITS (bit_buf, f_code); | 221 | delta += UBITS (bit_buf, f_code); |
200 | DUMPBITS (bit_buf, bits, f_code); | 222 | DUMPBITS (bit_buf, bits, f_code); |
@@ -224,6 +246,7 @@ static inline int get_dmv (mpeg2_decoder_t * const decoder) | |||
224 | tab = DMV_2 + UBITS (bit_buf, 2); | 246 | tab = DMV_2 + UBITS (bit_buf, 2); |
225 | DUMPBITS (bit_buf, bits, tab->len); | 247 | DUMPBITS (bit_buf, bits, tab->len); |
226 | return tab->dmv; | 248 | return tab->dmv; |
249 | |||
227 | #undef bit_buf | 250 | #undef bit_buf |
228 | #undef bits | 251 | #undef bits |
229 | #undef bit_ptr | 252 | #undef bit_ptr |
@@ -239,14 +262,14 @@ static inline int get_coded_block_pattern (mpeg2_decoder_t * const decoder) | |||
239 | 262 | ||
240 | NEEDBITS (bit_buf, bits, bit_ptr); | 263 | NEEDBITS (bit_buf, bits, bit_ptr); |
241 | 264 | ||
242 | if (bit_buf >= 0x20000000) { | 265 | if (bit_buf >= 0x20000000) |
243 | 266 | { | |
244 | tab = CBP_7 + (UBITS (bit_buf, 7) - 16); | 267 | tab = CBP_7 + (UBITS (bit_buf, 7) - 16); |
245 | DUMPBITS (bit_buf, bits, tab->len); | 268 | DUMPBITS (bit_buf, bits, tab->len); |
246 | return tab->cbp; | 269 | return tab->cbp; |
247 | 270 | } | |
248 | } else { | 271 | else |
249 | 272 | { | |
250 | tab = CBP_9 + UBITS (bit_buf, 9); | 273 | tab = CBP_9 + UBITS (bit_buf, 9); |
251 | DUMPBITS (bit_buf, bits, tab->len); | 274 | DUMPBITS (bit_buf, bits, tab->len); |
252 | return tab->cbp; | 275 | return tab->cbp; |
@@ -262,25 +285,33 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder) | |||
262 | #define bit_buf (decoder->bitstream_buf) | 285 | #define bit_buf (decoder->bitstream_buf) |
263 | #define bits (decoder->bitstream_bits) | 286 | #define bits (decoder->bitstream_bits) |
264 | #define bit_ptr (decoder->bitstream_ptr) | 287 | #define bit_ptr (decoder->bitstream_ptr) |
288 | |||
265 | const DCtab * tab; | 289 | const DCtab * tab; |
266 | int size; | 290 | int size; |
267 | int dc_diff; | 291 | int dc_diff; |
268 | 292 | ||
269 | if (bit_buf < 0xf8000000) { | 293 | if (bit_buf < 0xf8000000) |
294 | { | ||
270 | tab = DC_lum_5 + UBITS (bit_buf, 5); | 295 | tab = DC_lum_5 + UBITS (bit_buf, 5); |
271 | size = tab->size; | 296 | size = tab->size; |
272 | if (size) { | 297 | |
298 | if (size) | ||
299 | { | ||
273 | bits += tab->len + size; | 300 | bits += tab->len + size; |
274 | bit_buf <<= tab->len; | 301 | bit_buf <<= tab->len; |
275 | dc_diff = | 302 | dc_diff = |
276 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | 303 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); |
277 | bit_buf <<= size; | 304 | bit_buf <<= size; |
278 | return dc_diff << decoder->intra_dc_precision; | 305 | return dc_diff << decoder->intra_dc_precision; |
279 | } else { | 306 | } |
307 | else | ||
308 | { | ||
280 | DUMPBITS (bit_buf, bits, 3); | 309 | DUMPBITS (bit_buf, bits, 3); |
281 | return 0; | 310 | return 0; |
282 | } | 311 | } |
283 | } else { | 312 | } |
313 | else | ||
314 | { | ||
284 | tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); | 315 | tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0); |
285 | size = tab->size; | 316 | size = tab->size; |
286 | DUMPBITS (bit_buf, bits, tab->len); | 317 | DUMPBITS (bit_buf, bits, tab->len); |
@@ -289,6 +320,7 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder) | |||
289 | DUMPBITS (bit_buf, bits, size); | 320 | DUMPBITS (bit_buf, bits, size); |
290 | return dc_diff << decoder->intra_dc_precision; | 321 | return dc_diff << decoder->intra_dc_precision; |
291 | } | 322 | } |
323 | |||
292 | #undef bit_buf | 324 | #undef bit_buf |
293 | #undef bits | 325 | #undef bits |
294 | #undef bit_ptr | 326 | #undef bit_ptr |
@@ -299,25 +331,33 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder) | |||
299 | #define bit_buf (decoder->bitstream_buf) | 331 | #define bit_buf (decoder->bitstream_buf) |
300 | #define bits (decoder->bitstream_bits) | 332 | #define bits (decoder->bitstream_bits) |
301 | #define bit_ptr (decoder->bitstream_ptr) | 333 | #define bit_ptr (decoder->bitstream_ptr) |
334 | |||
302 | const DCtab * tab; | 335 | const DCtab * tab; |
303 | int size; | 336 | int size; |
304 | int dc_diff; | 337 | int dc_diff; |
305 | 338 | ||
306 | if (bit_buf < 0xf8000000) { | 339 | if (bit_buf < 0xf8000000) |
340 | { | ||
307 | tab = DC_chrom_5 + UBITS (bit_buf, 5); | 341 | tab = DC_chrom_5 + UBITS (bit_buf, 5); |
308 | size = tab->size; | 342 | size = tab->size; |
309 | if (size) { | 343 | |
344 | if (size) | ||
345 | { | ||
310 | bits += tab->len + size; | 346 | bits += tab->len + size; |
311 | bit_buf <<= tab->len; | 347 | bit_buf <<= tab->len; |
312 | dc_diff = | 348 | dc_diff = |
313 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); | 349 | UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size); |
314 | bit_buf <<= size; | 350 | bit_buf <<= size; |
315 | return dc_diff << decoder->intra_dc_precision; | 351 | return dc_diff << decoder->intra_dc_precision; |
316 | } else { | 352 | } |
353 | else | ||
354 | { | ||
317 | DUMPBITS (bit_buf, bits, 2); | 355 | DUMPBITS (bit_buf, bits, 2); |
318 | return 0; | 356 | return 0; |
319 | } | 357 | } |
320 | } else { | 358 | } |
359 | else | ||
360 | { | ||
321 | tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); | 361 | tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0); |
322 | size = tab->size; | 362 | size = tab->size; |
323 | DUMPBITS (bit_buf, bits, tab->len + 1); | 363 | DUMPBITS (bit_buf, bits, tab->len + 1); |
@@ -326,17 +366,18 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder) | |||
326 | DUMPBITS (bit_buf, bits, size); | 366 | DUMPBITS (bit_buf, bits, size); |
327 | return dc_diff << decoder->intra_dc_precision; | 367 | return dc_diff << decoder->intra_dc_precision; |
328 | } | 368 | } |
369 | |||
329 | #undef bit_buf | 370 | #undef bit_buf |
330 | #undef bits | 371 | #undef bits |
331 | #undef bit_ptr | 372 | #undef bit_ptr |
332 | } | 373 | } |
333 | 374 | ||
334 | #define SATURATE(val) \ | 375 | #define SATURATE(val) \ |
335 | do { \ | 376 | do { \ |
336 | val <<= 4; \ | 377 | val <<= 4; \ |
337 | if (unlikely (val != (int16_t) val)) \ | 378 | if (unlikely (val != (int16_t) val)) \ |
338 | val = (SBITS (val, 1) ^ 2047) << 4; \ | 379 | val = (SBITS (val, 1) ^ 2047) << 4; \ |
339 | } while (0) | 380 | } while (0) |
340 | 381 | ||
341 | static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | 382 | static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, |
342 | const uint16_t * const quant_matrix) | 383 | const uint16_t * const quant_matrix) |
@@ -361,9 +402,10 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | |||
361 | 402 | ||
362 | NEEDBITS (bit_buf, bits, bit_ptr); | 403 | NEEDBITS (bit_buf, bits, bit_ptr); |
363 | 404 | ||
364 | while (1) { | 405 | while (1) |
365 | if (bit_buf >= 0x28000000) { | 406 | { |
366 | 407 | if (bit_buf >= 0x28000000) | |
408 | { | ||
367 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | 409 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
368 | 410 | ||
369 | i += tab->run; | 411 | i += tab->run; |
@@ -387,9 +429,9 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | |||
387 | NEEDBITS (bit_buf, bits, bit_ptr); | 429 | NEEDBITS (bit_buf, bits, bit_ptr); |
388 | 430 | ||
389 | continue; | 431 | continue; |
390 | 432 | } | |
391 | } else if (bit_buf >= 0x04000000) { | 433 | else if (bit_buf >= 0x04000000) |
392 | 434 | { | |
393 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | 435 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
394 | 436 | ||
395 | i += tab->run; | 437 | i += tab->run; |
@@ -416,23 +458,30 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | |||
416 | NEEDBITS (bit_buf, bits, bit_ptr); | 458 | NEEDBITS (bit_buf, bits, bit_ptr); |
417 | 459 | ||
418 | continue; | 460 | continue; |
419 | 461 | } | |
420 | } else if (bit_buf >= 0x02000000) { | 462 | else if (bit_buf >= 0x02000000) |
463 | { | ||
421 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | 464 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
422 | i += tab->run; | 465 | i += tab->run; |
423 | if (i < 64) | 466 | if (i < 64) |
424 | goto normal_code; | 467 | goto normal_code; |
425 | } else if (bit_buf >= 0x00800000) { | 468 | } |
469 | else if (bit_buf >= 0x00800000) | ||
470 | { | ||
426 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | 471 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
427 | i += tab->run; | 472 | i += tab->run; |
428 | if (i < 64) | 473 | if (i < 64) |
429 | goto normal_code; | 474 | goto normal_code; |
430 | } else if (bit_buf >= 0x00200000) { | 475 | } |
476 | else if (bit_buf >= 0x00200000) | ||
477 | { | ||
431 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | 478 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
432 | i += tab->run; | 479 | i += tab->run; |
433 | if (i < 64) | 480 | if (i < 64) |
434 | goto normal_code; | 481 | goto normal_code; |
435 | } else { | 482 | } |
483 | else | ||
484 | { | ||
436 | tab = DCT_16 + UBITS (bit_buf, 16); | 485 | tab = DCT_16 + UBITS (bit_buf, 16); |
437 | bit_buf <<= 16; | 486 | bit_buf <<= 16; |
438 | GETWORD (bit_buf, bits + 16, bit_ptr); | 487 | GETWORD (bit_buf, bits + 16, bit_ptr); |
@@ -442,6 +491,7 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder, | |||
442 | } | 491 | } |
443 | break; /* illegal, check needed to avoid buffer overflow */ | 492 | break; /* illegal, check needed to avoid buffer overflow */ |
444 | } | 493 | } |
494 | |||
445 | dest[63] ^= mismatch & 16; | 495 | dest[63] ^= mismatch & 16; |
446 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | 496 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
447 | decoder->bitstream_buf = bit_buf; | 497 | decoder->bitstream_buf = bit_buf; |
@@ -472,14 +522,16 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, | |||
472 | 522 | ||
473 | NEEDBITS (bit_buf, bits, bit_ptr); | 523 | NEEDBITS (bit_buf, bits, bit_ptr); |
474 | 524 | ||
475 | while (1) { | 525 | while (1) |
476 | if (bit_buf >= 0x04000000) { | 526 | { |
477 | 527 | if (bit_buf >= 0x04000000) | |
528 | { | ||
478 | tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); | 529 | tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4); |
479 | 530 | ||
480 | i += tab->run; | 531 | i += tab->run; |
481 | if (i < 64) { | ||
482 | 532 | ||
533 | if (i < 64) | ||
534 | { | ||
483 | normal_code: | 535 | normal_code: |
484 | j = scan[i]; | 536 | j = scan[i]; |
485 | bit_buf <<= tab->len; | 537 | bit_buf <<= tab->len; |
@@ -497,9 +549,9 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, | |||
497 | NEEDBITS (bit_buf, bits, bit_ptr); | 549 | NEEDBITS (bit_buf, bits, bit_ptr); |
498 | 550 | ||
499 | continue; | 551 | continue; |
500 | 552 | } | |
501 | } else { | 553 | else |
502 | 554 | { | |
503 | /* end of block. I commented out this code because if we */ | 555 | /* end of block. I commented out this code because if we */ |
504 | /* dont exit here we will still exit at the later test :) */ | 556 | /* dont exit here we will still exit at the later test :) */ |
505 | 557 | ||
@@ -525,24 +577,31 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, | |||
525 | NEEDBITS (bit_buf, bits, bit_ptr); | 577 | NEEDBITS (bit_buf, bits, bit_ptr); |
526 | 578 | ||
527 | continue; | 579 | continue; |
528 | |||
529 | } | 580 | } |
530 | } else if (bit_buf >= 0x02000000) { | 581 | } |
582 | else if (bit_buf >= 0x02000000) | ||
583 | { | ||
531 | tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); | 584 | tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8); |
532 | i += tab->run; | 585 | i += tab->run; |
533 | if (i < 64) | 586 | if (i < 64) |
534 | goto normal_code; | 587 | goto normal_code; |
535 | } else if (bit_buf >= 0x00800000) { | 588 | } |
589 | else if (bit_buf >= 0x00800000) | ||
590 | { | ||
536 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | 591 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
537 | i += tab->run; | 592 | i += tab->run; |
538 | if (i < 64) | 593 | if (i < 64) |
539 | goto normal_code; | 594 | goto normal_code; |
540 | } else if (bit_buf >= 0x00200000) { | 595 | } |
596 | else if (bit_buf >= 0x00200000) | ||
597 | { | ||
541 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | 598 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
542 | i += tab->run; | 599 | i += tab->run; |
543 | if (i < 64) | 600 | if (i < 64) |
544 | goto normal_code; | 601 | goto normal_code; |
545 | } else { | 602 | } |
603 | else | ||
604 | { | ||
546 | tab = DCT_16 + UBITS (bit_buf, 16); | 605 | tab = DCT_16 + UBITS (bit_buf, 16); |
547 | bit_buf <<= 16; | 606 | bit_buf <<= 16; |
548 | GETWORD (bit_buf, bits + 16, bit_ptr); | 607 | GETWORD (bit_buf, bits + 16, bit_ptr); |
@@ -552,6 +611,7 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder, | |||
552 | } | 611 | } |
553 | break; /* illegal, check needed to avoid buffer overflow */ | 612 | break; /* illegal, check needed to avoid buffer overflow */ |
554 | } | 613 | } |
614 | |||
555 | dest[63] ^= mismatch & 16; | 615 | dest[63] ^= mismatch & 16; |
556 | DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ | 616 | DUMPBITS (bit_buf, bits, 4); /* dump end of block code */ |
557 | decoder->bitstream_buf = bit_buf; | 617 | decoder->bitstream_buf = bit_buf; |
@@ -581,15 +641,21 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder, | |||
581 | bit_ptr = decoder->bitstream_ptr; | 641 | bit_ptr = decoder->bitstream_ptr; |
582 | 642 | ||
583 | NEEDBITS (bit_buf, bits, bit_ptr); | 643 | NEEDBITS (bit_buf, bits, bit_ptr); |
584 | if (bit_buf >= 0x28000000) { | 644 | |
645 | if (bit_buf >= 0x28000000) | ||
646 | { | ||
585 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); | 647 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); |
586 | goto entry_1; | 648 | goto entry_1; |
587 | } else | 649 | } |
650 | else | ||
651 | { | ||
588 | goto entry_2; | 652 | goto entry_2; |
653 | } | ||
589 | 654 | ||
590 | while (1) { | 655 | while (1) |
591 | if (bit_buf >= 0x28000000) { | 656 | { |
592 | 657 | if (bit_buf >= 0x28000000) | |
658 | { | ||
593 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | 659 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
594 | 660 | ||
595 | entry_1: | 661 | entry_1: |
@@ -614,12 +680,11 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder, | |||
614 | NEEDBITS (bit_buf, bits, bit_ptr); | 680 | NEEDBITS (bit_buf, bits, bit_ptr); |
615 | 681 | ||
616 | continue; | 682 | continue; |
617 | |||
618 | } | 683 | } |
619 | 684 | ||
620 | entry_2: | 685 | entry_2: |
621 | if (bit_buf >= 0x04000000) { | 686 | if (bit_buf >= 0x04000000) |
622 | 687 | { | |
623 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | 688 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
624 | 689 | ||
625 | i += tab->run; | 690 | i += tab->run; |
@@ -647,23 +712,30 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder, | |||
647 | NEEDBITS (bit_buf, bits, bit_ptr); | 712 | NEEDBITS (bit_buf, bits, bit_ptr); |
648 | 713 | ||
649 | continue; | 714 | continue; |
650 | 715 | } | |
651 | } else if (bit_buf >= 0x02000000) { | 716 | else if (bit_buf >= 0x02000000) |
717 | { | ||
652 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | 718 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
653 | i += tab->run; | 719 | i += tab->run; |
654 | if (i < 64) | 720 | if (i < 64) |
655 | goto normal_code; | 721 | goto normal_code; |
656 | } else if (bit_buf >= 0x00800000) { | 722 | } |
723 | else if (bit_buf >= 0x00800000) | ||
724 | { | ||
657 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | 725 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
658 | i += tab->run; | 726 | i += tab->run; |
659 | if (i < 64) | 727 | if (i < 64) |
660 | goto normal_code; | 728 | goto normal_code; |
661 | } else if (bit_buf >= 0x00200000) { | 729 | } |
730 | else if (bit_buf >= 0x00200000) | ||
731 | { | ||
662 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | 732 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
663 | i += tab->run; | 733 | i += tab->run; |
664 | if (i < 64) | 734 | if (i < 64) |
665 | goto normal_code; | 735 | goto normal_code; |
666 | } else { | 736 | } |
737 | else | ||
738 | { | ||
667 | tab = DCT_16 + UBITS (bit_buf, 16); | 739 | tab = DCT_16 + UBITS (bit_buf, 16); |
668 | bit_buf <<= 16; | 740 | bit_buf <<= 16; |
669 | GETWORD (bit_buf, bits + 16, bit_ptr); | 741 | GETWORD (bit_buf, bits + 16, bit_ptr); |
@@ -673,6 +745,7 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder, | |||
673 | } | 745 | } |
674 | break; /* illegal, check needed to avoid buffer overflow */ | 746 | break; /* illegal, check needed to avoid buffer overflow */ |
675 | } | 747 | } |
748 | |||
676 | dest[63] ^= mismatch & 16; | 749 | dest[63] ^= mismatch & 16; |
677 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | 750 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
678 | decoder->bitstream_buf = bit_buf; | 751 | decoder->bitstream_buf = bit_buf; |
@@ -702,9 +775,10 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | |||
702 | 775 | ||
703 | NEEDBITS (bit_buf, bits, bit_ptr); | 776 | NEEDBITS (bit_buf, bits, bit_ptr); |
704 | 777 | ||
705 | while (1) { | 778 | while (1) |
706 | if (bit_buf >= 0x28000000) { | 779 | { |
707 | 780 | if (bit_buf >= 0x28000000) | |
781 | { | ||
708 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | 782 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
709 | 783 | ||
710 | i += tab->run; | 784 | i += tab->run; |
@@ -730,9 +804,9 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | |||
730 | NEEDBITS (bit_buf, bits, bit_ptr); | 804 | NEEDBITS (bit_buf, bits, bit_ptr); |
731 | 805 | ||
732 | continue; | 806 | continue; |
733 | 807 | } | |
734 | } else if (bit_buf >= 0x04000000) { | 808 | else if (bit_buf >= 0x04000000) |
735 | 809 | { | |
736 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | 810 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
737 | 811 | ||
738 | i += tab->run; | 812 | i += tab->run; |
@@ -750,10 +824,13 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | |||
750 | DUMPBITS (bit_buf, bits, 12); | 824 | DUMPBITS (bit_buf, bits, 12); |
751 | NEEDBITS (bit_buf, bits, bit_ptr); | 825 | NEEDBITS (bit_buf, bits, bit_ptr); |
752 | val = SBITS (bit_buf, 8); | 826 | val = SBITS (bit_buf, 8); |
753 | if (! (val & 0x7f)) { | 827 | |
828 | if (! (val & 0x7f)) | ||
829 | { | ||
754 | DUMPBITS (bit_buf, bits, 8); | 830 | DUMPBITS (bit_buf, bits, 8); |
755 | val = UBITS (bit_buf, 8) + 2 * val; | 831 | val = UBITS (bit_buf, 8) + 2 * val; |
756 | } | 832 | } |
833 | |||
757 | val = (val * quant_matrix[j]) / 16; | 834 | val = (val * quant_matrix[j]) / 16; |
758 | 835 | ||
759 | /* oddification */ | 836 | /* oddification */ |
@@ -766,23 +843,30 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | |||
766 | NEEDBITS (bit_buf, bits, bit_ptr); | 843 | NEEDBITS (bit_buf, bits, bit_ptr); |
767 | 844 | ||
768 | continue; | 845 | continue; |
769 | 846 | } | |
770 | } else if (bit_buf >= 0x02000000) { | 847 | else if (bit_buf >= 0x02000000) |
848 | { | ||
771 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | 849 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
772 | i += tab->run; | 850 | i += tab->run; |
773 | if (i < 64) | 851 | if (i < 64) |
774 | goto normal_code; | 852 | goto normal_code; |
775 | } else if (bit_buf >= 0x00800000) { | 853 | } |
854 | else if (bit_buf >= 0x00800000) | ||
855 | { | ||
776 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | 856 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
777 | i += tab->run; | 857 | i += tab->run; |
778 | if (i < 64) | 858 | if (i < 64) |
779 | goto normal_code; | 859 | goto normal_code; |
780 | } else if (bit_buf >= 0x00200000) { | 860 | } |
861 | else if (bit_buf >= 0x00200000) | ||
862 | { | ||
781 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | 863 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
782 | i += tab->run; | 864 | i += tab->run; |
783 | if (i < 64) | 865 | if (i < 64) |
784 | goto normal_code; | 866 | goto normal_code; |
785 | } else { | 867 | } |
868 | else | ||
869 | { | ||
786 | tab = DCT_16 + UBITS (bit_buf, 16); | 870 | tab = DCT_16 + UBITS (bit_buf, 16); |
787 | bit_buf <<= 16; | 871 | bit_buf <<= 16; |
788 | GETWORD (bit_buf, bits + 16, bit_ptr); | 872 | GETWORD (bit_buf, bits + 16, bit_ptr); |
@@ -792,6 +876,7 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder) | |||
792 | } | 876 | } |
793 | break; /* illegal, check needed to avoid buffer overflow */ | 877 | break; /* illegal, check needed to avoid buffer overflow */ |
794 | } | 878 | } |
879 | |||
795 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | 880 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
796 | decoder->bitstream_buf = bit_buf; | 881 | decoder->bitstream_buf = bit_buf; |
797 | decoder->bitstream_bits = bits; | 882 | decoder->bitstream_bits = bits; |
@@ -818,15 +903,20 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | |||
818 | bit_ptr = decoder->bitstream_ptr; | 903 | bit_ptr = decoder->bitstream_ptr; |
819 | 904 | ||
820 | NEEDBITS (bit_buf, bits, bit_ptr); | 905 | NEEDBITS (bit_buf, bits, bit_ptr); |
821 | if (bit_buf >= 0x28000000) { | 906 | if (bit_buf >= 0x28000000) |
907 | { | ||
822 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); | 908 | tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5); |
823 | goto entry_1; | 909 | goto entry_1; |
824 | } else | 910 | } |
911 | else | ||
912 | { | ||
825 | goto entry_2; | 913 | goto entry_2; |
914 | } | ||
826 | 915 | ||
827 | while (1) { | 916 | while (1) |
828 | if (bit_buf >= 0x28000000) { | 917 | { |
829 | 918 | if (bit_buf >= 0x28000000) | |
919 | { | ||
830 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); | 920 | tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5); |
831 | 921 | ||
832 | entry_1: | 922 | entry_1: |
@@ -853,12 +943,11 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | |||
853 | NEEDBITS (bit_buf, bits, bit_ptr); | 943 | NEEDBITS (bit_buf, bits, bit_ptr); |
854 | 944 | ||
855 | continue; | 945 | continue; |
856 | |||
857 | } | 946 | } |
858 | 947 | ||
859 | entry_2: | 948 | entry_2: |
860 | if (bit_buf >= 0x04000000) { | 949 | if (bit_buf >= 0x04000000) |
861 | 950 | { | |
862 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); | 951 | tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4); |
863 | 952 | ||
864 | i += tab->run; | 953 | i += tab->run; |
@@ -876,10 +965,13 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | |||
876 | DUMPBITS (bit_buf, bits, 12); | 965 | DUMPBITS (bit_buf, bits, 12); |
877 | NEEDBITS (bit_buf, bits, bit_ptr); | 966 | NEEDBITS (bit_buf, bits, bit_ptr); |
878 | val = SBITS (bit_buf, 8); | 967 | val = SBITS (bit_buf, 8); |
879 | if (! (val & 0x7f)) { | 968 | |
969 | if (! (val & 0x7f)) | ||
970 | { | ||
880 | DUMPBITS (bit_buf, bits, 8); | 971 | DUMPBITS (bit_buf, bits, 8); |
881 | val = UBITS (bit_buf, 8) + 2 * val; | 972 | val = UBITS (bit_buf, 8) + 2 * val; |
882 | } | 973 | } |
974 | |||
883 | val = 2 * (val + SBITS (val, 1)) + 1; | 975 | val = 2 * (val + SBITS (val, 1)) + 1; |
884 | val = (val * quant_matrix[j]) / 32; | 976 | val = (val * quant_matrix[j]) / 32; |
885 | 977 | ||
@@ -894,22 +986,30 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | |||
894 | 986 | ||
895 | continue; | 987 | continue; |
896 | 988 | ||
897 | } else if (bit_buf >= 0x02000000) { | 989 | } |
990 | else if (bit_buf >= 0x02000000) | ||
991 | { | ||
898 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); | 992 | tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8); |
899 | i += tab->run; | 993 | i += tab->run; |
900 | if (i < 64) | 994 | if (i < 64) |
901 | goto normal_code; | 995 | goto normal_code; |
902 | } else if (bit_buf >= 0x00800000) { | 996 | } |
997 | else if (bit_buf >= 0x00800000) | ||
998 | { | ||
903 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); | 999 | tab = DCT_13 + (UBITS (bit_buf, 13) - 16); |
904 | i += tab->run; | 1000 | i += tab->run; |
905 | if (i < 64) | 1001 | if (i < 64) |
906 | goto normal_code; | 1002 | goto normal_code; |
907 | } else if (bit_buf >= 0x00200000) { | 1003 | } |
1004 | else if (bit_buf >= 0x00200000) | ||
1005 | { | ||
908 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); | 1006 | tab = DCT_15 + (UBITS (bit_buf, 15) - 16); |
909 | i += tab->run; | 1007 | i += tab->run; |
910 | if (i < 64) | 1008 | if (i < 64) |
911 | goto normal_code; | 1009 | goto normal_code; |
912 | } else { | 1010 | } |
1011 | else | ||
1012 | { | ||
913 | tab = DCT_16 + UBITS (bit_buf, 16); | 1013 | tab = DCT_16 + UBITS (bit_buf, 16); |
914 | bit_buf <<= 16; | 1014 | bit_buf <<= 16; |
915 | GETWORD (bit_buf, bits + 16, bit_ptr); | 1015 | GETWORD (bit_buf, bits + 16, bit_ptr); |
@@ -919,6 +1019,7 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder) | |||
919 | } | 1019 | } |
920 | break; /* illegal, check needed to avoid buffer overflow */ | 1020 | break; /* illegal, check needed to avoid buffer overflow */ |
921 | } | 1021 | } |
1022 | |||
922 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ | 1023 | DUMPBITS (bit_buf, bits, 2); /* dump end of block code */ |
923 | decoder->bitstream_buf = bit_buf; | 1024 | decoder->bitstream_buf = bit_buf; |
924 | decoder->bitstream_bits = bits; | 1025 | decoder->bitstream_bits = bits; |
@@ -933,23 +1034,37 @@ static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder, | |||
933 | #define bit_buf (decoder->bitstream_buf) | 1034 | #define bit_buf (decoder->bitstream_buf) |
934 | #define bits (decoder->bitstream_bits) | 1035 | #define bits (decoder->bitstream_bits) |
935 | #define bit_ptr (decoder->bitstream_ptr) | 1036 | #define bit_ptr (decoder->bitstream_ptr) |
1037 | |||
936 | NEEDBITS (bit_buf, bits, bit_ptr); | 1038 | NEEDBITS (bit_buf, bits, bit_ptr); |
937 | /* Get the intra DC coefficient and inverse quantize it */ | 1039 | /* Get the intra DC coefficient and inverse quantize it */ |
938 | if (cc == 0) | 1040 | if (cc == 0) |
939 | decoder->DCTblock[0] = | 1041 | { |
940 | decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder); | 1042 | decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder); |
1043 | decoder->DCTblock[0] = decoder->dc_dct_pred[0]; | ||
1044 | |||
1045 | } | ||
941 | else | 1046 | else |
942 | decoder->DCTblock[0] = | 1047 | { |
943 | decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder); | 1048 | decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder); |
1049 | decoder->DCTblock[0] = decoder->dc_dct_pred[cc]; | ||
1050 | } | ||
944 | 1051 | ||
945 | if (decoder->mpeg1) { | 1052 | if (decoder->mpeg1) |
1053 | { | ||
946 | if (decoder->coding_type != D_TYPE) | 1054 | if (decoder->coding_type != D_TYPE) |
947 | get_mpeg1_intra_block (decoder); | 1055 | get_mpeg1_intra_block (decoder); |
948 | } else if (decoder->intra_vlc_format) | 1056 | } |
1057 | else if (decoder->intra_vlc_format) | ||
1058 | { | ||
949 | get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); | 1059 | get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); |
1060 | } | ||
950 | else | 1061 | else |
1062 | { | ||
951 | get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); | 1063 | get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]); |
1064 | } | ||
1065 | |||
952 | mpeg2_idct_copy (decoder->DCTblock, dest, stride); | 1066 | mpeg2_idct_copy (decoder->DCTblock, dest, stride); |
1067 | |||
953 | #undef bit_buf | 1068 | #undef bit_buf |
954 | #undef bits | 1069 | #undef bits |
955 | #undef bit_ptr | 1070 | #undef bit_ptr |
@@ -962,289 +1077,366 @@ static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder, | |||
962 | int last; | 1077 | int last; |
963 | 1078 | ||
964 | if (decoder->mpeg1) | 1079 | if (decoder->mpeg1) |
1080 | { | ||
965 | last = get_mpeg1_non_intra_block (decoder); | 1081 | last = get_mpeg1_non_intra_block (decoder); |
1082 | } | ||
966 | else | 1083 | else |
1084 | { | ||
967 | last = get_non_intra_block (decoder, | 1085 | last = get_non_intra_block (decoder, |
968 | decoder->quantizer_matrix[cc ? 3 : 1]); | 1086 | decoder->quantizer_matrix[cc ? 3 : 1]); |
1087 | } | ||
1088 | |||
969 | mpeg2_idct_add (last, decoder->DCTblock, dest, stride); | 1089 | mpeg2_idct_add (last, decoder->DCTblock, dest, stride); |
970 | } | 1090 | } |
971 | 1091 | ||
972 | #define MOTION_420(table,ref,motion_x,motion_y,size,y) \ | 1092 | #define MOTION_420(table, ref, motion_x, motion_y, size, y) \ |
973 | pos_x = 2 * decoder->offset + motion_x; \ | 1093 | pos_x = 2 * decoder->offset + motion_x; \ |
974 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | 1094 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ |
975 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1095 | \ |
1096 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1097 | { \ | ||
976 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1098 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
977 | motion_x = pos_x - 2 * decoder->offset; \ | 1099 | motion_x = pos_x - 2 * decoder->offset; \ |
978 | } \ | 1100 | } \ |
979 | if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | 1101 | \ |
980 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | 1102 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ |
981 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | 1103 | { \ |
982 | } \ | 1104 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ |
983 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1105 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ |
1106 | } \ | ||
1107 | \ | ||
1108 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
984 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | 1109 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ |
985 | ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \ | 1110 | ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \ |
986 | decoder->stride, size); \ | 1111 | decoder->stride, size); \ |
987 | motion_x /= 2; motion_y /= 2; \ | 1112 | \ |
988 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | 1113 | motion_x /= 2; \ |
989 | offset = (((decoder->offset + motion_x) >> 1) + \ | 1114 | motion_y /= 2; \ |
990 | ((((decoder->v_offset + motion_y) >> 1) + y/2) * \ | 1115 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ |
991 | decoder->uv_stride)); \ | 1116 | offset = ((decoder->offset + motion_x) >> 1) + \ |
992 | table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \ | 1117 | ((((decoder->v_offset + motion_y) >> 1) + y/2) * \ |
993 | (decoder->offset >> 1), ref[1] + offset, \ | 1118 | decoder->uv_stride); \ |
994 | decoder->uv_stride, size/2); \ | 1119 | \ |
995 | table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \ | 1120 | table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \ |
996 | (decoder->offset >> 1), ref[2] + offset, \ | 1121 | (decoder->offset >> 1), ref[1] + offset, \ |
1122 | decoder->uv_stride, size/2); \ | ||
1123 | table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \ | ||
1124 | (decoder->offset >> 1), ref[2] + offset, \ | ||
997 | decoder->uv_stride, size/2) | 1125 | decoder->uv_stride, size/2) |
998 | 1126 | ||
999 | #define MOTION_FIELD_420(table,ref,motion_x,motion_y,dest_field,op,src_field) \ | 1127 | #define MOTION_FIELD_420(table, ref, motion_x, motion_y, \ |
1000 | pos_x = 2 * decoder->offset + motion_x; \ | 1128 | dest_field, op, src_field) \ |
1001 | pos_y = decoder->v_offset + motion_y; \ | 1129 | pos_x = 2 * decoder->offset + motion_x; \ |
1002 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1130 | pos_y = decoder->v_offset + motion_y; \ |
1131 | \ | ||
1132 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1133 | { \ | ||
1003 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1134 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1004 | motion_x = pos_x - 2 * decoder->offset; \ | 1135 | motion_x = pos_x - 2 * decoder->offset; \ |
1005 | } \ | 1136 | } \ |
1006 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1137 | \ |
1138 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1139 | { \ | ||
1007 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1140 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1008 | motion_y = pos_y - decoder->v_offset; \ | 1141 | motion_y = pos_y - decoder->v_offset; \ |
1009 | } \ | 1142 | } \ |
1010 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1143 | \ |
1011 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | 1144 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1012 | decoder->offset, \ | 1145 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ |
1013 | (ref[0] + (pos_x >> 1) + \ | 1146 | decoder->offset, \ |
1014 | ((pos_y op) + src_field) * decoder->stride), \ | 1147 | (ref[0] + (pos_x >> 1) + \ |
1015 | 2 * decoder->stride, 8); \ | 1148 | ((pos_y op) + src_field) * decoder->stride), \ |
1016 | motion_x /= 2; motion_y /= 2; \ | 1149 | 2 * decoder->stride, 8); \ |
1017 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | 1150 | \ |
1018 | offset = (((decoder->offset + motion_x) >> 1) + \ | 1151 | motion_x /= 2; \ |
1019 | (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \ | 1152 | motion_y /= 2; \ |
1020 | decoder->uv_stride)); \ | 1153 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ |
1154 | offset = ((decoder->offset + motion_x) >> 1) + \ | ||
1155 | (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \ | ||
1156 | decoder->uv_stride); \ | ||
1157 | \ | ||
1021 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | 1158 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ |
1022 | (decoder->offset >> 1), ref[1] + offset, \ | 1159 | (decoder->offset >> 1), ref[1] + offset, \ |
1023 | 2 * decoder->uv_stride, 4); \ | 1160 | 2 * decoder->uv_stride, 4); \ |
1024 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | 1161 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ |
1025 | (decoder->offset >> 1), ref[2] + offset, \ | 1162 | (decoder->offset >> 1), ref[2] + offset, \ |
1026 | 2 * decoder->uv_stride, 4) | 1163 | 2 * decoder->uv_stride, 4) |
1027 | 1164 | ||
1028 | #define MOTION_DMV_420(table,ref,motion_x,motion_y) \ | 1165 | #define MOTION_DMV_420(table, ref, motion_x, motion_y) \ |
1029 | pos_x = 2 * decoder->offset + motion_x; \ | 1166 | pos_x = 2 * decoder->offset + motion_x; \ |
1030 | pos_y = decoder->v_offset + motion_y; \ | 1167 | pos_y = decoder->v_offset + motion_y; \ |
1031 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1168 | \ |
1169 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1170 | { \ | ||
1032 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1171 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1033 | motion_x = pos_x - 2 * decoder->offset; \ | 1172 | motion_x = pos_x - 2 * decoder->offset; \ |
1034 | } \ | 1173 | } \ |
1035 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1174 | \ |
1175 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1176 | { \ | ||
1036 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1177 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1037 | motion_y = pos_y - decoder->v_offset; \ | 1178 | motion_y = pos_y - decoder->v_offset; \ |
1038 | } \ | 1179 | } \ |
1039 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1180 | \ |
1040 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | 1181 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1041 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | 1182 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ |
1042 | ref[0] + offset, 2 * decoder->stride, 8); \ | 1183 | table[xy_half] (decoder->dest[0] + decoder->offset, \ |
1184 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1043 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | 1185 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ |
1044 | ref[0] + decoder->stride + offset, \ | 1186 | ref[0] + decoder->stride + offset, \ |
1045 | 2 * decoder->stride, 8); \ | 1187 | 2 * decoder->stride, 8); \ |
1046 | motion_x /= 2; motion_y /= 2; \ | 1188 | \ |
1047 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ | 1189 | motion_x /= 2; \ |
1048 | offset = (((decoder->offset + motion_x) >> 1) + \ | 1190 | motion_y /= 2; \ |
1049 | (((decoder->v_offset >> 1) + (motion_y & ~1)) * \ | 1191 | xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \ |
1050 | decoder->uv_stride)); \ | 1192 | offset = ((decoder->offset + motion_x) >> 1) + \ |
1193 | (((decoder->v_offset >> 1) + (motion_y & ~1)) * \ | ||
1194 | decoder->uv_stride); \ | ||
1195 | \ | ||
1051 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | 1196 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ |
1052 | ref[1] + offset, 2 * decoder->uv_stride, 4); \ | 1197 | ref[1] + offset, 2 * decoder->uv_stride, 4); \ |
1053 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | 1198 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ |
1054 | (decoder->offset >> 1), \ | 1199 | (decoder->offset >> 1), \ |
1055 | ref[1] + decoder->uv_stride + offset, \ | 1200 | ref[1] + decoder->uv_stride + offset, \ |
1056 | 2 * decoder->uv_stride, 4); \ | 1201 | 2 * decoder->uv_stride, 4); \ |
1057 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | 1202 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ |
1058 | ref[2] + offset, 2 * decoder->uv_stride, 4); \ | 1203 | ref[2] + offset, 2 * decoder->uv_stride, 4); \ |
1059 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | 1204 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ |
1060 | (decoder->offset >> 1), \ | 1205 | (decoder->offset >> 1), \ |
1061 | ref[2] + decoder->uv_stride + offset, \ | 1206 | ref[2] + decoder->uv_stride + offset, \ |
1062 | 2 * decoder->uv_stride, 4) | 1207 | 2 * decoder->uv_stride, 4) |
1063 | 1208 | ||
1064 | #define MOTION_ZERO_420(table,ref) \ | 1209 | #define MOTION_ZERO_420(table, ref) \ |
1065 | table[0] (decoder->dest[0] + decoder->offset, \ | 1210 | table[0] (decoder->dest[0] + decoder->offset, \ |
1066 | (ref[0] + decoder->offset + \ | 1211 | (ref[0] + decoder->offset + \ |
1067 | decoder->v_offset * decoder->stride), decoder->stride, 16); \ | 1212 | decoder->v_offset * decoder->stride), decoder->stride, 16); \ |
1068 | offset = ((decoder->offset >> 1) + \ | 1213 | \ |
1069 | (decoder->v_offset >> 1) * decoder->uv_stride); \ | 1214 | offset = ((decoder->offset >> 1) + \ |
1215 | (decoder->v_offset >> 1) * decoder->uv_stride); \ | ||
1216 | \ | ||
1070 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | 1217 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ |
1071 | ref[1] + offset, decoder->uv_stride, 8); \ | 1218 | ref[1] + offset, decoder->uv_stride, 8); \ |
1072 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | 1219 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ |
1073 | ref[2] + offset, decoder->uv_stride, 8) | 1220 | ref[2] + offset, decoder->uv_stride, 8) |
1074 | 1221 | ||
1075 | #define MOTION_422(table,ref,motion_x,motion_y,size,y) \ | 1222 | #define MOTION_422(table, ref, motion_x, motion_y, size, y) \ |
1076 | pos_x = 2 * decoder->offset + motion_x; \ | 1223 | pos_x = 2 * decoder->offset + motion_x; \ |
1077 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | 1224 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ |
1078 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1225 | \ |
1226 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1227 | { \ | ||
1079 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1228 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1080 | motion_x = pos_x - 2 * decoder->offset; \ | 1229 | motion_x = pos_x - 2 * decoder->offset; \ |
1081 | } \ | 1230 | } \ |
1082 | if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | 1231 | \ |
1083 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | 1232 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ |
1084 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | 1233 | { \ |
1085 | } \ | 1234 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ |
1086 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1235 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ |
1087 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | 1236 | } \ |
1237 | \ | ||
1238 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1239 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | ||
1240 | \ | ||
1088 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | 1241 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ |
1089 | ref[0] + offset, decoder->stride, size); \ | 1242 | ref[0] + offset, decoder->stride, size); \ |
1090 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | 1243 | \ |
1091 | motion_x /= 2; \ | 1244 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ |
1092 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | 1245 | motion_x /= 2; \ |
1093 | table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \ | 1246 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ |
1094 | (decoder->offset >> 1), ref[1] + offset, \ | 1247 | \ |
1248 | table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \ | ||
1249 | (decoder->offset >> 1), ref[1] + offset, \ | ||
1095 | decoder->uv_stride, size); \ | 1250 | decoder->uv_stride, size); \ |
1096 | table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \ | 1251 | table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \ |
1097 | (decoder->offset >> 1), ref[2] + offset, \ | 1252 | (decoder->offset >> 1), ref[2] + offset, \ |
1098 | decoder->uv_stride, size) | 1253 | decoder->uv_stride, size) |
1099 | 1254 | ||
1100 | #define MOTION_FIELD_422(table,ref,motion_x,motion_y,dest_field,op,src_field) \ | 1255 | #define MOTION_FIELD_422(table, ref, motion_x, motion_y, \ |
1101 | pos_x = 2 * decoder->offset + motion_x; \ | 1256 | dest_field, op, src_field) \ |
1102 | pos_y = decoder->v_offset + motion_y; \ | 1257 | pos_x = 2 * decoder->offset + motion_x; \ |
1103 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1258 | pos_y = decoder->v_offset + motion_y; \ |
1259 | \ | ||
1260 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1261 | { \ | ||
1104 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1262 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1105 | motion_x = pos_x - 2 * decoder->offset; \ | 1263 | motion_x = pos_x - 2 * decoder->offset; \ |
1106 | } \ | 1264 | } \ |
1107 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1265 | \ |
1266 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1267 | { \ | ||
1108 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1268 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1109 | motion_y = pos_y - decoder->v_offset; \ | 1269 | motion_y = pos_y - decoder->v_offset; \ |
1110 | } \ | 1270 | } \ |
1111 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1271 | \ |
1112 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | 1272 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1113 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | 1273 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ |
1114 | decoder->offset, ref[0] + offset, \ | 1274 | \ |
1115 | 2 * decoder->stride, 8); \ | 1275 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ |
1116 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | 1276 | decoder->offset, ref[0] + offset, \ |
1117 | motion_x /= 2; \ | 1277 | 2 * decoder->stride, 8); \ |
1118 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | 1278 | \ |
1279 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | ||
1280 | motion_x /= 2; \ | ||
1281 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | ||
1282 | \ | ||
1119 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ | 1283 | table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \ |
1120 | (decoder->offset >> 1), ref[1] + offset, \ | 1284 | (decoder->offset >> 1), ref[1] + offset, \ |
1121 | 2 * decoder->uv_stride, 8); \ | 1285 | 2 * decoder->uv_stride, 8); \ |
1122 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ | 1286 | table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \ |
1123 | (decoder->offset >> 1), ref[2] + offset, \ | 1287 | (decoder->offset >> 1), ref[2] + offset, \ |
1124 | 2 * decoder->uv_stride, 8) | 1288 | 2 * decoder->uv_stride, 8) |
1125 | 1289 | ||
1126 | #define MOTION_DMV_422(table,ref,motion_x,motion_y) \ | 1290 | #define MOTION_DMV_422(table, ref, motion_x, motion_y) \ |
1127 | pos_x = 2 * decoder->offset + motion_x; \ | 1291 | pos_x = 2 * decoder->offset + motion_x; \ |
1128 | pos_y = decoder->v_offset + motion_y; \ | 1292 | pos_y = decoder->v_offset + motion_y; \ |
1129 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1293 | \ |
1294 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1295 | { \ | ||
1130 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1296 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1131 | motion_x = pos_x - 2 * decoder->offset; \ | 1297 | motion_x = pos_x - 2 * decoder->offset; \ |
1132 | } \ | 1298 | } \ |
1133 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1299 | \ |
1300 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1301 | { \ | ||
1134 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1302 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1135 | motion_y = pos_y - decoder->v_offset; \ | 1303 | motion_y = pos_y - decoder->v_offset; \ |
1136 | } \ | 1304 | } \ |
1137 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1305 | \ |
1138 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | 1306 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1139 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | 1307 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ |
1140 | ref[0] + offset, 2 * decoder->stride, 8); \ | 1308 | \ |
1309 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | ||
1310 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1141 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | 1311 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ |
1142 | ref[0] + decoder->stride + offset, \ | 1312 | ref[0] + decoder->stride + offset, \ |
1143 | 2 * decoder->stride, 8); \ | 1313 | 2 * decoder->stride, 8); \ |
1144 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ | 1314 | \ |
1145 | motion_x /= 2; \ | 1315 | offset = (offset + (motion_x & (motion_x < 0))) >> 1; \ |
1146 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | 1316 | motion_x /= 2; \ |
1317 | xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \ | ||
1318 | \ | ||
1147 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ | 1319 | table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \ |
1148 | ref[1] + offset, 2 * decoder->uv_stride, 8); \ | 1320 | ref[1] + offset, 2 * decoder->uv_stride, 8); \ |
1149 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ | 1321 | table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \ |
1150 | (decoder->offset >> 1), \ | 1322 | (decoder->offset >> 1), \ |
1151 | ref[1] + decoder->uv_stride + offset, \ | 1323 | ref[1] + decoder->uv_stride + offset, \ |
1152 | 2 * decoder->uv_stride, 8); \ | 1324 | 2 * decoder->uv_stride, 8); \ |
1153 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ | 1325 | table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \ |
1154 | ref[2] + offset, 2 * decoder->uv_stride, 8); \ | 1326 | ref[2] + offset, 2 * decoder->uv_stride, 8); \ |
1155 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ | 1327 | table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \ |
1156 | (decoder->offset >> 1), \ | 1328 | (decoder->offset >> 1), \ |
1157 | ref[2] + decoder->uv_stride + offset, \ | 1329 | ref[2] + decoder->uv_stride + offset, \ |
1158 | 2 * decoder->uv_stride, 8) | 1330 | 2 * decoder->uv_stride, 8) |
1159 | 1331 | ||
1160 | #define MOTION_ZERO_422(table,ref) \ | 1332 | #define MOTION_ZERO_422(table, ref) \ |
1161 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ | 1333 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ |
1162 | table[0] (decoder->dest[0] + decoder->offset, \ | 1334 | table[0] (decoder->dest[0] + decoder->offset, \ |
1163 | ref[0] + offset, decoder->stride, 16); \ | 1335 | ref[0] + offset, decoder->stride, 16); \ |
1164 | offset >>= 1; \ | 1336 | offset >>= 1; \ |
1165 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ | 1337 | table[4] (decoder->dest[1] + (decoder->offset >> 1), \ |
1166 | ref[1] + offset, decoder->uv_stride, 16); \ | 1338 | ref[1] + offset, decoder->uv_stride, 16); \ |
1167 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | 1339 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ |
1168 | ref[2] + offset, decoder->uv_stride, 16) | 1340 | ref[2] + offset, decoder->uv_stride, 16) |
1169 | 1341 | ||
1170 | #define MOTION_444(table,ref,motion_x,motion_y,size,y) \ | 1342 | #define MOTION_444(table, ref, motion_x, motion_y, size, y) \ |
1171 | pos_x = 2 * decoder->offset + motion_x; \ | 1343 | pos_x = 2 * decoder->offset + motion_x; \ |
1172 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ | 1344 | pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \ |
1173 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1345 | \ |
1346 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1347 | { \ | ||
1174 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1348 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1175 | motion_x = pos_x - 2 * decoder->offset; \ | 1349 | motion_x = pos_x - 2 * decoder->offset; \ |
1176 | } \ | 1350 | } \ |
1177 | if (unlikely (pos_y > decoder->limit_y_ ## size)) { \ | 1351 | \ |
1178 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ | 1352 | if (unlikely (pos_y > decoder->limit_y_ ## size)) \ |
1179 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ | 1353 | { \ |
1180 | } \ | 1354 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \ |
1181 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1355 | motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \ |
1182 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | 1356 | } \ |
1357 | \ | ||
1358 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | ||
1359 | offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \ | ||
1360 | \ | ||
1183 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ | 1361 | table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \ |
1184 | ref[0] + offset, decoder->stride, size); \ | 1362 | ref[0] + offset, decoder->stride, size); \ |
1185 | table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \ | 1363 | table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \ |
1186 | ref[1] + offset, decoder->stride, size); \ | 1364 | ref[1] + offset, decoder->stride, size); \ |
1187 | table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \ | 1365 | table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \ |
1188 | ref[2] + offset, decoder->stride, size) | 1366 | ref[2] + offset, decoder->stride, size) |
1189 | 1367 | ||
1190 | #define MOTION_FIELD_444(table,ref,motion_x,motion_y,dest_field,op,src_field) \ | 1368 | #define MOTION_FIELD_444(table, ref, motion_x, motion_y, \ |
1191 | pos_x = 2 * decoder->offset + motion_x; \ | 1369 | dest_field, op, src_field) \ |
1192 | pos_y = decoder->v_offset + motion_y; \ | 1370 | pos_x = 2 * decoder->offset + motion_x; \ |
1193 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1371 | pos_y = decoder->v_offset + motion_y; \ |
1372 | \ | ||
1373 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1374 | { \ | ||
1194 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1375 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1195 | motion_x = pos_x - 2 * decoder->offset; \ | 1376 | motion_x = pos_x - 2 * decoder->offset; \ |
1196 | } \ | 1377 | } \ |
1197 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1378 | \ |
1379 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1380 | { \ | ||
1198 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1381 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1199 | motion_y = pos_y - decoder->v_offset; \ | 1382 | motion_y = pos_y - decoder->v_offset; \ |
1200 | } \ | 1383 | } \ |
1201 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1384 | \ |
1202 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ | 1385 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1203 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ | 1386 | offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \ |
1204 | decoder->offset, ref[0] + offset, \ | 1387 | \ |
1205 | 2 * decoder->stride, 8); \ | 1388 | table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \ |
1206 | table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \ | 1389 | decoder->offset, ref[0] + offset, \ |
1207 | decoder->offset, ref[1] + offset, \ | 1390 | 2 * decoder->stride, 8); \ |
1208 | 2 * decoder->stride, 8); \ | 1391 | table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \ |
1209 | table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \ | 1392 | decoder->offset, ref[1] + offset, \ |
1210 | decoder->offset, ref[2] + offset, \ | 1393 | 2 * decoder->stride, 8); \ |
1394 | table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \ | ||
1395 | decoder->offset, ref[2] + offset, \ | ||
1211 | 2 * decoder->stride, 8) | 1396 | 2 * decoder->stride, 8) |
1212 | 1397 | ||
1213 | #define MOTION_DMV_444(table,ref,motion_x,motion_y) \ | 1398 | #define MOTION_DMV_444(table, ref, motion_x, motion_y) \ |
1214 | pos_x = 2 * decoder->offset + motion_x; \ | 1399 | pos_x = 2 * decoder->offset + motion_x; \ |
1215 | pos_y = decoder->v_offset + motion_y; \ | 1400 | pos_y = decoder->v_offset + motion_y; \ |
1216 | if (unlikely (pos_x > decoder->limit_x)) { \ | 1401 | \ |
1402 | if (unlikely (pos_x > decoder->limit_x)) \ | ||
1403 | { \ | ||
1217 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ | 1404 | pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \ |
1218 | motion_x = pos_x - 2 * decoder->offset; \ | 1405 | motion_x = pos_x - 2 * decoder->offset; \ |
1219 | } \ | 1406 | } \ |
1220 | if (unlikely (pos_y > decoder->limit_y)) { \ | 1407 | \ |
1408 | if (unlikely (pos_y > decoder->limit_y)) \ | ||
1409 | { \ | ||
1221 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ | 1410 | pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \ |
1222 | motion_y = pos_y - decoder->v_offset; \ | 1411 | motion_y = pos_y - decoder->v_offset; \ |
1223 | } \ | 1412 | } \ |
1224 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ | 1413 | \ |
1225 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ | 1414 | xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \ |
1226 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | 1415 | offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \ |
1227 | ref[0] + offset, 2 * decoder->stride, 8); \ | 1416 | \ |
1417 | table[xy_half] (decoder->dest[0] + decoder->offset, \ | ||
1418 | ref[0] + offset, 2 * decoder->stride, 8); \ | ||
1228 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ | 1419 | table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \ |
1229 | ref[0] + decoder->stride + offset, \ | 1420 | ref[0] + decoder->stride + offset, \ |
1230 | 2 * decoder->stride, 8); \ | 1421 | 2 * decoder->stride, 8); \ |
1231 | table[xy_half] (decoder->dest[1] + decoder->offset, \ | 1422 | table[xy_half] (decoder->dest[1] + decoder->offset, \ |
1232 | ref[1] + offset, 2 * decoder->stride, 8); \ | 1423 | ref[1] + offset, 2 * decoder->stride, 8); \ |
1233 | table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \ | 1424 | table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \ |
1234 | ref[1] + decoder->stride + offset, \ | 1425 | ref[1] + decoder->stride + offset, \ |
1235 | 2 * decoder->stride, 8); \ | 1426 | 2 * decoder->stride, 8); \ |
1236 | table[xy_half] (decoder->dest[2] + decoder->offset, \ | 1427 | table[xy_half] (decoder->dest[2] + decoder->offset, \ |
1237 | ref[2] + offset, 2 * decoder->stride, 8); \ | 1428 | ref[2] + offset, 2 * decoder->stride, 8); \ |
1238 | table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \ | 1429 | table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \ |
1239 | ref[2] + decoder->stride + offset, \ | 1430 | ref[2] + decoder->stride + offset, \ |
1240 | 2 * decoder->stride, 8) | 1431 | 2 * decoder->stride, 8) |
1241 | 1432 | ||
1242 | #define MOTION_ZERO_444(table,ref) \ | 1433 | #define MOTION_ZERO_444(table, ref) \ |
1243 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ | 1434 | offset = decoder->offset + decoder->v_offset * decoder->stride; \ |
1244 | table[0] (decoder->dest[0] + decoder->offset, \ | 1435 | \ |
1245 | ref[0] + offset, decoder->stride, 16); \ | 1436 | table[0] (decoder->dest[0] + decoder->offset, \ |
1246 | table[4] (decoder->dest[1] + decoder->offset, \ | 1437 | ref[0] + offset, decoder->stride, 16); \ |
1247 | ref[1] + offset, decoder->stride, 16); \ | 1438 | table[4] (decoder->dest[1] + decoder->offset, \ |
1439 | ref[1] + offset, decoder->stride, 16); \ | ||
1248 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ | 1440 | table[4] (decoder->dest[2] + (decoder->offset >> 1), \ |
1249 | ref[2] + offset, decoder->stride, 16) | 1441 | ref[2] + offset, decoder->stride, 16) |
1250 | 1442 | ||
@@ -1260,17 +1452,17 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder, | |||
1260 | unsigned int pos_x, pos_y, xy_half, offset; | 1452 | unsigned int pos_x, pos_y, xy_half, offset; |
1261 | 1453 | ||
1262 | NEEDBITS (bit_buf, bits, bit_ptr); | 1454 | NEEDBITS (bit_buf, bits, bit_ptr); |
1263 | motion_x = (motion->pmv[0][0] + | 1455 | motion_x = motion->pmv[0][0] + |
1264 | (get_motion_delta (decoder, | 1456 | (get_motion_delta (decoder, |
1265 | motion->f_code[0]) << motion->f_code[1])); | 1457 | motion->f_code[0]) << motion->f_code[1]); |
1266 | motion_x = bound_motion_vector (motion_x, | 1458 | motion_x = bound_motion_vector (motion_x, |
1267 | motion->f_code[0] + motion->f_code[1]); | 1459 | motion->f_code[0] + motion->f_code[1]); |
1268 | motion->pmv[0][0] = motion_x; | 1460 | motion->pmv[0][0] = motion_x; |
1269 | 1461 | ||
1270 | NEEDBITS (bit_buf, bits, bit_ptr); | 1462 | NEEDBITS (bit_buf, bits, bit_ptr); |
1271 | motion_y = (motion->pmv[0][1] + | 1463 | motion_y = motion->pmv[0][1] + |
1272 | (get_motion_delta (decoder, | 1464 | (get_motion_delta (decoder, |
1273 | motion->f_code[0]) << motion->f_code[1])); | 1465 | motion->f_code[0]) << motion->f_code[1]); |
1274 | motion_y = bound_motion_vector (motion_y, | 1466 | motion_y = bound_motion_vector (motion_y, |
1275 | motion->f_code[0] + motion->f_code[1]); | 1467 | motion->f_code[0] + motion->f_code[1]); |
1276 | motion->pmv[0][1] = motion_y; | 1468 | motion->pmv[0][1] = motion_y; |
@@ -1278,227 +1470,228 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder, | |||
1278 | MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0); | 1470 | MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0); |
1279 | } | 1471 | } |
1280 | 1472 | ||
1281 | #define MOTION_FUNCTIONS(FORMAT,MOTION,MOTION_FIELD,MOTION_DMV,MOTION_ZERO) \ | 1473 | #define MOTION_FUNCTIONS(FORMAT, MOTION, MOTION_FIELD, \ |
1474 | MOTION_DMV, MOTION_ZERO) \ | ||
1282 | \ | 1475 | \ |
1283 | static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1476 | static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1284 | motion_t * const motion, \ | 1477 | motion_t * const motion, \ |
1285 | mpeg2_mc_fct * const * const table) \ | 1478 | mpeg2_mc_fct * const * const table) \ |
1286 | { \ | 1479 | { \ |
1287 | int motion_x, motion_y; \ | 1480 | int motion_x, motion_y; \ |
1288 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1481 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1289 | \ | 1482 | \ |
1290 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1483 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1291 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1484 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1292 | motion->f_code[0]); \ | 1485 | motion->f_code[0]); \ |
1293 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1486 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1294 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | 1487 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ |
1295 | \ | 1488 | \ |
1296 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1489 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1297 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | 1490 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ |
1298 | motion->f_code[1]); \ | 1491 | motion->f_code[1]); \ |
1299 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | 1492 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ |
1300 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | 1493 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ |
1301 | \ | 1494 | \ |
1302 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | 1495 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ |
1303 | } \ | 1496 | } \ |
1304 | \ | 1497 | \ |
1305 | static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1498 | static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1306 | motion_t * const motion, \ | 1499 | motion_t * const motion, \ |
1307 | mpeg2_mc_fct * const * const table) \ | 1500 | mpeg2_mc_fct * const * const table) \ |
1308 | { \ | 1501 | { \ |
1309 | int motion_x, motion_y, field; \ | 1502 | int motion_x, motion_y, field; \ |
1310 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1503 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1311 | \ | 1504 | \ |
1312 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1505 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1313 | field = UBITS (bit_buf, 1); \ | 1506 | field = UBITS (bit_buf, 1); \ |
1314 | DUMPBITS (bit_buf, bits, 1); \ | 1507 | DUMPBITS (bit_buf, bits, 1); \ |
1315 | \ | 1508 | \ |
1316 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1509 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1317 | motion->f_code[0]); \ | 1510 | motion->f_code[0]); \ |
1318 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1511 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1319 | motion->pmv[0][0] = motion_x; \ | 1512 | motion->pmv[0][0] = motion_x; \ |
1320 | \ | 1513 | \ |
1321 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1514 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1322 | motion_y = ((motion->pmv[0][1] >> 1) + \ | 1515 | motion_y = ((motion->pmv[0][1] >> 1) + \ |
1323 | get_motion_delta (decoder, motion->f_code[1])); \ | 1516 | get_motion_delta (decoder, motion->f_code[1])); \ |
1324 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | 1517 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ |
1325 | motion->pmv[0][1] = motion_y << 1; \ | 1518 | motion->pmv[0][1] = motion_y << 1; \ |
1326 | \ | 1519 | \ |
1327 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \ | 1520 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \ |
1328 | \ | 1521 | \ |
1329 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1522 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1330 | field = UBITS (bit_buf, 1); \ | 1523 | field = UBITS (bit_buf, 1); \ |
1331 | DUMPBITS (bit_buf, bits, 1); \ | 1524 | DUMPBITS (bit_buf, bits, 1); \ |
1332 | \ | 1525 | \ |
1333 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | 1526 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ |
1334 | motion->f_code[0]); \ | 1527 | motion->f_code[0]); \ |
1335 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1528 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1336 | motion->pmv[1][0] = motion_x; \ | 1529 | motion->pmv[1][0] = motion_x; \ |
1337 | \ | 1530 | \ |
1338 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1531 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1339 | motion_y = ((motion->pmv[1][1] >> 1) + \ | 1532 | motion_y = ((motion->pmv[1][1] >> 1) + \ |
1340 | get_motion_delta (decoder, motion->f_code[1])); \ | 1533 | get_motion_delta (decoder, motion->f_code[1])); \ |
1341 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | 1534 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ |
1342 | motion->pmv[1][1] = motion_y << 1; \ | 1535 | motion->pmv[1][1] = motion_y << 1; \ |
1343 | \ | 1536 | \ |
1344 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \ | 1537 | MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \ |
1345 | } \ | 1538 | } \ |
1346 | \ | 1539 | \ |
1347 | static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1540 | static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1348 | motion_t * const motion, \ | 1541 | motion_t * const motion, \ |
1349 | mpeg2_mc_fct * const * const table) \ | 1542 | mpeg2_mc_fct * const * const table) \ |
1350 | { \ | 1543 | { \ |
1351 | int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \ | 1544 | int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \ |
1352 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1545 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1353 | \ | 1546 | \ |
1354 | (void)table; \ | 1547 | (void)table; \ |
1355 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1548 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1356 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1549 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1357 | motion->f_code[0]); \ | 1550 | motion->f_code[0]); \ |
1358 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1551 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1359 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | 1552 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ |
1360 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1553 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1361 | dmv_x = get_dmv (decoder); \ | 1554 | dmv_x = get_dmv (decoder); \ |
1362 | \ | 1555 | \ |
1363 | motion_y = ((motion->pmv[0][1] >> 1) + \ | 1556 | motion_y = ((motion->pmv[0][1] >> 1) + \ |
1364 | get_motion_delta (decoder, motion->f_code[1])); \ | 1557 | get_motion_delta (decoder, motion->f_code[1])); \ |
1365 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ | 1558 | /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \ |
1366 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \ | 1559 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \ |
1367 | dmv_y = get_dmv (decoder); \ | 1560 | dmv_y = get_dmv (decoder); \ |
1368 | \ | 1561 | \ |
1369 | m = decoder->top_field_first ? 1 : 3; \ | 1562 | m = decoder->top_field_first ? 1 : 3; \ |
1370 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | 1563 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ |
1371 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \ | 1564 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \ |
1372 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \ | 1565 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \ |
1373 | \ | 1566 | \ |
1374 | m = decoder->top_field_first ? 3 : 1; \ | 1567 | m = decoder->top_field_first ? 3 : 1; \ |
1375 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ | 1568 | other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \ |
1376 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \ | 1569 | other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \ |
1377 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\ | 1570 | MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\ |
1378 | \ | 1571 | \ |
1379 | MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \ | 1572 | MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \ |
1380 | } \ | 1573 | } \ |
1381 | \ | 1574 | \ |
1382 | static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1575 | static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1383 | motion_t * const motion, \ | 1576 | motion_t * const motion, \ |
1384 | mpeg2_mc_fct * const * const table) \ | 1577 | mpeg2_mc_fct * const * const table) \ |
1385 | { \ | 1578 | { \ |
1386 | int motion_x, motion_y; \ | 1579 | int motion_x, motion_y; \ |
1387 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1580 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1388 | \ | 1581 | \ |
1389 | motion_x = motion->pmv[0][0]; \ | 1582 | motion_x = motion->pmv[0][0]; \ |
1390 | motion_y = motion->pmv[0][1]; \ | 1583 | motion_y = motion->pmv[0][1]; \ |
1391 | \ | 1584 | \ |
1392 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ | 1585 | MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \ |
1393 | } \ | 1586 | } \ |
1394 | \ | 1587 | \ |
1395 | static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1588 | static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1396 | motion_t * const motion, \ | 1589 | motion_t * const motion, \ |
1397 | mpeg2_mc_fct * const * const table) \ | 1590 | mpeg2_mc_fct * const * const table) \ |
1398 | { \ | 1591 | { \ |
1399 | unsigned int offset; \ | 1592 | unsigned int offset; \ |
1400 | \ | 1593 | \ |
1401 | motion->pmv[0][0] = motion->pmv[0][1] = 0; \ | 1594 | motion->pmv[0][0] = motion->pmv[0][1] = 0; \ |
1402 | motion->pmv[1][0] = motion->pmv[1][1] = 0; \ | 1595 | motion->pmv[1][0] = motion->pmv[1][1] = 0; \ |
1403 | \ | 1596 | \ |
1404 | MOTION_ZERO (table, motion->ref[0]); \ | 1597 | MOTION_ZERO (table, motion->ref[0]); \ |
1405 | } \ | 1598 | } \ |
1406 | \ | 1599 | \ |
1407 | static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1600 | static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1408 | motion_t * const motion, \ | 1601 | motion_t * const motion, \ |
1409 | mpeg2_mc_fct * const * const table) \ | 1602 | mpeg2_mc_fct * const * const table) \ |
1410 | { \ | 1603 | { \ |
1411 | int motion_x, motion_y; \ | 1604 | int motion_x, motion_y; \ |
1412 | uint8_t ** ref_field; \ | 1605 | uint8_t ** ref_field; \ |
1413 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1606 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1414 | \ | 1607 | \ |
1415 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1608 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1416 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | 1609 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ |
1417 | DUMPBITS (bit_buf, bits, 1); \ | 1610 | DUMPBITS (bit_buf, bits, 1); \ |
1418 | \ | 1611 | \ |
1419 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1612 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1420 | motion->f_code[0]); \ | 1613 | motion->f_code[0]); \ |
1421 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1614 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1422 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | 1615 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ |
1423 | \ | 1616 | \ |
1424 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1617 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1425 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | 1618 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ |
1426 | motion->f_code[1]); \ | 1619 | motion->f_code[1]); \ |
1427 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | 1620 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ |
1428 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | 1621 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ |
1429 | \ | 1622 | \ |
1430 | MOTION (table, ref_field, motion_x, motion_y, 16, 0); \ | 1623 | MOTION (table, ref_field, motion_x, motion_y, 16, 0); \ |
1431 | } \ | 1624 | } \ |
1432 | \ | 1625 | \ |
1433 | static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1626 | static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1434 | motion_t * const motion, \ | 1627 | motion_t * const motion, \ |
1435 | mpeg2_mc_fct * const * const table) \ | 1628 | mpeg2_mc_fct * const * const table) \ |
1436 | { \ | 1629 | { \ |
1437 | int motion_x, motion_y; \ | 1630 | int motion_x, motion_y; \ |
1438 | uint8_t ** ref_field; \ | 1631 | uint8_t ** ref_field; \ |
1439 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1632 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1440 | \ | 1633 | \ |
1441 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1634 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1442 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | 1635 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ |
1443 | DUMPBITS (bit_buf, bits, 1); \ | 1636 | DUMPBITS (bit_buf, bits, 1); \ |
1444 | \ | 1637 | \ |
1445 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1638 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1446 | motion->f_code[0]); \ | 1639 | motion->f_code[0]); \ |
1447 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1640 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1448 | motion->pmv[0][0] = motion_x; \ | 1641 | motion->pmv[0][0] = motion_x; \ |
1449 | \ | 1642 | \ |
1450 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1643 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1451 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | 1644 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ |
1452 | motion->f_code[1]); \ | 1645 | motion->f_code[1]); \ |
1453 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | 1646 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ |
1454 | motion->pmv[0][1] = motion_y; \ | 1647 | motion->pmv[0][1] = motion_y; \ |
1455 | \ | 1648 | \ |
1456 | MOTION (table, ref_field, motion_x, motion_y, 8, 0); \ | 1649 | MOTION (table, ref_field, motion_x, motion_y, 8, 0); \ |
1457 | \ | 1650 | \ |
1458 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1651 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1459 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ | 1652 | ref_field = motion->ref2[UBITS (bit_buf, 1)]; \ |
1460 | DUMPBITS (bit_buf, bits, 1); \ | 1653 | DUMPBITS (bit_buf, bits, 1); \ |
1461 | \ | 1654 | \ |
1462 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ | 1655 | motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \ |
1463 | motion->f_code[0]); \ | 1656 | motion->f_code[0]); \ |
1464 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1657 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1465 | motion->pmv[1][0] = motion_x; \ | 1658 | motion->pmv[1][0] = motion_x; \ |
1466 | \ | 1659 | \ |
1467 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1660 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1468 | motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \ | 1661 | motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \ |
1469 | motion->f_code[1]); \ | 1662 | motion->f_code[1]); \ |
1470 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | 1663 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ |
1471 | motion->pmv[1][1] = motion_y; \ | 1664 | motion->pmv[1][1] = motion_y; \ |
1472 | \ | 1665 | \ |
1473 | MOTION (table, ref_field, motion_x, motion_y, 8, 8); \ | 1666 | MOTION (table, ref_field, motion_x, motion_y, 8, 8); \ |
1474 | } \ | 1667 | } \ |
1475 | \ | 1668 | \ |
1476 | static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ | 1669 | static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \ |
1477 | motion_t * const motion, \ | 1670 | motion_t * const motion, \ |
1478 | mpeg2_mc_fct * const * const table) \ | 1671 | mpeg2_mc_fct * const * const table) \ |
1479 | { \ | 1672 | { \ |
1480 | int motion_x, motion_y, other_x, other_y; \ | 1673 | int motion_x, motion_y, other_x, other_y; \ |
1481 | unsigned int pos_x, pos_y, xy_half, offset; \ | 1674 | unsigned int pos_x, pos_y, xy_half, offset; \ |
1482 | \ | 1675 | \ |
1483 | (void)table; \ | 1676 | (void)table; \ |
1484 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1677 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1485 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ | 1678 | motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \ |
1486 | motion->f_code[0]); \ | 1679 | motion->f_code[0]); \ |
1487 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ | 1680 | motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \ |
1488 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ | 1681 | motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \ |
1489 | NEEDBITS (bit_buf, bits, bit_ptr); \ | 1682 | NEEDBITS (bit_buf, bits, bit_ptr); \ |
1490 | other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \ | 1683 | other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \ |
1491 | \ | 1684 | \ |
1492 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ | 1685 | motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \ |
1493 | motion->f_code[1]); \ | 1686 | motion->f_code[1]); \ |
1494 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ | 1687 | motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \ |
1495 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ | 1688 | motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \ |
1496 | other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \ | 1689 | other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \ |
1497 | decoder->dmv_offset); \ | 1690 | decoder->dmv_offset); \ |
1498 | \ | 1691 | \ |
1499 | MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \ | 1692 | MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \ |
1500 | MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \ | 1693 | MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \ |
1501 | } \ | 1694 | } \ |
1502 | 1695 | ||
1503 | MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420, | 1696 | MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420, |
1504 | MOTION_ZERO_420) | 1697 | MOTION_ZERO_420) |
@@ -1534,16 +1727,21 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder) | |||
1534 | NEEDBITS (bit_buf, bits, bit_ptr); | 1727 | NEEDBITS (bit_buf, bits, bit_ptr); |
1535 | DUMPBITS (bit_buf, bits, 1); /* remove field_select */ | 1728 | DUMPBITS (bit_buf, bits, 1); /* remove field_select */ |
1536 | 1729 | ||
1537 | tmp = (decoder->f_motion.pmv[0][0] + | 1730 | tmp = decoder->f_motion.pmv[0][0] + |
1538 | get_motion_delta (decoder, decoder->f_motion.f_code[0])); | 1731 | get_motion_delta (decoder, decoder->f_motion.f_code[0]); |
1539 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); | 1732 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]); |
1540 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp; | 1733 | |
1734 | decoder->f_motion.pmv[1][0] = | ||
1735 | decoder->f_motion.pmv[0][0] = tmp; | ||
1541 | 1736 | ||
1542 | NEEDBITS (bit_buf, bits, bit_ptr); | 1737 | NEEDBITS (bit_buf, bits, bit_ptr); |
1738 | |||
1543 | tmp = (decoder->f_motion.pmv[0][1] + | 1739 | tmp = (decoder->f_motion.pmv[0][1] + |
1544 | get_motion_delta (decoder, decoder->f_motion.f_code[1])); | 1740 | get_motion_delta (decoder, decoder->f_motion.f_code[1])); |
1545 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); | 1741 | tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]); |
1546 | decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp; | 1742 | |
1743 | decoder->f_motion.pmv[1][1] = | ||
1744 | decoder->f_motion.pmv[0][1] = tmp; | ||
1547 | 1745 | ||
1548 | DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ | 1746 | DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */ |
1549 | } | 1747 | } |
@@ -1552,34 +1750,44 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder) | |||
1552 | #undef bits | 1750 | #undef bits |
1553 | #undef bit_ptr | 1751 | #undef bit_ptr |
1554 | 1752 | ||
1555 | #define MOTION_CALL(routine,direction) \ | 1753 | #define MOTION_CALL(routine, direction) \ |
1556 | do { \ | 1754 | do { \ |
1557 | if ((direction) & MACROBLOCK_MOTION_FORWARD) \ | 1755 | if ((direction) & MACROBLOCK_MOTION_FORWARD) \ |
1558 | routine (decoder, &(decoder->f_motion), mpeg2_mc.put); \ | 1756 | routine (decoder, &decoder->f_motion, mpeg2_mc.put); \ |
1559 | if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ | 1757 | \ |
1560 | routine (decoder, &(decoder->b_motion), \ | 1758 | if ((direction) & MACROBLOCK_MOTION_BACKWARD) \ |
1561 | ((direction) & MACROBLOCK_MOTION_FORWARD ? \ | 1759 | { \ |
1562 | mpeg2_mc.avg : mpeg2_mc.put)); \ | 1760 | routine (decoder, &decoder->b_motion, \ |
1761 | ((direction) & MACROBLOCK_MOTION_FORWARD ? \ | ||
1762 | mpeg2_mc.avg : mpeg2_mc.put)); \ | ||
1763 | } \ | ||
1563 | } while (0) | 1764 | } while (0) |
1564 | 1765 | ||
1565 | #define NEXT_MACROBLOCK \ | 1766 | #define NEXT_MACROBLOCK \ |
1566 | do { \ | 1767 | do { \ |
1567 | decoder->offset += 16; \ | 1768 | decoder->offset += 16; \ |
1568 | if (decoder->offset == decoder->width) { \ | 1769 | \ |
1770 | if (decoder->offset == decoder->width) \ | ||
1771 | { \ | ||
1569 | do { /* just so we can use the break statement */ \ | 1772 | do { /* just so we can use the break statement */ \ |
1570 | if (decoder->convert) { \ | 1773 | if (decoder->convert) \ |
1774 | { \ | ||
1571 | decoder->convert (decoder->convert_id, decoder->dest, \ | 1775 | decoder->convert (decoder->convert_id, decoder->dest, \ |
1572 | decoder->v_offset); \ | 1776 | decoder->v_offset); \ |
1573 | if (decoder->coding_type == B_TYPE) \ | 1777 | if (decoder->coding_type == B_TYPE) \ |
1574 | break; \ | 1778 | break; \ |
1575 | } \ | 1779 | } \ |
1780 | \ | ||
1576 | decoder->dest[0] += decoder->slice_stride; \ | 1781 | decoder->dest[0] += decoder->slice_stride; \ |
1577 | decoder->dest[1] += decoder->slice_uv_stride; \ | 1782 | decoder->dest[1] += decoder->slice_uv_stride; \ |
1578 | decoder->dest[2] += decoder->slice_uv_stride; \ | 1783 | decoder->dest[2] += decoder->slice_uv_stride; \ |
1579 | } while (0); \ | 1784 | } while (0); \ |
1785 | \ | ||
1580 | decoder->v_offset += 16; \ | 1786 | decoder->v_offset += 16; \ |
1787 | \ | ||
1581 | if (decoder->v_offset > decoder->limit_y) \ | 1788 | if (decoder->v_offset > decoder->limit_y) \ |
1582 | return; \ | 1789 | return; \ |
1790 | \ | ||
1583 | decoder->offset = 0; \ | 1791 | decoder->offset = 0; \ |
1584 | } \ | 1792 | } \ |
1585 | } while (0) | 1793 | } while (0) |
@@ -1606,7 +1814,8 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3], | |||
1606 | decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1); | 1814 | decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1); |
1607 | decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1); | 1815 | decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1); |
1608 | 1816 | ||
1609 | if (decoder->picture_structure != FRAME_PICTURE) { | 1817 | if (decoder->picture_structure != FRAME_PICTURE) |
1818 | { | ||
1610 | decoder->dmv_offset = bottom_field ? 1 : -1; | 1819 | decoder->dmv_offset = bottom_field ? 1 : -1; |
1611 | decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field]; | 1820 | decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field]; |
1612 | decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field]; | 1821 | decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field]; |
@@ -1639,44 +1848,59 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3], | |||
1639 | decoder->limit_y_8 = 2 * height - 16; | 1848 | decoder->limit_y_8 = 2 * height - 16; |
1640 | decoder->limit_y = height - 16; | 1849 | decoder->limit_y = height - 16; |
1641 | 1850 | ||
1642 | if (decoder->mpeg1) { | 1851 | if (decoder->mpeg1) |
1852 | { | ||
1643 | decoder->motion_parser[0] = motion_zero_420; | 1853 | decoder->motion_parser[0] = motion_zero_420; |
1644 | decoder->motion_parser[MC_FRAME] = motion_mp1; | 1854 | decoder->motion_parser[MC_FRAME] = motion_mp1; |
1645 | decoder->motion_parser[4] = motion_reuse_420; | 1855 | decoder->motion_parser[4] = motion_reuse_420; |
1646 | } else if (decoder->picture_structure == FRAME_PICTURE) { | 1856 | } |
1647 | if (decoder->chroma_format == 0) { | 1857 | else if (decoder->picture_structure == FRAME_PICTURE) |
1858 | { | ||
1859 | if (decoder->chroma_format == 0) | ||
1860 | { | ||
1648 | decoder->motion_parser[0] = motion_zero_420; | 1861 | decoder->motion_parser[0] = motion_zero_420; |
1649 | decoder->motion_parser[MC_FIELD] = motion_fr_field_420; | 1862 | decoder->motion_parser[MC_FIELD] = motion_fr_field_420; |
1650 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_420; | 1863 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_420; |
1651 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_420; | 1864 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_420; |
1652 | decoder->motion_parser[4] = motion_reuse_420; | 1865 | decoder->motion_parser[4] = motion_reuse_420; |
1653 | } else if (decoder->chroma_format == 1) { | 1866 | } |
1867 | else if (decoder->chroma_format == 1) | ||
1868 | { | ||
1654 | decoder->motion_parser[0] = motion_zero_422; | 1869 | decoder->motion_parser[0] = motion_zero_422; |
1655 | decoder->motion_parser[MC_FIELD] = motion_fr_field_422; | 1870 | decoder->motion_parser[MC_FIELD] = motion_fr_field_422; |
1656 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_422; | 1871 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_422; |
1657 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_422; | 1872 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_422; |
1658 | decoder->motion_parser[4] = motion_reuse_422; | 1873 | decoder->motion_parser[4] = motion_reuse_422; |
1659 | } else { | 1874 | } |
1875 | else | ||
1876 | { | ||
1660 | decoder->motion_parser[0] = motion_zero_444; | 1877 | decoder->motion_parser[0] = motion_zero_444; |
1661 | decoder->motion_parser[MC_FIELD] = motion_fr_field_444; | 1878 | decoder->motion_parser[MC_FIELD] = motion_fr_field_444; |
1662 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_444; | 1879 | decoder->motion_parser[MC_FRAME] = motion_fr_frame_444; |
1663 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_444; | 1880 | decoder->motion_parser[MC_DMV] = motion_fr_dmv_444; |
1664 | decoder->motion_parser[4] = motion_reuse_444; | 1881 | decoder->motion_parser[4] = motion_reuse_444; |
1665 | } | 1882 | } |
1666 | } else { | 1883 | } |
1667 | if (decoder->chroma_format == 0) { | 1884 | else |
1885 | { | ||
1886 | if (decoder->chroma_format == 0) | ||
1887 | { | ||
1668 | decoder->motion_parser[0] = motion_zero_420; | 1888 | decoder->motion_parser[0] = motion_zero_420; |
1669 | decoder->motion_parser[MC_FIELD] = motion_fi_field_420; | 1889 | decoder->motion_parser[MC_FIELD] = motion_fi_field_420; |
1670 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_420; | 1890 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_420; |
1671 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_420; | 1891 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_420; |
1672 | decoder->motion_parser[4] = motion_reuse_420; | 1892 | decoder->motion_parser[4] = motion_reuse_420; |
1673 | } else if (decoder->chroma_format == 1) { | 1893 | } |
1894 | else if (decoder->chroma_format == 1) | ||
1895 | { | ||
1674 | decoder->motion_parser[0] = motion_zero_422; | 1896 | decoder->motion_parser[0] = motion_zero_422; |
1675 | decoder->motion_parser[MC_FIELD] = motion_fi_field_422; | 1897 | decoder->motion_parser[MC_FIELD] = motion_fi_field_422; |
1676 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_422; | 1898 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_422; |
1677 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_422; | 1899 | decoder->motion_parser[MC_DMV] = motion_fi_dmv_422; |
1678 | decoder->motion_parser[4] = motion_reuse_422; | 1900 | decoder->motion_parser[4] = motion_reuse_422; |
1679 | } else { | 1901 | } |
1902 | else | ||
1903 | { | ||
1680 | decoder->motion_parser[0] = motion_zero_444; | 1904 | decoder->motion_parser[0] = motion_zero_444; |
1681 | decoder->motion_parser[MC_FIELD] = motion_fi_field_444; | 1905 | decoder->motion_parser[MC_FIELD] = motion_fi_field_444; |
1682 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_444; | 1906 | decoder->motion_parser[MC_16X8] = motion_fi_16x8_444; |
@@ -1691,6 +1915,7 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code) | |||
1691 | #define bit_buf (decoder->bitstream_buf) | 1915 | #define bit_buf (decoder->bitstream_buf) |
1692 | #define bits (decoder->bitstream_bits) | 1916 | #define bits (decoder->bitstream_bits) |
1693 | #define bit_ptr (decoder->bitstream_ptr) | 1917 | #define bit_ptr (decoder->bitstream_ptr) |
1918 | |||
1694 | int offset; | 1919 | int offset; |
1695 | const MBAtab * mba; | 1920 | const MBAtab * mba; |
1696 | 1921 | ||
@@ -1702,14 +1927,19 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code) | |||
1702 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | 1927 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; |
1703 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | 1928 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; |
1704 | 1929 | ||
1705 | if (decoder->vertical_position_extension) { | 1930 | if (decoder->vertical_position_extension) |
1931 | { | ||
1706 | code += UBITS (bit_buf, 3) << 7; | 1932 | code += UBITS (bit_buf, 3) << 7; |
1707 | DUMPBITS (bit_buf, bits, 3); | 1933 | DUMPBITS (bit_buf, bits, 3); |
1708 | } | 1934 | } |
1935 | |||
1709 | decoder->v_offset = (code - 1) * 16; | 1936 | decoder->v_offset = (code - 1) * 16; |
1710 | offset = 0; | 1937 | offset = 0; |
1938 | |||
1711 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) | 1939 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) |
1940 | { | ||
1712 | offset = (code - 1) * decoder->slice_stride; | 1941 | offset = (code - 1) * decoder->slice_stride; |
1942 | } | ||
1713 | 1943 | ||
1714 | decoder->dest[0] = decoder->picture_dest[0] + offset; | 1944 | decoder->dest[0] = decoder->picture_dest[0] + offset; |
1715 | offset >>= (2 - decoder->chroma_format); | 1945 | offset >>= (2 - decoder->chroma_format); |
@@ -1719,51 +1949,68 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code) | |||
1719 | get_quantizer_scale (decoder); | 1949 | get_quantizer_scale (decoder); |
1720 | 1950 | ||
1721 | /* ignore intra_slice and all the extra data */ | 1951 | /* ignore intra_slice and all the extra data */ |
1722 | while (bit_buf & 0x80000000) { | 1952 | while (bit_buf & 0x80000000) |
1953 | { | ||
1723 | DUMPBITS (bit_buf, bits, 9); | 1954 | DUMPBITS (bit_buf, bits, 9); |
1724 | NEEDBITS (bit_buf, bits, bit_ptr); | 1955 | NEEDBITS (bit_buf, bits, bit_ptr); |
1725 | } | 1956 | } |
1726 | 1957 | ||
1727 | /* decode initial macroblock address increment */ | 1958 | /* decode initial macroblock address increment */ |
1728 | offset = 0; | 1959 | offset = 0; |
1729 | while (1) { | 1960 | while (1) |
1730 | if (bit_buf >= 0x08000000) { | 1961 | { |
1962 | if (bit_buf >= 0x08000000) | ||
1963 | { | ||
1731 | mba = MBA_5 + (UBITS (bit_buf, 6) - 2); | 1964 | mba = MBA_5 + (UBITS (bit_buf, 6) - 2); |
1732 | break; | 1965 | break; |
1733 | } else if (bit_buf >= 0x01800000) { | 1966 | } |
1967 | else if (bit_buf >= 0x01800000) | ||
1968 | { | ||
1734 | mba = MBA_11 + (UBITS (bit_buf, 12) - 24); | 1969 | mba = MBA_11 + (UBITS (bit_buf, 12) - 24); |
1735 | break; | 1970 | break; |
1736 | } else switch (UBITS (bit_buf, 12)) { | 1971 | } |
1737 | case 8: /* macroblock_escape */ | 1972 | else |
1738 | offset += 33; | 1973 | { |
1739 | DUMPBITS (bit_buf, bits, 11); | 1974 | switch (UBITS (bit_buf, 12)) |
1740 | NEEDBITS (bit_buf, bits, bit_ptr); | 1975 | { |
1741 | continue; | 1976 | case 8: /* macroblock_escape */ |
1742 | case 15: /* macroblock_stuffing (MPEG1 only) */ | 1977 | offset += 33; |
1743 | bit_buf &= 0xfffff; | 1978 | DUMPBITS (bit_buf, bits, 11); |
1744 | DUMPBITS (bit_buf, bits, 11); | 1979 | NEEDBITS (bit_buf, bits, bit_ptr); |
1745 | NEEDBITS (bit_buf, bits, bit_ptr); | 1980 | continue; |
1746 | continue; | 1981 | case 15: /* macroblock_stuffing (MPEG1 only) */ |
1747 | default: /* error */ | 1982 | bit_buf &= 0xfffff; |
1748 | return 1; | 1983 | DUMPBITS (bit_buf, bits, 11); |
1984 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
1985 | continue; | ||
1986 | default: /* error */ | ||
1987 | return 1; | ||
1988 | } | ||
1749 | } | 1989 | } |
1750 | } | 1990 | } |
1991 | |||
1751 | DUMPBITS (bit_buf, bits, mba->len + 1); | 1992 | DUMPBITS (bit_buf, bits, mba->len + 1); |
1752 | decoder->offset = (offset + mba->mba) << 4; | 1993 | decoder->offset = (offset + mba->mba) << 4; |
1753 | 1994 | ||
1754 | while (decoder->offset - decoder->width >= 0) { | 1995 | while (decoder->offset - decoder->width >= 0) |
1996 | { | ||
1755 | decoder->offset -= decoder->width; | 1997 | decoder->offset -= decoder->width; |
1756 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) { | 1998 | |
1999 | if (!(decoder->convert) || decoder->coding_type != B_TYPE) | ||
2000 | { | ||
1757 | decoder->dest[0] += decoder->slice_stride; | 2001 | decoder->dest[0] += decoder->slice_stride; |
1758 | decoder->dest[1] += decoder->slice_uv_stride; | 2002 | decoder->dest[1] += decoder->slice_uv_stride; |
1759 | decoder->dest[2] += decoder->slice_uv_stride; | 2003 | decoder->dest[2] += decoder->slice_uv_stride; |
1760 | } | 2004 | } |
2005 | |||
1761 | decoder->v_offset += 16; | 2006 | decoder->v_offset += 16; |
1762 | } | 2007 | } |
2008 | |||
1763 | if (decoder->v_offset > decoder->limit_y) | 2009 | if (decoder->v_offset > decoder->limit_y) |
1764 | return 1; | 2010 | return 1; |
1765 | 2011 | ||
1766 | return 0; | 2012 | return 0; |
2013 | |||
1767 | #undef bit_buf | 2014 | #undef bit_buf |
1768 | #undef bits | 2015 | #undef bits |
1769 | #undef bit_ptr | 2016 | #undef bit_ptr |
@@ -1781,7 +2028,8 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1781 | if (slice_init (decoder, code)) | 2028 | if (slice_init (decoder, code)) |
1782 | return; | 2029 | return; |
1783 | 2030 | ||
1784 | while (1) { | 2031 | while (1) |
2032 | { | ||
1785 | int macroblock_modes; | 2033 | int macroblock_modes; |
1786 | int mba_inc; | 2034 | int mba_inc; |
1787 | const MBAtab * mba; | 2035 | const MBAtab * mba; |
@@ -1794,28 +2042,34 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1794 | if (macroblock_modes & MACROBLOCK_QUANT) | 2042 | if (macroblock_modes & MACROBLOCK_QUANT) |
1795 | get_quantizer_scale (decoder); | 2043 | get_quantizer_scale (decoder); |
1796 | 2044 | ||
1797 | if (macroblock_modes & MACROBLOCK_INTRA) { | 2045 | if (macroblock_modes & MACROBLOCK_INTRA) |
1798 | 2046 | { | |
1799 | int DCT_offset, DCT_stride; | 2047 | int DCT_offset, DCT_stride; |
1800 | int offset; | 2048 | int offset; |
1801 | uint8_t * dest_y; | 2049 | uint8_t * dest_y; |
1802 | 2050 | ||
1803 | if (decoder->concealment_motion_vectors) { | 2051 | if (decoder->concealment_motion_vectors) |
2052 | { | ||
1804 | if (decoder->picture_structure == FRAME_PICTURE) | 2053 | if (decoder->picture_structure == FRAME_PICTURE) |
1805 | motion_fr_conceal (decoder); | 2054 | motion_fr_conceal (decoder); |
1806 | else | 2055 | else |
1807 | motion_fi_conceal (decoder); | 2056 | motion_fi_conceal (decoder); |
1808 | } else { | 2057 | } |
2058 | else | ||
2059 | { | ||
1809 | decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; | 2060 | decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0; |
1810 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; | 2061 | decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0; |
1811 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; | 2062 | decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0; |
1812 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; | 2063 | decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0; |
1813 | } | 2064 | } |
1814 | 2065 | ||
1815 | if (macroblock_modes & DCT_TYPE_INTERLACED) { | 2066 | if (macroblock_modes & DCT_TYPE_INTERLACED) |
2067 | { | ||
1816 | DCT_offset = decoder->stride; | 2068 | DCT_offset = decoder->stride; |
1817 | DCT_stride = decoder->stride * 2; | 2069 | DCT_stride = decoder->stride * 2; |
1818 | } else { | 2070 | } |
2071 | else | ||
2072 | { | ||
1819 | DCT_offset = decoder->stride * 8; | 2073 | DCT_offset = decoder->stride * 8; |
1820 | DCT_stride = decoder->stride; | 2074 | DCT_stride = decoder->stride; |
1821 | } | 2075 | } |
@@ -1826,27 +2080,38 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1826 | slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride); | 2080 | slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride); |
1827 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride); | 2081 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride); |
1828 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride); | 2082 | slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride); |
1829 | if (likely (decoder->chroma_format == 0)) { | 2083 | |
2084 | if (likely (decoder->chroma_format == 0)) | ||
2085 | { | ||
1830 | slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1), | 2086 | slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1), |
1831 | decoder->uv_stride); | 2087 | decoder->uv_stride); |
1832 | slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1), | 2088 | slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1), |
1833 | decoder->uv_stride); | 2089 | decoder->uv_stride); |
1834 | if (decoder->coding_type == D_TYPE) { | 2090 | |
2091 | if (decoder->coding_type == D_TYPE) | ||
2092 | { | ||
1835 | NEEDBITS (bit_buf, bits, bit_ptr); | 2093 | NEEDBITS (bit_buf, bits, bit_ptr); |
1836 | DUMPBITS (bit_buf, bits, 1); | 2094 | DUMPBITS (bit_buf, bits, 1); |
1837 | } | 2095 | } |
1838 | } else if (likely (decoder->chroma_format == 1)) { | 2096 | } |
2097 | else if (likely (decoder->chroma_format == 1)) | ||
2098 | { | ||
1839 | uint8_t * dest_u = decoder->dest[1] + (offset >> 1); | 2099 | uint8_t * dest_u = decoder->dest[1] + (offset >> 1); |
1840 | uint8_t * dest_v = decoder->dest[2] + (offset >> 1); | 2100 | uint8_t * dest_v = decoder->dest[2] + (offset >> 1); |
2101 | |||
1841 | DCT_stride >>= 1; | 2102 | DCT_stride >>= 1; |
1842 | DCT_offset >>= 1; | 2103 | DCT_offset >>= 1; |
2104 | |||
1843 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | 2105 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); |
1844 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | 2106 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); |
1845 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | 2107 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); |
1846 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); | 2108 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride); |
1847 | } else { | 2109 | } |
2110 | else | ||
2111 | { | ||
1848 | uint8_t * dest_u = decoder->dest[1] + offset; | 2112 | uint8_t * dest_u = decoder->dest[1] + offset; |
1849 | uint8_t * dest_v = decoder->dest[2] + offset; | 2113 | uint8_t * dest_v = decoder->dest[2] + offset; |
2114 | |||
1850 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); | 2115 | slice_intra_DCT (decoder, 1, dest_u, DCT_stride); |
1851 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); | 2116 | slice_intra_DCT (decoder, 2, dest_v, DCT_stride); |
1852 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); | 2117 | slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride); |
@@ -1858,52 +2123,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1858 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8, | 2123 | slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8, |
1859 | DCT_stride); | 2124 | DCT_stride); |
1860 | } | 2125 | } |
1861 | } else { | 2126 | } |
1862 | 2127 | else | |
2128 | { | ||
1863 | motion_parser_t * parser; | 2129 | motion_parser_t * parser; |
1864 | 2130 | ||
1865 | parser = | 2131 | parser = |
1866 | decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT]; | 2132 | decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT]; |
1867 | MOTION_CALL (parser, macroblock_modes); | 2133 | MOTION_CALL (parser, macroblock_modes); |
1868 | 2134 | ||
1869 | if (macroblock_modes & MACROBLOCK_PATTERN) { | 2135 | if (macroblock_modes & MACROBLOCK_PATTERN) |
2136 | { | ||
1870 | int coded_block_pattern; | 2137 | int coded_block_pattern; |
1871 | int DCT_offset, DCT_stride; | 2138 | int DCT_offset, DCT_stride; |
1872 | 2139 | ||
1873 | if (macroblock_modes & DCT_TYPE_INTERLACED) { | 2140 | if (macroblock_modes & DCT_TYPE_INTERLACED) |
2141 | { | ||
1874 | DCT_offset = decoder->stride; | 2142 | DCT_offset = decoder->stride; |
1875 | DCT_stride = decoder->stride * 2; | 2143 | DCT_stride = decoder->stride * 2; |
1876 | } else { | 2144 | } |
2145 | else | ||
2146 | { | ||
1877 | DCT_offset = decoder->stride * 8; | 2147 | DCT_offset = decoder->stride * 8; |
1878 | DCT_stride = decoder->stride; | 2148 | DCT_stride = decoder->stride; |
1879 | } | 2149 | } |
1880 | 2150 | ||
1881 | coded_block_pattern = get_coded_block_pattern (decoder); | 2151 | coded_block_pattern = get_coded_block_pattern (decoder); |
1882 | 2152 | ||
1883 | if (likely (decoder->chroma_format == 0)) { | 2153 | if (likely (decoder->chroma_format == 0)) |
2154 | { | ||
1884 | int offset = decoder->offset; | 2155 | int offset = decoder->offset; |
1885 | uint8_t * dest_y = decoder->dest[0] + offset; | 2156 | uint8_t * dest_y = decoder->dest[0] + offset; |
2157 | |||
1886 | if (coded_block_pattern & 1) | 2158 | if (coded_block_pattern & 1) |
1887 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | 2159 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); |
2160 | |||
1888 | if (coded_block_pattern & 2) | 2161 | if (coded_block_pattern & 2) |
1889 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | 2162 | slice_non_intra_DCT (decoder, 0, dest_y + 8, |
1890 | DCT_stride); | 2163 | DCT_stride); |
2164 | |||
1891 | if (coded_block_pattern & 4) | 2165 | if (coded_block_pattern & 4) |
1892 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | 2166 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, |
1893 | DCT_stride); | 2167 | DCT_stride); |
2168 | |||
1894 | if (coded_block_pattern & 8) | 2169 | if (coded_block_pattern & 8) |
1895 | slice_non_intra_DCT (decoder, 0, | 2170 | slice_non_intra_DCT (decoder, 0, |
1896 | dest_y + DCT_offset + 8, | 2171 | dest_y + DCT_offset + 8, |
1897 | DCT_stride); | 2172 | DCT_stride); |
2173 | |||
1898 | if (coded_block_pattern & 16) | 2174 | if (coded_block_pattern & 16) |
1899 | slice_non_intra_DCT (decoder, 1, | 2175 | slice_non_intra_DCT (decoder, 1, |
1900 | decoder->dest[1] + (offset >> 1), | 2176 | decoder->dest[1] + (offset >> 1), |
1901 | decoder->uv_stride); | 2177 | decoder->uv_stride); |
2178 | |||
1902 | if (coded_block_pattern & 32) | 2179 | if (coded_block_pattern & 32) |
1903 | slice_non_intra_DCT (decoder, 2, | 2180 | slice_non_intra_DCT (decoder, 2, |
1904 | decoder->dest[2] + (offset >> 1), | 2181 | decoder->dest[2] + (offset >> 1), |
1905 | decoder->uv_stride); | 2182 | decoder->uv_stride); |
1906 | } else if (likely (decoder->chroma_format == 1)) { | 2183 | } |
2184 | else if (likely (decoder->chroma_format == 1)) | ||
2185 | { | ||
1907 | int offset; | 2186 | int offset; |
1908 | uint8_t * dest_y; | 2187 | uint8_t * dest_y; |
1909 | 2188 | ||
@@ -1912,14 +2191,18 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1912 | 2191 | ||
1913 | offset = decoder->offset; | 2192 | offset = decoder->offset; |
1914 | dest_y = decoder->dest[0] + offset; | 2193 | dest_y = decoder->dest[0] + offset; |
2194 | |||
1915 | if (coded_block_pattern & 1) | 2195 | if (coded_block_pattern & 1) |
1916 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | 2196 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); |
2197 | |||
1917 | if (coded_block_pattern & 2) | 2198 | if (coded_block_pattern & 2) |
1918 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | 2199 | slice_non_intra_DCT (decoder, 0, dest_y + 8, |
1919 | DCT_stride); | 2200 | DCT_stride); |
2201 | |||
1920 | if (coded_block_pattern & 4) | 2202 | if (coded_block_pattern & 4) |
1921 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | 2203 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, |
1922 | DCT_stride); | 2204 | DCT_stride); |
2205 | |||
1923 | if (coded_block_pattern & 8) | 2206 | if (coded_block_pattern & 8) |
1924 | slice_non_intra_DCT (decoder, 0, | 2207 | slice_non_intra_DCT (decoder, 0, |
1925 | dest_y + DCT_offset + 8, | 2208 | dest_y + DCT_offset + 8, |
@@ -1927,23 +2210,29 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1927 | 2210 | ||
1928 | DCT_stride >>= 1; | 2211 | DCT_stride >>= 1; |
1929 | DCT_offset = (DCT_offset + offset) >> 1; | 2212 | DCT_offset = (DCT_offset + offset) >> 1; |
2213 | |||
1930 | if (coded_block_pattern & 16) | 2214 | if (coded_block_pattern & 16) |
1931 | slice_non_intra_DCT (decoder, 1, | 2215 | slice_non_intra_DCT (decoder, 1, |
1932 | decoder->dest[1] + (offset >> 1), | 2216 | decoder->dest[1] + (offset >> 1), |
1933 | DCT_stride); | 2217 | DCT_stride); |
2218 | |||
1934 | if (coded_block_pattern & 32) | 2219 | if (coded_block_pattern & 32) |
1935 | slice_non_intra_DCT (decoder, 2, | 2220 | slice_non_intra_DCT (decoder, 2, |
1936 | decoder->dest[2] + (offset >> 1), | 2221 | decoder->dest[2] + (offset >> 1), |
1937 | DCT_stride); | 2222 | DCT_stride); |
2223 | |||
1938 | if (coded_block_pattern & (2 << 30)) | 2224 | if (coded_block_pattern & (2 << 30)) |
1939 | slice_non_intra_DCT (decoder, 1, | 2225 | slice_non_intra_DCT (decoder, 1, |
1940 | decoder->dest[1] + DCT_offset, | 2226 | decoder->dest[1] + DCT_offset, |
1941 | DCT_stride); | 2227 | DCT_stride); |
2228 | |||
1942 | if (coded_block_pattern & (1 << 30)) | 2229 | if (coded_block_pattern & (1 << 30)) |
1943 | slice_non_intra_DCT (decoder, 2, | 2230 | slice_non_intra_DCT (decoder, 2, |
1944 | decoder->dest[2] + DCT_offset, | 2231 | decoder->dest[2] + DCT_offset, |
1945 | DCT_stride); | 2232 | DCT_stride); |
1946 | } else { | 2233 | } |
2234 | else | ||
2235 | { | ||
1947 | int offset; | 2236 | int offset; |
1948 | uint8_t * dest_y, * dest_u, * dest_v; | 2237 | uint8_t * dest_y, * dest_u, * dest_v; |
1949 | 2238 | ||
@@ -1957,12 +2246,15 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1957 | 2246 | ||
1958 | if (coded_block_pattern & 1) | 2247 | if (coded_block_pattern & 1) |
1959 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); | 2248 | slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride); |
2249 | |||
1960 | if (coded_block_pattern & 2) | 2250 | if (coded_block_pattern & 2) |
1961 | slice_non_intra_DCT (decoder, 0, dest_y + 8, | 2251 | slice_non_intra_DCT (decoder, 0, dest_y + 8, |
1962 | DCT_stride); | 2252 | DCT_stride); |
2253 | |||
1963 | if (coded_block_pattern & 4) | 2254 | if (coded_block_pattern & 4) |
1964 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, | 2255 | slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset, |
1965 | DCT_stride); | 2256 | DCT_stride); |
2257 | |||
1966 | if (coded_block_pattern & 8) | 2258 | if (coded_block_pattern & 8) |
1967 | slice_non_intra_DCT (decoder, 0, | 2259 | slice_non_intra_DCT (decoder, 0, |
1968 | dest_y + DCT_offset + 8, | 2260 | dest_y + DCT_offset + 8, |
@@ -1970,24 +2262,31 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
1970 | 2262 | ||
1971 | if (coded_block_pattern & 16) | 2263 | if (coded_block_pattern & 16) |
1972 | slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride); | 2264 | slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride); |
2265 | |||
1973 | if (coded_block_pattern & 32) | 2266 | if (coded_block_pattern & 32) |
1974 | slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride); | 2267 | slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride); |
2268 | |||
1975 | if (coded_block_pattern & (32 << 26)) | 2269 | if (coded_block_pattern & (32 << 26)) |
1976 | slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset, | 2270 | slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset, |
1977 | DCT_stride); | 2271 | DCT_stride); |
2272 | |||
1978 | if (coded_block_pattern & (16 << 26)) | 2273 | if (coded_block_pattern & (16 << 26)) |
1979 | slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset, | 2274 | slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset, |
1980 | DCT_stride); | 2275 | DCT_stride); |
2276 | |||
1981 | if (coded_block_pattern & (8 << 26)) | 2277 | if (coded_block_pattern & (8 << 26)) |
1982 | slice_non_intra_DCT (decoder, 1, dest_u + 8, | 2278 | slice_non_intra_DCT (decoder, 1, dest_u + 8, |
1983 | DCT_stride); | 2279 | DCT_stride); |
2280 | |||
1984 | if (coded_block_pattern & (4 << 26)) | 2281 | if (coded_block_pattern & (4 << 26)) |
1985 | slice_non_intra_DCT (decoder, 2, dest_v + 8, | 2282 | slice_non_intra_DCT (decoder, 2, dest_v + 8, |
1986 | DCT_stride); | 2283 | DCT_stride); |
2284 | |||
1987 | if (coded_block_pattern & (2 << 26)) | 2285 | if (coded_block_pattern & (2 << 26)) |
1988 | slice_non_intra_DCT (decoder, 1, | 2286 | slice_non_intra_DCT (decoder, 1, |
1989 | dest_u + DCT_offset + 8, | 2287 | dest_u + DCT_offset + 8, |
1990 | DCT_stride); | 2288 | DCT_stride); |
2289 | |||
1991 | if (coded_block_pattern & (1 << 26)) | 2290 | if (coded_block_pattern & (1 << 26)) |
1992 | slice_non_intra_DCT (decoder, 2, | 2291 | slice_non_intra_DCT (decoder, 2, |
1993 | dest_v + DCT_offset + 8, | 2292 | dest_v + DCT_offset + 8, |
@@ -2003,46 +2302,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code, | |||
2003 | 2302 | ||
2004 | NEEDBITS (bit_buf, bits, bit_ptr); | 2303 | NEEDBITS (bit_buf, bits, bit_ptr); |
2005 | mba_inc = 0; | 2304 | mba_inc = 0; |
2006 | while (1) { | 2305 | |
2007 | if (bit_buf >= 0x10000000) { | 2306 | while (1) |
2307 | { | ||
2308 | if (bit_buf >= 0x10000000) | ||
2309 | { | ||
2008 | mba = MBA_5 + (UBITS (bit_buf, 5) - 2); | 2310 | mba = MBA_5 + (UBITS (bit_buf, 5) - 2); |
2009 | break; | 2311 | break; |
2010 | } else if (bit_buf >= 0x03000000) { | 2312 | } |
2313 | else if (bit_buf >= 0x03000000) | ||
2314 | { | ||
2011 | mba = MBA_11 + (UBITS (bit_buf, 11) - 24); | 2315 | mba = MBA_11 + (UBITS (bit_buf, 11) - 24); |
2012 | break; | 2316 | break; |
2013 | } else switch (UBITS (bit_buf, 11)) { | 2317 | } |
2014 | case 8: /* macroblock_escape */ | 2318 | else |
2015 | mba_inc += 33; | 2319 | { |
2016 | /* pass through */ | 2320 | switch (UBITS (bit_buf, 11)) |
2017 | case 15: /* macroblock_stuffing (MPEG1 only) */ | 2321 | { |
2018 | DUMPBITS (bit_buf, bits, 11); | 2322 | case 8: /* macroblock_escape */ |
2019 | NEEDBITS (bit_buf, bits, bit_ptr); | 2323 | mba_inc += 33; |
2020 | continue; | 2324 | /* pass through */ |
2021 | default: /* end of slice, or error */ | 2325 | case 15: /* macroblock_stuffing (MPEG1 only) */ |
2022 | return; | 2326 | DUMPBITS (bit_buf, bits, 11); |
2327 | NEEDBITS (bit_buf, bits, bit_ptr); | ||
2328 | continue; | ||
2329 | default: /* end of slice, or error */ | ||
2330 | return; | ||
2331 | } | ||
2023 | } | 2332 | } |
2024 | } | 2333 | } |
2334 | |||
2025 | DUMPBITS (bit_buf, bits, mba->len); | 2335 | DUMPBITS (bit_buf, bits, mba->len); |
2026 | mba_inc += mba->mba; | 2336 | mba_inc += mba->mba; |
2027 | 2337 | ||
2028 | if (mba_inc) { | 2338 | if (mba_inc) |
2339 | { | ||
2029 | decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = | 2340 | decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] = |
2030 | decoder->dc_dct_pred[2] = 16384; | 2341 | decoder->dc_dct_pred[2] = 16384; |
2031 | 2342 | ||
2032 | if (decoder->coding_type == P_TYPE) { | 2343 | if (decoder->coding_type == P_TYPE) |
2033 | do { | 2344 | { |
2345 | do | ||
2346 | { | ||
2034 | MOTION_CALL (decoder->motion_parser[0], | 2347 | MOTION_CALL (decoder->motion_parser[0], |
2035 | MACROBLOCK_MOTION_FORWARD); | 2348 | MACROBLOCK_MOTION_FORWARD); |
2036 | NEXT_MACROBLOCK; | 2349 | NEXT_MACROBLOCK; |
2037 | } while (--mba_inc); | 2350 | } |
2038 | } else { | 2351 | while (--mba_inc); |
2039 | do { | 2352 | } |
2353 | else | ||
2354 | { | ||
2355 | do | ||
2356 | { | ||
2040 | MOTION_CALL (decoder->motion_parser[4], macroblock_modes); | 2357 | MOTION_CALL (decoder->motion_parser[4], macroblock_modes); |
2041 | NEXT_MACROBLOCK; | 2358 | NEXT_MACROBLOCK; |
2042 | } while (--mba_inc); | 2359 | } |
2360 | while (--mba_inc); | ||
2043 | } | 2361 | } |
2044 | } | 2362 | } |
2045 | } | 2363 | } |
2364 | |||
2046 | #undef bit_buf | 2365 | #undef bit_buf |
2047 | #undef bits | 2366 | #undef bits |
2048 | #undef bit_ptr | 2367 | #undef bit_ptr |