[FFmpeg-cvslog] avcodec/proresenc_kostya: remove one LUT indirection for run/level to codebook mapping

Clément Bœsch git at videolan.org
Wed Jan 10 15:21:52 EET 2024


ffmpeg | branch: master | Clément Bœsch <u at pkh.me> | Mon Dec 11 01:14:06 2023 +0100| [c35733006ac55702b306bee529cf0d38a477bbfc] | committer: Clément Bœsch

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

This is following the same logic as proresenc_anatoliy.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=c35733006ac55702b306bee529cf0d38a477bbfc
---

 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 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++;



More information about the ffmpeg-cvslog mailing list