-static int build_table(VLC *vlc, int table_nb_bits,
- int nb_codes,
- const void *bits, int bits_wrap, int bits_size,
- const void *codes, int codes_wrap, int codes_size,
- uint32_t code_prefix, int n_prefix, int flags)
+static av_always_inline uint32_t bitswap_32(uint32_t x) {
+ return av_reverse[x&0xFF]<<24
+ | av_reverse[(x>>8)&0xFF]<<16
+ | av_reverse[(x>>16)&0xFF]<<8
+ | av_reverse[x>>24];
+}
+
+typedef struct {
+ uint8_t bits;
+ uint16_t symbol;
+ /** codeword, with the first bit-to-be-read in the msb
+ * (even if intended for a little-endian bitstream reader) */
+ uint32_t code;
+} VLCcode;
+
+static int compare_vlcspec(const void *a, const void *b)
+{
+ const VLCcode *sa=a, *sb=b;
+ return (sa->code >> 1) - (sb->code >> 1);
+}
+
+/**
+ * Build VLC decoding tables suitable for use with get_vlc().
+ *
+ * @param vlc the context to be initted
+ *
+ * @param table_nb_bits max length of vlc codes to store directly in this table
+ * (Longer codes are delegated to subtables.)
+ *
+ * @param nb_codes number of elements in codes[]
+ *
+ * @param codes descriptions of the vlc codes
+ * These must be ordered such that codes going into the same subtable are contiguous.
+ * Sorting by VLCcode.code is sufficient, though not necessary.
+ */
+static int build_table(VLC *vlc, int table_nb_bits, int nb_codes,
+ VLCcode *codes, int flags)