summaryrefslogtreecommitdiff
path: root/libavcodec/vp3.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-11-06 10:14:22 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-08 17:51:46 +0100
commit22241d12c7bc7f317832d8101ebed8d2db78a41f (patch)
tree9e1dfe0ffa569a83987434cfe4485d14f545a6ca /libavcodec/vp3.c
parent984fdfd042aeec7d48cd906661b2192568874730 (diff)
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: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/vp3.c')
-rw-r--r--libavcodec/vp3.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c
index c4ad43a299..34c48f8725 100644
--- a/libavcodec/vp3.c
+++ b/libavcodec/vp3.c
@@ -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++)