]> git.sesse.net Git - ffmpeg/commitdiff
avcodec/magicyuv: Reuse array instead of using multiple arrays
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Mon, 31 Aug 2020 17:55:28 +0000 (19:55 +0200)
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
Tue, 1 Sep 2020 09:05:38 +0000 (11:05 +0200)
The lengths of the VLC codes are implicitly contained in the VLC tables
itself; apart from that they are not used lateron. So it is unnecessary
to store them and the very same array can be reused to parse the Huffman
table for the next plane.

Reviewed-by: Paul B Mahol <onemda@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
libavcodec/magicyuv.c

index 9282b397239f94a361d761fa8e2ceabfdd700411..a16135e68373b20d2021db1e9a05ad3858722b5f 100644 (file)
@@ -68,7 +68,7 @@ typedef struct MagicYUVContext {
     int               vshift[4];
     Slice            *slices[4];      // slice bitstream positions for each plane
     unsigned int      slices_size[4]; // slice sizes for each plane
-    uint8_t           len[4][4096];   // table of code lengths for each plane
+    uint8_t           len[4096];      // scratch table of code lengths
     VLC               vlc[4];         // VLC for each plane
     int (*huff_build)(VLC *vlc, uint8_t *len);
     int (*magy_decode_slice)(AVCodecContext *avctx, void *tdata,
@@ -465,11 +465,11 @@ static int build_huffman(AVCodecContext *avctx, GetBitContext *gbit, int max)
         }
 
         for (; j < k; j++)
-            s->len[i][j] = x;
+            s->len[j] = x;
 
         if (j == max) {
             j = 0;
-            if (s->huff_build(&s->vlc[i], s->len[i])) {
+            if (s->huff_build(&s->vlc[i], s->len)) {
                 av_log(avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n");
                 return AVERROR_INVALIDDATA;
             }