[FFmpeg-cvslog] avcodec/cfhd: use LUT for 9 and 18 codebook decompanding

Paul B Mahol git at videolan.org
Mon Aug 3 23:28:54 EEST 2020


ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Mon Aug  3 09:33:36 2020 +0200| [05e58ce4e29ea47b2e06888c64055aa2f8d3e76c] | committer: Paul B Mahol

avcodec/cfhd: use LUT for 9 and 18 codebook decompanding

Also fix codebook 9 decompanding, fixing artifact with codebook 9
samples. Reused Gagandeep Singh patch.

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

 libavcodec/cfhd.c | 35 +++++++++++++++++++++++++----------
 libavcodec/cfhd.h |  2 ++
 2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/libavcodec/cfhd.c b/libavcodec/cfhd.c
index 60bba9ff81..8cd475cba4 100644
--- a/libavcodec/cfhd.c
+++ b/libavcodec/cfhd.c
@@ -46,6 +46,27 @@ static av_cold int cfhd_init(AVCodecContext *avctx)
 
     s->avctx                   = avctx;
 
+    for (int i = 0; i < 64; i++) {
+        int val = i;
+
+        if (val >= 40) {
+            if (val >= 54) {
+                val -= 54;
+                val <<= 2;
+                val += 54;
+            }
+
+            val -= 40;
+            val <<= 2;
+            val += 40;
+        }
+
+        s->lut[0][i] = val;
+    }
+
+    for (int i = 0; i < 256; i++)
+        s->lut[1][i] = i + ((768 * i * i * i) / (256 * 256 * 256));
+
     return ff_cfhd_init_vlcs(s);
 }
 
@@ -83,16 +104,10 @@ static void init_frame_defaults(CFHDContext *s)
     init_peak_table_defaults(s);
 }
 
-/* TODO: merge with VLC tables or use LUT */
-static inline int dequant_and_decompand(int level, int quantisation, int codebook)
+static inline int dequant_and_decompand(CFHDContext *s, int level, int quantisation, int codebook)
 {
     if (codebook == 0 || codebook == 1) {
-        int64_t abslevel = abs(level);
-        if (abslevel < 256)
-            return (abslevel + ((768 * abslevel * abslevel * abslevel) / (256 * 256 * 256))) *
-               FFSIGN(level) * quantisation;
-        else
-            return level * quantisation;
+        return s->lut[codebook][abs(level)] * FFSIGN(level) * quantisation;
     } else
         return level * quantisation;
 }
@@ -708,7 +723,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
                         if (count > expected)
                             break;
 
-                        coeff = dequant_and_decompand(level, s->quantisation, 0);
+                        coeff = dequant_and_decompand(s, level, s->quantisation, 0);
                         for (i = 0; i < run; i++)
                             *coeff_data++ = coeff;
                     }
@@ -727,7 +742,7 @@ static int cfhd_decode(AVCodecContext *avctx, void *data, int *got_frame,
                         if (count > expected)
                             break;
 
-                        coeff = dequant_and_decompand(level, s->quantisation, s->codebook);
+                        coeff = dequant_and_decompand(s, level, s->quantisation, s->codebook);
                         for (i = 0; i < run; i++)
                             *coeff_data++ = coeff;
                     }
diff --git a/libavcodec/cfhd.h b/libavcodec/cfhd.h
index 0e3155be23..7f35ac45f3 100644
--- a/libavcodec/cfhd.h
+++ b/libavcodec/cfhd.h
@@ -136,6 +136,8 @@ typedef struct CFHDContext {
     CFHD_RL_VLC_ELEM table_18_rl_vlc[4572];
     VLC vlc_18;
 
+    int lut[2][256];
+
     GetBitContext gb;
 
     int coded_width;



More information about the ffmpeg-cvslog mailing list