[gimp] app: add gimp_babl_format_get_color_profile()



commit 3fd6435198577b9cdd5a2f2b9400f4ff94a9c94c
Author: Michael Natterer <mitch gimp org>
Date:   Fri Apr 15 23:02:19 2016 +0100

    app: add gimp_babl_format_get_color_profile()
    
    and remove the code duplication added a few commits before.

 app/core/gimpbuffer.c              |   60 +-------------------------------
 app/core/gimpimage-color-profile.c |   57 +------------------------------
 app/gegl/gimp-babl.c               |   66 ++++++++++++++++++++++++++++++++++++
 app/gegl/gimp-babl.h               |    1 +
 4 files changed, 71 insertions(+), 113 deletions(-)
---
diff --git a/app/core/gimpbuffer.c b/app/core/gimpbuffer.c
index cd2ef8f..b3c9a2e 100644
--- a/app/core/gimpbuffer.c
+++ b/app/core/gimpbuffer.c
@@ -347,68 +347,12 @@ gimp_buffer_color_managed_get_icc_profile (GimpColorManaged *managed,
 static GimpColorProfile *
 gimp_buffer_color_managed_get_color_profile (GimpColorManaged *managed)
 {
-  GimpBuffer              *buffer              = GIMP_BUFFER (managed);
-  static GimpColorProfile *srgb_profile        = NULL;
-  static GimpColorProfile *linear_rgb_profile  = NULL;
-  static GimpColorProfile *gray_profile        = NULL;
-  static GimpColorProfile *linear_gray_profile = NULL;
-  const  Babl             *format;
+  GimpBuffer *buffer = GIMP_BUFFER (managed);
 
   if (buffer->color_profile)
     return buffer->color_profile;
 
-  format = gimp_buffer_get_format (buffer);
-
-  if (gimp_babl_format_get_base_type (format) == GIMP_GRAY)
-    {
-      if (gimp_babl_format_get_linear (format))
-        {
-          if (! linear_gray_profile)
-            {
-              linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
-              g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
-                                         (gpointer) &linear_gray_profile);
-            }
-
-          return linear_gray_profile;
-        }
-      else
-        {
-          if (! gray_profile)
-            {
-              gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
-              g_object_add_weak_pointer (G_OBJECT (gray_profile),
-                                         (gpointer) &gray_profile);
-            }
-
-          return gray_profile;
-        }
-    }
-  else
-    {
-      if (gimp_babl_format_get_linear (format))
-        {
-          if (! linear_rgb_profile)
-            {
-              linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
-              g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
-                                         (gpointer) &linear_rgb_profile);
-            }
-
-          return linear_rgb_profile;
-        }
-      else
-        {
-          if (! srgb_profile)
-            {
-              srgb_profile = gimp_color_profile_new_rgb_srgb ();
-              g_object_add_weak_pointer (G_OBJECT (srgb_profile),
-                                         (gpointer) &srgb_profile);
-            }
-
-          return srgb_profile;
-        }
-    }
+  return gimp_babl_format_get_color_profile (gimp_buffer_get_format (buffer));
 }
 
 static void
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index d682631..61372f8 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -307,66 +307,13 @@ gimp_image_set_color_profile (GimpImage         *image,
 GimpColorProfile *
 gimp_image_get_builtin_color_profile (GimpImage *image)
 {
-  static GimpColorProfile *srgb_profile        = NULL;
-  static GimpColorProfile *linear_rgb_profile  = NULL;
-  static GimpColorProfile *gray_profile        = NULL;
-  static GimpColorProfile *linear_gray_profile = NULL;
-  const  Babl             *format;
+  const Babl *format;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
 
   format = gimp_image_get_layer_format (image, FALSE);
 
-  if (gimp_image_get_base_type (image) == GIMP_GRAY)
-    {
-      if (gimp_babl_format_get_linear (format))
-        {
-          if (! linear_gray_profile)
-            {
-              linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
-              g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
-                                         (gpointer) &linear_gray_profile);
-            }
-
-          return linear_gray_profile;
-        }
-      else
-        {
-          if (! gray_profile)
-            {
-              gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
-              g_object_add_weak_pointer (G_OBJECT (gray_profile),
-                                         (gpointer) &gray_profile);
-            }
-
-          return gray_profile;
-        }
-    }
-  else
-    {
-      if (gimp_babl_format_get_linear (format))
-        {
-          if (! linear_rgb_profile)
-            {
-              linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
-              g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
-                                         (gpointer) &linear_rgb_profile);
-            }
-
-          return linear_rgb_profile;
-        }
-      else
-        {
-          if (! srgb_profile)
-            {
-              srgb_profile = gimp_color_profile_new_rgb_srgb ();
-              g_object_add_weak_pointer (G_OBJECT (srgb_profile),
-                                         (gpointer) &srgb_profile);
-            }
-
-          return srgb_profile;
-        }
-    }
+  return gimp_babl_format_get_color_profile (format);
 }
 
 gboolean
diff --git a/app/gegl/gimp-babl.c b/app/gegl/gimp-babl.c
index 5fa4f10..4430135 100644
--- a/app/gegl/gimp-babl.c
+++ b/app/gegl/gimp-babl.c
@@ -20,8 +20,12 @@
 
 #include "config.h"
 
+#include <cairo.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
 
+#include "libgimpcolor/gimpcolor.h"
+
 #include "gimp-gegl-types.h"
 
 #include "gimp-babl.h"
@@ -395,6 +399,68 @@ gimp_babl_format_get_description (const Babl *babl)
                       babl_get_name (babl), NULL);
 }
 
+GimpColorProfile *
+gimp_babl_format_get_color_profile (const Babl *format)
+{
+  static GimpColorProfile *srgb_profile        = NULL;
+  static GimpColorProfile *linear_rgb_profile  = NULL;
+  static GimpColorProfile *gray_profile        = NULL;
+  static GimpColorProfile *linear_gray_profile = NULL;
+
+  g_return_val_if_fail (format != NULL, NULL);
+
+  if (gimp_babl_format_get_base_type (format) == GIMP_GRAY)
+    {
+      if (gimp_babl_format_get_linear (format))
+        {
+          if (! linear_gray_profile)
+            {
+              linear_gray_profile = gimp_color_profile_new_d65_gray_linear ();
+              g_object_add_weak_pointer (G_OBJECT (linear_gray_profile),
+                                         (gpointer) &linear_gray_profile);
+            }
+
+          return linear_gray_profile;
+        }
+      else
+        {
+          if (! gray_profile)
+            {
+              gray_profile = gimp_color_profile_new_d65_gray_srgb_trc ();
+              g_object_add_weak_pointer (G_OBJECT (gray_profile),
+                                         (gpointer) &gray_profile);
+            }
+
+          return gray_profile;
+        }
+    }
+  else
+    {
+      if (gimp_babl_format_get_linear (format))
+        {
+          if (! linear_rgb_profile)
+            {
+              linear_rgb_profile = gimp_color_profile_new_rgb_srgb_linear ();
+              g_object_add_weak_pointer (G_OBJECT (linear_rgb_profile),
+                                         (gpointer) &linear_rgb_profile);
+            }
+
+          return linear_rgb_profile;
+        }
+      else
+        {
+          if (! srgb_profile)
+            {
+              srgb_profile = gimp_color_profile_new_rgb_srgb ();
+              g_object_add_weak_pointer (G_OBJECT (srgb_profile),
+                                         (gpointer) &srgb_profile);
+            }
+
+          return srgb_profile;
+        }
+    }
+}
+
 GimpImageBaseType
 gimp_babl_format_get_base_type (const Babl *format)
 {
diff --git a/app/gegl/gimp-babl.h b/app/gegl/gimp-babl.h
index 1da4235..e6cb8eb 100644
--- a/app/gegl/gimp-babl.h
+++ b/app/gegl/gimp-babl.h
@@ -25,6 +25,7 @@
 void                gimp_babl_init                      (void);
 
 const gchar       * gimp_babl_format_get_description    (const Babl *format);
+GimpColorProfile  * gimp_babl_format_get_color_profile  (const Babl *format);
 
 GimpImageBaseType   gimp_babl_format_get_base_type      (const Babl *format);
 GimpComponentType   gimp_babl_format_get_component_type (const Babl *format);


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