[vlc-commits] video_output: opengl: add BT.2020 decoding matrices

Niklas Haas git at videolan.org
Fri Nov 3 11:11:48 CET 2017


vlc | branch: master | Niklas Haas <git at haasn.xyz> | Wed Nov  1 17:09:22 2017 +0100| [a4ef9238413a07976903b539041b8b1ed1d33a8f] | committer: Thomas Guillem

video_output: opengl: add BT.2020 decoding matrices

Generated the matrices using the following small program:

    #include <stdio.h>
    #include <libplacebo/colorspace.h>

    void main()
    {
        struct pl_color_repr repr = {
            .sys    = PL_COLOR_SYSTEM_BT_2020_NC,
            .levels = PL_COLOR_LEVELS_TV,
        };

        struct pl_transform3x3 tf = pl_color_repr_decode(&repr, NULL);
        for (int i = 0; i < 3; i++) {
            printf("% .15f, % .15f, % .15f, % .15f ,\n",
                  tf.mat.m[i][0], tf.mat.m[i][1], tf.mat.m[i][2], tf.c[i]);
        }
    }

I've also verified that the BT.709 and BT.601 matrices are identical
within an error margin of several orders of magnitude. (Probably due to
floating point inaccuracy)

P.s. VLC doesn't seem to distinguish between BT.2020-NC and BT.2020-CL,
which I believe is a bug. But anyway, we can only easily handle
BT.2020-NC anyway, so hard-code it as that. (BT.2020-CL support would
require some more libplacebo integration)

Signed-off-by: Thomas Guillem <thomas at gllm.fr>

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

 modules/video_output/opengl/fragment_shaders.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/modules/video_output/opengl/fragment_shaders.c b/modules/video_output/opengl/fragment_shaders.c
index 9516dbd767..950bb9090b 100644
--- a/modules/video_output/opengl/fragment_shaders.c
+++ b/modules/video_output/opengl/fragment_shaders.c
@@ -231,6 +231,11 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
         1.164383561643836, -0.21324861427373,  -0.532909328559444,  0.301482665475862 ,
         1.164383561643836,  2.112401785714286,  0.0000,            -1.133402217873451 ,
     };
+    static const float matrix_bt2020_tv2full[12] = {
+        1.164383530616760,  0.0000,             1.678674221038818, -0.915687978267670 ,
+        1.164383530616760, -0.187326118350029, -0.650424420833588,  0.347458571195602 ,
+        1.164383530616760,  2.141772270202637,  0.0000,            -1.148145079612732 ,
+    };
 
     const float *matrix;
     switch (yuv_space)
@@ -238,6 +243,9 @@ tc_yuv_base_init(opengl_tex_converter_t *tc, GLenum tex_target,
         case COLOR_SPACE_BT601:
             matrix = matrix_bt601_tv2full;
             break;
+        case COLOR_SPACE_BT2020:
+            matrix = matrix_bt2020_tv2full;
+            break;
         default:
             matrix = matrix_bt709_tv2full;
     };



More information about the vlc-commits mailing list