summaryrefslogtreecommitdiff
path: root/libavcodec/speedhqenc.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@gmail.com>2020-12-10 09:19:08 +0100
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-05-05 17:55:37 +0200
commit03008c2811ec26cf338780a89b6b2b849b399e3c (patch)
treee59dd60186881a5dbfea0fd4ed8683d02263b536 /libavcodec/speedhqenc.c
parentb05631f7b959fd9ec266a4315db60cc77b655cd9 (diff)
avcodec/speedhqenc: Hardcode table to save space
The SpeedHQ encoder currently reverses the entries of two small tables and stores them in other tables. These other tables have a size of 48 bytes, yet the code for their initialization takes 135 bytes (GCC 9.3, x64, O3 albeit in an av_cold function). So remove the runtime initialization and hardcode the tables. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
Diffstat (limited to 'libavcodec/speedhqenc.c')
-rw-r--r--libavcodec/speedhqenc.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/libavcodec/speedhqenc.c b/libavcodec/speedhqenc.c
index 529df4f5b6..43437223db 100644
--- a/libavcodec/speedhqenc.c
+++ b/libavcodec/speedhqenc.c
@@ -38,8 +38,13 @@
extern RLTable ff_rl_speedhq;
static uint8_t speedhq_static_rl_table_store[2][2*MAX_RUN + MAX_LEVEL + 3];
-static uint16_t mpeg12_vlc_dc_lum_code_reversed[12];
-static uint16_t mpeg12_vlc_dc_chroma_code_reversed[12];
+/* Exactly the same as MPEG-2, except little-endian. */
+static const uint16_t mpeg12_vlc_dc_lum_code_reversed[12] = {
+ 0x1, 0x0, 0x2, 0x5, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF
+};
+static const uint16_t mpeg12_vlc_dc_chroma_code_reversed[12] = {
+ 0x0, 0x2, 0x1, 0x3, 0x7, 0xF, 0x1F, 0x3F, 0x7F, 0xFF, 0x1FF, 0x3FF
+};
/* simple include everything table for dc, first byte is bits
* number next 3 are code */
@@ -48,30 +53,8 @@ static uint32_t speedhq_chr_dc_uni[512];
static uint8_t uni_speedhq_ac_vlc_len[64 * 64 * 2];
-static uint32_t reverse(uint32_t num, int bits)
-{
- return bitswap_32(num) >> (32 - bits);
-}
-
-static void reverse_code(const uint16_t *code, const uint8_t *bits,
- uint16_t *reversed_code, int num_entries)
-{
- for (int i = 0; i < num_entries; i++)
- reversed_code[i] = reverse(code[i], bits[i]);
-}
-
static av_cold void speedhq_init_static_data(void)
{
- /* Exactly the same as MPEG-2, except little-endian. */
- reverse_code(ff_mpeg12_vlc_dc_lum_code,
- ff_mpeg12_vlc_dc_lum_bits,
- mpeg12_vlc_dc_lum_code_reversed,
- 12);
- reverse_code(ff_mpeg12_vlc_dc_chroma_code,
- ff_mpeg12_vlc_dc_chroma_bits,
- mpeg12_vlc_dc_chroma_code_reversed,
- 12);
-
ff_rl_init(&ff_rl_speedhq, speedhq_static_rl_table_store);
/* build unified dc encoding tables */