annotate libmpeg2/slice.c @ 10560:11826d9f90c7

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