Parent Directory | Revision Log
Revision 1.37 - (view) (download)
1 : | edgomez | 1.26 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | edgomez | 1.27 | * - Macro Block coding functions - |
5 : | edgomez | 1.26 | * |
6 : | * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> | ||
7 : | * | ||
8 : | edgomez | 1.33 | * This file is part of XviD, a free MPEG-4 video encoder/decoder |
9 : | edgomez | 1.26 | * |
10 : | edgomez | 1.33 | * XviD is free software; you can redistribute it and/or modify it |
11 : | * under the terms of the GNU General Public License as published by | ||
12 : | edgomez | 1.26 | * the Free Software Foundation; either version 2 of the License, or |
13 : | * (at your option) any later version. | ||
14 : | * | ||
15 : | * This program is distributed in the hope that it will be useful, | ||
16 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 : | * GNU General Public License for more details. | ||
19 : | * | ||
20 : | * You should have received a copy of the GNU General Public License | ||
21 : | * along with this program; if not, write to the Free Software | ||
22 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 : | * | ||
24 : | edgomez | 1.33 | * Under section 8 of the GNU General Public License, the copyright |
25 : | * holders of XVID explicitly forbid distribution in the following | ||
26 : | * countries: | ||
27 : | * | ||
28 : | * - Japan | ||
29 : | * - United States of America | ||
30 : | * | ||
31 : | * Linking XviD statically or dynamically with other modules is making a | ||
32 : | * combined work based on XviD. Thus, the terms and conditions of the | ||
33 : | * GNU General Public License cover the whole combination. | ||
34 : | * | ||
35 : | * As a special exception, the copyright holders of XviD give you | ||
36 : | * permission to link XviD with independent modules that communicate with | ||
37 : | * XviD solely through the VFW1.1 and DShow interfaces, regardless of the | ||
38 : | * license terms of these independent modules, and to copy and distribute | ||
39 : | * the resulting combined work under terms of your choice, provided that | ||
40 : | * every copy of the combined work is accompanied by a complete copy of | ||
41 : | * the source code of XviD (the version of XviD used to produce the | ||
42 : | * combined work), being distributed under the terms of the GNU General | ||
43 : | * Public License plus this exception. An independent module is a module | ||
44 : | * which is not derived from or based on XviD. | ||
45 : | * | ||
46 : | * Note that people who make modified versions of XviD are not obligated | ||
47 : | * to grant this special exception for their modified versions; it is | ||
48 : | * their choice whether to do so. The GNU General Public License gives | ||
49 : | * permission to release a modified version without this exception; this | ||
50 : | * exception also makes it possible to release a modified version which | ||
51 : | * carries forward this exception. | ||
52 : | * | ||
53 : | edgomez | 1.37 | * $Id$ |
54 : | edgomez | 1.26 | * |
55 : | ****************************************************************************/ | ||
56 : | suxen_drol | 1.11 | |
57 : | Isibaar | 1.8 | #include <stdlib.h> |
58 : | Isibaar | 1.1 | #include "../portab.h" |
59 : | #include "bitstream.h" | ||
60 : | #include "zigzag.h" | ||
61 : | #include "vlc_codes.h" | ||
62 : | Isibaar | 1.8 | #include "mbcoding.h" |
63 : | Isibaar | 1.1 | |
64 : | #include "../utils/mbfunctions.h" | ||
65 : | |||
66 : | #define ABS(X) (((X)>0)?(X):-(X)) | ||
67 : | #define CLIP(X,A) (X > A) ? (A) : (X) | ||
68 : | |||
69 : | edgomez | 1.37 | /*#define _BIGLUT_*/ |
70 : | |||
71 : | #ifdef _BIGLUT_ | ||
72 : | #define LEVELOFFSET 2048 | ||
73 : | #else | ||
74 : | #define LEVELOFFSET 32 | ||
75 : | #endif | ||
76 : | |||
77 : | edgomez | 1.26 | /***************************************************************************** |
78 : | * Local data | ||
79 : | ****************************************************************************/ | ||
80 : | |||
81 : | edgomez | 1.37 | static REVERSE_EVENT DCT3D[2][4096]; |
82 : | edgomez | 1.26 | |
83 : | edgomez | 1.37 | #ifdef _BIGLUT_ |
84 : | static VLC coeff_VLC[2][2][4096][64]; | ||
85 : | VLC *intra_table, *inter_table; | ||
86 : | #else | ||
87 : | static VLC coeff_VLC[2][2][64][64]; | ||
88 : | #endif | ||
89 : | edgomez | 1.26 | |
90 : | /***************************************************************************** | ||
91 : | edgomez | 1.27 | * Vector Length Coding Initialization |
92 : | edgomez | 1.26 | ****************************************************************************/ |
93 : | Isibaar | 1.1 | |
94 : | edgomez | 1.17 | void |
95 : | init_vlc_tables(void) | ||
96 : | Isibaar | 1.1 | { |
97 : | edgomez | 1.37 | uint32_t i, j, intra, last, run, offset; |
98 : | int32_t level; | ||
99 : | VLC coeff_VLC_temp[2][2][64][64]; | ||
100 : | edgomez | 1.7 | |
101 : | edgomez | 1.37 | #ifdef _BIGLUT_ |
102 : | intra_table = coeff_VLC[1]; | ||
103 : | inter_table = coeff_VLC[0]; | ||
104 : | #endif | ||
105 : | |||
106 : | |||
107 : | for (intra = 0; intra < 2; intra++) | ||
108 : | for (i = 0; i < 4096; i++) | ||
109 : | DCT3D[intra][i].event.level = 0; | ||
110 : | |||
111 : | for (intra = 0; intra < 2; intra++) | ||
112 : | for (last = 0; last < 2; last++) | ||
113 : | { | ||
114 : | for (run = 0; run < 63 + last; run++) | ||
115 : | for (level = 0; level < 32 << intra; level++) | ||
116 : | { | ||
117 : | #ifdef _BIGLUT_ | ||
118 : | offset = LEVELOFFSET; | ||
119 : | #else | ||
120 : | offset = !intra * LEVELOFFSET; | ||
121 : | #endif | ||
122 : | coeff_VLC_temp[intra][last][level][run].len = 128; | ||
123 : | coeff_VLC[intra][last][level + offset][run].len = 128; | ||
124 : | Isibaar | 1.1 | } |
125 : | edgomez | 1.37 | } |
126 : | Isibaar | 1.8 | |
127 : | edgomez | 1.37 | for (intra = 0; intra < 2; intra++) |
128 : | for (i = 0; i < 102; i++) | ||
129 : | { | ||
130 : | #ifdef _BIGLUT_ | ||
131 : | offset = LEVELOFFSET; | ||
132 : | #else | ||
133 : | offset = !intra * LEVELOFFSET; | ||
134 : | #endif | ||
135 : | for (j = 0; j < 1 << (12 - coeff_tab[intra][i].vlc.len); j++) | ||
136 : | { | ||
137 : | DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].len = coeff_tab[intra][i].vlc.len; | ||
138 : | DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event; | ||
139 : | } | ||
140 : | Isibaar | 1.8 | |
141 : | edgomez | 1.37 | coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code |
142 : | = coeff_tab[intra][i].vlc.code << 1; | ||
143 : | coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len | ||
144 : | = coeff_tab[intra][i].vlc.len + 1; | ||
145 : | |||
146 : | coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code | ||
147 : | = coeff_tab[intra][i].vlc.code << 1; | ||
148 : | coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len | ||
149 : | = coeff_tab[intra][i].vlc.len + 1; | ||
150 : | #ifndef _BIGLUT_ | ||
151 : | if (!intra) | ||
152 : | #endif | ||
153 : | { | ||
154 : | coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code | ||
155 : | = (coeff_tab[intra][i].vlc.code << 1) | 1; | ||
156 : | coeff_VLC[intra][coeff_tab[intra][i].event.last][offset - coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len | ||
157 : | = coeff_tab[intra][i].vlc.len + 1; | ||
158 : | Isibaar | 1.1 | } |
159 : | } | ||
160 : | |||
161 : | edgomez | 1.37 | for (intra = 0; intra < 2; intra++) |
162 : | for (last = 0; last < 2; last++) | ||
163 : | for (run = 0; run < 63 + last; run++) | ||
164 : | { | ||
165 : | for (level = 1; level < 32 << intra; level++) | ||
166 : | { | ||
167 : | #ifdef _BIGLUT_ | ||
168 : | offset = LEVELOFFSET; | ||
169 : | #else | ||
170 : | offset = !intra * LEVELOFFSET; | ||
171 : | #endif | ||
172 : | if ((max_level[intra][last][run]) && (level > max_level[intra][last][run])) | ||
173 : | if (coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len != 128 | ||
174 : | && coeff_VLC[intra][last][level + offset][run].len == 128) | ||
175 : | { | ||
176 : | coeff_VLC[intra][last][level + offset][run].code | ||
177 : | = (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len) | ||
178 : | | coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code; | ||
179 : | coeff_VLC[intra][last][level + offset][run].len | ||
180 : | = coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1; | ||
181 : | #ifndef _BIGLUT_ | ||
182 : | if (!intra) | ||
183 : | #endif | ||
184 : | { | ||
185 : | coeff_VLC[intra][last][offset - level][run].code | ||
186 : | = (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len) | ||
187 : | | coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code | 1; | ||
188 : | coeff_VLC[intra][last][offset - level][run].len | ||
189 : | = coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1; | ||
190 : | } | ||
191 : | } | ||
192 : | if (run > max_run[intra][last][level]) | ||
193 : | if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len != 128 | ||
194 : | && coeff_VLC[intra][last][level + offset][run].len == 128) | ||
195 : | /*use the lower test instead of the upper to use shorter escape codes when possible : | ||
196 : | if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2 | ||
197 : | < coeff_VLC[intra][last][level + offset][run].len)*/ | ||
198 : | { | ||
199 : | coeff_VLC[intra][last][level + offset][run].code | ||
200 : | = (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len) | ||
201 : | | coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code; | ||
202 : | coeff_VLC[intra][last][level + offset][run].len | ||
203 : | = coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2; | ||
204 : | #ifndef _BIGLUT_ | ||
205 : | if (!intra) | ||
206 : | #endif | ||
207 : | { | ||
208 : | coeff_VLC[intra][last][offset - level][run].code | ||
209 : | = (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len) | ||
210 : | | coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code | 1; | ||
211 : | coeff_VLC[intra][last][offset - level][run].len | ||
212 : | = coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2; | ||
213 : | } | ||
214 : | } | ||
215 : | #ifndef _BIGLUT_ | ||
216 : | if (!intra) | ||
217 : | #endif | ||
218 : | if (coeff_VLC[intra][last][level + offset][run].len == 128) | ||
219 : | { | ||
220 : | coeff_VLC[intra][last][level + offset][run].code | ||
221 : | = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1; | ||
222 : | coeff_VLC[intra][last][level + offset][run].len = 30; | ||
223 : | |||
224 : | coeff_VLC[intra][last][offset - level][run].code | ||
225 : | = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1; | ||
226 : | coeff_VLC[intra][last][offset - level][run].len = 30; | ||
227 : | } | ||
228 : | } | ||
229 : | #ifdef _BIGLUT_ | ||
230 : | for (level = 32 << intra; level < 2048; level++) | ||
231 : | { | ||
232 : | coeff_VLC[intra][last][level + offset][run].code | ||
233 : | = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1; | ||
234 : | coeff_VLC[intra][last][level + offset][run].len = 30; | ||
235 : | |||
236 : | coeff_VLC[intra][last][offset - level][run].code | ||
237 : | = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1; | ||
238 : | coeff_VLC[intra][last][offset - level][run].len = 30; | ||
239 : | } | ||
240 : | #else | ||
241 : | if (!intra) | ||
242 : | { | ||
243 : | coeff_VLC[intra][last][0][run].code | ||
244 : | = (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-32 & 0xfff) << 1) | 1; | ||
245 : | coeff_VLC[intra][last][0][run].len = 30; | ||
246 : | } | ||
247 : | #endif | ||
248 : | } | ||
249 : | Isibaar | 1.1 | } |
250 : | |||
251 : | edgomez | 1.27 | /***************************************************************************** |
252 : | * Local inlined functions for MB coding | ||
253 : | ****************************************************************************/ | ||
254 : | |||
255 : | edgomez | 1.17 | static __inline void |
256 : | CodeVector(Bitstream * bs, | ||
257 : | int32_t value, | ||
258 : | int32_t f_code, | ||
259 : | Statistics * pStat) | ||
260 : | Isibaar | 1.1 | { |
261 : | edgomez | 1.7 | |
262 : | Isibaar | 1.1 | const int scale_factor = 1 << (f_code - 1); |
263 : | const int cmp = scale_factor << 5; | ||
264 : | |||
265 : | edgomez | 1.17 | if (value < (-1 * cmp)) |
266 : | Isibaar | 1.1 | value += 64 * scale_factor; |
267 : | edgomez | 1.17 | |
268 : | if (value > (cmp - 1)) | ||
269 : | Isibaar | 1.1 | value -= 64 * scale_factor; |
270 : | |||
271 : | edgomez | 1.7 | pStat->iMvSum += value * value; |
272 : | pStat->iMvCount++; | ||
273 : | Isibaar | 1.1 | |
274 : | edgomez | 1.7 | if (value == 0) { |
275 : | edgomez | 1.17 | BitstreamPutBits(bs, mb_motion_table[32].code, |
276 : | mb_motion_table[32].len); | ||
277 : | edgomez | 1.7 | } else { |
278 : | Isibaar | 1.1 | uint16_t length, code, mv_res, sign; |
279 : | edgomez | 1.17 | |
280 : | Isibaar | 1.1 | length = 16 << f_code; |
281 : | f_code--; | ||
282 : | edgomez | 1.17 | |
283 : | Isibaar | 1.1 | sign = (value < 0); |
284 : | |||
285 : | edgomez | 1.17 | if (value >= length) |
286 : | Isibaar | 1.1 | value -= 2 * length; |
287 : | edgomez | 1.17 | else if (value < -length) |
288 : | Isibaar | 1.1 | value += 2 * length; |
289 : | |||
290 : | edgomez | 1.17 | if (sign) |
291 : | Isibaar | 1.1 | value = -value; |
292 : | |||
293 : | value--; | ||
294 : | mv_res = value & ((1 << f_code) - 1); | ||
295 : | code = ((value - mv_res) >> f_code) + 1; | ||
296 : | |||
297 : | edgomez | 1.17 | if (sign) |
298 : | Isibaar | 1.1 | code = -code; |
299 : | |||
300 : | code += 32; | ||
301 : | edgomez | 1.17 | BitstreamPutBits(bs, mb_motion_table[code].code, |
302 : | mb_motion_table[code].len); | ||
303 : | |||
304 : | if (f_code) | ||
305 : | Isibaar | 1.1 | BitstreamPutBits(bs, mv_res, f_code); |
306 : | edgomez | 1.7 | } |
307 : | |||
308 : | Isibaar | 1.1 | } |
309 : | |||
310 : | edgomez | 1.37 | #ifdef __BIGLUT_ |
311 : | |||
312 : | edgomez | 1.17 | static __inline void |
313 : | CodeCoeff(Bitstream * bs, | ||
314 : | const int16_t qcoeff[64], | ||
315 : | VLC * table, | ||
316 : | const uint16_t * zigzag, | ||
317 : | uint16_t intra) | ||
318 : | edgomez | 1.7 | { |
319 : | |||
320 : | Isibaar | 1.1 | uint32_t j, last; |
321 : | short v; | ||
322 : | VLC *vlc; | ||
323 : | edgomez | 1.17 | |
324 : | Isibaar | 1.1 | j = intra; |
325 : | Isibaar | 1.10 | last = intra; |
326 : | Isibaar | 1.1 | |
327 : | edgomez | 1.17 | while (j < 64 && (v = qcoeff[zigzag[j]]) == 0) |
328 : | j++; | ||
329 : | |||
330 : | Isibaar | 1.1 | do { |
331 : | edgomez | 1.37 | vlc = table + 64 * 2048 + (v << 6) + j - last; |
332 : | Isibaar | 1.15 | last = ++j; |
333 : | |||
334 : | edgomez | 1.34 | /* count zeroes */ |
335 : | edgomez | 1.17 | while (j < 64 && (v = qcoeff[zigzag[j]]) == 0) |
336 : | j++; | ||
337 : | |||
338 : | edgomez | 1.34 | /* write code */ |
339 : | edgomez | 1.17 | if (j != 64) { |
340 : | Isibaar | 1.1 | BitstreamPutBits(bs, vlc->code, vlc->len); |
341 : | } else { | ||
342 : | edgomez | 1.37 | vlc += 64 * 4096; |
343 : | Isibaar | 1.1 | BitstreamPutBits(bs, vlc->code, vlc->len); |
344 : | break; | ||
345 : | } | ||
346 : | edgomez | 1.17 | } while (1); |
347 : | edgomez | 1.7 | |
348 : | Isibaar | 1.1 | } |
349 : | |||
350 : | edgomez | 1.37 | #else |
351 : | |||
352 : | static __inline void | ||
353 : | CodeCoeffInter(Bitstream * bs, | ||
354 : | const int16_t qcoeff[64], | ||
355 : | const uint16_t * zigzag) | ||
356 : | { | ||
357 : | uint32_t i, run, prev_run, code, len; | ||
358 : | int32_t level, prev_level, level_shifted; | ||
359 : | |||
360 : | i = 0; | ||
361 : | run = 0; | ||
362 : | |||
363 : | while (!(level = qcoeff[zigzag[i++]])) | ||
364 : | run++; | ||
365 : | |||
366 : | prev_level = level; | ||
367 : | prev_run = run; | ||
368 : | run = 0; | ||
369 : | |||
370 : | while (i < 64) | ||
371 : | { | ||
372 : | if ((level = qcoeff[zigzag[i++]]) != 0) | ||
373 : | { | ||
374 : | level_shifted = prev_level + 32; | ||
375 : | if (!(level_shifted & -64)) | ||
376 : | { | ||
377 : | code = coeff_VLC[0][0][level_shifted][prev_run].code; | ||
378 : | len = coeff_VLC[0][0][level_shifted][prev_run].len; | ||
379 : | } | ||
380 : | else | ||
381 : | { | ||
382 : | code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1; | ||
383 : | len = 30; | ||
384 : | } | ||
385 : | BitstreamPutBits(bs, code, len); | ||
386 : | prev_level = level; | ||
387 : | prev_run = run; | ||
388 : | run = 0; | ||
389 : | } | ||
390 : | else | ||
391 : | run++; | ||
392 : | } | ||
393 : | |||
394 : | level_shifted = prev_level + 32; | ||
395 : | if (!(level_shifted & -64)) | ||
396 : | { | ||
397 : | code = coeff_VLC[0][1][level_shifted][prev_run].code; | ||
398 : | len = coeff_VLC[0][1][level_shifted][prev_run].len; | ||
399 : | } | ||
400 : | else | ||
401 : | { | ||
402 : | code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1; | ||
403 : | len = 30; | ||
404 : | } | ||
405 : | BitstreamPutBits(bs, code, len); | ||
406 : | } | ||
407 : | |||
408 : | static __inline void | ||
409 : | CodeCoeffIntra(Bitstream * bs, | ||
410 : | const int16_t qcoeff[64], | ||
411 : | const uint16_t * zigzag) | ||
412 : | { | ||
413 : | uint32_t i, abs_level, run, prev_run, code, len; | ||
414 : | int32_t level, prev_level; | ||
415 : | |||
416 : | i = 1; | ||
417 : | run = 0; | ||
418 : | |||
419 : | while (!(level = qcoeff[zigzag[i++]])) | ||
420 : | run++; | ||
421 : | |||
422 : | prev_level = level; | ||
423 : | prev_run = run; | ||
424 : | run = 0; | ||
425 : | |||
426 : | while (i < 64) | ||
427 : | { | ||
428 : | if ((level = qcoeff[zigzag[i++]]) != 0) | ||
429 : | { | ||
430 : | abs_level = ABS(prev_level); | ||
431 : | abs_level = abs_level < 64 ? abs_level : 0; | ||
432 : | code = coeff_VLC[1][0][abs_level][prev_run].code; | ||
433 : | len = coeff_VLC[1][0][abs_level][prev_run].len; | ||
434 : | if (len != 128) | ||
435 : | code |= (prev_level < 0); | ||
436 : | else | ||
437 : | { | ||
438 : | code = (ESCAPE3 << 21) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1; | ||
439 : | len = 30; | ||
440 : | } | ||
441 : | BitstreamPutBits(bs, code, len); | ||
442 : | prev_level = level; | ||
443 : | prev_run = run; | ||
444 : | run = 0; | ||
445 : | } | ||
446 : | else | ||
447 : | run++; | ||
448 : | } | ||
449 : | |||
450 : | abs_level = ABS(prev_level); | ||
451 : | abs_level = abs_level < 64 ? abs_level : 0; | ||
452 : | code = coeff_VLC[1][1][abs_level][prev_run].code; | ||
453 : | len = coeff_VLC[1][1][abs_level][prev_run].len; | ||
454 : | if (len != 128) | ||
455 : | code |= (prev_level < 0); | ||
456 : | else | ||
457 : | { | ||
458 : | code = (ESCAPE3 << 21) | (1 << 20) | (prev_run << 14) | (1 << 13) | ((prev_level & 0xfff) << 1) | 1; | ||
459 : | len = 30; | ||
460 : | } | ||
461 : | BitstreamPutBits(bs, code, len); | ||
462 : | } | ||
463 : | |||
464 : | #endif | ||
465 : | |||
466 : | edgomez | 1.27 | /***************************************************************************** |
467 : | * Local functions | ||
468 : | ****************************************************************************/ | ||
469 : | Isibaar | 1.1 | |
470 : | edgomez | 1.17 | static void |
471 : | CodeBlockIntra(const FRAMEINFO * frame, | ||
472 : | const MACROBLOCK * pMB, | ||
473 : | int16_t qcoeff[6 * 64], | ||
474 : | edgomez | 1.7 | Bitstream * bs, |
475 : | Statistics * pStat) | ||
476 : | Isibaar | 1.1 | { |
477 : | edgomez | 1.7 | |
478 : | Isibaar | 1.1 | uint32_t i, mcbpc, cbpy, bits; |
479 : | |||
480 : | cbpy = pMB->cbp >> 2; | ||
481 : | |||
482 : | edgomez | 1.34 | /* write mcbpc */ |
483 : | edgomez | 1.17 | if (frame->coding_type == I_VOP) { |
484 : | edgomez | 1.7 | mcbpc = ((pMB->mode >> 1) & 3) | ((pMB->cbp & 3) << 2); |
485 : | edgomez | 1.17 | BitstreamPutBits(bs, mcbpc_intra_tab[mcbpc].code, |
486 : | mcbpc_intra_tab[mcbpc].len); | ||
487 : | } else { | ||
488 : | edgomez | 1.7 | mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); |
489 : | edgomez | 1.17 | BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, |
490 : | mcbpc_inter_tab[mcbpc].len); | ||
491 : | Isibaar | 1.4 | } |
492 : | Isibaar | 1.1 | |
493 : | edgomez | 1.34 | /* ac prediction flag */ |
494 : | edgomez | 1.17 | if (pMB->acpred_directions[0]) |
495 : | edgomez | 1.7 | BitstreamPutBits(bs, 1, 1); |
496 : | Isibaar | 1.1 | else |
497 : | edgomez | 1.7 | BitstreamPutBits(bs, 0, 1); |
498 : | Isibaar | 1.1 | |
499 : | edgomez | 1.34 | /* write cbpy */ |
500 : | edgomez | 1.17 | BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
501 : | Isibaar | 1.1 | |
502 : | edgomez | 1.34 | /* write dquant */ |
503 : | edgomez | 1.17 | if (pMB->mode == MODE_INTRA_Q) |
504 : | Isibaar | 1.1 | BitstreamPutBits(bs, pMB->dquant, 2); |
505 : | |||
506 : | edgomez | 1.34 | /* write interlacing */ |
507 : | edgomez | 1.17 | if (frame->global_flags & XVID_INTERLACING) { |
508 : | h | 1.6 | BitstreamPutBit(bs, pMB->field_dct); |
509 : | } | ||
510 : | edgomez | 1.34 | /* code block coeffs */ |
511 : | edgomez | 1.17 | for (i = 0; i < 6; i++) { |
512 : | if (i < 4) | ||
513 : | BitstreamPutBits(bs, dcy_tab[qcoeff[i * 64 + 0] + 255].code, | ||
514 : | dcy_tab[qcoeff[i * 64 + 0] + 255].len); | ||
515 : | Isibaar | 1.1 | else |
516 : | edgomez | 1.17 | BitstreamPutBits(bs, dcc_tab[qcoeff[i * 64 + 0] + 255].code, |
517 : | dcc_tab[qcoeff[i * 64 + 0] + 255].len); | ||
518 : | |||
519 : | if (pMB->cbp & (1 << (5 - i))) { | ||
520 : | Isibaar | 1.1 | bits = BitstreamPos(bs); |
521 : | |||
522 : | edgomez | 1.37 | #ifdef _BIGLUT_ |
523 : | edgomez | 1.17 | CodeCoeff(bs, &qcoeff[i * 64], intra_table, |
524 : | scan_tables[pMB->acpred_directions[i]], 1); | ||
525 : | edgomez | 1.37 | #else |
526 : | CodeCoeffIntra(bs, &qcoeff[i * 64], scan_tables[pMB->acpred_directions[i]]); | ||
527 : | #endif | ||
528 : | Isibaar | 1.1 | bits = BitstreamPos(bs) - bits; |
529 : | pStat->iTextBits += bits; | ||
530 : | } | ||
531 : | } | ||
532 : | edgomez | 1.7 | |
533 : | Isibaar | 1.1 | } |
534 : | |||
535 : | |||
536 : | edgomez | 1.17 | static void |
537 : | CodeBlockInter(const FRAMEINFO * frame, | ||
538 : | const MACROBLOCK * pMB, | ||
539 : | int16_t qcoeff[6 * 64], | ||
540 : | edgomez | 1.7 | Bitstream * bs, |
541 : | Statistics * pStat) | ||
542 : | Isibaar | 1.1 | { |
543 : | edgomez | 1.7 | |
544 : | Isibaar | 1.1 | int32_t i; |
545 : | uint32_t bits, mcbpc, cbpy; | ||
546 : | |||
547 : | edgomez | 1.7 | mcbpc = (pMB->mode & 7) | ((pMB->cbp & 3) << 3); |
548 : | Isibaar | 1.1 | cbpy = 15 - (pMB->cbp >> 2); |
549 : | |||
550 : | edgomez | 1.34 | /* write mcbpc */ |
551 : | edgomez | 1.17 | BitstreamPutBits(bs, mcbpc_inter_tab[mcbpc].code, |
552 : | mcbpc_inter_tab[mcbpc].len); | ||
553 : | Isibaar | 1.1 | |
554 : | edgomez | 1.34 | /* write cbpy */ |
555 : | Isibaar | 1.1 | BitstreamPutBits(bs, cbpy_tab[cbpy].code, cbpy_tab[cbpy].len); |
556 : | |||
557 : | edgomez | 1.34 | /* write dquant */ |
558 : | edgomez | 1.17 | if (pMB->mode == MODE_INTER_Q) |
559 : | Isibaar | 1.1 | BitstreamPutBits(bs, pMB->dquant, 2); |
560 : | edgomez | 1.17 | |
561 : | edgomez | 1.34 | /* interlacing */ |
562 : | edgomez | 1.17 | if (frame->global_flags & XVID_INTERLACING) { |
563 : | h | 1.25 | if (pMB->cbp) { |
564 : | BitstreamPutBit(bs, pMB->field_dct); | ||
565 : | edgomez | 1.32 | DPRINTF(DPRINTF_DEBUG, "codep: field_dct: %d", pMB->field_dct); |
566 : | h | 1.25 | } |
567 : | h | 1.6 | |
568 : | edgomez | 1.34 | /* if inter block, write field ME flag */ |
569 : | edgomez | 1.17 | if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) { |
570 : | h | 1.6 | BitstreamPutBit(bs, pMB->field_pred); |
571 : | edgomez | 1.32 | DPRINTF(DPRINTF_DEBUG, "codep: field_pred: %d", pMB->field_pred); |
572 : | h | 1.6 | |
573 : | edgomez | 1.34 | /* write field prediction references */ |
574 : | edgomez | 1.17 | if (pMB->field_pred) { |
575 : | h | 1.6 | BitstreamPutBit(bs, pMB->field_for_top); |
576 : | BitstreamPutBit(bs, pMB->field_for_bot); | ||
577 : | } | ||
578 : | } | ||
579 : | } | ||
580 : | edgomez | 1.34 | /* code motion vector(s) */ |
581 : | edgomez | 1.17 | for (i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) { |
582 : | suxen_drol | 1.13 | CodeVector(bs, pMB->pmvs[i].x, frame->fcode, pStat); |
583 : | CodeVector(bs, pMB->pmvs[i].y, frame->fcode, pStat); | ||
584 : | Isibaar | 1.1 | } |
585 : | |||
586 : | bits = BitstreamPos(bs); | ||
587 : | edgomez | 1.17 | |
588 : | edgomez | 1.34 | /* code block coeffs */ |
589 : | edgomez | 1.17 | for (i = 0; i < 6; i++) |
590 : | if (pMB->cbp & (1 << (5 - i))) | ||
591 : | edgomez | 1.37 | #ifdef _BIGLUT_ |
592 : | edgomez | 1.17 | CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0); |
593 : | edgomez | 1.37 | #else |
594 : | CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]); | ||
595 : | #endif | ||
596 : | Isibaar | 1.1 | |
597 : | bits = BitstreamPos(bs) - bits; | ||
598 : | pStat->iTextBits += bits; | ||
599 : | edgomez | 1.7 | |
600 : | Isibaar | 1.1 | } |
601 : | |||
602 : | edgomez | 1.27 | /***************************************************************************** |
603 : | * Macro Block bitstream encoding functions | ||
604 : | ****************************************************************************/ | ||
605 : | Isibaar | 1.1 | |
606 : | edgomez | 1.17 | void |
607 : | MBCoding(const FRAMEINFO * frame, | ||
608 : | MACROBLOCK * pMB, | ||
609 : | int16_t qcoeff[6 * 64], | ||
610 : | Bitstream * bs, | ||
611 : | Statistics * pStat) | ||
612 : | Isibaar | 1.1 | { |
613 : | edgomez | 1.7 | |
614 : | edgomez | 1.17 | if (frame->coding_type == P_VOP) { |
615 : | edgomez | 1.34 | BitstreamPutBit(bs, 0); /* coded */ |
616 : | Isibaar | 1.1 | } |
617 : | |||
618 : | chl | 1.22 | if (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q) |
619 : | suxen_drol | 1.13 | CodeBlockIntra(frame, pMB, qcoeff, bs, pStat); |
620 : | Isibaar | 1.1 | else |
621 : | suxen_drol | 1.13 | CodeBlockInter(frame, pMB, qcoeff, bs, pStat); |
622 : | edgomez | 1.7 | |
623 : | Isibaar | 1.1 | } |
624 : | chl | 1.24 | |
625 : | |||
626 : | void | ||
627 : | MBSkip(Bitstream * bs) | ||
628 : | { | ||
629 : | edgomez | 1.34 | BitstreamPutBit(bs, 1); /* not coded */ |
630 : | chl | 1.24 | return; |
631 : | } | ||
632 : | Isibaar | 1.1 | |
633 : | edgomez | 1.27 | /***************************************************************************** |
634 : | * decoding stuff starts here | ||
635 : | ****************************************************************************/ | ||
636 : | Isibaar | 1.1 | |
637 : | edgomez | 1.27 | /* |
638 : | * For IVOP addbits == 0 | ||
639 : | * For PVOP addbits == fcode - 1 | ||
640 : | * For BVOP addbits == max(fcode,bcode) - 1 | ||
641 : | * returns true or false | ||
642 : | */ | ||
643 : | suxen_drol | 1.19 | |
644 : | int | ||
645 : | check_resync_marker(Bitstream * bs, int addbits) | ||
646 : | { | ||
647 : | uint32_t nbits; | ||
648 : | uint32_t code; | ||
649 : | uint32_t nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits; | ||
650 : | |||
651 : | nbits = BitstreamNumBitsToByteAlign(bs); | ||
652 : | code = BitstreamShowBits(bs, nbits); | ||
653 : | |||
654 : | if (code == (((uint32_t)1 << (nbits - 1)) - 1)) | ||
655 : | { | ||
656 : | return BitstreamShowBitsFromByteAlign(bs, nbitsresyncmarker) == RESYNC_MARKER; | ||
657 : | } | ||
658 : | |||
659 : | return 0; | ||
660 : | } | ||
661 : | |||
662 : | |||
663 : | |||
664 : | edgomez | 1.17 | int |
665 : | get_mcbpc_intra(Bitstream * bs) | ||
666 : | Isibaar | 1.1 | { |
667 : | edgomez | 1.7 | |
668 : | Isibaar | 1.1 | uint32_t index; |
669 : | edgomez | 1.17 | |
670 : | suxen_drol | 1.19 | index = BitstreamShowBits(bs, 9); |
671 : | Isibaar | 1.1 | index >>= 3; |
672 : | |||
673 : | BitstreamSkip(bs, mcbpc_intra_table[index].len); | ||
674 : | edgomez | 1.7 | |
675 : | Isibaar | 1.1 | return mcbpc_intra_table[index].code; |
676 : | edgomez | 1.7 | |
677 : | Isibaar | 1.1 | } |
678 : | |||
679 : | edgomez | 1.17 | int |
680 : | get_mcbpc_inter(Bitstream * bs) | ||
681 : | Isibaar | 1.1 | { |
682 : | edgomez | 1.7 | |
683 : | Isibaar | 1.1 | uint32_t index; |
684 : | suxen_drol | 1.19 | |
685 : | index = CLIP(BitstreamShowBits(bs, 9), 256); | ||
686 : | Isibaar | 1.1 | |
687 : | edgomez | 1.17 | BitstreamSkip(bs, mcbpc_inter_table[index].len); |
688 : | edgomez | 1.7 | |
689 : | Isibaar | 1.1 | return mcbpc_inter_table[index].code; |
690 : | edgomez | 1.7 | |
691 : | Isibaar | 1.1 | } |
692 : | |||
693 : | edgomez | 1.17 | int |
694 : | get_cbpy(Bitstream * bs, | ||
695 : | int intra) | ||
696 : | Isibaar | 1.1 | { |
697 : | edgomez | 1.7 | |
698 : | Isibaar | 1.1 | int cbpy; |
699 : | uint32_t index = BitstreamShowBits(bs, 6); | ||
700 : | |||
701 : | BitstreamSkip(bs, cbpy_table[index].len); | ||
702 : | cbpy = cbpy_table[index].code; | ||
703 : | |||
704 : | edgomez | 1.17 | if (!intra) |
705 : | Isibaar | 1.1 | cbpy = 15 - cbpy; |
706 : | |||
707 : | return cbpy; | ||
708 : | edgomez | 1.7 | |
709 : | Isibaar | 1.1 | } |
710 : | |||
711 : | edgomez | 1.17 | int |
712 : | get_mv_data(Bitstream * bs) | ||
713 : | Isibaar | 1.1 | { |
714 : | edgomez | 1.7 | |
715 : | Isibaar | 1.1 | uint32_t index; |
716 : | |||
717 : | edgomez | 1.17 | if (BitstreamGetBit(bs)) |
718 : | Isibaar | 1.1 | return 0; |
719 : | edgomez | 1.17 | |
720 : | Isibaar | 1.1 | index = BitstreamShowBits(bs, 12); |
721 : | |||
722 : | edgomez | 1.17 | if (index >= 512) { |
723 : | Isibaar | 1.1 | index = (index >> 8) - 2; |
724 : | BitstreamSkip(bs, TMNMVtab0[index].len); | ||
725 : | return TMNMVtab0[index].code; | ||
726 : | } | ||
727 : | edgomez | 1.17 | |
728 : | if (index >= 128) { | ||
729 : | Isibaar | 1.1 | index = (index >> 2) - 32; |
730 : | BitstreamSkip(bs, TMNMVtab1[index].len); | ||
731 : | return TMNMVtab1[index].code; | ||
732 : | } | ||
733 : | |||
734 : | edgomez | 1.17 | index -= 4; |
735 : | Isibaar | 1.1 | |
736 : | BitstreamSkip(bs, TMNMVtab2[index].len); | ||
737 : | return TMNMVtab2[index].code; | ||
738 : | edgomez | 1.7 | |
739 : | Isibaar | 1.1 | } |
740 : | |||
741 : | edgomez | 1.17 | int |
742 : | get_mv(Bitstream * bs, | ||
743 : | int fcode) | ||
744 : | Isibaar | 1.1 | { |
745 : | edgomez | 1.7 | |
746 : | Isibaar | 1.1 | int data; |
747 : | int res; | ||
748 : | int mv; | ||
749 : | int scale_fac = 1 << (fcode - 1); | ||
750 : | |||
751 : | data = get_mv_data(bs); | ||
752 : | edgomez | 1.17 | |
753 : | if (scale_fac == 1 || data == 0) | ||
754 : | Isibaar | 1.1 | return data; |
755 : | |||
756 : | res = BitstreamGetBits(bs, fcode - 1); | ||
757 : | mv = ((ABS(data) - 1) * scale_fac) + res + 1; | ||
758 : | edgomez | 1.17 | |
759 : | Isibaar | 1.1 | return data < 0 ? -mv : mv; |
760 : | edgomez | 1.7 | |
761 : | Isibaar | 1.1 | } |
762 : | |||
763 : | edgomez | 1.17 | int |
764 : | get_dc_dif(Bitstream * bs, | ||
765 : | uint32_t dc_size) | ||
766 : | Isibaar | 1.1 | { |
767 : | edgomez | 1.7 | |
768 : | Isibaar | 1.1 | int code = BitstreamGetBits(bs, dc_size); |
769 : | int msb = code >> (dc_size - 1); | ||
770 : | |||
771 : | edgomez | 1.17 | if (msb == 0) |
772 : | return (-1 * (code ^ ((1 << dc_size) - 1))); | ||
773 : | Isibaar | 1.1 | |
774 : | return code; | ||
775 : | edgomez | 1.7 | |
776 : | Isibaar | 1.1 | } |
777 : | |||
778 : | edgomez | 1.17 | int |
779 : | get_dc_size_lum(Bitstream * bs) | ||
780 : | Isibaar | 1.1 | { |
781 : | edgomez | 1.7 | |
782 : | Isibaar | 1.1 | int code, i; |
783 : | edgomez | 1.17 | |
784 : | Isibaar | 1.1 | code = BitstreamShowBits(bs, 11); |
785 : | |||
786 : | edgomez | 1.17 | for (i = 11; i > 3; i--) { |
787 : | if (code == 1) { | ||
788 : | Isibaar | 1.1 | BitstreamSkip(bs, i); |
789 : | return i + 1; | ||
790 : | } | ||
791 : | code >>= 1; | ||
792 : | } | ||
793 : | |||
794 : | BitstreamSkip(bs, dc_lum_tab[code].len); | ||
795 : | return dc_lum_tab[code].code; | ||
796 : | edgomez | 1.7 | |
797 : | Isibaar | 1.1 | } |
798 : | |||
799 : | |||
800 : | edgomez | 1.17 | int |
801 : | get_dc_size_chrom(Bitstream * bs) | ||
802 : | Isibaar | 1.1 | { |
803 : | edgomez | 1.7 | |
804 : | Isibaar | 1.1 | uint32_t code, i; |
805 : | edgomez | 1.17 | |
806 : | Isibaar | 1.1 | code = BitstreamShowBits(bs, 12); |
807 : | |||
808 : | edgomez | 1.17 | for (i = 12; i > 2; i--) { |
809 : | if (code == 1) { | ||
810 : | Isibaar | 1.1 | BitstreamSkip(bs, i); |
811 : | return i; | ||
812 : | } | ||
813 : | code >>= 1; | ||
814 : | } | ||
815 : | |||
816 : | return 3 - BitstreamGetBits(bs, 2); | ||
817 : | edgomez | 1.7 | |
818 : | Isibaar | 1.1 | } |
819 : | edgomez | 1.27 | |
820 : | /***************************************************************************** | ||
821 : | * Local inlined function to "decode" written vlc codes | ||
822 : | ****************************************************************************/ | ||
823 : | |||
824 : | static __inline int | ||
825 : | get_coeff(Bitstream * bs, | ||
826 : | int *run, | ||
827 : | int *last, | ||
828 : | int intra, | ||
829 : | int short_video_header) | ||
830 : | { | ||
831 : | |||
832 : | uint32_t mode; | ||
833 : | int32_t level; | ||
834 : | edgomez | 1.37 | REVERSE_EVENT *reverse_event; |
835 : | edgomez | 1.27 | |
836 : | edgomez | 1.34 | if (short_video_header) /* inter-VLCs will be used for both intra and inter blocks */ |
837 : | edgomez | 1.27 | intra = 0; |
838 : | |||
839 : | edgomez | 1.37 | if (BitstreamShowBits(bs, 7) != ESCAPE) { |
840 : | reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)]; | ||
841 : | |||
842 : | if ((level = reverse_event->event.level) == 0) | ||
843 : | goto error; | ||
844 : | edgomez | 1.27 | |
845 : | edgomez | 1.37 | *last = reverse_event->event.last; |
846 : | *run = reverse_event->event.run; | ||
847 : | edgomez | 1.27 | |
848 : | edgomez | 1.37 | BitstreamSkip(bs, reverse_event->len); |
849 : | edgomez | 1.27 | |
850 : | edgomez | 1.37 | return BitstreamGetBits(bs, 1) ? -level : level; |
851 : | edgomez | 1.27 | } |
852 : | |||
853 : | edgomez | 1.37 | BitstreamSkip(bs, 7); |
854 : | |||
855 : | edgomez | 1.27 | if (short_video_header) { |
856 : | edgomez | 1.34 | /* escape mode 4 - H.263 type, only used if short_video_header = 1 */ |
857 : | edgomez | 1.27 | *last = BitstreamGetBit(bs); |
858 : | *run = BitstreamGetBits(bs, 6); | ||
859 : | level = BitstreamGetBits(bs, 8); | ||
860 : | |||
861 : | if (level == 0 || level == 128) | ||
862 : | edgomez | 1.32 | DPRINTF(DPRINTF_ERROR, "Illegal LEVEL for ESCAPE mode 4: %d", level); |
863 : | edgomez | 1.27 | |
864 : | edgomez | 1.37 | return (level << 24) >> 24; |
865 : | edgomez | 1.27 | } |
866 : | |||
867 : | mode = BitstreamShowBits(bs, 2); | ||
868 : | |||
869 : | if (mode < 3) { | ||
870 : | BitstreamSkip(bs, (mode == 2) ? 2 : 1); | ||
871 : | |||
872 : | edgomez | 1.37 | reverse_event = &DCT3D[intra][BitstreamShowBits(bs, 12)]; |
873 : | |||
874 : | if ((level = reverse_event->event.level) == 0) | ||
875 : | edgomez | 1.27 | goto error; |
876 : | |||
877 : | edgomez | 1.37 | *last = reverse_event->event.last; |
878 : | *run = reverse_event->event.run; | ||
879 : | edgomez | 1.27 | |
880 : | edgomez | 1.37 | BitstreamSkip(bs, reverse_event->len); |
881 : | edgomez | 1.27 | |
882 : | edgomez | 1.34 | if (mode < 2) /* first escape mode, level is offset */ |
883 : | edgomez | 1.37 | level += max_level[intra][*last][*run]; |
884 : | else /* second escape mode, run is offset */ | ||
885 : | *run += max_run[intra][*last][level] + 1; | ||
886 : | edgomez | 1.27 | |
887 : | edgomez | 1.37 | return BitstreamGetBits(bs, 1) ? -level : level; |
888 : | edgomez | 1.27 | } |
889 : | edgomez | 1.37 | |
890 : | edgomez | 1.34 | /* third escape mode - fixed length codes */ |
891 : | edgomez | 1.27 | BitstreamSkip(bs, 2); |
892 : | *last = BitstreamGetBits(bs, 1); | ||
893 : | *run = BitstreamGetBits(bs, 6); | ||
894 : | edgomez | 1.34 | BitstreamSkip(bs, 1); /* marker */ |
895 : | edgomez | 1.27 | level = BitstreamGetBits(bs, 12); |
896 : | edgomez | 1.34 | BitstreamSkip(bs, 1); /* marker */ |
897 : | edgomez | 1.27 | |
898 : | edgomez | 1.37 | return (level << 20) >> 20; |
899 : | edgomez | 1.27 | |
900 : | error: | ||
901 : | *run = VLC_ERROR; | ||
902 : | return 0; | ||
903 : | } | ||
904 : | |||
905 : | /***************************************************************************** | ||
906 : | * MB reading functions | ||
907 : | ****************************************************************************/ | ||
908 : | Isibaar | 1.1 | |
909 : | edgomez | 1.17 | void |
910 : | get_intra_block(Bitstream * bs, | ||
911 : | int16_t * block, | ||
912 : | int direction, | ||
913 : | int coeff) | ||
914 : | Isibaar | 1.1 | { |
915 : | edgomez | 1.7 | |
916 : | edgomez | 1.17 | const uint16_t *scan = scan_tables[direction]; |
917 : | Isibaar | 1.1 | int level; |
918 : | int run; | ||
919 : | int last; | ||
920 : | |||
921 : | edgomez | 1.17 | do { |
922 : | Isibaar | 1.1 | level = get_coeff(bs, &run, &last, 1, 0); |
923 : | edgomez | 1.17 | if (run == -1) { |
924 : | edgomez | 1.32 | DPRINTF(DPRINTF_DEBUG, "fatal: invalid run"); |
925 : | Isibaar | 1.1 | break; |
926 : | } | ||
927 : | coeff += run; | ||
928 : | edgomez | 1.17 | block[scan[coeff]] = level; |
929 : | suxen_drol | 1.20 | |
930 : | DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[coeff], level); | ||
931 : | edgomez | 1.34 | /*DPRINTF(DPRINTF_COEFF,"block[%i] %i %08x", scan[coeff], level, BitstreamShowBits(bs, 32)); */ |
932 : | suxen_drol | 1.20 | |
933 : | suxen_drol | 1.36 | if (level < -2047 || level > 2047) { |
934 : | edgomez | 1.32 | DPRINTF(DPRINTF_DEBUG, "warning: intra_overflow: %d", level); |
935 : | Isibaar | 1.1 | } |
936 : | coeff++; | ||
937 : | } while (!last); | ||
938 : | edgomez | 1.7 | |
939 : | Isibaar | 1.1 | } |
940 : | |||
941 : | edgomez | 1.17 | void |
942 : | get_inter_block(Bitstream * bs, | ||
943 : | int16_t * block) | ||
944 : | Isibaar | 1.1 | { |
945 : | edgomez | 1.7 | |
946 : | edgomez | 1.17 | const uint16_t *scan = scan_tables[0]; |
947 : | Isibaar | 1.1 | int p; |
948 : | int level; | ||
949 : | int run; | ||
950 : | int last; | ||
951 : | |||
952 : | p = 0; | ||
953 : | edgomez | 1.17 | do { |
954 : | Isibaar | 1.1 | level = get_coeff(bs, &run, &last, 0, 0); |
955 : | edgomez | 1.17 | if (run == -1) { |
956 : | edgomez | 1.32 | DPRINTF(DPRINTF_ERROR, "fatal: invalid run"); |
957 : | Isibaar | 1.1 | break; |
958 : | } | ||
959 : | p += run; | ||
960 : | chenm001 | 1.16 | |
961 : | edgomez | 1.17 | block[scan[p]] = level; |
962 : | suxen_drol | 1.20 | |
963 : | DPRINTF(DPRINTF_COEFF,"block[%i] %i", scan[p], level); | ||
964 : | |||
965 : | suxen_drol | 1.36 | if (level < -2047 || level > 2047) { |
966 : | edgomez | 1.32 | DPRINTF(DPRINTF_DEBUG, "warning: inter_overflow: %d", level); |
967 : | Isibaar | 1.1 | } |
968 : | p++; | ||
969 : | } while (!last); | ||
970 : | edgomez | 1.7 | |
971 : | Isibaar | 1.1 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |