[gimp] app: add gimpdisplayshell-profile.[ch]



commit 326721814350d68559e54c1d81b57163915ae3a2
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 27 12:28:33 2015 +0200

    app: add gimpdisplayshell-profile.[ch]
    
    which will take over display color management from the display
    filter module. This is WIP, the code is still unused.

 app/display/Makefile.am                |    2 +
 app/display/gimpdisplayshell-profile.c |  171 ++++++++++++++++++++++++++++++++
 app/display/gimpdisplayshell-profile.h |   32 ++++++
 app/display/gimpdisplayshell.c         |   35 ++++++-
 app/display/gimpdisplayshell.h         |   24 +++--
 5 files changed, 253 insertions(+), 11 deletions(-)
---
diff --git a/app/display/Makefile.am b/app/display/Makefile.am
index 6a42172..b181888 100644
--- a/app/display/Makefile.am
+++ b/app/display/Makefile.am
@@ -109,6 +109,8 @@ libappdisplay_a_sources = \
        gimpdisplayshell-icon.h                 \
        gimpdisplayshell-items.c                \
        gimpdisplayshell-items.h                \
+       gimpdisplayshell-profile.c              \
+       gimpdisplayshell-profile.h              \
        gimpdisplayshell-progress.c             \
        gimpdisplayshell-progress.h             \
        gimpdisplayshell-render.c               \
diff --git a/app/display/gimpdisplayshell-profile.c b/app/display/gimpdisplayshell-profile.c
new file mode 100644
index 0000000..c0fc41b
--- /dev/null
+++ b/app/display/gimpdisplayshell-profile.c
@@ -0,0 +1,171 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include <lcms2.h>
+
+#include <gegl.h>
+#include <gtk/gtk.h>
+
+#include "libgimpbase/gimpbase.h"
+#include "libgimpcolor/gimpcolor.h"
+#include "libgimpconfig/gimpconfig.h"
+#include "libgimpmath/gimpmath.h"
+#include "libgimpwidgets/gimpwidgets.h"
+
+#include "display-types.h"
+
+#include "config/gimpcoreconfig.h"
+
+#include "gegl/gimp-babl.h"
+
+#include "core/gimppickable.h"
+
+#include "gimpdisplay.h"
+#include "gimpdisplayshell.h"
+#include "gimpdisplayshell-profile.h"
+#include "gimpdisplayxfer.h"
+
+#include "gimp-intl.h"
+
+
+void
+gimp_display_shell_profile_dispose (GimpDisplayShell *shell)
+{
+  if (shell->profile_transform)
+    {
+      cmsDeleteTransform (shell->profile_transform);
+      shell->profile_transform   = NULL;
+      shell->profile_src_format  = NULL;
+      shell->profile_dest_format = NULL;
+    }
+
+  if (shell->profile_buffer)
+    {
+      g_object_unref (shell->profile_buffer);
+      shell->profile_buffer = NULL;
+      shell->profile_data   = NULL;
+      shell->profile_stride = 0;
+    }
+}
+
+void
+gimp_display_shell_profile_update (GimpDisplayShell *shell)
+{
+  GimpImage         *image;
+  GimpDisplayConfig *display_config;
+  GimpColorConfig   *config;
+  GimpColorManaged  *managed;
+  const Babl        *src_format;
+  const Babl        *dest_format;
+
+  gimp_display_shell_profile_dispose (shell);
+
+  image = gimp_display_get_image (shell->display);
+
+  g_printerr ("gimp_display_shell_profile_update\n");
+
+  if (! image)
+    return;
+
+  display_config = shell->display->config;
+  config         = GIMP_CORE_CONFIG (display_config)->color_management;
+  managed        = GIMP_COLOR_MANAGED (shell);
+
+  src_format = gimp_pickable_get_format (GIMP_PICKABLE (image));
+
+  if (shell->filter_stack && shell->filter_stack->filters)
+    dest_format = gimp_babl_format (GIMP_RGB,
+                                    gimp_babl_precision (GIMP_COMPONENT_TYPE_FLOAT,
+                                                         gimp_babl_format_get_linear (src_format)),
+                                    TRUE);
+  else
+    dest_format = gimp_babl_format (GIMP_RGB,
+                                    gimp_babl_precision (GIMP_COMPONENT_TYPE_FLOAT,
+                                                         gimp_babl_format_get_linear (src_format)),
+                                    TRUE);
+
+  g_printerr ("src_format: %s\n", babl_get_name (src_format));
+  g_printerr ("dest_format: %s\n", babl_get_name (dest_format));
+
+  shell->profile_transform =
+    gimp_widget_get_color_transform (gtk_widget_get_toplevel (GTK_WIDGET (shell)),
+                                     managed, config,
+                                     &src_format,
+                                     &dest_format);
+
+  if (shell->profile_transform)
+    {
+      gint w = GIMP_DISPLAY_RENDER_BUF_WIDTH  * GIMP_DISPLAY_RENDER_MAX_SCALE;
+      gint h = GIMP_DISPLAY_RENDER_BUF_HEIGHT * GIMP_DISPLAY_RENDER_MAX_SCALE;
+
+      shell->profile_src_format  = src_format;
+      shell->profile_dest_format = dest_format;
+
+      shell->profile_data =
+        gegl_malloc (w * h * babl_format_get_bytes_per_pixel (src_format));
+
+      shell->profile_stride =
+        w * babl_format_get_bytes_per_pixel (src_format);
+
+      shell->profile_buffer =
+        gegl_buffer_linear_new_from_data (shell->profile_data,
+                                          src_format,
+                                          GEGL_RECTANGLE (0, 0, w, h),
+                                          GEGL_AUTO_ROWSTRIDE,
+                                          (GDestroyNotify) gegl_free,
+                                          shell->profile_data);
+    }
+}
+
+void
+gimp_display_shell_profile_convert_buffer (GimpDisplayShell *shell,
+                                           GeglBuffer       *src_buffer,
+                                           GeglRectangle    *src_area,
+                                           GeglBuffer       *dest_buffer,
+                                           GeglRectangle    *dest_area)
+{
+  GeglBufferIterator *iter;
+  const Babl         *fish;
+
+  if (! shell->profile_transform)
+    return;
+
+  iter = gegl_buffer_iterator_new (src_buffer, src_area, 0,
+                                   shell->profile_src_format,
+                                   GEGL_ACCESS_READ, GEGL_ABYSS_NONE);
+
+  gegl_buffer_iterator_add (iter, dest_buffer, dest_area, 0,
+                            shell->profile_dest_format,
+                            GEGL_ACCESS_WRITE, GEGL_ABYSS_NONE);
+
+  fish = babl_fish (shell->profile_src_format,
+                    shell->profile_dest_format);
+
+  while (gegl_buffer_iterator_next (iter))
+    {
+      gpointer src_data  = iter->data[0];
+      gpointer dest_data = iter->data[1];
+
+      babl_process (fish, src_data, dest_data, iter->length);
+
+      cmsDoTransform (shell->profile_transform,
+                      src_data, dest_data,
+                      iter->length);
+    }
+}
diff --git a/app/display/gimpdisplayshell-profile.h b/app/display/gimpdisplayshell-profile.h
new file mode 100644
index 0000000..09f2ea9
--- /dev/null
+++ b/app/display/gimpdisplayshell-profile.h
@@ -0,0 +1,32 @@
+/* GIMP - The GNU Image Manipulation Program
+ * Copyright (C) 1995 Spencer Kimball and Peter Mattis
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GIMP_DISPLAY_SHELL_PROFILE_H__
+#define __GIMP_DISPLAY_SHELL_PROFILE_H__
+
+
+void   gimp_display_shell_profile_dispose        (GimpDisplayShell *shell);
+void   gimp_display_shell_profile_update         (GimpDisplayShell *shell);
+
+void   gimp_display_shell_profile_convert_buffer (GimpDisplayShell *shell,
+                                                  GeglBuffer       *src_buffer,
+                                                  GeglRectangle    *src_area,
+                                                  GeglBuffer       *dest_buffer,
+                                                  GeglRectangle    *dest_area);
+
+
+#endif /*  __GIMP_DISPLAY_SHELL_PROFILE_H__  */
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index 53e90fe..23af1f8 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -66,6 +66,7 @@
 #include "gimpdisplayshell-filter.h"
 #include "gimpdisplayshell-handlers.h"
 #include "gimpdisplayshell-items.h"
+#include "gimpdisplayshell-profile.h"
 #include "gimpdisplayshell-progress.h"
 #include "gimpdisplayshell-render.h"
 #include "gimpdisplayshell-rotate.h"
@@ -146,9 +147,12 @@ static void      gimp_display_shell_real_scaled    (GimpDisplayShell *shell);
 static void      gimp_display_shell_real_scrolled  (GimpDisplayShell *shell);
 static void      gimp_display_shell_real_rotated   (GimpDisplayShell *shell);
 
-static const guint8 * gimp_display_shell_get_icc_profile
-                                                   (GimpColorManaged *managed,
+static const guint8 *
+                 gimp_display_shell_get_icc_profile(GimpColorManaged *managed,
                                                     gsize            *len);
+static GimpColorProfile
+               gimp_display_shell_get_color_profile(GimpColorManaged *managed);
+static void      gimp_display_shell_profile_changed(GimpColorManaged *managed);
 
 static void      gimp_display_shell_menu_position  (GtkMenu          *menu,
                                                     gint             *x,
@@ -302,7 +306,9 @@ gimp_display_shell_class_init (GimpDisplayShellClass *klass)
 static void
 gimp_color_managed_iface_init (GimpColorManagedInterface *iface)
 {
-  iface->get_icc_profile = gimp_display_shell_get_icc_profile;
+  iface->get_icc_profile   = gimp_display_shell_get_icc_profile;
+  iface->get_color_profile = gimp_display_shell_get_color_profile;
+  iface->profile_changed   = gimp_display_shell_profile_changed;
 }
 
 static void
@@ -806,6 +812,8 @@ gimp_display_shell_dispose (GObject *object)
       shell->checkerboard = NULL;
     }
 
+  gimp_display_shell_profile_dispose (shell);
+
   if (shell->filter_buffer)
     {
       g_object_unref (shell->filter_buffer);
@@ -1128,6 +1136,27 @@ gimp_display_shell_get_icc_profile (GimpColorManaged *managed,
   return NULL;
 }
 
+static GimpColorProfile
+gimp_display_shell_get_color_profile (GimpColorManaged *managed)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (managed);
+  GimpImage        *image = gimp_display_get_image (shell->display);
+
+  if (image)
+    return gimp_color_managed_get_color_profile (GIMP_COLOR_MANAGED (image));
+
+  return NULL;
+}
+
+static void
+gimp_display_shell_profile_changed (GimpColorManaged *managed)
+{
+  GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (managed);
+
+  gimp_display_shell_profile_update (shell);
+  gimp_display_shell_expose_full (shell);
+}
+
 static void
 gimp_display_shell_menu_position (GtkMenu  *menu,
                                   gint     *x,
diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h
index b49e02c..0773df1 100644
--- a/app/display/gimpdisplayshell.h
+++ b/app/display/gimpdisplayshell.h
@@ -110,14 +110,6 @@ struct _GimpDisplayShell
 
   GtkWidget         *statusbar;        /*  statusbar                          */
 
-  GimpDisplayXfer   *xfer;             /*  manages image buffer transfers     */
-  cairo_surface_t   *mask_surface;     /*  buffer for rendering the mask      */
-  cairo_pattern_t   *checkerboard;     /*  checkerboard pattern               */
-
-  GeglBuffer        *filter_buffer;    /*  buffer for display filters         */
-  guchar            *filter_data;      /*  filter_buffer's pixels             */
-  gint               filter_stride;    /*  filter_buffer's stride             */
-
   GimpCanvasItem    *canvas_item;      /*  items drawn on the canvas          */
   GimpCanvasItem    *unrotated_item;   /*  unrotated items for e.g. cursor    */
   GimpCanvasItem    *passe_partout;    /*  item for the highlight             */
@@ -155,10 +147,26 @@ struct _GimpDisplayShell
   GtkWidget         *nav_popup;        /*  navigation popup                   */
   GtkWidget         *grid_dialog;      /*  grid configuration dialog          */
 
+  GimpColorTransform profile_transform;
+  const Babl        *profile_src_format;
+  const Babl        *profile_dest_format;
+
+  GeglBuffer        *profile_buffer;   /*  buffer for profile transform       */
+  guchar            *profile_data;     /*  profile_buffer's pixels            */
+  gint               profile_stride;   /*  profile_buffer's stride            */
+
   GimpColorDisplayStack *filter_stack;   /* color display conversion stuff    */
   guint                  filter_idle_id;
   GtkWidget             *filters_dialog; /* color display filter dialog       */
 
+  GeglBuffer        *filter_buffer;    /*  buffer for display filters         */
+  guchar            *filter_data;      /*  filter_buffer's pixels             */
+  gint               filter_stride;    /*  filter_buffer's stride             */
+
+  GimpDisplayXfer   *xfer;             /*  manages image buffer transfers     */
+  cairo_surface_t   *mask_surface;     /*  buffer for rendering the mask      */
+  cairo_pattern_t   *checkerboard;     /*  checkerboard pattern               */
+
   gint               paused_count;
 
   GimpTreeHandler   *vectors_freeze_handler;


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