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,
64 int words = length >> 4;
65 int bits = length & 15;
72 for (i = 0; i < words; i++)
87 #define GET_DATA(v, table, i, wrap, size) \
89 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
92 v = *(const uint8_t *)ptr; \
95 v = *(const uint16_t *)ptr; \
98 v = *(const uint32_t *)ptr; \
122 return (uint32_t)
ff_reverse[ x & 0xFF] << 24 |
139 return (sa->
code >> 1) - (sb->code >> 1);
158 int table_size, table_index,
index, code_prefix, symbol, subtable_bits;
159 int i, j, k,
n, nb, inc;
163 table_size = 1 << table_nb_bits;
164 if (table_nb_bits > 30)
167 av_dlog(NULL,
"new table index=%d size=%d\n", table_index, table_size);
172 for (i = 0; i < table_size; i++) {
178 for (i = 0; i < nb_codes; i++) {
180 code = codes[i].
code;
182 av_dlog(NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
183 if (n <= table_nb_bits) {
185 j = code >> (32 - table_nb_bits);
186 nb = 1 << (table_nb_bits -
n);
192 for (k = 0; k < nb; k++) {
193 av_dlog(NULL,
"%4x: code=%d n=%d\n", j, i, n);
194 if (
table[j][1] != 0) {
199 table[j][0] = symbol;
205 code_prefix = code >> (32 - table_nb_bits);
208 codes[i].
code = code << table_nb_bits;
209 for (k = i+1; k < nb_codes; k++) {
210 n = codes[k].
bits - table_nb_bits;
213 code = codes[k].
code;
214 if (code >> (32 - table_nb_bits) != code_prefix)
217 codes[k].
code = code << table_nb_bits;
218 subtable_bits =
FFMAX(subtable_bits, n);
220 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
222 table[j][1] = -subtable_bits;
223 av_dlog(NULL,
"%4x: n=%d (subtable)\n",
224 j, codes[i].
bits + table_nb_bits);
225 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
265 const void *
bits,
int bits_wrap,
int bits_size,
266 const void *codes,
int codes_wrap,
int codes_size,
267 const void *symbols,
int symbols_wrap,
int symbols_size,
281 bits, bits_wrap, bits_size,
282 codes, codes_wrap, codes_size,
283 symbols, symbols_wrap, symbols_size,
284 flags & ~INIT_VLC_USE_NEW_STATIC);
299 av_dlog(NULL,
"build table nb_codes=%d\n", nb_codes);
307 #define COPY(condition)\
308 for (i = 0; i < nb_codes; i++) { \
309 GET_DATA(buf[j].bits, bits, i, bits_wrap, bits_size); \
312 if (buf[j].bits > 3*nb_bits || buf[j].bits>32) { \
313 av_log(NULL, AV_LOG_ERROR, "Too long VLC (%d) in init_vlc\n", buf[j].bits);\
317 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
318 if (buf[j].code >= (1LL<<buf[j].bits)) { \
319 av_log(NULL, AV_LOG_ERROR, "Invalid code in init_vlc\n"); \
323 if (flags & INIT_VLC_LE) \
324 buf[j].code = bitswap_32(buf[j].code); \
326 buf[j].code <<= 32 - buf[j].bits; \
328 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
333 COPY(buf[j].bits > nb_bits);
336 COPY(buf[j].bits && buf[j].bits <= nb_bits);
339 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);