avcodec/imc: Make Huffman tables smaller

The IMC decoder uses Huffman tables which are created at runtime from
length tables of type uint8_t and code tables of type uint16_t together
with an implicit symbols table (i.e. symbol[i] == i). This commit
changes this: All three tables are subjected to the same permutation to
order the codes from left to right in the tree; afterwards the codes can
be omitted because they are easily computable at runtime from the
lengths, whereas the symbols need to be explicitly coded now. But said
symbols fit into an uint8_t, so one saves space.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
Andreas Rheinhardt 2020-10-25 15:35:00 +01:00
parent b0094be719
commit 200e8e80aa
2 changed files with 37 additions and 36 deletions

View File

@ -239,9 +239,10 @@ static av_cold int imc_decode_init(AVCodecContext *avctx)
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]]; huffman_vlc[i][j].table = &vlc_tables[vlc_offsets[i * 4 + j]];
huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j]; huffman_vlc[i][j].table_allocated = vlc_offsets[i * 4 + j + 1] - vlc_offsets[i * 4 + j];
init_vlc(&huffman_vlc[i][j], IMC_VLC_BITS, imc_huffman_sizes[i], ff_init_vlc_from_lengths(&huffman_vlc[i][j], IMC_VLC_BITS, imc_huffman_sizes[i],
imc_huffman_lens[i][j], 1, 1, imc_huffman_lens[i][j], 1,
imc_huffman_bits[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); imc_huffman_syms[i][j], 1, 1,
0, INIT_VLC_USE_NEW_STATIC, NULL);
} }
} }

View File

@ -114,55 +114,55 @@ static const uint8_t imc_huffman_sizes[4] = {
static const uint8_t imc_huffman_lens[4][4][18] = { static const uint8_t imc_huffman_lens[4][4][18] = {
{ {
{ 16, 15, 13, 11, 8, 5, 3, 1, 2, 4, 6, 9, 10, 12, 14, 16, 7, 0 }, { 1, 2, 5, 6, 11, 12, 15, 16, 16, 14, 13, 10, 9, 8, 7, 4, 3 },
{ 10, 8, 7, 6, 4, 4, 3, 2, 2, 3, 4, 6, 7, 9, 11, 11, 7, 0 }, { 2, 3, 3, 4, 4, 4, 6, 6, 7, 7, 7, 8, 9, 10, 11, 11, 2 },
{ 15, 15, 14, 11, 8, 6, 4, 2, 1, 4, 5, 7, 9, 10, 12, 13, 4, 0 }, { 1, 4, 4, 7, 9, 10, 12, 15, 15, 14, 13, 11, 8, 6, 5, 4, 2 },
{ 13, 11, 10, 8, 6, 4, 2, 2, 2, 3, 5, 7, 9, 12, 15, 15, 14, 0 }, { 2, 2, 4, 8, 9, 14, 15, 15, 13, 12, 11, 10, 7, 6, 5, 3, 2 },
}, },
{ {
{ 14, 12, 10, 8, 7, 4, 2, 2, 2, 3, 5, 7, 9, 11, 13, 14, 7, 0 }, { 2, 2, 3, 4, 7, 7, 10, 11, 12, 14, 14, 13, 9, 8, 7, 5, 2 },
{ 14, 13, 11, 8, 6, 4, 3, 2, 2, 3, 5, 7, 9, 10, 12, 14, 3, 0 }, { 2, 3, 14, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2 },
{ 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, { 2, 3, 3, 4, 4, 5, 7, 9, 11, 12, 13, 13, 10, 8, 6, 4, 2 },
{ 13, 12, 10, 7, 5, 4, 3, 2, 2, 3, 4, 6, 8, 9, 11, 13, 4, 0 }, { 2, 3, 3, 4, 4, 5, 7, 9, 11, 12, 13, 13, 10, 8, 6, 4, 2 },
}, },
{ {
{ 16, 14, 12, 10, 8, 5, 3, 1, 2, 4, 7, 9, 11, 13, 15, 17, 6, 17 }, { 3, 5, 8, 9, 12, 15, 17, 17, 16, 14, 13, 11, 10, 7, 6, 4, 2, 1 },
{ 15, 13, 11, 8, 6, 4, 2, 2, 2, 3, 5, 7, 10, 12, 14, 16, 9, 16 }, { 4, 7, 8, 10, 11, 12, 15, 16, 16, 14, 13, 9, 6, 5, 3, 2, 2, 2 },
{ 14, 12, 11, 9, 8, 6, 3, 1, 2, 5, 7, 10, 13, 15, 16, 17, 4, 17 }, { 4, 5, 6, 7, 12, 13, 17, 17, 16, 15, 14, 11, 10, 9, 8, 3, 2, 1 },
{ 16, 14, 12, 9, 7, 5, 2, 2, 2, 3, 4, 6, 8, 11, 13, 15, 10, 16 }, { 2, 5, 7, 8, 14, 15, 16, 16, 13, 12, 11, 10, 9, 6, 4, 3, 2, 2 },
}, },
{ {
{ 13, 11, 10, 8, 7, 5, 2, 2, 2, 4, 6, 9, 12, 14, 15, 16, 3, 16 }, { 2, 4, 7, 9, 10, 12, 13, 15, 16, 16, 14, 11, 8, 6, 5, 3, 2, 2 },
{ 11, 11, 10, 9, 8, 7, 5, 4, 3, 3, 3, 3, 3, 3, 4, 5, 6, 5 }, { 3, 5, 5, 7, 10, 11, 11, 9, 8, 6, 5, 4, 4, 3, 3, 3, 3, 3 },
{ 9, 9, 7, 6, 5, 4, 3, 3, 2, 3, 4, 5, 4, 5, 5, 6, 8, 6 }, { 5, 8, 9, 9, 7, 6, 6, 6, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2 },
{ 13, 12, 10, 8, 5, 3, 3, 2, 2, 3, 4, 7, 9, 11, 14, 15, 6, 15 }, { 2, 3, 5, 7, 8, 11, 12, 13, 15, 15, 14, 10, 9, 6, 4, 3, 3, 2 },
} }
}; };
static const uint16_t imc_huffman_bits[4][4][18] = { static const uint8_t imc_huffman_syms[4][4][18] = {
{ {
{ 0xCC32, 0x6618, 0x1987, 0x0660, 0x00CD, 0x0018, 0x0007, 0x0000, 0x0002, 0x000D, 0x0032, 0x0199, 0x0331, 0x0CC2, 0x330D, 0xCC33, 0x0067, 0x0000 }, { 7, 8, 5, 10, 3, 13, 1, 0, 15, 14, 2, 12, 11, 4, 16, 9, 6 },
{ 0x02FE, 0x00BE, 0x005E, 0x002D, 0x000A, 0x0009, 0x0003, 0x0003, 0x0000, 0x0002, 0x0008, 0x002C, 0x005D, 0x017E, 0x05FE, 0x05FF, 0x005C, 0x0000 }, { 8, 9, 6, 10, 5, 4, 11, 3, 16, 12, 2, 1, 13, 0, 14, 15, 7 },
{ 0x5169, 0x5168, 0x28B5, 0x0517, 0x00A3, 0x0029, 0x0008, 0x0003, 0x0000, 0x0009, 0x0015, 0x0050, 0x0144, 0x028A, 0x0A2C, 0x145B, 0x000B, 0x0000 }, { 8, 6, 9, 11, 12, 13, 14, 1, 0, 2, 15, 3, 4, 5, 10, 16, 7 },
{ 0x1231, 0x048D, 0x0247, 0x0090, 0x0025, 0x0008, 0x0001, 0x0003, 0x0000, 0x0005, 0x0013, 0x0049, 0x0122, 0x0919, 0x48C3, 0x48C2, 0x2460, 0x0000 }, { 8, 6, 5, 3, 12, 16, 15, 14, 0, 13, 1, 2, 11, 4, 10, 9, 7 },
}, },
{ {
{ 0x2D1D, 0x0B46, 0x02D0, 0x00B5, 0x0059, 0x000A, 0x0003, 0x0001, 0x0000, 0x0004, 0x0017, 0x005B, 0x0169, 0x05A2, 0x168F, 0x2D1C, 0x0058, 0x0000 }, { 8, 7, 9, 5, 16, 4, 2, 13, 1, 15, 0, 14, 12, 3, 11, 10, 6 },
{ 0x1800, 0x0C01, 0x0301, 0x0061, 0x0019, 0x0007, 0x0004, 0x0003, 0x0000, 0x0005, 0x000D, 0x0031, 0x00C1, 0x0181, 0x0601, 0x1801, 0x0002, 0x0000 }, { 8, 16, 0, 15, 1, 14, 2, 13, 12, 3, 11, 4, 10, 5, 6, 9, 7 },
{ 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, { 8, 6, 9, 10, 16, 4, 3, 13, 14, 1, 0, 15, 2, 12, 11, 5, 7 },
{ 0x1556, 0x0AAA, 0x02AB, 0x0054, 0x0014, 0x000B, 0x0002, 0x0003, 0x0000, 0x0003, 0x0008, 0x002B, 0x00AB, 0x0154, 0x0554, 0x1557, 0x0009, 0x0000 }, { 8, 6, 9, 10, 16, 4, 3, 13, 14, 1, 0, 15, 2, 12, 11, 5, 7 },
}, },
{ {
{ 0x2993, 0x0A65, 0x0298, 0x00A7, 0x0028, 0x0004, 0x0000, 0x0001, 0x0001, 0x0003, 0x0015, 0x0052, 0x014D, 0x0533, 0x14C8, 0x5324, 0x000B, 0x5325 }, { 6, 5, 4, 11, 2, 14, 15, 17, 0, 1, 13, 12, 3, 10, 16, 9, 8, 7 },
{ 0x09B8, 0x026F, 0x009A, 0x0012, 0x0005, 0x0000, 0x0001, 0x0002, 0x0003, 0x0001, 0x0003, 0x0008, 0x004C, 0x0136, 0x04DD, 0x1373, 0x0027, 0x1372 }, { 5, 11, 3, 12, 2, 13, 0, 17, 15, 14, 1, 16, 4, 10, 9, 6, 7, 8 },
{ 0x0787, 0x01E0, 0x00F1, 0x003D, 0x001F, 0x0006, 0x0001, 0x0001, 0x0001, 0x0002, 0x000E, 0x0079, 0x03C2, 0x0F0D, 0x1E19, 0x3C30, 0x0000, 0x3C31 }, { 16, 9, 5, 10, 1, 12, 15, 17, 14, 13, 0, 2, 11, 3, 4, 6, 8, 7 },
{ 0x4B06, 0x12C0, 0x04B1, 0x0097, 0x0024, 0x0008, 0x0002, 0x0003, 0x0000, 0x0003, 0x0005, 0x0013, 0x004A, 0x0259, 0x0961, 0x2582, 0x012D, 0x4B07 }, { 8, 5, 4, 12, 1, 15, 0, 17, 14, 2, 13, 16, 3, 11, 10, 9, 6, 7 },
}, },
{ {
{ 0x0A5A, 0x0297, 0x014A, 0x0053, 0x0028, 0x000B, 0x0003, 0x0000, 0x0002, 0x0004, 0x0015, 0x00A4, 0x052C, 0x14B7, 0x296C, 0x52DB, 0x0003, 0x52DA }, { 7, 9, 4, 11, 2, 12, 0, 14, 17, 15, 13, 1, 3, 10, 5, 16, 8, 6 },
{ 0x0193, 0x0192, 0x00C8, 0x0065, 0x0033, 0x0018, 0x0007, 0x0004, 0x0000, 0x0004, 0x0005, 0x0007, 0x0006, 0x0003, 0x0005, 0x0005, 0x000D, 0x0004 }, { 8, 17, 15, 5, 2, 1, 0, 3, 4, 16, 6, 7, 14, 13, 9, 10, 12, 11 },
{ 0x0012, 0x0013, 0x0005, 0x0003, 0x0000, 0x0003, 0x0005, 0x0004, 0x0003, 0x0003, 0x0005, 0x0005, 0x0004, 0x0004, 0x0003, 0x0005, 0x0008, 0x0004 }, { 4, 16, 0, 1, 2, 3, 17, 15, 14, 13, 11, 5, 12, 10, 9, 7, 6, 8 },
{ 0x0D66, 0x06B2, 0x01AD, 0x006A, 0x000C, 0x0005, 0x0004, 0x0000, 0x0003, 0x0002, 0x0007, 0x0034, 0x00D7, 0x0358, 0x1ACF, 0x359C, 0x001B, 0x359D }, { 7, 9, 4, 11, 3, 13, 1, 0, 15, 17, 14, 2, 12, 16, 10, 6, 5, 8 },
} }
}; };