annotate libmpeg2/slice.c @ 1607:7336606415f2

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