diff mbox series

[FFmpeg-devel,v2,028/162] avcodec/cook: Avoid big length tables for VLC initialization

Message ID 20201120072116.818090-29-andreas.rheinhardt@gmail.com
State Accepted
Commit 3ff0179b196106b97f8b53b3e4685837e57196cb
Headers show
Series VLC, esp. init_vlc patches | expand

Checks

Context Check Description
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
Permuting the tables used to initialize the Cook VLCs so that the code
tables are ordered from left to right in the tree revealed that the
length of the codes are ascending from left to right. Therefore one can
run-length encode them to avoid the big length tables; this saves a bit
more than 1KB.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavcodec/cook.c     |  38 ++++++---
 libavcodec/cookdata.h | 187 +++++++-----------------------------------
 2 files changed, 54 insertions(+), 171 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/cook.c b/libavcodec/cook.c
index 7756098d97..4d06488c10 100644
--- a/libavcodec/cook.c
+++ b/libavcodec/cook.c
@@ -190,6 +190,21 @@  static av_cold void init_gain_table(COOKContext *q)
                                (1.0 / (double) q->gain_size_factor));
 }
 
+static av_cold int build_vlc(VLC *vlc, int nb_bits, const uint8_t counts[16],
+                             const void *syms, int symbol_size, int offset,
+                             void *logctx)
+{
+    uint8_t lens[MAX_COOK_VLC_ENTRIES];
+    unsigned num = 0;
+
+    for (int i = 0; i < 16; i++)
+        for (unsigned count = num + counts[i]; num < count; num++)
+            lens[num] = i + 1;
+
+    return ff_init_vlc_from_lengths(vlc, nb_bits, num, lens, 1,
+                                    syms, symbol_size, symbol_size,
+                                    offset, 0, logctx);
+}
 
 static av_cold int init_cook_vlc_tables(COOKContext *q)
 {
@@ -197,27 +212,24 @@  static av_cold int init_cook_vlc_tables(COOKContext *q)
 
     result = 0;
     for (i = 0; i < 13; i++) {
-        result |= ff_init_vlc_from_lengths(&q->envelope_quant_index[i], 9, 24,
-                                           envelope_quant_index_huffbits[i], 1,
-                                           envelope_quant_index_huffsyms[i], 1, 1,
-                                           -12, 0, q->avctx);
+        result |= build_vlc(&q->envelope_quant_index[i], 9,
+                            envelope_quant_index_huffcounts[i],
+                            envelope_quant_index_huffsyms[i], 1, -12, q->avctx);
     }
     av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n");
     for (i = 0; i < 7; i++) {
         int sym_size = 1 + (i == 3);
-        result |= ff_init_vlc_from_lengths(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i],
-                                           cvh_huffbits[i], 1,
-                                           cvh_huffsyms[i], sym_size, sym_size,
-                                           0, 0, q->avctx);
+        result |= build_vlc(&q->sqvh[i], vhvlcsize_tab[i],
+                            cvh_huffcounts[i],
+                            cvh_huffsyms[i], sym_size, 0, q->avctx);
     }
 
     for (i = 0; i < q->num_subpackets; i++) {
         if (q->subpacket[i].joint_stereo == 1) {
-            result |= ff_init_vlc_from_lengths(&q->subpacket[i].channel_coupling, 6,
-                                               (1 << q->subpacket[i].js_vlc_bits) - 1,
-                                               ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1,
-                                               ccpl_huffsyms[q->subpacket[i].js_vlc_bits - 2], 1, 1,
-                                               0, 0, q->avctx);
+            result |= build_vlc(&q->subpacket[i].channel_coupling, 6,
+                                ccpl_huffcounts[q->subpacket[i].js_vlc_bits - 2],
+                                ccpl_huffsyms[q->subpacket[i].js_vlc_bits - 2], 1,
+                                0, q->avctx);
             av_log(q->avctx, AV_LOG_DEBUG, "subpacket %i Joint-stereo VLC used.\n", i);
         }
     }
diff --git a/libavcodec/cookdata.h b/libavcodec/cookdata.h
index 05d1eef23b..a4ca1201bf 100644
--- a/libavcodec/cookdata.h
+++ b/libavcodec/cookdata.h
@@ -70,41 +70,26 @@  static const int vpr_tab[7] = {
 
 /* VLC data */
 
-static const int vhsize_tab[7] = {
-    181, 94, 48, 520, 209, 192, 32,
-};
+#define MAX_COOK_VLC_ENTRIES 520
 
 static const int vhvlcsize_tab[7] = {
     8, 7, 7, 10, 9, 9, 6,
 };
 
-static const uint8_t envelope_quant_index_huffbits[13][24] = {
-    { 3,  3,  3,  4,  4,  4,  4,  4,  4,  4,  4,  5,
-      5,  5,  6,  7,  8,  9, 11, 11, 12, 12, 12, 12 },
-    { 3,  3,  3,  3,  3,  3,  4,  4,  5,  5,  5,  6,
-      7,  8,  9, 10, 11, 12, 13, 15, 15, 15, 16, 16 },
-    { 3,  3,  3,  4,  4,  4,  4,  4,  4,  4,  4,  5,
-      5,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 14 },
-    { 3,  3,  3,  3,  3,  4,  4,  4,  4,  5,  5,  5,
-      7,  7,  7,  9,  9,  9, 10, 11, 13, 13, 13, 13 },
-    { 3,  3,  3,  3,  3,  4,  4,  4,  5,  5,  5,  5,
-      6,  6,  6,  7,  8,  9, 10, 11, 12, 13, 14, 14 },
-    { 3,  3,  3,  3,  3,  4,  4,  4,  4,  5,  5,  5,
-      7,  7,  8,  8,  8,  9, 10, 11, 12, 13, 14, 14 },
-    { 2,  3,  3,  3,  3,  4,  4,  5,  5,  5,  6,  7,
-      8,  9, 10, 11, 12, 13, 15, 15, 16, 16, 16, 16 },
-    { 2,  3,  3,  3,  3,  4,  4,  5,  5,  5,  7,  7,
-      7,  9,  9,  9, 10, 11, 12, 14, 14, 14, 15, 15 },
-    { 3,  3,  3,  3,  3,  3,  4,  4,  5,  5,  6,  6,
-      7,  7,  8,  8,  9,  9,  9, 10, 11, 12, 13, 13 },
-    { 3,  3,  3,  3,  3,  3,  4,  4,  5,  5,  6,  6,
-      6,  8,  8,  8,  9, 10, 11, 12, 14, 14, 14, 14 },
-    { 2,  3,  3,  3,  4,  4,  4,  4,  5,  5,  6,  6,
-      6,  8,  8,  9,  9,  9, 10, 11, 12, 13, 14, 14 },
-    { 2,  3,  3,  3,  4,  4,  4,  4,  5,  5,  5,  6,
-      7,  8,  9, 10, 11, 12, 13, 14, 16, 16, 16, 16 },
-    { 2,  3,  3,  3,  3,  4,  4,  5,  5,  5,  7,  7,
-      7,  8,  9, 10, 11, 13, 14, 14, 14, 14, 14, 14 },
+static const uint8_t envelope_quant_index_huffcounts[13][16] = {
+    {  0,  0,  3,  8,  3,  1,  1,  1,  1,  0,  2,  4,  0,  0,  0,  0  },
+    {  0,  0,  6,  2,  3,  1,  1,  1,  1,  1,  1,  1,  1,  0,  3,  2  },
+    {  0,  0,  3,  8,  3,  1,  1,  1,  1,  1,  1,  1,  1,  2,  0,  0  },
+    {  0,  0,  5,  4,  3,  0,  3,  0,  3,  1,  1,  0,  4,  0,  0,  0  },
+    {  0,  0,  5,  3,  4,  3,  1,  1,  1,  1,  1,  1,  1,  2,  0,  0  },
+    {  0,  0,  5,  4,  3,  0,  2,  3,  1,  1,  1,  1,  1,  2,  0,  0  },
+    {  0,  1,  4,  2,  3,  1,  1,  1,  1,  1,  1,  1,  1,  0,  2,  4  },
+    {  0,  1,  4,  2,  3,  0,  3,  0,  3,  1,  1,  1,  0,  3,  2,  0  },
+    {  0,  0,  6,  2,  2,  2,  2,  2,  3,  1,  1,  1,  2,  0,  0,  0  },
+    {  0,  0,  6,  2,  2,  3,  0,  3,  1,  1,  1,  1,  0,  4,  0,  0  },
+    {  0,  1,  3,  4,  2,  3,  0,  2,  3,  1,  1,  1,  1,  2,  0,  0  },
+    {  0,  1,  3,  4,  3,  1,  1,  1,  1,  1,  1,  1,  1,  1,  0,  4  },
+    {  0,  1,  4,  2,  3,  0,  3,  1,  1,  1,  1,  0,  1,  6,  0,  0  },
 };
 
 static const uint8_t envelope_quant_index_huffsyms[13][24] = {
@@ -137,18 +122,14 @@  static const uint8_t envelope_quant_index_huffsyms[13][24] = {
 };
 
 
-static const uint8_t cvh_huffbits0[181] = {
-     1,  4,  4,  5,  5,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,  7,  7,
-     8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  9,  9,  9,
-     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
-     9,  9,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12,
-    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13,
-    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
-    14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16,
-    16,
+static const uint8_t cvh_huffcounts[7][16] = {
+    {  1,  0,  0,  2,  2,  5,  8, 15, 31, 33, 28, 17, 15,  8,  8,   8  },
+    {  1,  0,  0,  2,  4,  5,  7, 16, 18, 12, 11,  7,  3,  5,  1,   2  },
+    {  1,  0,  1,  2,  4,  2,  5,  8,  7,  8,  2,  3,  1,  1,  1,   2  },
+    {  0,  1,  0,  2,  5, 12,  7, 27, 22, 41, 32, 41, 55, 23, 32, 220  },
+    {  0,  1,  0,  5,  7,  4,  8,  9, 17, 10, 13, 17, 12, 14, 92,   0  },
+    {  0,  1,  0,  5,  6,  8,  8,  8,  4,  7, 11, 23, 21, 10, 80,   0  },
+    {  1,  0,  0,  5,  0,  9,  1,  7,  4,  3,  2,  0,  0,  0,  0,   0  },
 };
 
 static const uint8_t cvh_huffsyms0[181] = {
@@ -167,16 +148,6 @@  static const uint8_t cvh_huffsyms0[181] = {
     190,
 };
 
-static const uint8_t cvh_huffbits1[94] = {
-     1,  4,  4,  5,  5,  5,  5,  6,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,
-     7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  9,
-     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9, 10,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14,
-    14, 15, 16, 16,
-};
-
-
 static const uint8_t cvh_huffsyms1[94] = {
      0,  1, 10,  2, 11, 20, 21,  3, 12, 22, 30, 31,  4, 13, 14, 23, 32, 40, 41,
      5,  6, 15, 16, 24, 25, 33, 34, 42, 43, 50, 51, 52, 60, 61, 62,  7, 17, 18,
@@ -185,50 +156,12 @@  static const uint8_t cvh_huffsyms1[94] = {
     39, 58, 67, 75, 76, 85, 93, 49, 68, 94, 59, 77, 78, 86, 95, 69, 87, 96,
 };
 
-static const uint8_t cvh_huffbits2[48] = {
-     1,  3,  4,  4,  5,  5,  5,  5,  6,  6,  7,  7,  7,  7,  7,  8,  8,  8,
-     8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10,
-    10, 10, 11, 11, 12, 12, 12, 13, 14, 15, 16, 16,
-};
-
 static const uint8_t cvh_huffsyms2[48] = {
      0,  7,  1,  8,  2,  9, 14, 15, 16, 22,  3, 10, 17, 21, 23,  4, 11, 18, 24,
     28, 29, 30, 35,  5, 12, 25, 31, 36, 37, 42,  6, 13, 19, 20, 26, 32, 38, 43,
     39, 44, 27, 33, 45, 46, 34, 40, 41, 47,
 };
 
-static const uint8_t cvh_huffbits3[520] = {
-     2,  4,  4,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  6,  6,  6,  6,
-     6,  6,  7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,
-     8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,  8,
-     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,
-     9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
-    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
-    12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13,
-    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14,
-    14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-    16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16,
-};
-
 static const uint16_t cvh_huffsyms3[520] = {
       0,   1, 125,   5,   6,  25,  30, 150,   2,   7,  26,  31, 126, 130, 131,
     151, 155, 156, 250, 275,  10,  35,  36,  50,  55, 175, 180,   3,   8,  11,
@@ -267,21 +200,6 @@  static const uint16_t cvh_huffsyms3[520] = {
     583, 585, 586, 587, 590, 591, 600, 601, 605, 606,
 };
 
-static const uint8_t cvh_huffbits4[209] = {
-     2,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  7,
-     7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,  8,  9,  9,
-     9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9,  9, 10, 10, 10,
-    10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
-    12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14,
-    14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-};
-
 static const uint8_t cvh_huffsyms4[209] = {
       0,   1,   4,  16,  64,  80,   5,  17,  20,  21,  65,  68,  84,  69,  81,
      85, 128,   2,   6,   8,  25,  32,  96, 100, 144,   9,  22,  24,  36,  37,
@@ -299,20 +217,6 @@  static const uint8_t cvh_huffsyms4[209] = {
     218, 220, 221, 225, 226, 228, 229, 230, 232, 233, 240, 241, 244, 245,
 };
 
-static const uint8_t cvh_huffbits5[192] = {
-     2,  4,  4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,
-     6,  6,  7,  7,  7,  7,  7,  7,  7,  7,  8,  8,  8,  8,  8,  8,  8,  8,
-     9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11,
-    11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
-    12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
-    13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14,
-    14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
-};
-
 static const uint8_t cvh_huffsyms5[192] = {
       0,   1,   3,   9,  27,  81,   4,  12,  36,  82,  84, 108,  10,  13,  28,
      30,  39,  90, 109, 117,  31,  37,  40,  85,  91,  93, 111, 120,   2,  54,
@@ -329,11 +233,6 @@  static const uint8_t cvh_huffsyms5[192] = {
     205, 207, 208, 210, 211, 217, 219, 220, 225, 226, 228, 229,
 };
 
-static const uint8_t cvh_huffbits6[32] = {
-     1,  4,  4,  4,  4,  4,  6,  6,  6,  6,  6,  6,  6,  6,  6,  7,  8,  8,
-     8,  8,  8,  8,  8,  9,  9,  9,  9, 10, 10, 10, 11, 11,
-};
-
 static const uint8_t cvh_huffsyms6[32] = {
      0,  1,  2,  4,  8, 16,  3,  5,  6,  9, 10, 12, 17, 20, 24, 18,  7, 11, 14,
     19, 22, 26, 28, 13, 21, 25, 30, 15, 27, 29, 23, 31,
@@ -344,12 +243,6 @@  static const void* const cvh_huffsyms[7] = {
     cvh_huffsyms4, cvh_huffsyms5, cvh_huffsyms6,
 };
 
-static const uint8_t* const cvh_huffbits[7] = {
-    cvh_huffbits0, cvh_huffbits1, cvh_huffbits2, cvh_huffbits3,
-    cvh_huffbits4, cvh_huffbits5, cvh_huffbits6,
-};
-
-
 static const uint8_t ccpl_huffsyms2[3] = {
      1,  0,  2,
 };
@@ -374,28 +267,12 @@  static const uint8_t ccpl_huffsyms6[63] = {
      2, 60, 61,  1,  0, 62,
 };
 
-static const uint8_t ccpl_huffbits2[3] = {
-     1,  2,  2,
-};
-
-static const uint8_t ccpl_huffbits3[7] = {
-     1,  2,  3,  4,  5,  6,  6,
-};
-
-static const uint8_t ccpl_huffbits4[15] = {
-     1,  3,  3,  4,  4,  5,  5,  6,  6,  7,  7,  8,  8,  8,  8,
-};
-
-static const uint8_t ccpl_huffbits5[31] = {
-     1,  3,  3,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  8,  8,  8,
-     8,  9,  9,  9,  9, 10, 10, 10, 10, 10, 10, 10, 10,
-};
-
-static const uint8_t ccpl_huffbits6[63] = {
-     1,  3,  4,  5,  5,  5,  5,  6,  6,  6,  6,  7,  7,  7,  7,  7,  7,  7,
-     7,  8,  8,  8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  9,  9,  9,
-    10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12,
-    12, 13, 13, 14, 14, 14, 15, 16, 16,
+static const uint8_t ccpl_huffcounts[5][16] = {
+    {  1,  2,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
+    {  1,  1,  1,  1,  1,  2,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0  },
+    {  1,  0,  2,  2,  2,  2,  2,  4,  0,  0,  0,  0,  0,  0,  0,  0  },
+    {  1,  0,  2,  0,  4,  4,  4,  4,  4,  8,  0,  0,  0,  0,  0,  0  },
+    {  1,  0,  1,  1,  4,  4,  8,  8,  9,  9,  8,  2,  2,  3,  1,  2  },
 };
 
 static const uint8_t *const ccpl_huffsyms[5] = {
@@ -403,12 +280,6 @@  static const uint8_t *const ccpl_huffsyms[5] = {
     ccpl_huffsyms4, ccpl_huffsyms5, ccpl_huffsyms6
 };
 
-static const uint8_t* const ccpl_huffbits[5] = {
-    ccpl_huffbits2,ccpl_huffbits3,
-    ccpl_huffbits4,ccpl_huffbits5,ccpl_huffbits6
-};
-
-
 //Coupling tables
 
 static const int cplband[51] = {