[FFmpeg-cvslog] avcodec/proresenc_kostya: save a few operations in DC encoding

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


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

avcodec/proresenc_kostya: save a few operations in DC encoding

This matches the logic from proresenc_anatoliy.

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

 libavcodec/proresenc_kostya.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index cc53d142bc..cf49614c84 100644
--- a/libavcodec/proresenc_kostya.c
+++ b/libavcodec/proresenc_kostya.c
@@ -135,13 +135,6 @@ static const uint8_t prores_quant_matrices[][64] = {
     },
 };
 
-static const uint8_t prores_dc_codebook[4] = {
-    0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0
-    0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0
-    0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1
-    0x70  // rice_order = 3, exp_golomb_order = 4, switch_bits = 0
-};
-
 #define NUM_MB_LIMITS 4
 static const int prores_mb_limits[NUM_MB_LIMITS] = {
     1620, // up to 720x576
@@ -416,7 +409,7 @@ static void encode_dcs(PutBitContext *pb, int16_t *blocks,
                        int blocks_per_slice, int scale)
 {
     int i;
-    int codebook = 3, code, dc, prev_dc, delta, sign, new_sign;
+    int codebook = 5, code, dc, prev_dc, delta, sign, new_sign;
 
     prev_dc = (blocks[0] - 0x4000) / scale;
     encode_vlc_codeword(pb, FIRST_DC_CB, MAKE_CODE(prev_dc));
@@ -429,9 +422,8 @@ static void encode_dcs(PutBitContext *pb, int16_t *blocks,
         new_sign = GET_SIGN(delta);
         delta    = (delta ^ sign) - sign;
         code     = MAKE_CODE(delta);
-        encode_vlc_codeword(pb, prores_dc_codebook[codebook], code);
-        codebook = (code + (code & 1)) >> 1;
-        codebook = FFMIN(codebook, 3);
+        encode_vlc_codeword(pb, ff_prores_dc_codebook[codebook], code);
+        codebook = FFMIN(code, 6);
         sign     = new_sign;
         prev_dc  = dc;
     }
@@ -649,7 +641,7 @@ static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice,
                         int scale)
 {
     int i;
-    int codebook = 3, code, dc, prev_dc, delta, sign, new_sign;
+    int codebook = 5, code, dc, prev_dc, delta, sign, new_sign;
     int bits;
 
     prev_dc  = (blocks[0] - 0x4000) / scale;
@@ -665,9 +657,8 @@ static int estimate_dcs(int *error, int16_t *blocks, int blocks_per_slice,
         new_sign = GET_SIGN(delta);
         delta    = (delta ^ sign) - sign;
         code     = MAKE_CODE(delta);
-        bits    += estimate_vlc(prores_dc_codebook[codebook], code);
-        codebook = (code + (code & 1)) >> 1;
-        codebook = FFMIN(codebook, 3);
+        bits    += estimate_vlc(ff_prores_dc_codebook[codebook], code);
+        codebook = FFMIN(code, 6);
         sign     = new_sign;
         prev_dc  = dc;
     }



More information about the ffmpeg-cvslog mailing list