41 0, 0, 0, 0, 1, 1, 1, 1,
42 2, 2, 2, 2, 3, 3, 3, 3,
43 4, 4, 5, 5, 6, 6, 7, 7,
44 8, 9,10,11,12,13,14,15,
45 16,17,18,19,20,21,22,23,
67 int words = length >> 4;
68 int bits = length & 15;
77 for (i = 0; i < words; i++)
92 #define GET_DATA(v, table, i, wrap, size) \
94 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
97 v = *(const uint8_t *)ptr; \
100 v = *(const uint16_t *)ptr; \
103 v = *(const uint32_t *)ptr; \
131 return (uint32_t)
ff_reverse[ x & 0xFF] << 24 |
148 return (sa->
code >> 1) - (sb->code >> 1);
167 int table_size, table_index,
index, code_prefix, symbol, subtable_bits;
168 int i, j, k,
n, nb, inc;
172 table_size = 1 << table_nb_bits;
173 if (table_nb_bits > 30)
176 ff_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
182 for (i = 0; i < nb_codes; i++) {
184 code = codes[i].
code;
186 ff_dlog(
NULL,
"i=%d n=%d code=0x%x\n", i, n, code);
187 if (n <= table_nb_bits) {
189 j = code >> (32 - table_nb_bits);
190 nb = 1 << (table_nb_bits -
n);
196 for (k = 0; k < nb; k++) {
199 if (bits != 0 && bits != n) {
204 table[j][0] = symbol;
210 code_prefix = code >> (32 - table_nb_bits);
213 codes[i].
code = code << table_nb_bits;
214 for (k = i+1; k < nb_codes; k++) {
215 n = codes[k].
bits - table_nb_bits;
218 code = codes[k].
code;
219 if (code >> (32 - table_nb_bits) != code_prefix)
222 codes[k].
code = code << table_nb_bits;
223 subtable_bits =
FFMAX(subtable_bits, n);
225 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
227 table[j][1] = -subtable_bits;
229 j, codes[i].
bits + table_nb_bits);
230 index =
build_table(vlc, subtable_bits, k-i, codes+i, flags);
240 for (i = 0; i < table_size; i++) {
241 if (
table[i][1] == 0)
276 const void *
bits,
int bits_wrap,
int bits_size,
277 const void *codes,
int codes_wrap,
int codes_size,
278 const void *symbols,
int symbols_wrap,
int symbols_size,
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);\
314 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
318 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
319 if (buf[j].code >= (1LL<<buf[j].bits)) { \
320 av_log(NULL, AV_LOG_ERROR, "Invalid code %x for %d in init_vlc\n", buf[j].code, i);\
321 if (!(flags & INIT_VLC_USE_NEW_STATIC)) \
325 if (flags & INIT_VLC_LE) \
326 buf[j].code = bitswap_32(buf[j].code); \
328 buf[j].code <<= 32 - buf[j].bits; \
330 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
335 COPY(buf[j].bits > nb_bits);
338 COPY(buf[j].bits && buf[j].bits <= nb_bits);
341 ret =
build_table(vlc, nb_bits, nb_codes, buf, flags);
343 if (flags & INIT_VLC_USE_NEW_STATIC) {
const uint8_t ff_log2_run[41]
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define av_realloc_f(p, o, n)
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
int ff_init_vlc_sparse(VLC *vlc_arg, int nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, const void *symbols, int symbols_wrap, int symbols_size, int flags)
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
Copy the content of src to the bitstream.
void avpriv_align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, VLCcode *codes, int flags)
Build VLC decoding tables suitable for use with get_vlc().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_always_inline uint32_t bitswap_32(uint32_t x)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static uint8_t * put_bits_ptr(PutBitContext *s)
Return the pointer to the byte where the bitstream writer will put the next bit.
static int put_bits_left(PutBitContext *s)
static const struct endianess table[]
uint32_t code
codeword, with the first bit-to-be-read in the msb (even if intended for a little-endian bitstream re...
const uint8_t ff_reverse[256]
simple assert() macros that are a bit more flexible than ISO C assert().
static int put_bits_count(PutBitContext *s)
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static int compare_vlcspec(const void *a, const void *b)
#define FF_ARRAY_ELEMS(a)
Libavcodec external API header.
common internal api header.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define INIT_VLC_USE_NEW_STATIC
VLC_TYPE(* table)[2]
code, bits
void avpriv_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
#define av_malloc_array(a, b)
void ff_free_vlc(VLC *vlc)
#define AV_QSORT(p, num, type, cmp)
Quicksort This sort is fast, and fully inplace but not stable and it is possible to construct input t...
static int alloc_table(VLC *vlc, int size, int use_static)