1 |
|
#include <stdlib.h> |
2 |
#include "../portab.h" |
#include "../portab.h" |
3 |
#include "bitstream.h" |
#include "bitstream.h" |
4 |
#include "zigzag.h" |
#include "zigzag.h" |
5 |
#include "vlc_codes.h" |
#include "vlc_codes.h" |
6 |
|
#include "mbcoding.h" |
7 |
|
|
8 |
#include "../utils/mbfunctions.h" |
#include "../utils/mbfunctions.h" |
9 |
|
|
|
#include <stdlib.h> /* malloc, free */ |
|
|
|
|
10 |
#define ESCAPE 7167 |
#define ESCAPE 7167 |
11 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
12 |
#define CLIP(X,A) (X > A) ? (A) : (X) |
#define CLIP(X,A) (X > A) ? (A) : (X) |
13 |
|
|
14 |
|
VLC DCT3Dintra[4096]; |
15 |
|
VLC DCT3Dinter[4096]; |
16 |
static VLC *DCT3D[2]; |
static VLC *DCT3D[2]; |
17 |
|
|
18 |
VLC *intra_table, *inter_table; |
VLC intra_table[65536]; |
19 |
|
VLC inter_table[65536]; |
20 |
|
|
21 |
static short clip_table[4096]; |
static short clip_table[4096]; |
22 |
|
|
23 |
void create_vlc_tables(void) |
void init_vlc_tables(void) |
24 |
{ |
{ |
25 |
|
|
26 |
int32_t k, l, i, intra, last; |
int32_t k, l, i, intra, last; |
27 |
VLC *vlc[2]; |
VLC *vlc[2]; |
28 |
VLC **coeff_ptr; |
VLC **coeff_ptr; |
29 |
VLC *vlc1, *vlc2; |
VLC *vlc1, *vlc2; |
30 |
|
|
|
VLC *DCT3Dintra; |
|
|
VLC *DCT3Dinter; |
|
|
|
|
|
DCT3Dintra = (VLC *) malloc(sizeof(VLC) * 4096); |
|
|
DCT3Dinter = (VLC *) malloc(sizeof(VLC) * 4096); |
|
|
|
|
31 |
vlc1 = DCT3Dintra; |
vlc1 = DCT3Dintra; |
32 |
vlc2 = DCT3Dinter; |
vlc2 = DCT3Dinter; |
33 |
|
|
34 |
vlc[0] = intra_table = (VLC *) malloc(128 * 511 * sizeof(VLC)); |
vlc[0] = intra_table; |
35 |
vlc[1] = inter_table = (VLC *) malloc(128 * 511 * sizeof(VLC)); |
vlc[1] = inter_table; |
36 |
|
|
37 |
// initialize the clipping table |
// initialize the clipping table |
38 |
for(i = -2048; i < 2048; i++) { |
for(i = -2048; i < 2048; i++) { |
43 |
clip_table[i + 2048] = 255; |
clip_table[i + 2048] = 255; |
44 |
} |
} |
45 |
|
|
46 |
// generate intra/inter vlc lookup table |
// generate encoding vlc lookup tables |
47 |
for(i = 0; i < 4; i++) { |
for(i = 0; i < 4; i++) { |
48 |
intra = i % 2; |
intra = i % 2; |
49 |
last = i >> 1; |
last = i / 2; |
50 |
|
|
51 |
coeff_ptr = coeff_vlc[last + (intra << 1)]; |
coeff_ptr = coeff_vlc[last + 2 * intra]; |
52 |
|
|
53 |
for(k = -255; k < 256; k++) { // level |
for(k = -255; k < 256; k++) { // level |
54 |
char *max_level_ptr = max_level[last + (intra << 1)]; |
int8_t *max_level_ptr = max_level[last + 2 * intra]; |
55 |
char *max_run_ptr = max_run[last + (intra << 1)]; |
int8_t *max_run_ptr = max_run[last + 2 * intra]; |
56 |
|
|
57 |
for(l = 0; l < 64; l++) { // run |
for(l = 0; l < 64; l++) { // run |
58 |
int32_t level = k; |
int32_t level = k; |
59 |
uint32_t run = l; |
uint32_t run = l; |
60 |
|
|
61 |
if(abs(level) <= max_level_ptr[run] && run <= max_run_ptr[abs(level)]) { |
if((abs(level) <= max_level_ptr[run]) && |
62 |
|
(run <= max_run_ptr[abs(level)])) { // level < max_level and run < max_run |
63 |
|
|
|
if(level > 0) { |
|
|
vlc[intra]->code = (coeff_ptr[run][level - 1].code) << 1; |
|
|
vlc[intra]->len = coeff_ptr[run][level - 1].len + 1; |
|
|
} |
|
|
else if(level < 0) { |
|
|
vlc[intra]->code = ((coeff_ptr[run][-level - 1].code) << 1) + 1; |
|
|
vlc[intra]->len = coeff_ptr[run][-level - 1].len + 1; |
|
|
} |
|
|
else { |
|
64 |
vlc[intra]->code = 0; |
vlc[intra]->code = 0; |
65 |
vlc[intra]->len = 0; |
vlc[intra]->len = 0; |
66 |
|
goto loop_end; |
67 |
} |
} |
68 |
} else { |
else { |
69 |
if(level > 0) |
if(level > 0) // correct level |
70 |
level -= max_level_ptr[run]; |
level -= max_level_ptr[run]; |
71 |
else |
else |
72 |
level += max_level_ptr[run]; |
level += max_level_ptr[run]; |
73 |
|
|
74 |
if(abs(level) <= max_level_ptr[run] && |
if((abs(level) <= max_level_ptr[run]) && |
75 |
run <= max_run_ptr[abs(level)]) { |
(run <= max_run_ptr[abs(level)])) { |
76 |
|
|
|
if(level > 0) { |
|
|
vlc[intra]->code = (0x06 << (coeff_ptr[run][level - 1].len + 1)) | |
|
|
(coeff_ptr[run][level - 1].code << 1); |
|
|
vlc[intra]->len = (coeff_ptr[run][level - 1].len + 1) + 8; |
|
|
} |
|
|
else if(level < 0) { |
|
|
vlc[intra]->code = (0x06 << (coeff_ptr[run][-level - 1].len + 1)) | |
|
|
((coeff_ptr[run][-level - 1].code << 1) + 1); |
|
|
vlc[intra]->len = (coeff_ptr[run][-level - 1].len + 1) + 8; |
|
|
} |
|
|
else { |
|
77 |
vlc[intra]->code = 0x06; |
vlc[intra]->code = 0x06; |
78 |
vlc[intra]->len = 8; |
vlc[intra]->len = 8; |
79 |
|
goto loop_end; |
80 |
} |
} |
81 |
} else { |
|
82 |
if(level > 0) |
if(level > 0) // still here? |
83 |
level += max_level_ptr[run]; |
level += max_level_ptr[run]; // restore level |
84 |
else |
else |
85 |
level -= max_level_ptr[run]; |
level -= max_level_ptr[run]; |
86 |
|
|
87 |
run -= max_run_ptr[abs(level)] + 1; |
run -= max_run_ptr[abs(level)] + 1; // and change run |
88 |
|
|
89 |
if(abs(level) <= max_level_ptr[run] && |
if((abs(level) <= max_level_ptr[run]) && |
90 |
run <= max_run_ptr[abs(level)]) { |
(run <= max_run_ptr[abs(level)])) { |
91 |
|
|
|
if(level > 0) { |
|
|
vlc[intra]->code = (0x0e << (coeff_ptr[run][level - 1].len + 1)) | |
|
|
(coeff_ptr[run][level - 1].code << 1); |
|
|
vlc[intra]->len = (coeff_ptr[run][level - 1].len + 1) + 9; |
|
|
} |
|
|
else if(level < 0) { |
|
|
vlc[intra]->code = (0x0e << (coeff_ptr[run][-level - 1].len + 1)) | |
|
|
((coeff_ptr[run][-level - 1].code << 1) + 1); |
|
|
vlc[intra]->len = (coeff_ptr[run][-level - 1].len + 1) + 9; |
|
|
} |
|
|
else { |
|
92 |
vlc[intra]->code = 0x0e; |
vlc[intra]->code = 0x0e; |
93 |
vlc[intra]->len = 9; |
vlc[intra]->len = 9; |
94 |
|
goto loop_end; |
95 |
} |
} |
|
} else { |
|
|
if(level != 0) |
|
96 |
run += max_run_ptr[abs(level)] + 1; |
run += max_run_ptr[abs(level)] + 1; |
97 |
else |
} |
|
run++; |
|
98 |
|
|
99 |
vlc[intra]->code = (uint32_t) ((0x1e + last) << 20) | |
vlc[intra]->code = (uint32_t) ((l << 14) | (0x1e + last) << 20) | |
100 |
(l << 14) | (1 << 13) | ((k & 0xfff) << 1) | 1; |
(1 << 13) | ((k & 0xfff) << 1) | 1; |
101 |
|
|
102 |
vlc[intra]->len = 30; |
vlc[intra]->len = 30; |
103 |
|
vlc[intra]++; |
104 |
|
continue; |
105 |
|
|
106 |
|
loop_end: |
107 |
|
if(level != 0) { |
108 |
|
vlc[intra]->code = (vlc[intra]->code << (coeff_ptr[run][abs(level) - 1].len + 1)) | |
109 |
|
(coeff_ptr[run][abs(level) - 1].code << 1); |
110 |
|
vlc[intra]->len = (coeff_ptr[run][abs(level) - 1].len + 1) + vlc[intra]->len; |
111 |
|
|
112 |
|
if(level < 0) |
113 |
|
vlc[intra]->code += 1; |
114 |
} |
} |
115 |
} |
|
|
} |
|
116 |
vlc[intra]++; |
vlc[intra]++; |
117 |
} |
} |
118 |
} |
} |
119 |
} |
} |
|
intra_table += 64*255; // center vlc tables |
|
|
inter_table += 64*255; // center vlc tables |
|
120 |
|
|
121 |
for(i = 0; i < 4096; i++) { |
for(i = 0; i < 4096; i++) { |
122 |
if(i >= 512) { |
if(i >= 512) { |
144 |
|
|
145 |
} |
} |
146 |
|
|
147 |
void destroy_vlc_tables(void) { |
static __inline void CodeVector(Bitstream *bs, |
148 |
|
int16_t value, |
149 |
if(intra_table != NULL && inter_table != NULL) { |
int16_t f_code, |
150 |
intra_table -= 64*255; // uncenter vlc tables |
Statistics *pStat) |
|
inter_table -= 64*255; // uncenter vlc tables |
|
|
|
|
|
free(intra_table); |
|
|
free(inter_table); |
|
|
} |
|
|
|
|
|
if(DCT3D[0] != NULL && DCT3D[1] != NULL) { |
|
|
free(DCT3D[0]); |
|
|
free(DCT3D[1]); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
static __inline void CodeVector(Bitstream *bs, int16_t value, int16_t f_code, Statistics *pStat) |
|
151 |
{ |
{ |
152 |
|
|
153 |
const int scale_factor = 1 << (f_code - 1); |
const int scale_factor = 1 << (f_code - 1); |
154 |
const int cmp = scale_factor << 5; |
const int cmp = scale_factor << 5; |
155 |
|
|
162 |
pStat->iMvSum += value * value; |
pStat->iMvSum += value * value; |
163 |
pStat->iMvCount++; |
pStat->iMvCount++; |
164 |
|
|
165 |
if (value == 0) |
if (value == 0) { |
166 |
BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len); |
BitstreamPutBits(bs, mb_motion_table[32].code, mb_motion_table[32].len); |
167 |
else { |
} else { |
168 |
uint16_t length, code, mv_res, sign; |
uint16_t length, code, mv_res, sign; |
169 |
|
|
170 |
length = 16 << f_code; |
length = 16 << f_code; |
193 |
if(f_code) |
if(f_code) |
194 |
BitstreamPutBits(bs, mv_res, f_code); |
BitstreamPutBits(bs, mv_res, f_code); |
195 |
} |
} |
196 |
|
|
197 |
} |
} |
198 |
|
|
199 |
|
|
200 |
static __inline void CodeCoeff(Bitstream *bs, int16_t qcoeff[64], VLC *table, |
static __inline void CodeCoeff(Bitstream *bs, |
201 |
const uint16_t *zigzag, uint16_t intra) { |
int16_t qcoeff[64], |
202 |
|
VLC *table, |
203 |
|
const uint16_t *zigzag, |
204 |
|
uint16_t intra) |
205 |
|
{ |
206 |
|
|
207 |
uint32_t j, last; |
uint32_t j, last; |
208 |
short v; |
short v; |
209 |
VLC *vlc; |
VLC *vlc; |
215 |
|
|
216 |
do { |
do { |
217 |
// count zeroes |
// count zeroes |
218 |
vlc = table + (clip_table[2048+v] << 6) + j - last; |
vlc = table + 64*255 + (clip_table[2048+v] << 6) + j - last; |
219 |
last = j + 1; |
last = j + 1; |
220 |
while(j < 64 && (v = qcoeff[zigzag[j++]]) == 0); |
while(j < 64 && (v = qcoeff[zigzag[j++]]) == 0); |
221 |
|
|
228 |
break; |
break; |
229 |
} |
} |
230 |
} while(1); |
} while(1); |
231 |
|
|
232 |
} |
} |
233 |
|
|
234 |
|
|
235 |
static void CodeBlockIntra(const MBParam * pParam, const MACROBLOCK *pMB, |
static void CodeBlockIntra(const MBParam * pParam, |
236 |
int16_t qcoeff[][64], Bitstream * bs, Statistics * pStat) |
const MACROBLOCK *pMB, |
237 |
|
int16_t qcoeff[6*64], |
238 |
|
Bitstream * bs, |
239 |
|
Statistics * pStat) |
240 |
{ |
{ |
241 |
|
|
242 |
uint32_t i, mcbpc, cbpy, bits; |
uint32_t i, mcbpc, cbpy, bits; |
243 |
|
|
244 |
cbpy = pMB->cbp >> 2; |
cbpy = pMB->cbp >> 2; |
266 |
if(pMB->mode == MODE_INTRA_Q) |
if(pMB->mode == MODE_INTRA_Q) |
267 |
BitstreamPutBits(bs, pMB->dquant, 2); |
BitstreamPutBits(bs, pMB->dquant, 2); |
268 |
|
|
269 |
|
// write interlacing |
270 |
|
if (pParam->global_flags & XVID_INTERLACING) |
271 |
|
{ |
272 |
|
BitstreamPutBit(bs, pMB->field_dct); |
273 |
|
} |
274 |
|
|
275 |
// code block coeffs |
// code block coeffs |
276 |
for(i = 0; i < 6; i++) |
for(i = 0; i < 6; i++) |
277 |
{ |
{ |
278 |
if(i < 4) |
if(i < 4) |
279 |
BitstreamPutBits(bs, dcy_tab[qcoeff[i][0] + 255].code, |
BitstreamPutBits(bs, |
280 |
dcy_tab[qcoeff[i][0] + 255].len); |
dcy_tab[qcoeff[i*64 + 0] + 255].code, |
281 |
|
dcy_tab[qcoeff[i*64 + 0] + 255].len); |
282 |
else |
else |
283 |
BitstreamPutBits(bs, dcc_tab[qcoeff[i][0] + 255].code, |
BitstreamPutBits(bs, |
284 |
dcc_tab[qcoeff[i][0] + 255].len); |
dcc_tab[qcoeff[i*64 + 0] + 255].code, |
285 |
|
dcc_tab[qcoeff[i*64 + 0] + 255].len); |
286 |
|
|
287 |
if(pMB->cbp & (1 << (5 - i))) |
if(pMB->cbp & (1 << (5 - i))) |
288 |
{ |
{ |
289 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
290 |
|
|
291 |
CodeCoeff(bs, qcoeff[i], intra_table, scan_tables[pMB->acpred_directions[i]], 1); |
CodeCoeff(bs, |
292 |
|
&qcoeff[i*64], |
293 |
|
intra_table, |
294 |
|
scan_tables[pMB->acpred_directions[i]], |
295 |
|
1); |
296 |
|
|
297 |
bits = BitstreamPos(bs) - bits; |
bits = BitstreamPos(bs) - bits; |
298 |
pStat->iTextBits += bits; |
pStat->iTextBits += bits; |
299 |
} |
} |
300 |
} |
} |
301 |
|
|
302 |
} |
} |
303 |
|
|
304 |
|
|
305 |
static void CodeBlockInter(const MBParam * pParam, const MACROBLOCK *pMB, |
static void CodeBlockInter(const MBParam * pParam, |
306 |
int16_t qcoeff[][64], Bitstream * bs, Statistics * pStat) |
const MACROBLOCK *pMB, |
307 |
|
int16_t qcoeff[6*64], |
308 |
|
Bitstream * bs, |
309 |
|
Statistics * pStat) |
310 |
{ |
{ |
311 |
|
|
312 |
int32_t i; |
int32_t i; |
313 |
uint32_t bits, mcbpc, cbpy; |
uint32_t bits, mcbpc, cbpy; |
314 |
|
|
325 |
if(pMB->mode == MODE_INTER_Q) |
if(pMB->mode == MODE_INTER_Q) |
326 |
BitstreamPutBits(bs, pMB->dquant, 2); |
BitstreamPutBits(bs, pMB->dquant, 2); |
327 |
|
|
328 |
|
// interlacing |
329 |
|
if (pParam->global_flags & XVID_INTERLACING) |
330 |
|
{ |
331 |
|
BitstreamPutBit(bs, pMB->field_dct); |
332 |
|
DEBUG1("codep: field_dct: ", pMB->field_dct); |
333 |
|
|
334 |
|
// if inter block, write field ME flag |
335 |
|
if (pMB->mode == MODE_INTER || pMB->mode == MODE_INTER_Q) |
336 |
|
{ |
337 |
|
BitstreamPutBit(bs, pMB->field_pred); |
338 |
|
DEBUG1("codep: field_pred: ", pMB->field_pred); |
339 |
|
|
340 |
|
// write field prediction references |
341 |
|
if (pMB->field_pred) |
342 |
|
{ |
343 |
|
BitstreamPutBit(bs, pMB->field_for_top); |
344 |
|
BitstreamPutBit(bs, pMB->field_for_bot); |
345 |
|
} |
346 |
|
} |
347 |
|
} |
348 |
|
|
349 |
// code motion vector(s) |
// code motion vector(s) |
350 |
for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) |
for(i = 0; i < (pMB->mode == MODE_INTER4V ? 4 : 1); i++) |
351 |
{ |
{ |
358 |
// code block coeffs |
// code block coeffs |
359 |
for(i = 0; i < 6; i++) |
for(i = 0; i < 6; i++) |
360 |
if(pMB->cbp & (1 << (5 - i))) |
if(pMB->cbp & (1 << (5 - i))) |
361 |
CodeCoeff(bs, qcoeff[i], inter_table, scan_tables[0], 0); |
CodeCoeff(bs, &qcoeff[i*64], inter_table, scan_tables[0], 0); |
362 |
|
|
363 |
bits = BitstreamPos(bs) - bits; |
bits = BitstreamPos(bs) - bits; |
364 |
pStat->iTextBits += bits; |
pStat->iTextBits += bits; |
365 |
|
|
366 |
} |
} |
367 |
|
|
368 |
|
|
369 |
void MBCoding(const MBParam * pParam, MACROBLOCK *pMB, |
void MBCoding(const MBParam * pParam, |
370 |
int16_t qcoeff[][64], |
MACROBLOCK *pMB, |
371 |
Bitstream * bs, Statistics * pStat) |
int16_t qcoeff[6*64], |
372 |
|
Bitstream * bs, |
373 |
|
Statistics * pStat) |
374 |
{ |
{ |
375 |
|
|
376 |
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
int intra = (pMB->mode == MODE_INTRA || pMB->mode == MODE_INTRA_Q); |
377 |
|
|
378 |
if(pParam->coding_type == P_VOP) { |
if(pParam->coding_type == P_VOP) { |
390 |
CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat); |
CodeBlockIntra(pParam, pMB, qcoeff, bs, pStat); |
391 |
else |
else |
392 |
CodeBlockInter(pParam, pMB, qcoeff, bs, pStat); |
CodeBlockInter(pParam, pMB, qcoeff, bs, pStat); |
393 |
|
|
394 |
} |
} |
395 |
|
|
396 |
|
|
400 |
|
|
401 |
int get_mcbpc_intra(Bitstream * bs) |
int get_mcbpc_intra(Bitstream * bs) |
402 |
{ |
{ |
403 |
|
|
404 |
uint32_t index; |
uint32_t index; |
405 |
|
|
406 |
while((index = BitstreamShowBits(bs, 9)) == 1) |
while((index = BitstreamShowBits(bs, 9)) == 1) |
409 |
index >>= 3; |
index >>= 3; |
410 |
|
|
411 |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
BitstreamSkip(bs, mcbpc_intra_table[index].len); |
412 |
|
|
413 |
return mcbpc_intra_table[index].code; |
return mcbpc_intra_table[index].code; |
414 |
|
|
415 |
} |
} |
416 |
|
|
417 |
int get_mcbpc_inter(Bitstream * bs) |
int get_mcbpc_inter(Bitstream * bs) |
418 |
{ |
{ |
419 |
|
|
420 |
uint32_t index; |
uint32_t index; |
421 |
|
|
422 |
while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1) |
while((index = CLIP(BitstreamShowBits(bs, 9), 256)) == 1) |
423 |
BitstreamSkip(bs, 9); |
BitstreamSkip(bs, 9); |
424 |
|
|
425 |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
BitstreamSkip(bs, mcbpc_inter_table[index].len); |
426 |
|
|
427 |
return mcbpc_inter_table[index].code; |
return mcbpc_inter_table[index].code; |
428 |
|
|
429 |
} |
} |
430 |
|
|
431 |
int get_cbpy(Bitstream * bs, int intra) |
int get_cbpy(Bitstream * bs, int intra) |
432 |
{ |
{ |
433 |
|
|
434 |
int cbpy; |
int cbpy; |
435 |
uint32_t index = BitstreamShowBits(bs, 6); |
uint32_t index = BitstreamShowBits(bs, 6); |
436 |
|
|
441 |
cbpy = 15 - cbpy; |
cbpy = 15 - cbpy; |
442 |
|
|
443 |
return cbpy; |
return cbpy; |
444 |
|
|
445 |
} |
} |
446 |
|
|
447 |
int get_mv_data(Bitstream * bs) |
int get_mv_data(Bitstream * bs) |
448 |
{ |
{ |
449 |
|
|
450 |
uint32_t index; |
uint32_t index; |
451 |
|
|
452 |
if(BitstreamGetBit(bs)) |
if(BitstreamGetBit(bs)) |
472 |
|
|
473 |
BitstreamSkip(bs, TMNMVtab2[index].len); |
BitstreamSkip(bs, TMNMVtab2[index].len); |
474 |
return TMNMVtab2[index].code; |
return TMNMVtab2[index].code; |
475 |
|
|
476 |
} |
} |
477 |
|
|
478 |
int get_mv(Bitstream * bs, int fcode) |
int get_mv(Bitstream * bs, int fcode) |
479 |
{ |
{ |
480 |
|
|
481 |
int data; |
int data; |
482 |
int res; |
int res; |
483 |
int mv; |
int mv; |
492 |
mv = ((ABS(data) - 1) * scale_fac) + res + 1; |
mv = ((ABS(data) - 1) * scale_fac) + res + 1; |
493 |
|
|
494 |
return data < 0 ? -mv : mv; |
return data < 0 ? -mv : mv; |
495 |
|
|
496 |
} |
} |
497 |
|
|
498 |
int get_dc_dif(Bitstream * bs, uint32_t dc_size) |
int get_dc_dif(Bitstream * bs, uint32_t dc_size) |
499 |
{ |
{ |
500 |
|
|
501 |
int code = BitstreamGetBits(bs, dc_size); |
int code = BitstreamGetBits(bs, dc_size); |
502 |
int msb = code >> (dc_size - 1); |
int msb = code >> (dc_size - 1); |
503 |
|
|
505 |
return (-1 * (code^((1 << dc_size) - 1))); |
return (-1 * (code^((1 << dc_size) - 1))); |
506 |
|
|
507 |
return code; |
return code; |
508 |
|
|
509 |
} |
} |
510 |
|
|
511 |
int get_dc_size_lum(Bitstream * bs) |
int get_dc_size_lum(Bitstream * bs) |
512 |
{ |
{ |
513 |
|
|
514 |
int code, i; |
int code, i; |
515 |
code = BitstreamShowBits(bs, 11); |
code = BitstreamShowBits(bs, 11); |
516 |
|
|
524 |
|
|
525 |
BitstreamSkip(bs, dc_lum_tab[code].len); |
BitstreamSkip(bs, dc_lum_tab[code].len); |
526 |
return dc_lum_tab[code].code; |
return dc_lum_tab[code].code; |
527 |
|
|
528 |
} |
} |
529 |
|
|
530 |
|
|
531 |
int get_dc_size_chrom(Bitstream * bs) |
int get_dc_size_chrom(Bitstream * bs) |
532 |
{ |
{ |
533 |
|
|
534 |
uint32_t code, i; |
uint32_t code, i; |
535 |
code = BitstreamShowBits(bs, 12); |
code = BitstreamShowBits(bs, 12); |
536 |
|
|
543 |
} |
} |
544 |
|
|
545 |
return 3 - BitstreamGetBits(bs, 2); |
return 3 - BitstreamGetBits(bs, 2); |
546 |
|
|
547 |
} |
} |
548 |
|
|
549 |
int get_coeff(Bitstream * bs, int *run, int *last, int intra, int short_video_header) |
int get_coeff(Bitstream * bs, int *run, int *last, int intra, int short_video_header) |
550 |
{ |
{ |
551 |
|
|
552 |
uint32_t mode; |
uint32_t mode; |
553 |
const VLC *tab; |
const VLC *tab; |
554 |
int32_t level; |
int32_t level; |
636 |
error: |
error: |
637 |
*run = VLC_ERROR; |
*run = VLC_ERROR; |
638 |
return 0; |
return 0; |
639 |
|
|
640 |
} |
} |
641 |
|
|
642 |
|
|
643 |
void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff) |
void get_intra_block(Bitstream * bs, int16_t * block, int direction, int coeff) |
644 |
{ |
{ |
645 |
|
|
646 |
const uint16_t * scan = scan_tables[ direction ]; |
const uint16_t * scan = scan_tables[ direction ]; |
647 |
int level; |
int level; |
648 |
int run; |
int run; |
664 |
} |
} |
665 |
coeff++; |
coeff++; |
666 |
} while (!last); |
} while (!last); |
667 |
|
|
668 |
} |
} |
669 |
|
|
670 |
void get_inter_block(Bitstream * bs, int16_t * block) |
void get_inter_block(Bitstream * bs, int16_t * block) |
671 |
{ |
{ |
672 |
|
|
673 |
const uint16_t * scan = scan_tables[0]; |
const uint16_t * scan = scan_tables[0]; |
674 |
int p; |
int p; |
675 |
int level; |
int level; |
693 |
} |
} |
694 |
p++; |
p++; |
695 |
} while (!last); |
} while (!last); |
696 |
|
|
697 |
} |
} |