[vlc-commits] [Git][videolan/vlc][master] opengl: support .cube LUTs

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Oct 21 13:42:01 UTC 2022



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
934e23b6 by Niklas Haas at 2022-10-21T13:26:46+00:00
opengl: support .cube LUTs

To keep the API and integration as simple as possible, only support
"conversion" style LUTs, i.e. LUTs which are intended to map from the
source color space to the display color space in one step.

This represents the most common type of LUT in practice, and in
particular, the sample files that have been requested by users.

- - - - -


2 changed files:

- modules/video_output/opengl/sampler.c
- modules/video_output/opengl/vout_helper.h


Changes:

=====================================
modules/video_output/opengl/sampler.c
=====================================
@@ -27,6 +27,7 @@
 #include <vlc_common.h>
 #include <vlc_memstream.h>
 #include <vlc_opengl.h>
+#include <vlc_fs.h>
 
 #ifdef HAVE_LIBPLACEBO_GL
 #include <libplacebo/opengl.h>
@@ -63,7 +64,7 @@ struct vlc_gl_sampler_priv {
     pl_log pl_log;
     pl_opengl pl_opengl;
     pl_shader pl_sh;
-    pl_shader_obj dither_state, tone_map_state;
+    pl_shader_obj dither_state, tone_map_state, lut_state;
     const struct pl_shader_res *pl_sh_res;
 #endif
 
@@ -650,6 +651,45 @@ sampler_planes_init(struct vlc_gl_sampler *sampler)
     return VLC_SUCCESS;
 }
 
+#ifdef HAVE_LIBPLACEBO_GL
+static struct pl_custom_lut *LoadCustomLUT(struct vlc_gl_sampler *sampler,
+                                           const char *filepath)
+{
+    struct vlc_gl_sampler_priv *priv = PRIV(sampler);
+    if (!filepath || !filepath[0])
+        return NULL;
+
+    FILE *fs = vlc_fopen(filepath, "rb");
+    struct pl_custom_lut *lut = NULL;
+    char *lut_file = NULL;
+    if (!fs)
+        goto error;
+    int ret = fseek(fs, 0, SEEK_END);
+    if (ret == -1)
+        goto error;
+    long length = ftell(fs);
+    if (length < 0)
+        goto error;
+    rewind(fs);
+
+    lut_file = vlc_alloc(length, sizeof(*lut_file));
+    if (!lut_file)
+        goto error;
+    ret = fread(lut_file, length, 1, fs);
+    if (ret != 1)
+        goto error;
+
+    lut = pl_lut_parse_cube(priv->pl_log, lut_file, length);
+    // fall through
+
+error:
+    if (fs)
+        fclose(fs);
+    free(lut_file);
+    return lut;
+}
+#endif
+
 static int
 opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, bool expose_planes)
 {
@@ -709,13 +749,27 @@ opengl_fragment_shader_init(struct vlc_gl_sampler *sampler, bool expose_planes)
         struct pl_color_map_params color_params;
         vlc_placebo_ColorMapParams(VLC_OBJECT(priv->gl), "gl", &color_params);
 
+        struct pl_color_space src_space = vlc_placebo_ColorSpace(fmt);
         struct pl_color_space dst_space = pl_color_space_unknown;
         dst_space.primaries = var_InheritInteger(priv->gl, "target-prim");
         dst_space.transfer = var_InheritInteger(priv->gl, "target-trc");
 
-        pl_shader_color_map(sh, &color_params,
-                vlc_placebo_ColorSpace(fmt),
-                dst_space, &priv->tone_map_state, false);
+        char *lut_file = var_InheritString(priv->gl, "gl-lut-file");
+        struct pl_custom_lut *lut = LoadCustomLUT(sampler, lut_file);
+        if (lut) {
+            // Transform from the video input to the LUT input color space,
+            // defaulting to a no-op if LUT input color space info is unknown
+            dst_space = lut->color_in;
+            pl_color_space_merge(&dst_space, &src_space);
+        }
+
+        pl_shader_color_map(sh, &color_params, src_space, dst_space,
+                            &priv->tone_map_state, false);
+
+        if (lut) {
+            pl_shader_custom_lut(sh, lut, &priv->lut_state);
+            pl_lut_free(&lut);
+        }
 
         int method = var_InheritInteger(priv->gl, "dither-algo");
         if (method >= 0) {
@@ -938,6 +992,7 @@ vlc_gl_sampler_Delete(struct vlc_gl_sampler *sampler)
     FREENULL(priv->uloc.pl_vars);
     FREENULL(priv->uloc.pl_descs);
     pl_shader_free(&priv->pl_sh);
+    pl_shader_obj_destroy(&priv->lut_state);
     pl_shader_obj_destroy(&priv->tone_map_state);
     pl_shader_obj_destroy(&priv->dither_state);
     pl_opengl_destroy(&priv->pl_opengl);


=====================================
modules/video_output/opengl/vout_helper.h
=====================================
@@ -46,7 +46,8 @@
     add_integer("dither-algo", -1, DITHER_TEXT, DITHER_LONGTEXT) \
             change_integer_list(dither_values, dither_text) \
     add_integer_with_range("dither-depth", 0, 0, 16, \
-            DITHER_DEPTH_TEXT, DITHER_DEPTH_LONGTEXT)
+            DITHER_DEPTH_TEXT, DITHER_DEPTH_LONGTEXT) \
+    add_loadfile("gl-lut-file", NULL, LUT_FILE_TEXT, LUT_FILE_LONGTEXT)
 #else
 #define add_glopts_placebo()
 #endif



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/934e23b6101bbeceed8ee23a7fb751df2e1e3533

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/934e23b6101bbeceed8ee23a7fb751df2e1e3533
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list