66 |
#define ABS(X) (((X)>0)?(X):-(X)) |
#define ABS(X) (((X)>0)?(X):-(X)) |
67 |
#define CLIP(X,A) (X > A) ? (A) : (X) |
#define CLIP(X,A) (X > A) ? (A) : (X) |
68 |
|
|
69 |
/*#define _BIGLUT_*/ |
/* #define BIGLUT */ |
70 |
|
|
71 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
72 |
#define LEVELOFFSET 2048 |
#define LEVELOFFSET 2048 |
73 |
#else |
#else |
74 |
#define LEVELOFFSET 32 |
#define LEVELOFFSET 32 |
80 |
|
|
81 |
static REVERSE_EVENT DCT3D[2][4096]; |
static REVERSE_EVENT DCT3D[2][4096]; |
82 |
|
|
83 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
84 |
static VLC coeff_VLC[2][2][4096][64]; |
static VLC coeff_VLC[2][2][4096][64]; |
85 |
VLC *intra_table, *inter_table; |
static VLC *intra_table, *inter_table; |
86 |
#else |
#else |
87 |
static VLC coeff_VLC[2][2][64][64]; |
static VLC coeff_VLC[2][2][64][64]; |
88 |
#endif |
#endif |
94 |
void |
void |
95 |
init_vlc_tables(void) |
init_vlc_tables(void) |
96 |
{ |
{ |
97 |
uint32_t i, j, intra, last, run, offset; |
ptr_t i, j, intra, last, run, run_esc, level, level_esc, escape, escape_len, offset; |
|
int32_t level; |
|
|
VLC coeff_VLC_temp[2][2][64][64]; |
|
98 |
|
|
99 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
100 |
intra_table = coeff_VLC[1]; |
intra_table = (VLC*)coeff_VLC[1]; |
101 |
inter_table = coeff_VLC[0]; |
inter_table = (VLC*)coeff_VLC[0]; |
102 |
#endif |
#endif |
103 |
|
|
104 |
|
|
112 |
for (run = 0; run < 63 + last; run++) |
for (run = 0; run < 63 + last; run++) |
113 |
for (level = 0; level < 32 << intra; level++) |
for (level = 0; level < 32 << intra; level++) |
114 |
{ |
{ |
115 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
116 |
offset = LEVELOFFSET; |
offset = LEVELOFFSET; |
117 |
#else |
#else |
118 |
offset = !intra * LEVELOFFSET; |
offset = !intra * LEVELOFFSET; |
119 |
#endif |
#endif |
|
coeff_VLC_temp[intra][last][level][run].len = 128; |
|
120 |
coeff_VLC[intra][last][level + offset][run].len = 128; |
coeff_VLC[intra][last][level + offset][run].len = 128; |
121 |
} |
} |
122 |
} |
} |
124 |
for (intra = 0; intra < 2; intra++) |
for (intra = 0; intra < 2; intra++) |
125 |
for (i = 0; i < 102; i++) |
for (i = 0; i < 102; i++) |
126 |
{ |
{ |
127 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
128 |
offset = LEVELOFFSET; |
offset = LEVELOFFSET; |
129 |
#else |
#else |
130 |
offset = !intra * LEVELOFFSET; |
offset = !intra * LEVELOFFSET; |
135 |
DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event; |
DCT3D[intra][(coeff_tab[intra][i].vlc.code << (12 - coeff_tab[intra][i].vlc.len)) | j].event = coeff_tab[intra][i].event; |
136 |
} |
} |
137 |
|
|
|
coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].code |
|
|
= coeff_tab[intra][i].vlc.code << 1; |
|
|
coeff_VLC_temp[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level][coeff_tab[intra][i].event.run].len |
|
|
= coeff_tab[intra][i].vlc.len + 1; |
|
|
|
|
138 |
coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code |
coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].code |
139 |
= coeff_tab[intra][i].vlc.code << 1; |
= coeff_tab[intra][i].vlc.code << 1; |
140 |
coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len |
coeff_VLC[intra][coeff_tab[intra][i].event.last][coeff_tab[intra][i].event.level + offset][coeff_tab[intra][i].event.run].len |
141 |
= coeff_tab[intra][i].vlc.len + 1; |
= coeff_tab[intra][i].vlc.len + 1; |
142 |
#ifndef _BIGLUT_ |
#ifndef BIGLUT |
143 |
if (!intra) |
if (!intra) |
144 |
#endif |
#endif |
145 |
{ |
{ |
156 |
{ |
{ |
157 |
for (level = 1; level < 32 << intra; level++) |
for (level = 1; level < 32 << intra; level++) |
158 |
{ |
{ |
159 |
#ifdef _BIGLUT_ |
if (level <= max_level[intra][last][run] && run <= max_run[intra][last][level]) |
160 |
|
continue; |
161 |
|
|
162 |
|
#ifdef BIGLUT |
163 |
offset = LEVELOFFSET; |
offset = LEVELOFFSET; |
164 |
#else |
#else |
165 |
offset = !intra * LEVELOFFSET; |
offset = !intra * LEVELOFFSET; |
166 |
#endif |
#endif |
167 |
if ((max_level[intra][last][run]) && (level > max_level[intra][last][run])) |
level_esc = level - max_level[intra][last][run]; |
168 |
if (coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len != 128 |
run_esc = run - 1 - max_run[intra][last][level]; |
169 |
&& coeff_VLC[intra][last][level + offset][run].len == 128) |
/*use this test to use shorter esc2 codes when possible |
170 |
|
if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc] |
171 |
|
&& !(coeff_VLC[intra][last][level_esc + offset][run].len + 7 + 1 |
172 |
|
> coeff_VLC[intra][last][level + offset][run_esc].code + 7 + 2))*/ |
173 |
|
|
174 |
|
if (level_esc <= max_level[intra][last][run] && run <= max_run[intra][last][level_esc]) |
175 |
|
{ |
176 |
|
escape = ESCAPE1; |
177 |
|
escape_len = 7 + 1; |
178 |
|
run_esc = run; |
179 |
|
} |
180 |
|
else |
181 |
{ |
{ |
182 |
coeff_VLC[intra][last][level + offset][run].code |
if (level <= max_level[intra][last][run_esc] && run_esc <= max_run[intra][last][level]) |
183 |
= (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len) |
{ |
184 |
| coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code; |
escape = ESCAPE2; |
185 |
coeff_VLC[intra][last][level + offset][run].len |
escape_len = 7 + 2; |
186 |
= coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1; |
level_esc = level; |
187 |
#ifndef _BIGLUT_ |
} |
188 |
|
else |
189 |
|
{ |
190 |
|
#ifndef BIGLUT |
191 |
if (!intra) |
if (!intra) |
192 |
#endif |
#endif |
193 |
{ |
{ |
194 |
|
coeff_VLC[intra][last][level + offset][run].code |
195 |
|
= (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1; |
196 |
|
coeff_VLC[intra][last][level + offset][run].len = 30; |
197 |
coeff_VLC[intra][last][offset - level][run].code |
coeff_VLC[intra][last][offset - level][run].code |
198 |
= (ESCAPE1 << coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len) |
= (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1; |
199 |
| coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].code | 1; |
coeff_VLC[intra][last][offset - level][run].len = 30; |
|
coeff_VLC[intra][last][offset - level][run].len |
|
|
= coeff_VLC_temp[intra][last][level - max_level[intra][last][run]][run].len + 7 + 1; |
|
200 |
} |
} |
201 |
|
continue; |
202 |
} |
} |
203 |
if (run > max_run[intra][last][level]) |
} |
204 |
if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len != 128 |
|
|
&& coeff_VLC[intra][last][level + offset][run].len == 128) |
|
|
/*use the lower test instead of the upper to use shorter escape codes when possible : |
|
|
if (coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2 |
|
|
< coeff_VLC[intra][last][level + offset][run].len)*/ |
|
|
{ |
|
205 |
coeff_VLC[intra][last][level + offset][run].code |
coeff_VLC[intra][last][level + offset][run].code |
206 |
= (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len) |
= (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len) |
207 |
| coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code; |
| coeff_VLC[intra][last][level_esc + offset][run_esc].code; |
208 |
coeff_VLC[intra][last][level + offset][run].len |
coeff_VLC[intra][last][level + offset][run].len |
209 |
= coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2; |
= coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len; |
210 |
#ifndef _BIGLUT_ |
#ifndef BIGLUT |
211 |
if (!intra) |
if (!intra) |
212 |
#endif |
#endif |
213 |
{ |
{ |
214 |
coeff_VLC[intra][last][offset - level][run].code |
coeff_VLC[intra][last][offset - level][run].code |
215 |
= (ESCAPE2 << coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len) |
= (escape << coeff_VLC[intra][last][level_esc + offset][run_esc].len) |
216 |
| coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].code | 1; |
| coeff_VLC[intra][last][level_esc + offset][run_esc].code | 1; |
217 |
coeff_VLC[intra][last][offset - level][run].len |
coeff_VLC[intra][last][offset - level][run].len |
218 |
= coeff_VLC_temp[intra][last][level][run - 1 - max_run[intra][last][level]].len + 7 + 2; |
= coeff_VLC[intra][last][level_esc + offset][run_esc].len + escape_len; |
219 |
} |
} |
220 |
} |
} |
|
#ifndef _BIGLUT_ |
|
|
if (!intra) |
|
|
#endif |
|
|
if (coeff_VLC[intra][last][level + offset][run].len == 128) |
|
|
{ |
|
|
coeff_VLC[intra][last][level + offset][run].code |
|
|
= (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((level & 0xfff) << 1) | 1; |
|
|
coeff_VLC[intra][last][level + offset][run].len = 30; |
|
221 |
|
|
222 |
coeff_VLC[intra][last][offset - level][run].code |
#ifdef BIGLUT |
|
= (ESCAPE3 << 21) | (last << 20) | (run << 14) | (1 << 13) | ((-level & 0xfff) << 1) | 1; |
|
|
coeff_VLC[intra][last][offset - level][run].len = 30; |
|
|
} |
|
|
} |
|
|
#ifdef _BIGLUT_ |
|
223 |
for (level = 32 << intra; level < 2048; level++) |
for (level = 32 << intra; level < 2048; level++) |
224 |
{ |
{ |
225 |
coeff_VLC[intra][last][level + offset][run].code |
coeff_VLC[intra][last][level + offset][run].code |
300 |
|
|
301 |
} |
} |
302 |
|
|
303 |
#ifdef __BIGLUT_ |
#ifdef BIGLUT |
304 |
|
|
305 |
static __inline void |
static __inline void |
306 |
CodeCoeff(Bitstream * bs, |
CodeCoeff(Bitstream * bs, |
512 |
if (pMB->cbp & (1 << (5 - i))) { |
if (pMB->cbp & (1 << (5 - i))) { |
513 |
bits = BitstreamPos(bs); |
bits = BitstreamPos(bs); |
514 |
|
|
515 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
516 |
CodeCoeff(bs, &qcoeff[i * 64], intra_table, |
CodeCoeff(bs, &qcoeff[i * 64], intra_table, |
517 |
scan_tables[pMB->acpred_directions[i]], 1); |
scan_tables[pMB->acpred_directions[i]], 1); |
518 |
#else |
#else |
581 |
/* code block coeffs */ |
/* code block coeffs */ |
582 |
for (i = 0; i < 6; i++) |
for (i = 0; i < 6; i++) |
583 |
if (pMB->cbp & (1 << (5 - i))) |
if (pMB->cbp & (1 << (5 - i))) |
584 |
#ifdef _BIGLUT_ |
#ifdef BIGLUT |
585 |
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0); |
CodeCoeff(bs, &qcoeff[i * 64], inter_table, scan_tables[0], 0); |
586 |
#else |
#else |
587 |
CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]); |
CodeCoeffInter(bs, &qcoeff[i * 64], scan_tables[0]); |