diff mbox series

[FFmpeg-devel,v2,081/162] avcodec/sheervideo: Simplify creating VLC table

Message ID 20201120072116.818090-82-andreas.rheinhardt@gmail.com
State New
Headers show
Series VLC, esp. init_vlc patches
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Nov. 20, 2020, 7:19 a.m. UTC
ff_init_vlc_from_lengths() can be used to offload the computation
of the codes; it also needn't check whether the codes are already
properly ordered (they are).

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/sheervideo.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/sheervideo.c b/libavcodec/sheervideo.c
index 3e60ef26a5..876b5cace6 100644
--- a/libavcodec/sheervideo.c
+++ b/libavcodec/sheervideo.c
@@ -1784,11 +1784,10 @@  static void decode_rgb(AVCodecContext *avctx, AVFrame *p, GetBitContext *gb)
 static av_cold int build_vlc(VLC *vlc, const SheerTable *table)
 {
     const uint8_t *cur = table->lens;
-    uint16_t codes[1024];
     uint8_t  lens[1024];
     unsigned count = 0;
 
-    for (unsigned step = 1, len = 1, index = 0; len > 0; len += step) {
+    for (unsigned step = 1, len = 1; len > 0; len += step) {
         unsigned new_count = count;
 
         if (len == 16) {
@@ -1797,17 +1796,13 @@  static av_cold int build_vlc(VLC *vlc, const SheerTable *table)
         } else
             new_count += *cur++;
 
-        for (; count < new_count; count++) {
-            codes[count] = index >> (32 - len);
-            index       += 1U    << (32 - len);
+        for (; count < new_count; count++)
             lens[count]  = len;
-        }
     }
 
     ff_free_vlc(vlc);
-    return init_vlc(vlc, SHEER_VLC_BITS, count,
-                    lens,  sizeof(*lens),  sizeof(*lens),
-                    codes, sizeof(*codes), sizeof(*codes), 0);
+    return ff_init_vlc_from_lengths(vlc, SHEER_VLC_BITS, count,
+                                    lens, sizeof(*lens), NULL, 0, 0, 0, 0, NULL);
 }
 
 static int decode_frame(AVCodecContext *avctx,