1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00

avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping

This is following the same logic as proresenc_anatoliy.
This commit is contained in:
Clément Bœsch 2023-12-11 01:14:06 +01:00
parent 3ba52f18e4
commit c35733006a

View File

@ -142,25 +142,6 @@ static const uint8_t prores_dc_codebook[4] = {
0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 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 #define NUM_MB_LIMITS 4
static const int prores_mb_limits[NUM_MB_LIMITS] = { static const int prores_mb_limits[NUM_MB_LIMITS] = {
1620, // up to 720x576 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) const uint8_t *scan, const int16_t *qmat)
{ {
int idx, i; 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 max_coeffs, abs_level;
max_coeffs = blocks_per_slice << 6; max_coeffs = blocks_per_slice << 6;
run_cb = prores_run_to_cb_index[4];
lev_cb = prores_lev_to_cb_index[2];
run = 0; run = 0;
for (i = 1; i < 64; i++) { 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]]; level = blocks[idx] / qmat[scan[i]];
if (level) { if (level) {
abs_level = FFABS(level); abs_level = FFABS(level);
encode_vlc_codeword(pb, prores_ac_codebook[run_cb], run); encode_vlc_codeword(pb, ff_prores_run_to_cb[prev_run], run);
encode_vlc_codeword(pb, prores_ac_codebook[lev_cb], encode_vlc_codeword(pb, ff_prores_level_to_cb[prev_level],
abs_level - 1); abs_level - 1);
put_sbits(pb, 1, GET_SIGN(level)); put_sbits(pb, 1, GET_SIGN(level));
run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; prev_run = FFMIN(run, 15);
lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; prev_level = FFMIN(abs_level, 9);
run = 0; run = 0;
} else { } else {
run++; 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) const uint8_t *scan, const int16_t *qmat)
{ {
int idx, i; 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 max_coeffs, abs_level;
int bits = 0; int bits = 0;
max_coeffs = blocks_per_slice << 6; max_coeffs = blocks_per_slice << 6;
run_cb = prores_run_to_cb_index[4];
lev_cb = prores_lev_to_cb_index[2];
run = 0; run = 0;
for (i = 1; i < 64; i++) { 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]]; *error += FFABS(blocks[idx]) % qmat[scan[i]];
if (level) { if (level) {
abs_level = FFABS(level); abs_level = FFABS(level);
bits += estimate_vlc(prores_ac_codebook[run_cb], run); bits += estimate_vlc(ff_prores_run_to_cb[prev_run], run);
bits += estimate_vlc(prores_ac_codebook[lev_cb], bits += estimate_vlc(ff_prores_level_to_cb[prev_level],
abs_level - 1) + 1; abs_level - 1) + 1;
run_cb = prores_run_to_cb_index[FFMIN(run, 15)]; prev_run = FFMIN(run, 15);
lev_cb = prores_lev_to_cb_index[FFMIN(abs_level, 9)]; prev_level = FFMIN(abs_level, 9);
run = 0; run = 0;
} else { } else {
run++; run++;