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

Showing the changes to libavcodec (2 of 2 files). Show all

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
60 60
61static const int32_t *hq_quants[NUM_HQ_QUANTS][2][4];61static const int32_t *hq_quants[NUM_HQ_QUANTS][2][4];
62 62
63static VLCElem hq_ac_vlc[1184];63static RL_VLC_ELEM hq_ac_rvlc[1184];
64 64
65static inline void put_blocks(HQContext *c, AVFrame *pic,65static inline void put_blocks(HQContext *c, AVFrame *pic,
66 int plane, int x, int y, int ilace,66 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
78 int qsel, int is_chroma, int is_hqa)78 int qsel, int is_chroma, int is_hqa)
79{79{
80 const int32_t *q;80 const int32_t *q;
81 int val, pos = 1;
82 81
83 if (!is_hqa) {82 if (!is_hqa) {
84 block[0] = get_sbits(gb, 9) * 64;83 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
88 block[0] = get_sbits(gb, 9) * 64;87 block[0] = get_sbits(gb, 9) * 64;
89 }88 }
90 89
91 for (;;) {90 OPEN_READER(re, gb);
92 val = get_vlc2(gb, hq_ac_vlc, 9, 2);91 for (int pos = 1;;) {
93 if (val < 0)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);
94 return AVERROR_INVALIDDATA;97 return AVERROR_INVALIDDATA;
98 }
95 99
96 pos += hq_ac_skips[val];100 pos += run;
97 if (pos >= 64)101 if (pos >= 64)
98 break;102 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;
100 pos++;104 pos++;
101 }105 }
106 CLOSE_READER(re, gb);
102 107
103 return 0;108 return 0;
104}109}
@@ -372,9 +377,27 @@ static int hq_hqa_decode_frame(AVCodecContext *avctx, AVFrame *pic, · 267 unmodified lines
372 377
373static av_cold void hq_init_static(void)378static av_cold void hq_init_static(void)
374{379{
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,
376 hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);381 hq_ac_bits, 1, 1, hq_ac_codes, 2, 2, 0);
377 382
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
378 for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_quants); ++i) {401 for (size_t i = 0; i < FF_ARRAY_ELEMS(hq_quants); ++i) {
379 for (size_t j = 0; j < FF_ARRAY_ELEMS(hq_quants[0]); ++j) {402 for (size_t j = 0; j < FF_ARRAY_ELEMS(hq_quants[0]); ++j) {
380 for (size_t k = 0; k < FF_ARRAY_ELEMS(hq_quants[0][0]); ++k)403 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
1155 { { QMAT3A, QMAT48, QMAT4C, QMAT4C }, { QMAT3B, QMAT49, QMAT4D, QMAT4D } },1155 { { QMAT3A, QMAT48, QMAT4C, QMAT4C }, { QMAT3B, QMAT49, QMAT4D, QMAT4D } },
1156};1156};
1157 1157
1158#define HQ_AC_INVALID_RUN 128
1159
1158static const uint8_t hq_ac_bits[NUM_HQ_AC_ENTRIES] = {1160static const uint8_t hq_ac_bits[NUM_HQ_AC_ENTRIES] = {
1159 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,1161 3, 3, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6,
1160 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,1162 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