40 0, 0, 0, 0, 1, 1, 1, 1,
41 2, 2, 2, 2, 3, 3, 3, 3,
42 4, 4, 5, 5, 6, 6, 7, 7,
43 8, 9,10,11,12,13,14,15,
44 16,17,18,19,20,21,22,23,
48 #if FF_API_AVPRIV_PUT_BITS
71 int words = length >> 4;
72 int bits = length & 15;
81 for (
i = 0;
i < words;
i++)
96 #define GET_DATA(v, table, i, wrap, size) \
98 const uint8_t *ptr = (const uint8_t *)table + i * wrap; \
101 v = *(const uint8_t *)ptr; \
104 v = *(const uint16_t *)ptr; \
108 av_assert1(size == 4); \
109 v = *(const uint32_t *)ptr; \
135 #define LOCALBUF_ELEMS 1500
150 (*vlc)->
bits = nb_bits;
153 *localvlc = *vlc_arg;
157 (*vlc)->table =
NULL;
158 (*vlc)->table_allocated = 0;
159 (*vlc)->table_size = 0;
173 return (sa->
code >> 1) - (sb->code >> 1);
193 int i, j, k, n, nb, inc;
197 if (table_nb_bits > 30)
199 table_size = 1 << table_nb_bits;
201 ff_dlog(
NULL,
"new table index=%d size=%d\n", table_index, table_size);
207 for (
i = 0;
i < nb_codes;
i++) {
212 if (n <= table_nb_bits) {
214 j =
code >> (32 - table_nb_bits);
215 nb = 1 << (table_nb_bits - n);
221 for (k = 0; k < nb; k++) {
223 int oldsym =
table[j][0];
225 if ((
bits || oldsym) && (
bits != n || oldsym != symbol)) {
230 table[j][0] = symbol;
240 for (k =
i+1; k < nb_codes; k++) {
241 n = codes[k].
bits - table_nb_bits;
248 codes[k].
code =
code << table_nb_bits;
249 subtable_bits =
FFMAX(subtable_bits, n);
251 subtable_bits =
FFMIN(subtable_bits, table_nb_bits);
253 table[j][1] = -subtable_bits;
255 j, codes[
i].
bits + table_nb_bits);
270 for (
i = 0;
i < table_size;
i++) {
290 if (codes != localbuf)
324 const void *
bits,
int bits_wrap,
int bits_size,
325 const void *codes,
int codes_wrap,
int codes_size,
326 const void *symbols,
int symbols_wrap,
int symbols_size,
340 #define COPY(condition)\
341 for (i = 0; i < nb_codes; i++) { \
343 GET_DATA(len, bits, i, bits_wrap, bits_size); \
346 if (len > 3*nb_bits || len > 32) { \
347 av_log(NULL, AV_LOG_ERROR, "Too long VLC (%u) in init_vlc\n", len);\
348 if (buf != localbuf) \
350 return AVERROR(EINVAL); \
353 GET_DATA(buf[j].code, codes, i, codes_wrap, codes_size); \
354 if (buf[j].code >= (1LL<<buf[j].bits)) { \
355 av_log(NULL, AV_LOG_ERROR, "Invalid code %"PRIx32" for %d in " \
356 "init_vlc\n", buf[j].code, i); \
357 if (buf != localbuf) \
359 return AVERROR(EINVAL); \
361 if (flags & INIT_VLC_INPUT_LE) \
362 buf[j].code = bitswap_32(buf[j].code); \
364 buf[j].code <<= 32 - buf[j].bits; \
366 GET_DATA(buf[j].symbol, symbols, i, symbols_wrap, symbols_size) \
378 flags, vlc_arg, localbuf);
382 const int8_t *lens,
int lens_wrap,
383 const void *symbols,
int symbols_wrap,
int symbols_size,
389 int ret, j, len_max =
FFMIN(32, 3 * nb_bits);
397 for (
int i = 0;
i < nb_codes;
i++, lens += lens_wrap) {
404 GET_DATA(sym, symbols,
i, symbols_wrap, symbols_size)
409 }
else if (
len < 0) {
413 if (
len > len_max ||
code & ((1U << (32 -
len)) - 1)) {
418 if (
code > UINT32_MAX + 1ULL) {
424 flags, vlc_arg, localbuf);
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Libavcodec external API header.
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)
#define GET_DATA(v, table, i, wrap, size)
static int vlc_common_end(VLC *vlc, int nb_bits, int nb_codes, VLCcode *codes, int flags, VLC *vlc_arg, VLCcode localbuf[LOCALBUF_ELEMS])
void ff_free_vlc(VLC *vlc)
int ff_init_vlc_from_lengths(VLC *vlc_arg, int nb_bits, int nb_codes, const int8_t *lens, int lens_wrap, const void *symbols, int symbols_wrap, int symbols_size, int offset, int flags, void *logctx)
Build VLC decoding tables suitable for use with get_vlc2()
static int alloc_table(VLC *vlc, int size, int use_static)
void ff_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)
static int compare_vlcspec(const void *a, const void *b)
void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length)
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().
static int vlc_common_init(VLC *vlc_arg, int nb_bits, int nb_codes, VLC **vlc, VLC *localvlc, VLCcode **buf, int flags)
void ff_put_string(PutBitContext *pb, const char *string, int terminate_string)
Put the string string in the bitstream.
const uint8_t ff_log2_run[41]
#define flags(name, subs,...)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
common internal API header
static av_always_inline uint32_t bitswap_32(uint32_t x)
static const uint16_t table[]
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_count(PutBitContext *s)
static int put_bits_left(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static void skip_put_bytes(PutBitContext *s, int n)
Skip the given number of bytes.
static void align_put_bits(PutBitContext *s)
Pad the bitstream with zeros up to the next byte boundary.
static const unsigned code_prefix[]
#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...
VLC_TYPE(* table)[2]
code, bits
uint32_t code
codeword, with the first bit-to-be-read in the msb (even if intended for a little-endian bitstream re...
#define av_malloc_array(a, b)
#define av_realloc_f(p, o, n)
#define avpriv_request_sample(...)
static const uint8_t offset[127][2]
#define INIT_VLC_USE_NEW_STATIC
#define INIT_VLC_STATIC_OVERLONG
#define INIT_VLC_OUTPUT_LE