diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-11-01 00:26:32 +0100 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-12-08 17:51:46 +0100 |
commit | 70bbb4cce80ec2255b023b8f9e964dcf5d2ea9f6 (patch) | |
tree | 3ec10ee8985c2dec83bd2ffc098d4978e44fcf71 /libavcodec/mss4.c | |
parent | e7f15f777dfef0904da3e066de198fd3632eba53 (diff) | |
download | ffmpeg-70bbb4cce80ec2255b023b8f9e964dcf5d2ea9f6.tar.gz |
avcodec/mss4: Simplify creating VLC tables
The lengths of the codes used by the mss4 decoder are ascending from
left to right and therefore the lengths can be run-length encoded and
the codes can be easily derived from them. And this is how it is indeed
done. Yet some things can nevertheless be improved:
a) The number of entries of the current VLC is implicitly contained in
the run-length table and needn't be externally prescribed.
b) The maximum length of a code is just the length of the last code
(given that the lengths are ascending), so there is no point in setting
max_bits in the loop itself.
c) One can offload the actual calculation of the codes to
ff_init_vlc_from_lengths().
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/mss4.c')
-rw-r--r-- | libavcodec/mss4.c | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/libavcodec/mss4.c b/libavcodec/mss4.c index a6d036f3f7..e8aa66e0a8 100644 --- a/libavcodec/mss4.c +++ b/libavcodec/mss4.c @@ -143,25 +143,21 @@ typedef struct MSS4Context { } MSS4Context; static av_cold int mss4_init_vlc(VLC *vlc, const uint8_t *lens, - const uint8_t *syms, int num_syms) + const uint8_t *syms) { uint8_t bits[MAX_ENTRIES]; - uint16_t codes[MAX_ENTRIES]; int i, j; - int prefix = 0, max_bits = 0, idx = 0; + int idx = 0; for (i = 0; i < 16; i++) { for (j = 0; j < lens[i]; j++) { bits[idx] = i + 1; - codes[idx] = prefix++; - max_bits = i + 1; idx++; } - prefix <<= 1; } - return ff_init_vlc_sparse(vlc, FFMIN(max_bits, 9), num_syms, bits, 1, 1, - codes, 2, 2, syms, 1, 1, 0); + return ff_init_vlc_from_lengths(vlc, FFMIN(bits[idx - 1], 9), idx, + bits, 1, syms, 1, 1, 0, 0, NULL); } static av_cold int mss4_init_vlcs(MSS4Context *ctx) @@ -169,15 +165,15 @@ static av_cold int mss4_init_vlcs(MSS4Context *ctx) int ret, i; for (i = 0; i < 2; i++) { - ret = mss4_init_vlc(&ctx->dc_vlc[i], mss4_dc_vlc_lens[i], NULL, 12); + ret = mss4_init_vlc(&ctx->dc_vlc[i], mss4_dc_vlc_lens[i], NULL); if (ret) return ret; ret = mss4_init_vlc(&ctx->ac_vlc[i], mss4_ac_vlc_lens[i], - mss4_ac_vlc_syms[i], 162); + mss4_ac_vlc_syms[i]); if (ret) return ret; ret = mss4_init_vlc(&ctx->vec_entry_vlc[i], mss4_vec_entry_vlc_lens[i], - mss4_vec_entry_vlc_syms[i], 9); + mss4_vec_entry_vlc_syms[i]); if (ret) return ret; } |