[FFmpeg-devel] [PATCH 05/35] avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping
Stefano Sabatini
stefasab at gmail.com
Tue Dec 12 10:16:00 EET 2023
On date Monday 2023-12-11 02:35:06 +0100, Clément Bœsch wrote:
> This is following the same logic as proresenc_anatoliy.
> ---
> libavcodec/proresenc_kostya.c | 47 +++++++++++------------------------
> 1 file changed, 14 insertions(+), 33 deletions(-)
>
> diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
> index 6e1d5a0cef..f883ab550b 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_lev_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++;
> @@ -699,13 +680,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++) {
> @@ -714,12 +695,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_lev_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++;
LGTM.
More information about the ffmpeg-devel
mailing list