1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-04 22:03:09 +02:00

avcodec/hq_hqa: Use RL-VLC table

This moves indirections to init.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-04-09 18:54:38 +02:00
parent 18309fba3c
commit ce0074f97b
2 changed files with 33 additions and 8 deletions

View File

@ -60,7 +60,7 @@ typedef struct HQContext {
static const int32_t *hq_quants[NUM_HQ_QUANTS][2][4]; static const int32_t *hq_quants[NUM_HQ_QUANTS][2][4];
static VLCElem hq_ac_vlc[1184]; static RL_VLC_ELEM hq_ac_rvlc[1184];
static inline void put_blocks(HQContext *c, AVFrame *pic, static inline void put_blocks(HQContext *c, AVFrame *pic,
int plane, int x, int y, int ilace, int plane, int x, int y, int ilace,
@ -78,7 +78,6 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
int qsel, int is_chroma, int is_hqa) int qsel, int is_chroma, int is_hqa)
{ {
const int32_t *q; const int32_t *q;
int val, pos = 1;
if (!is_hqa) { if (!is_hqa) {
block[0] = get_sbits(gb, 9) * 64; block[0] = get_sbits(gb, 9) * 64;
@ -88,17 +87,23 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64],
block[0] = get_sbits(gb, 9) * 64; block[0] = get_sbits(gb, 9) * 64;
} }
for (;;) { OPEN_READER(re, gb);
val = get_vlc2(gb, hq_ac_vlc, 9, 2); for (int pos = 1;;) {
if (val < 0) int level, run;
UPDATE_CACHE(re, gb);
GET_RL_VLC(level, run, re, gb, hq_ac_rvlc, 9, 2, 0);
if (run == HQ_AC_INVALID_RUN) {
CLOSE_READER(re, gb);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
}
pos += hq_ac_skips[val]; pos += run;
if (pos >= 64) if (pos >= 64)
break; break;
block[ff_zigzag_direct[pos]] = (int)(hq_ac_syms[val] * (unsigned)q[pos]) >> 12; block[ff_zigzag_direct[pos]] = (int)(level * (unsigned)q[pos]) >> 12;
pos++; pos++;
} }
CLOSE_READER(re, gb);
return 0; return 0;
} }
@ -372,9 +377,27 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic,
static av_cold void hq_init_static(void) static av_cold void hq_init_static(void)
{ {
VLC_INIT_STATIC_TABLE(hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES, VLC_INIT_STATIC_TABLE(hq_ac_rvlc, 9, NUM_HQ_AC_ENTRIES,
hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0); hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);
for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_ac_rvlc); ++i) {
int len = hq_ac_rvlc[i].len;
int sym = hq_ac_rvlc[i].sym, level = sym;
int run;
if (len > 0) {
level = hq_ac_syms[sym];
run = hq_ac_skips[sym];
} else if (len < 0) { // More bits needed
run = 0;
} else { // Invalid code
run = HQ_AC_INVALID_RUN;
}
hq_ac_rvlc[i].len8 = len;
hq_ac_rvlc[i].run = run;
hq_ac_rvlc[i].level = level;
}
for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_quants); ++i) { for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_quants); ++i) {
for (size_t j = 0; j < FF_ARRAY_ELEMS(hq_quants[0]); ++j) { for (size_t j = 0; j < FF_ARRAY_ELEMS(hq_quants[0]); ++j) {
for (size_t k = 0; k < FF_ARRAY_ELEMS(hq_quants[0][0]); ++k) for (size_t k = 0; k < FF_ARRAY_ELEMS(hq_quants[0][0]); ++k)

View File

@ -1155,6 +1155,8 @@ static const uint8_t hq_quant_map[NUM_HQ_QUANTS][2][4] =
{ { QMAT3A, QMAT48, QMAT4C, QMAT4C }, { QMAT3B, QMAT49, QMAT4D, QMAT4D } }, { { QMAT3A, QMAT48, QMAT4C, QMAT4C }, { QMAT3B, QMAT49, QMAT4D, QMAT4D } },
}; };
#define HQ_AC_INVALID_RUN 128
static const uint8_t hq_ac_bits[NUM_HQ_AC_ENTRIES] = { static const uint8_t hq_ac_bits[NUM_HQ_AC_ENTRIES] = {
3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 3, 3, 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, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,