summaryrefslogtreecommitdiff
path: root/libavcodec/proresenc_kostya.c
diff options
context:
space:
mode:
authorClément Bœsch <u@pkh.me>2023-12-11 01:14:06 +0100
committerClément Bœsch <u@pkh.me>2024-01-10 14:08:00 +0100
commitc35733006ac55702b306bee529cf0d38a477bbfc (patch)
tree8636a54619070b58a01ad1ef0b7664229bac06ad /libavcodec/proresenc_kostya.c
parent3ba52f18e4ec7755cf5866a90bb944bcba4d824b (diff)
avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping
This is following the same logic as proresenc_anatoliy.
Diffstat (limited to 'libavcodec/proresenc_kostya.c')
-rw-r--r--libavcodec/proresenc_kostya.c47
1 files changed, 14 insertions, 33 deletions
diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index 2d5dee05e6..cc53d142bc 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = {
0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0
};
-static const uint8_t prores_ac_codebook[7] = {
- 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0
- 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0
- 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0
- 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1
- 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1
- 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2
- 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2
-};
-
-/**
- * Lookup tables for adaptive switching between codebooks
- * according with previous run/level value.
- */
-static const uint8_t prores_run_to_cb_index[16] =
- { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 };
-
-static const uint8_t prores_lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 };
-
#define NUM_MB_LIMITS 4
static const int prores_mb_limits[NUM_MB_LIMITS] = {
1620, // up to 720x576
@@ -461,12 +442,12 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks,
const uint8_t *scan, const int16_t *qmat)
{
int idx, i;
- int run, level, run_cb, lev_cb;
+ int prev_run = 4;
+ int prev_level = 2;
+ int run, level;
int max_coeffs, abs_level;
max_coeffs = blocks_per_slice << 6;
- run_cb = prores_run_to_cb_index[4];
- lev_cb = prores_lev_to_cb_index[2];
run = 0;
for (i = 1; i < 64; i++) {
@@ -474,13 +455,13 @@ static void encode_acs(PutBitContext *pb, int16_t *blocks,
level = blocks[idx] / qmat[scan[i]];
if (level) {
abs_level = FFABS(level);
- encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run);
- encode_vlc_codeword(pb, prores_ac_codebook[lev_cb],
+ encode_vlc_codeword(pb, ff_prores_run_to_cb[prev_run], run);
+ encode_vlc_codeword(pb, ff_prores_level_to_cb[prev_level],
abs_level - 1);
put_sbits(pb, 1, GET_SIGN(level));
- run_cb = prores_run_to_cb_index[FFMIN(run, 15)];
- lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)];
+ prev_run = FFMIN(run, 15);
+ prev_level = FFMIN(abs_level, 9);
run = 0;
} else {
run++;
@@ -698,13 +679,13 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice,
const uint8_t *scan, const int16_t *qmat)
{
int idx, i;
- int run, level, run_cb, lev_cb;
+ int prev_run = 4;
+ int prev_level = 2;
+ int run, level;
int max_coeffs, abs_level;
int bits = 0;
max_coeffs = blocks_per_slice << 6;
- run_cb = prores_run_to_cb_index[4];
- lev_cb = prores_lev_to_cb_index[2];
run = 0;
for (i = 1; i < 64; i++) {
@@ -713,12 +694,12 @@ static int estimate_acs(int *error, int16_t *blocks, int blocks_per_slice,
*error += FFABS(blocks[idx]) % qmat[scan[i]];
if (level) {
abs_level = FFABS(level);
- bits += estimate_vlc(prores_ac_codebook[run_cb], run);
- bits += estimate_vlc(prores_ac_codebook[lev_cb],
+ bits += estimate_vlc(ff_prores_run_to_cb[prev_run], run);
+ bits += estimate_vlc(ff_prores_level_to_cb[prev_level],
abs_level - 1) + 1;
- run_cb = prores_run_to_cb_index[FFMIN(run, 15)];
- lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)];
+ prev_run = FFMIN(run, 15);
+ prev_level = FFMIN(abs_level, 9);
run = 0;
} else {
run++;