[libav-commits] webp: add a special case for a huffman table with only 1 symbol

Justin Ruggles git at libav.org
Fri Dec 6 02:38:15 CET 2013


Module: libav
Branch: master
Commit: d085f80fa1381b363b0b91689407d5646d78ed28

Author:    Justin Ruggles <justin.ruggles at gmail.com>
Committer: Justin Ruggles <justin.ruggles at gmail.com>
Date:      Wed Dec  4 16:53:18 2013 -0500

webp: add a special case for a huffman table with only 1 symbol

The vlc reader cannot handle 0-bit huffman codes. For most
situations WebP uses the "simple" huffman coding for this case,
but that will only handle symbols up to 255. For the LZ77 distance
codes, larger symbol values are needed, so it can happen in rare
cases that a normal huffman table is used that only has a single
symbol.

---

 libavcodec/webp.c |   18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/libavcodec/webp.c b/libavcodec/webp.c
index d531a78..f9f8bfc 100644
--- a/libavcodec/webp.c
+++ b/libavcodec/webp.c
@@ -277,10 +277,26 @@ static int huff_reader_get_symbol(HuffReader *r, GetBitContext *gb)
 static int huff_reader_build_canonical(HuffReader *r, int *code_lengths,
                                        int alphabet_size)
 {
-    int len, sym, code, ret;
+    int len = 0, sym, code = 0, ret;
     int max_code_length = 0;
     uint16_t *codes;
 
+    /* special-case 1 symbol since the vlc reader cannot handle it */
+    for (sym = 0; sym < alphabet_size; sym++) {
+        if (code_lengths[sym] > 0) {
+            len++;
+            code = sym;
+            if (len > 1)
+                break;
+        }
+    }
+    if (len == 1) {
+        r->nb_symbols = 1;
+        r->simple_symbols[0] = code;
+        r->simple = 1;
+        return 0;
+    }
+
     for (sym = 0; sym < alphabet_size; sym++)
         max_code_length = FFMAX(max_code_length, code_lengths[sym]);
 



More information about the libav-commits mailing list