annotate libmpeg2/slice.c @ 21:9311e47da144

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