[gegl] bin: make use of display color management configurable



commit 2990cf6699e3cfedc16aa0153f9a8a2925ff3406
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Jan 12 00:47:10 2019 +0100

    bin: make use of display color management configurable

 bin/Makefile.am |  2 +-
 bin/mrg-gegl.c  | 86 +++++++++++++++++++++++++++++++--------------------------
 bin/mrg-gegl.h  | 29 +++++++++++++++++++
 bin/ui.c        | 29 ++++++-------------
 4 files changed, 86 insertions(+), 60 deletions(-)
---
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 4179c0237..cbe075803 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -51,7 +51,7 @@ argvs-commands.inc: gegl.c ui.c argvs.c Makefile
 
 if HAVE_MRG
 if HAVE_GEXIV2
-gegl_SOURCES += ui.c mrg-gegl.c
+gegl_SOURCES += ui.c mrg-gegl.c mrg-gegl.h
 AM_CFLAGS += $(SDL_CFLAGS)
 AM_LDFLAGS += $(SDL_LIBS)
 endif
diff --git a/bin/mrg-gegl.c b/bin/mrg-gegl.c
index f70d8dcdd..b83e03aa2 100644
--- a/bin/mrg-gegl.c
+++ b/bin/mrg-gegl.c
@@ -42,26 +42,11 @@
 #include <gegl-paramspecs.h>
 #include <SDL.h>
 #include <gegl-audio-fragment.h>
+#include "mrg-gegl.h"
 
 static unsigned char *copy_buf = NULL;
 static int copy_buf_len = 0;
 
-void mrg_gegl_buffer_blit (Mrg *mrg,
-                           float x0, float y0,
-                           float width, float height,
-                           GeglBuffer *buffer,
-                           float u, float v,
-                           float scale,
-                           float preview_multiplier);
-
-
-void mrg_gegl_blit (Mrg *mrg,
-                    float x0, float y0,
-                    float width, float height,
-                    GeglNode *node,
-                    float u, float v,
-                    float scale,
-                    float preview_multiplier);
 
 static float cached_x0 = 0;
 static float cached_y0 = 0;
@@ -85,7 +70,8 @@ void mrg_gegl_buffer_blit (Mrg *mrg,
                            GeglBuffer *buffer,
                            float u, float v,
                            float scale,
-                           float preview_multiplier)
+                           float preview_multiplier,
+                           int   color_manage_display)
 {
   float fake_factor = preview_multiplier;
   GeglRectangle bounds;
@@ -151,21 +137,30 @@ void mrg_gegl_buffer_blit (Mrg *mrg,
     copy_buf = malloc (copy_buf_len);
   }
   {
-    static int foo = 0;
     unsigned char *buf = copy_buf;
     GeglRectangle roi = {u, v, width, height};
-    static const Babl *fmt = NULL;
+    const Babl *fmt = NULL;
+    static const Babl *fmt_icc = NULL;
+    static const Babl *fmt_srgb = NULL;
 
-foo++;
-    if (!fmt)
+    if (color_manage_display)
+    {
+      if (!fmt_icc)
+      {
+        int icc_length = 0;
+        unsigned const char *icc_data = mrg_get_profile (mrg, &icc_length);
+        const Babl *space = NULL;
+        if (icc_data)
+          space = babl_space_from_icc ((char*)icc_data, icc_length, BABL_ICC_INTENT_RELATIVE_COLORIMETRIC, 
NULL);
+        fmt_icc = babl_format_with_space ("cairo-RGB24", space);
+      }
+      fmt = fmt_icc;
+    }
+    else
     {
-      int icc_length = 0;
-      unsigned const char *icc_data = mrg_get_profile (mrg, &icc_length);
-      const Babl *space = NULL;
-      if (icc_data)
-         space = babl_space_from_icc ((char*)icc_data, icc_length, BABL_ICC_INTENT_RELATIVE_COLORIMETRIC, 
NULL);
-      fmt = babl_format_with_space ("cairo-RGB24", space);
-    //  fmt = babl_format_with_space ("cairo-RGB24", NULL);
+      if (!fmt_srgb)
+        fmt_srgb = babl_format_with_space ("cairo-RGB24", NULL);
+      fmt = fmt_srgb;
     }
     gegl_buffer_get (buffer, &roi, scale / fake_factor, fmt, buf, width * 4,
          GEGL_ABYSS_NONE);
@@ -206,7 +201,8 @@ void mrg_gegl_blit (Mrg *mrg,
                     GeglNode *node,
                     float u, float v,
                     float scale,
-                    float preview_multiplier)
+                    float preview_multiplier,
+                    int color_manage_display)
 {
   float fake_factor = preview_multiplier;
   GeglRectangle bounds;
@@ -243,21 +239,33 @@ void mrg_gegl_blit (Mrg *mrg,
     copy_buf = malloc (copy_buf_len);
   }
   {
-    static int foo = 0;
     unsigned char *buf = copy_buf;
     GeglRectangle roi = {u, v, width, height};
-    static const Babl *fmt = NULL;
+    const Babl *fmt = NULL;
+    static const Babl *fmt_icc = NULL;
+    static const Babl *fmt_srgb = NULL;
 
-foo++;
-    if (!fmt)
+    if (color_manage_display)
+    {
+      if (!fmt_icc)
+      {
+        int icc_length = 0;
+        unsigned const char *icc_data = mrg_get_profile (mrg, &icc_length);
+        const Babl *space = NULL;
+        if (icc_data)
+          space = babl_space_from_icc ((char*)icc_data, icc_length, BABL_ICC_INTENT_RELATIVE_COLORIMETRIC, 
NULL);
+        fmt_icc = babl_format_with_space ("cairo-RGB24", space);
+      }
+      fmt = fmt_icc;
+    }
+    else
     {
-      int icc_length = 0;
-      unsigned const char *icc_data = mrg_get_profile (mrg, &icc_length);
-      const Babl *space = NULL;
-      if (icc_data)
-         space = babl_space_from_icc ((char*)icc_data, icc_length, BABL_ICC_INTENT_RELATIVE_COLORIMETRIC, 
NULL);
-      fmt = babl_format_with_space ("cairo-RGB24", space);
+      if (!fmt_srgb)
+        fmt_srgb = babl_format_with_space ("cairo-RGB24", NULL);
+      fmt = fmt_srgb;
     }
+
+
     gegl_node_blit (node, scale / fake_factor, &roi, fmt, buf, width * 4,
          GEGL_BLIT_DEFAULT);
   surface = cairo_image_surface_create_for_data (buf, CAIRO_FORMAT_RGB24, width, height, width * 4);
diff --git a/bin/mrg-gegl.h b/bin/mrg-gegl.h
new file mode 100644
index 000000000..f335d45dd
--- /dev/null
+++ b/bin/mrg-gegl.h
@@ -0,0 +1,29 @@
+#ifndef MRG_GEGL_H
+#define MRG_GEGL_H
+
+#include <mrg/mrg.h>
+#include <gegl/gegl.h>
+
+void mrg_gegl_buffer_blit (Mrg *mrg,
+                           float x0, float y0,
+                           float width, float height,
+                           GeglBuffer *buffer,
+                           float u, float v,
+                           float scale,
+                           float preview_multiplier,
+                           int   color_manage);
+
+
+void mrg_gegl_blit (Mrg *mrg,
+                    float x0, float y0,
+                    float width, float height,
+                    GeglNode *node,
+                    float u, float v,
+                    float scale,
+                    float preview_multiplier,
+                    int   color_manage);
+
+
+void mrg_gegl_dirty (void);
+
+#endif
diff --git a/bin/ui.c b/bin/ui.c
index 13f4a2659..47b283f91 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -68,27 +68,12 @@ void mrg_gegl_dirty (void);
 #include <gegl-paramspecs.h>
 #include <gegl-operation.h>
 #include <gegl-audio-fragment.h>
+#include "mrg-gegl.h"
 #include "argvs.h"
 
 /* set this to 1 to print the active gegl chain
  */
 
-void mrg_gegl_blit (Mrg *mrg,
-                    float x0, float y0,
-                    float width, float height,
-                    GeglNode *node,
-                    float u, float v,
-                    float scale,
-                    float preview_multiplier);
-
-void mrg_gegl_buffer_blit (Mrg *mrg,
-                           float x0, float y0,
-                           float width, float height,
-                           GeglBuffer *buffer,
-                           float u, float v,
-                           float scale,
-                           float preview_multiplier);
-
 static GeglNode *gegl_node_get_consumer_no (GeglNode *node,
                                             const char *output_pad,
                                             const char **consumer_pad,
@@ -217,6 +202,7 @@ struct _State {
   GeglNode      *decode_load;
   GeglNode      *decode_store;
   int            playing;
+  int            color_manage_display;
 
   int            is_video;
   int            prev_frame_played;
@@ -260,6 +246,7 @@ Setting settings[]=
   INT_PROP(show_controls, "show image viewer controls (maybe merge with show-graph and give better name)"),
   INT_PROP(slide_enabled, "slide show going"),
   INT_PROP_RO(is_video, ""),
+  INT_PROP(color_manage_display, "perform ICC color management and convert output to display ICC profile 
instead of passing out sRGB, passing out sRGB is faster."),
   INT_PROP(playing, "wheter we are playing or not set to 0 for pause 1 for playing"),
 
   INT_PROP(frame_no, "current frame number in video/animation")
@@ -2149,8 +2136,8 @@ static void iterate_frame (State *o)
          mrg_pcm_queue (mrg, (void*)&temp_buf[0], sample_count);
          }
 
-         while (mrg_pcm_get_queued (mrg) > sample_count)
-            g_usleep (50);
+         while (mrg_pcm_get_queued (mrg) > sample_count * 3)
+            g_usleep (10);
 
          o->prev_frame_played = o->frame_no;
          deferred_redraw (mrg, NULL);
@@ -2233,7 +2220,8 @@ static void gegl_ui (Mrg *mrg, void *data)
                       o->sink,
                       o->u, o->v,
                       o->scale,
-                      o->render_quality);
+                      o->render_quality,
+                      o->color_manage_display);
      break;
      case GEGL_RENDERER_THREAD:
      case GEGL_RENDERER_IDLE:
@@ -2246,7 +2234,8 @@ static void gegl_ui (Mrg *mrg, void *data)
                                buffer,
                                o->u, o->v,
                                o->scale,
-                               o->render_quality);
+                               o->render_quality,
+                               o->color_manage_display);
          g_object_unref (buffer);
        }
        break;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]