This is trivial as well as beneficial because frame threads now use the same table, saving cache/memory.
Unified · Split
| @@ -68,7 +68,6 @@ typedef struct HQXContext { · 67 unmodified lines | ||
| 68 | 68 | unsigned int data_size; |
| 69 | 69 | uint32_t slice_off[17]; |
| 70 | 70 | |
| 71 | − VLC cbp_vlc; | |
| 72 | 71 | VLC dc_vlc[3]; |
| 73 | 72 | } HQXContext; |
| 74 | 73 | |
| @@ -224,12 +223,12 @@ static int hqx_decode_422a(HQXContext *ctx, int slice_no, int x, int y) · 149 unmodified lines | ||
| 224 | 223 | int i, ret; |
| 225 | 224 | int cbp; |
| 226 | 225 | |
| 227 | − cbp = get_vlc2(gb, ctx->cbp_vlc.table, HQX_CBP_VLC_BITS, 1); | |
| 228 | − | |
| 229 | 226 | for (i = 0; i < 12; i++) |
| 230 | 227 | memset(slice->block[i], 0, sizeof(**slice->block) * 64); |
| 231 | 228 | for (i = 0; i < 12; i++) |
| 232 | 229 | slice->block[i][0] = -0x800; |
| 230 | + | |
| 231 | + cbp = get_vlc2(gb, cbp_vlc, HQX_CBP_VLC_BITS, 1); | |
| 233 | 232 | if (cbp) { |
| 234 | 233 | if (ctx->interlaced) |
| 235 | 234 | flag = get_bits1(gb); |
| @@ -310,12 +309,12 @@ static int hqx_decode_444a(HQXContext *ctx, int slice_no, int x, int y) · 74 unmodified lines | ||
| 310 | 309 | int i, ret; |
| 311 | 310 | int cbp; |
| 312 | 311 | |
| 313 | − cbp = get_vlc2(gb, ctx->cbp_vlc.table, HQX_CBP_VLC_BITS, 1); | |
| 314 | − | |
| 315 | 312 | for (i = 0; i < 16; i++) |
| 316 | 313 | memset(slice->block[i], 0, sizeof(**slice->block) * 64); |
| 317 | 314 | for (i = 0; i < 16; i++) |
| 318 | 315 | slice->block[i][0] = -0x800; |
| 316 | + | |
| 317 | + cbp = get_vlc2(gb, cbp_vlc, HQX_CBP_VLC_BITS, 1); | |
| 319 | 318 | if (cbp) { |
| 320 | 319 | if (ctx->interlaced) |
| 321 | 320 | flag = get_bits1(gb); |
| @@ -543,7 +542,6 @@ static av_cold int hqx_decode_close(AVCodecContext *avctx) · 221 unmodified lines | ||
| 543 | 542 | int i; |
| 544 | 543 | HQXContext *ctx = avctx->priv_data; |
| 545 | 544 | |
| 546 | − ff_vlc_free(&ctx->cbp_vlc); | |
| 547 | 545 | for (i = 0; i < 3; i++) { |
| 548 | 546 | ff_vlc_free(&ctx->dc_vlc[i]); |
| 549 | 547 | } |
| @@ -555,10 +553,7 @@ static av_cold int hqx_decode_init(AVCodecContext *avctx) · 5 unmodified lines | ||
| 555 | 553 | { |
| 556 | 554 | static AVOnce init_static_once = AV_ONCE_INIT; |
| 557 | 555 | HQXContext *ctx = avctx->priv_data; |
| 558 | − int ret = vlc_init(&ctx->cbp_vlc, HQX_CBP_VLC_BITS, FF_ARRAY_ELEMS(cbp_vlc_lens), | |
| 559 | − cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); | |
| 560 | − if (ret < 0) | |
| 561 | − return ret; | |
| 556 | + int ret; | |
| 562 | 557 | |
| 563 | 558 | INIT_DC_TABLE(0, dc9); |
| 564 | 559 | INIT_DC_TABLE(1, dc10); |
| @@ -1529,7 +1529,7 @@ static const uint8_t hqx_ac_lens[] = { · 1528 unmodified lines | ||
| 1529 | 1529 | |
| 1530 | 1530 | static const uint16_t hqx_ac_nb_elems[] = { 815, 907, 512, 354, 257, 194 }; |
| 1531 | 1531 | |
| 1532 | −static RL_VLC_ELEM hqx_ac_rl_vlc[15630]; | |
| 1532 | +static VLCElem cbp_vlc[(1 << HQX_CBP_VLC_BITS) + 15630 /* RL_VLC_ELEMS for hqx_ac */]; | |
| 1533 | 1533 | |
| 1534 | 1534 | #define INIT_DC_TABLE(idx, name) \ |
| 1535 | 1535 | do { \ |
| @@ -1543,10 +1543,13 @@ static RL_VLC_ELEM hqx_ac_rl_vlc[15630]; · 7 unmodified lines | ||
| 1543 | 1543 | |
| 1544 | 1544 | static av_cold av_unused void hqx_init_static(void) |
| 1545 | 1545 | { |
| 1546 | − VLCInitState state = VLC_INIT_STATE(hqx_ac_rl_vlc); | |
| 1546 | + VLCInitState state = VLC_INIT_STATE(cbp_vlc); | |
| 1547 | 1547 | const uint8_t *lens = hqx_ac_lens; |
| 1548 | 1548 | const int16_t *run_level = hqx_ac_run_level; |
| 1549 | 1549 | |
| 1550 | + ff_vlc_init_tables(&state, HQX_CBP_VLC_BITS, FF_ARRAY_ELEMS(cbp_vlc_lens), | |
| 1551 | + cbp_vlc_lens, 1, 1, cbp_vlc_bits, 1, 1, 0); | |
| 1552 | + | |
| 1550 | 1553 | for (int i = 0; i < NUM_HQX_AC; ++i) { |
| 1551 | 1554 | RL_VLC_ELEM *lut = state.table; |
| 1552 | 1555 | unsigned nb_codes = state.size; |