diff options
author | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-10-12 09:05:42 +0200 |
---|---|---|
committer | Andreas Rheinhardt <andreas.rheinhardt@gmail.com> | 2020-10-12 22:40:00 +0200 |
commit | 00772ef4f7c87e708b5292a696c3efc78d234366 (patch) | |
tree | c88cd3c46b3ba872c22eb014e0eb96a56db74646 /libavcodec/webp.c | |
parent | d7a503ecf9f42561b4a6e2207812a97074f43687 (diff) | |
download | ffmpeg-00772ef4f7c87e708b5292a696c3efc78d234366.tar.gz |
avcodec/webp: Use LE VLC table for LE bitstream reader
The WebP format uses Huffman tables and the decoder therefore uses
VLC tables. Given that WebP is a LE format, a LE bitreader is used;
yet the VLC table is not created for a LE reader (the process used to
create the tables puts the last bit to be read in the lowest bit) and
therefore custom code for reading the VLCs that reverses the bits
read is used instead of get_vlc2(). This commit changes this to use
a table designed for LE bitreader which allows to use get_vlc2() directly.
The necessary reversing of the codes is delegated to
ff_init_vlc_sparse() (and is therefore only done during init and not
when actually reading the VLCs).
Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/webp.c')
-rw-r--r-- | libavcodec/webp.c | 42 |
1 files changed, 2 insertions, 40 deletions
diff --git a/libavcodec/webp.c b/libavcodec/webp.c index c6d0206846..6140c7ea4a 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -232,44 +232,6 @@ static void image_ctx_free(ImageContext *img) memset(img, 0, sizeof(*img)); } - -/* Differs from get_vlc2() in the following ways: - * - codes are bit-reversed - * - assumes 8-bit table to make reversal simpler - * - assumes max depth of 2 since the max code length for WebP is 15 - */ -static av_always_inline int webp_get_vlc(GetBitContext *gb, VLC_TYPE (*table)[2]) -{ - int n, nb_bits; - unsigned int index; - int code; - - OPEN_READER(re, gb); - UPDATE_CACHE(re, gb); - - index = SHOW_UBITS(re, gb, 8); - index = ff_reverse[index]; - code = table[index][0]; - n = table[index][1]; - - if (n < 0) { - LAST_SKIP_BITS(re, gb, 8); - UPDATE_CACHE(re, gb); - - nb_bits = -n; - - index = SHOW_UBITS(re, gb, nb_bits); - index = (ff_reverse[index] >> (8 - nb_bits)) + code; - code = table[index][0]; - n = table[index][1]; - } - SKIP_BITS(re, gb, n); - - CLOSE_READER(re, gb); - - return code; -} - static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb) { if (r->simple) { @@ -278,7 +240,7 @@ static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb) else return r->simple_symbols[get_bits1(gb)]; } else - return webp_get_vlc(gb, r->vlc.table); + return get_vlc2(gb, r->vlc.table, 8, 2); } static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, @@ -332,7 +294,7 @@ static int huff_reader_build_canonical(HuffReader *r, int *code_lengths, ret = init_vlc(&r->vlc, 8, alphabet_size, code_lengths, sizeof(*code_lengths), sizeof(*code_lengths), - codes, sizeof(*codes), sizeof(*codes), 0); + codes, sizeof(*codes), sizeof(*codes), INIT_VLC_OUTPUT_LE); if (ret < 0) { av_free(codes); return ret; |