+static av_cold void build_vlc(VLC *vlc, const uint8_t counts[16],
+ const uint16_t **syms, unsigned *offset)
+{
+ uint8_t lens[MAX_VLC_ENTRIES];
+ unsigned num = 0;
+
+ for (int i = 0; i < 16; i++) {
+ unsigned count = counts[i];
+ if (count == 255) /* Special case for Y_3 table */
+ count = 303;
+ for (count += num; num < count; num++)
+ lens[num] = i + 1;
+ }
+ vlc->table = &vlc_buf[*offset];
+ vlc->table_allocated = FF_ARRAY_ELEMS(vlc_buf) - *offset;
+ ff_init_vlc_from_lengths(vlc, CLV_VLC_BITS, num, lens, 1,
+ *syms, 2, 2, 0, INIT_VLC_STATIC_OVERLONG, NULL);
+ *syms += num;
+ *offset += vlc->table_size;
+}
+
+static av_cold void clv_init_static(void)
+{
+ const uint16_t *mv_syms = clv_mv_syms, *bias_syms = clv_bias_syms;
+
+ INIT_VLC_STATIC_FROM_LENGTHS(&dc_vlc, CLV_VLC_BITS, NUM_DC_CODES,
+ clv_dc_lens, 1,
+ clv_dc_syms, 1, 1, -63, 0, 1104);
+ INIT_VLC_STATIC_FROM_LENGTHS(&ac_vlc, CLV_VLC_BITS, NUM_AC_CODES,
+ clv_ac_bits, 1,
+ clv_ac_syms, 2, 2, 0, 0, 554);
+ for (unsigned i = 0, j = 0, k = 0, offset = 0;; i++) {
+ if (0x36F & (1 << i)) {
+ build_vlc(&lev[i].mv_cb, clv_mv_len_counts[k], &mv_syms, &offset);
+ k++;
+ }
+ if (i == FF_ARRAY_ELEMS(lev) - 1)
+ break;
+ if (0x1B7 & (1 << i)) {
+ lev[i].flags_cb.table = &vlc_buf[offset];
+ lev[i].flags_cb.table_allocated = FF_ARRAY_ELEMS(vlc_buf) - offset;
+ ff_init_vlc_from_lengths(&lev[i].flags_cb, CLV_VLC_BITS, 16,
+ clv_flags_bits[j], 1,
+ clv_flags_syms[j], 1, 1,
+ 0, INIT_VLC_STATIC_OVERLONG, NULL);
+ offset += lev[i].flags_cb.table_size;
+
+ build_vlc(&lev[i + 1].bias_cb, clv_bias_len_counts[j],
+ &bias_syms, &offset);
+ j++;
+ }
+ }
+}
+