[FFmpeg-devel] avfilter/vf_libvmaf: fix filtering of >8 bit data

Submitted by Paul B Mahol on Oct. 12, 2019, 7:48 p.m.

Details

Message ID 20191012194851.18363-1-onemda@gmail.com
State New
Headers show

Commit Message

Paul B Mahol Oct. 12, 2019, 7:48 p.m.
This is what reference does.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavfilter/vf_libvmaf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/libavfilter/vf_libvmaf.c b/libavfilter/vf_libvmaf.c
index 249e50c720..e071df77c5 100644
--- a/libavfilter/vf_libvmaf.c
+++ b/libavfilter/vf_libvmaf.c
@@ -110,6 +110,7 @@  FRAMESYNC_DEFINE_CLASS(libvmaf, LIBVMAFContext, fs);
         const type *main_ptr = (const type *) s->gmain->data[0];                \
         \
         float *ptr = ref_data;                                                  \
+        float factor = 1.f / ((1 << bits) - 8);                                 \
         \
         int h = s->height;                                                      \
         int w = s->width;                                                       \
@@ -118,7 +119,7 @@  FRAMESYNC_DEFINE_CLASS(libvmaf, LIBVMAFContext, fs);
         \
         for (i = 0; i < h; i++) {                                               \
             for ( j = 0; j < w; j++) {                                          \
-                ptr[j] = (float)ref_ptr[j];                                     \
+                ptr[j] = ref_ptr[j] * factor;                                   \
             }                                                                   \
             ref_ptr += ref_stride / sizeof(*ref_ptr);                           \
             ptr += stride / sizeof(*ptr);                                       \
@@ -128,7 +129,7 @@  FRAMESYNC_DEFINE_CLASS(libvmaf, LIBVMAFContext, fs);
         \
         for (i = 0; i < h; i++) {                                               \
             for (j = 0; j < w; j++) {                                           \
-                ptr[j] = (float)main_ptr[j];                                    \
+                ptr[j] = main_ptr[j] * factor;                                  \
             }                                                                   \
             main_ptr += main_stride / sizeof(*main_ptr);                        \
             ptr += stride / sizeof(*ptr);                                       \