avcodec/intrax8: Avoid indirection when accessing VLC table

To do so, store the pointer to the VLC table and not to the VLC.
This is possible, because all the VLCs of the same type use
the same number of bits.
Also use a const VLCElem*, because the target is static and must
therefore not be modified after its initialization.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
pull/388/head
Andreas Rheinhardt 2 years ago
parent b0e38c7d1e
commit 900ce6f8c3
  1. 24
      libavcodec/intrax8.c
  2. 6
      libavcodec/intrax8.h

@ -91,9 +91,9 @@ static av_cold void x8_vlc_init(void)
static void x8_reset_vlc_tables(IntraX8Context *w)
{
memset(w->j_dc_vlc, 0, sizeof(w->j_dc_vlc));
memset(w->j_ac_vlc, 0, sizeof(w->j_ac_vlc));
w->j_orient_vlc = NULL;
memset(w->j_dc_vlc_table, 0, sizeof(w->j_dc_vlc_table));
memset(w->j_ac_vlc_table, 0, sizeof(w->j_ac_vlc_table));
w->j_orient_vlc_table = NULL;
}
static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
@ -102,23 +102,23 @@ static inline void x8_select_ac_table(IntraX8Context *const w, int mode)
av_assert2(mode < 4);
if (w->j_ac_vlc[mode])
if (w->j_ac_vlc_table[mode])
return;
table_index = get_bits(w->gb, 3);
// 2 modes use same tables
w->j_ac_vlc[mode] = &j_ac_vlc[w->quant < 13][mode >> 1][table_index];
w->j_ac_vlc_table[mode] = j_ac_vlc[w->quant < 13][mode >> 1][table_index].table;
av_assert2(w->j_ac_vlc[mode]);
}
static inline int x8_get_orient_vlc(IntraX8Context *w)
{
if (!w->j_orient_vlc) {
if (!w->j_orient_vlc_table) {
int table_index = get_bits(w->gb, 1 + (w->quant < 13));
w->j_orient_vlc = &j_orient_vlc[w->quant < 13][table_index];
w->j_orient_vlc_table = j_orient_vlc[w->quant < 13][table_index].table;
}
return get_vlc2(w->gb, w->j_orient_vlc->table, OR_VLC_BITS, OR_VLC_MTD);
return get_vlc2(w->gb, w->j_orient_vlc_table, OR_VLC_BITS, OR_VLC_MTD);
}
#define extra_bits(eb) (eb) // 3 bits
@ -174,7 +174,7 @@ static void x8_get_ac_rlf(IntraX8Context *const w, const int mode,
int i, e;
// x8_select_ac_table(w, mode);
i = get_vlc2(w->gb, w->j_ac_vlc[mode]->table, AC_VLC_BITS, AC_VLC_MTD);
i = get_vlc2(w->gb, w->j_ac_vlc_table[mode], AC_VLC_BITS, AC_VLC_MTD);
if (i < 46) { // [0-45]
int t, l;
@ -254,13 +254,13 @@ static int x8_get_dc_rlf(IntraX8Context *const w, const int mode,
int i, e, c;
av_assert2(mode < 3);
if (!w->j_dc_vlc[mode]) {
if (!w->j_dc_vlc_table[mode]) {
int table_index = get_bits(w->gb, 3);
// 4 modes, same table
w->j_dc_vlc[mode] = &j_dc_vlc[w->quant < 13][table_index];
w->j_dc_vlc_table[mode] = j_dc_vlc[w->quant < 13][table_index].table;
}
i = get_vlc2(w->gb, w->j_dc_vlc[mode]->table, DC_VLC_BITS, DC_VLC_MTD);
i = get_vlc2(w->gb, w->j_dc_vlc_table[mode], DC_VLC_BITS, DC_VLC_MTD);
/* (i >= 17) { i -= 17; final =1; } */
c = i > 16;

@ -27,9 +27,9 @@
#include "mpegpicture.h"
typedef struct IntraX8Context {
VLC *j_ac_vlc[4]; // they point to the static j_mb_vlc
VLC *j_orient_vlc;
VLC *j_dc_vlc[3];
const VLCElem *j_ac_vlc_table[4]; // they point to the static j_mb_vlc.table
const VLCElem *j_orient_vlc_table;
const VLCElem *j_dc_vlc_table[3];
int use_quant_matrix;

Loading…
Cancel
Save