提交 22241d12 编写于 作者: A Andreas Rheinhardt

avcodec/vp3: Apply VLC offset during init

By switching to ff_init_vlc_from_lengths() one can apply both positive
as well as negative offsets for free; in this case it even saves space
because one replaces codes tables that don't fit into an uint8_t by
symbols tables that fit into an uint8_t or can even be completely
avoided as they are trivial.
Signed-off-by: NAndreas Rheinhardt <andreas.rheinhardt@gmail.com>
上级 984fdfd0
......@@ -48,6 +48,9 @@
#include "vp3dsp.h"
#include "xiph.h"
#define VP4_MV_VLC_BITS 6
#define SUPERBLOCK_VLC_BITS 6
#define FRAGMENT_PIXELS 8
// FIXME split things out into their own arrays
......@@ -489,7 +492,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
bit ^= 1;
current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
6, 2) + 1;
SUPERBLOCK_VLC_BITS, 2);
if (current_run == 34)
current_run += get_bits(gb, 12);
......@@ -523,7 +526,7 @@ static int unpack_superblocks(Vp3DecodeContext *s, GetBitContext *gb)
bit ^= 1;
current_run = get_vlc2(gb, s->superblock_run_length_vlc.table,
6, 2) + 1;
SUPERBLOCK_VLC_BITS, 2);
if (current_run == 34)
current_run += get_bits(gb, 12);
......@@ -885,7 +888,8 @@ static int unpack_modes(Vp3DecodeContext *s, GetBitContext *gb)
static int vp4_get_mv(Vp3DecodeContext *s, GetBitContext *gb, int axis, int last_motion)
{
int v = get_vlc2(gb, s->vp4_mv_vlc[axis][vp4_mv_table_selector[FFABS(last_motion)]].table, 6, 2) - 31;
int v = get_vlc2(gb, s->vp4_mv_vlc[axis][vp4_mv_table_selector[FFABS(last_motion)]].table,
VP4_MV_VLC_BITS, 2);
return last_motion < 0 ? -v : v;
}
......@@ -1104,7 +1108,8 @@ static int unpack_block_qpis(Vp3DecodeContext *s, GetBitContext *gb)
else
bit ^= 1;
run_length = get_vlc2(gb, s->superblock_run_length_vlc.table, 6, 2) + 1;
run_length = get_vlc2(gb, s->superblock_run_length_vlc.table,
SUPERBLOCK_VLC_BITS, 2);
if (run_length == 34)
run_length += get_bits(gb, 12);
blocks_decoded += run_length;
......@@ -2452,9 +2457,10 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
}
}
if ((ret = init_vlc(&s->superblock_run_length_vlc, 6, 34,
&superblock_run_length_vlc_table[0][1], 4, 2,
&superblock_run_length_vlc_table[0][0], 4, 2, 0)) < 0)
ret = ff_init_vlc_from_lengths(&s->superblock_run_length_vlc, SUPERBLOCK_VLC_BITS, 34,
superblock_run_length_vlc_lens, 1,
NULL, 0, 0, 1, 0, avctx);
if (ret < 0)
return ret;
if ((ret = init_vlc(&s->fragment_run_length_vlc, 5, 30,
......@@ -2474,11 +2480,14 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx)
#if CONFIG_VP4_DECODER
for (j = 0; j < 2; j++)
for (i = 0; i < 7; i++)
if ((ret = init_vlc(&s->vp4_mv_vlc[j][i], 6, 63,
&vp4_mv_vlc[j][i][0][1], 4, 2,
&vp4_mv_vlc[j][i][0][0], 4, 2, 0)) < 0)
for (i = 0; i < 7; i++) {
ret = ff_init_vlc_from_lengths(&s->vp4_mv_vlc[j][i], VP4_MV_VLC_BITS, 63,
&vp4_mv_vlc[j][i][0][1], 2,
&vp4_mv_vlc[j][i][0][0], 2, 1, -31,
0, avctx);
if (ret < 0)
return ret;
}
/* version >= 2 */
for (i = 0; i < 2; i++)
......
......@@ -95,25 +95,11 @@ static const uint8_t vp31_filter_limit_values[64] = {
0, 0, 0, 0, 0, 0, 0, 0
};
static const uint16_t superblock_run_length_vlc_table[34][2] = {
{ 0, 1 },
{ 4, 3 }, { 5, 3 },
{ 0xC, 4 }, { 0xD, 4 },
{ 0x38, 6 }, { 0x39, 6 }, { 0x3A, 6 }, { 0x3B, 6 },
{ 0xF0, 8 }, { 0xF1, 8 }, { 0xF2, 8 }, { 0xF3, 8 },
{ 0xF4, 8 }, { 0xF5, 8 }, { 0xF6, 8 }, { 0xF7, 8 },
{ 0x3E0, 10 }, { 0x3E1, 10 }, { 0x3E2, 10 }, { 0x3E3, 10 },
{ 0x3E4, 10 }, { 0x3E5, 10 }, { 0x3E6, 10 }, { 0x3E7, 10 },
{ 0x3E8, 10 }, { 0x3E9, 10 }, { 0x3EA, 10 }, { 0x3EB, 10 },
{ 0x3EC, 10 }, { 0x3ED, 10 }, { 0x3EE, 10 }, { 0x3EF, 10 },
{ 0x3F, 6 } /* this last VLC is a special case for reading 12 more
* bits from stream and adding the value 34 */
static const uint8_t superblock_run_length_vlc_lens[34] = {
1, 3, 3, 4, 4, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
6, /* This last value is a special case for reading 12 more
* bits from the stream and adding the value 34. */
};
static const uint16_t fragment_run_length_vlc_table[30][2] = {
......
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册