38 0, 0, 0, 0, 1, 1, 1, 1,
39 2, 2, 2, 2, 3, 3, 3, 3,
40 4, 4, 5, 5, 6, 6, 7, 7,
41 8, 9,10,11,12,13,14,15,
42 16,17,18,19,20,21,22,23,
84 #define GET_DATA(v, table, i, wrap, size) \
86 const uint8_t *ptr = (const uint8_t *)table + i * wrap;\
89 v = *(const uint8_t *)ptr;\
92 v = *(const uint16_t *)ptr;\
95 v = *(const uint32_t *)ptr;\
136 return (sa->
code >> 1) - (sb->code >> 1);
156 int table_size, table_index,
index, code_prefix, symbol, subtable_bits;
157 int i, j, k, n, nb, inc;
161 table_size = 1 << table_nb_bits;
162 if (table_nb_bits > 30)
165 av_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
170 for (i = 0; i < table_size; i++) {
176 for (i = 0; i < nb_codes; i++) {
178 code = codes[i].
code;
180 av_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
181 if (n <= table_nb_bits) {
183 j = code >> (32 - table_nb_bits);
184 nb = 1 << (table_nb_bits - n);
190 for (k = 0; k < nb; k++) {
192 if (
table[j][1] != 0) {
197 table[j][0] = symbol;
203 code_prefix = code >> (32 - table_nb_bits);
206 codes[i].
code = code << table_nb_bits;
207 for (k = i+1; k < nb_codes; k++) {
208 n = codes[k].
bits - table_nb_bits;
211 code = codes[k].
code;
212 if (code >> (32 - table_nb_bits) != code_prefix)
215 codes[k].
code = code << table_nb_bits;
216 subtable_bits =
FFMAX(subtable_bits, n);
218 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
220 table[j][1] = -subtable_bits;
222 j, codes[i].
bits + table_nb_bits);
223 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
263 const void *
bits,
int bits_wrap,
int bits_size,
264 const void *codes,
int codes_wrap,
int codes_size,
265 const void *symbols,
int symbols_wrap,
int symbols_size,
279 bits, bits_wrap, bits_size,
280 codes, codes_wrap, codes_size,
281 symbols, symbols_wrap, symbols_size,
282 flags & ~INIT_VLC_USE_NEW_STATIC);
297 av_dlog(
NULL,
"build table nb_codes=%d\n", nb_codes);
303 #define COPY(condition)\
304 for (i = 0; i < nb_codes; i++) {\
305 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size);\
308 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size);\
309 if (flags & INIT_VLC_LE)\
310 buf[j].code = bitswap_32(buf[j].code);\
312 buf[j].code <<= 32 - buf[j].bits;\
314 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size)\
319 COPY(buf[j].bits > nb_bits);
322 COPY(buf[j].bits && buf[j].bits <= nb_bits);
325 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);