History

avcodec/hq_hqa: Use RL-VLC table

This moves indirections to init.

Andreas Rheinhardt committed 1 year ago

Commit ce0074f1 parent 18309fb2 files · +33 −8Browse files

Unified · Split

2 files
  1. libavcodec/hq_hqa.c +31 −8
  2. libavcodec/hq_hqadata.h +2 −0
libavcodec/hq_hqa.c+31−8
@@ -60,7 +60,7 @@ typedef struct HQContext { · 59 unmodified lines
6060
6161 static const int32_t *hq_quants[NUM_HQ_QUANTS][2][4];
6262
63−static VLCElem hq_ac_vlc[1184];
63+static RL_VLC_ELEM hq_ac_rvlc[1184];
6464
6565 static inline void put_blocks(HQContext *c, AVFrame *pic,
6666 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], · 11 unmodified lines
7878 int qsel, int is_chroma, int is_hqa)
7979 {
8080 const int32_t *q;
81− int val, pos = 1;
8281
8382 if (!is_hqa) {
8483 block[0] = get_sbits(gb, 9) * 64;
@@ -88,17 +87,23 @@ static int hq_decode_block(HQContext *c, GetBitContext *gb, int16_t block[64], · 3 unmodified lines
8887 block[0] = get_sbits(gb, 9) * 64;
8988 }
9089
91− for (;;) {
92− val = get_vlc2(gb, hq_ac_vlc, 9, 2);
93− if (val < 0)
90+ OPEN_READER(re, gb);
91+ for (int pos = 1;;) {
92+ int level, run;
93+ UPDATE_CACHE(re, gb);
94+ GET_RL_VLC(level, run, re, gb, hq_ac_rvlc, 9, 2, 0);
95+ if (run == HQ_AC_INVALID_RUN) {
96+ CLOSE_READER(re, gb);
9497 return AVERROR_INVALIDDATA;
98+ }
9599
96− pos += hq_ac_skips[val];
100+ pos += run;
97101 if (pos >= 64)
98102 break;
99− block[ff_zigzag_direct[pos]] = (int)(hq_ac_syms[val] * (unsigned)q[pos]) >> 12;
103+ block[ff_zigzag_direct[pos]] = (int)(level * (unsigned)q[pos]) >> 12;
100104 pos++;
101105 }
106+ CLOSE_READER(re, gb);
102107
103108 return 0;
104109 }
@@ -372,9 +377,27 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic, · 267 unmodified lines
372377
373378 static av_cold void hq_init_static(void)
374379 {
375− VLC_INIT_STATIC_TABLE(hq_ac_vlc, 9, NUM_HQ_AC_ENTRIES,
380+ VLC_INIT_STATIC_TABLE(hq_ac_rvlc, 9, NUM_HQ_AC_ENTRIES,
376381 hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);
377382
383+ for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_ac_rvlc); ++i) {
384+ int len = hq_ac_rvlc[i].len;
385+ int sym = hq_ac_rvlc[i].sym, level = sym;
386+ int run;
387+
388+ if (len > 0) {
389+ level = hq_ac_syms[sym];
390+ run = hq_ac_skips[sym];
391+ } else if (len < 0) { // More bits needed
392+ run = 0;
393+ } else { // Invalid code
394+ run = HQ_AC_INVALID_RUN;
395+ }
396+ hq_ac_rvlc[i].len8 = len;
397+ hq_ac_rvlc[i].run = run;
398+ hq_ac_rvlc[i].level = level;
399+ }
400+
378401 for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_quants); ++i) {
379402 for (size_t j = 0; j < FF_ARRAY_ELEMS(hq_quants[0]); ++j) {
380403 for (size_t k = 0; k < FF_ARRAY_ELEMS(hq_quants[0][0]); ++k)
libavcodec/hq_hqadata.h+2−0
@@ -1155,6 +1155,8 @@ static const uint8_t hq_quant_map[NUM_HQ_QUANTS][2][4] = · 1154 unmodified lines
11551155 { { QMAT3A, QMAT48, QMAT4C, QMAT4C }, { QMAT3B, QMAT49, QMAT4D, QMAT4D } },
11561156 };
11571157
1158+#define HQ_AC_INVALID_RUN 128
1159+
11581160 static const uint8_t hq_ac_bits[NUM_HQ_AC_ENTRIES] = {
11591161 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
11601162 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t