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

avcodec/hqxvlc: Avoid hardcoded RL VLC table

hqxvlc.c contains sort-of run-length VLCs in hardcoded form;
they amount to 26688 elements, taking 104KiB. These tables contain
many duplicated entries (they are partially created via a RPT_1024
macro). There are actually only 3039 different codes in all tables
combined, making this very wasteful.

This commit changes this by extracting the underlying entries
and creating a (static) RL-VLC. This only costs 3*3039 bytes
of .rodata. The resulting table needs only 15630 entries,
because our VLC init code uses smaller subtables when possible
(for an incomplete code, the negative of the length stored in
the VLC code is the number of bits the subtable uses; the hardcoded
tables uses a worst-case per table value).

Using GET_RL_VLC also gets rid of an unnecessary reload in case
a code is too long to be parsed in the first stage.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-03-13 10:57:56 +01:00
parent 49d15dfc35
commit abffd9313d
3 changed files with 829 additions and 1430 deletions

View File

@ -97,19 +97,16 @@ static inline void put_blocks(HQXContext *ctx, int plane,
} }
static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac, static inline void hqx_get_ac(GetBitContext *gb, const HQXAC *ac,
int *run, int *lev) int *runp, int *lev)
{ {
int val; int level, run;
OPEN_READER(re, gb);
val = show_bits(gb, ac->lut_bits); UPDATE_CACHE(re, gb);
if (ac->lut[val].bits == -1) { GET_RL_VLC(level, run, re, gb, ac->lut, ac->bits, 2, 0);
GetBitContext gb2 = *gb; CLOSE_READER(re, gb);
skip_bits(&gb2, ac->lut_bits); *runp = run;
val = ac->lut[val].lev + show_bits(&gb2, ac->extra_bits); *lev = level;
}
*run = ac->lut[val].run;
*lev = ac->lut[val].lev;
skip_bits(gb, ac->lut[val].bits);
} }
static int decode_block(GetBitContext *gb, VLC *vlc, static int decode_block(GetBitContext *gb, VLC *vlc,

View File

@ -39,15 +39,9 @@ enum HQXACMode {
NUM_HQX_AC NUM_HQX_AC
}; };
typedef struct HQXLUT {
int16_t lev;
uint8_t run;
int8_t bits;
} HQXLUT;
typedef struct HQXAC { typedef struct HQXAC {
int lut_bits, extra_bits; int bits;
const HQXLUT *lut; const RL_VLC_ELEM *lut;
} HQXAC; } HQXAC;
struct HQXContext; struct HQXContext;
@ -81,7 +75,7 @@ typedef struct HQXContext {
#define HQX_CBP_VLC_BITS 5 #define HQX_CBP_VLC_BITS 5
#define HQX_DC_VLC_BITS 9 #define HQX_DC_VLC_BITS 9
extern const HQXAC ff_hqx_ac[NUM_HQX_AC]; extern HQXAC ff_hqx_ac[NUM_HQX_AC];
int ff_hqx_init_vlcs(HQXContext *ctx); int ff_hqx_init_vlcs(HQXContext *ctx);

File diff suppressed because it is too large Load Diff