annotate libmpeg2/slice.c @ 36095:042329ce1297

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