diff mbox series

[FFmpeg-devel,08/35] avcodec/proresenc_kostya: save a few operations in DC encoding

Message ID 20231211014429.1841681-9-u@pkh.me
State Accepted
Commit 631fa19ee0d6fbbe8e82516345090f433cea6532
Headers show
Series [FFmpeg-devel,01/35] avcodec/proresenc_kostya: remove an unnecessary parenthesis level in MAKE_CODE() macro | expand

Commit Message

Clément Bœsch Dec. 11, 2023, 1:35 a.m. UTC
This matches the logic from proresenc_anatoliy.
---
 libavcodec/proresenc_kostya.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)

Comments

Stefano Sabatini Dec. 16, 2023, 4:54 p.m. UTC | #1
On date Monday 2023-12-11 02:35:09 +0100, Clément Bœsch wrote:
> This matches the logic from proresenc_anatoliy.
> ---
>  libavcodec/proresenc_kostya.c | 21 ++++++---------------
>  1 file changed, 6 insertions(+), 15 deletions(-)

LGTM.
diff mbox series

Patch

diff --git a/libavcodec/proresenc_kostya.c b/libavcodec/proresenc_kostya.c
index f883ab550b..2d45f9a685 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;
     }
@@ -650,7 +642,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;
@@ -666,9 +658,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;
     }