[gimp] app: add gimp_image_set_color_profile(), currently unused



commit b8eeb9ed002044c17213e837589b743f8ffd6382
Author: Michael Natterer <mitch gimp org>
Date:   Tue Jun 2 23:25:52 2015 +0200

    app: add gimp_image_set_color_profile(), currently unused
    
    also remove the fallback-to-colorconfig code from
    gimp_image_get_color_profile() and move it to
    gimp_image_color_managed_get_icc_profile(), so
    gimp_image_get_color_profile() returns NULL if the image has no own
    profile.

 app/core/gimpimage-profile.c |   53 +++++++++++++++++++++++++++++++----------
 app/core/gimpimage-profile.h |    3 ++
 app/core/gimpimage.c         |    7 +++++
 3 files changed, 50 insertions(+), 13 deletions(-)
---
diff --git a/app/core/gimpimage-profile.c b/app/core/gimpimage-profile.c
index 1bb002c..508c7ce 100644
--- a/app/core/gimpimage-profile.c
+++ b/app/core/gimpimage-profile.c
@@ -19,8 +19,6 @@
 
 #include <string.h>
 
-#include <lcms2.h>
-
 #include <cairo.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
 #include <gegl.h>
@@ -95,11 +93,11 @@ gimp_image_validate_icc_profile (GimpImage           *image,
       g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
                            _("ICC profile validation failed: "
                              "Color profile is not for RGB color space"));
-      cmsCloseProfile (profile);
+      gimp_lcms_profile_close (profile);
       return FALSE;
     }
 
-  cmsCloseProfile (profile);
+  gimp_lcms_profile_close (profile);
 
   return TRUE;
 }
@@ -136,7 +134,6 @@ gimp_image_get_color_profile (GimpImage  *image,
                               GError    **error)
 {
   const GimpParasite *parasite;
-  GimpColorProfile   *profile = NULL;
 
   g_return_val_if_fail (GIMP_IS_IMAGE (image), NULL);
   g_return_val_if_fail (error == NULL || *error == NULL, NULL);
@@ -144,17 +141,47 @@ gimp_image_get_color_profile (GimpImage  *image,
   parasite = gimp_image_get_icc_profile (image);
 
   if (parasite)
+    return gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
+                                             gimp_parasite_data_size (parasite),
+                                             error);
+
+  return NULL;
+}
+
+gboolean
+gimp_image_set_color_profile (GimpImage         *image,
+                              GimpColorProfile   profile,
+                              GError           **error)
+{
+  GimpParasite *parasite = NULL;
+
+  g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (profile)
     {
-      profile = gimp_lcms_profile_open_from_data (gimp_parasite_data (parasite),
-                                                  gimp_parasite_data_size (parasite),
-                                                  error);
+      guint8 *data;
+      gsize   length;
+
+      data = gimp_lcms_profile_save_to_data (profile, &length, error);
+      if (! data)
+        return FALSE;
+
+      parasite = gimp_parasite_new (GIMP_ICC_PROFILE_PARASITE_NAME,
+                                    GIMP_PARASITE_PERSISTENT |
+                                    GIMP_PARASITE_UNDOABLE,
+                                    length, data);
+      g_free (data);
     }
-  else
-    {
-      GimpColorConfig *config = image->gimp->config->color_management;
 
-      profile = gimp_color_config_get_rgb_profile (config, error);
+  if (! gimp_image_validate_icc_profile (image, parasite, error))
+    {
+      gimp_parasite_free (parasite);
+      return FALSE;
     }
 
-  return profile;
+  gimp_image_set_icc_profile (image, parasite);
+  gimp_parasite_free (parasite);
+
+  return FALSE;
 }
diff --git a/app/core/gimpimage-profile.h b/app/core/gimpimage-profile.h
index 1c9355f..73e5aa2 100644
--- a/app/core/gimpimage-profile.h
+++ b/app/core/gimpimage-profile.h
@@ -31,6 +31,9 @@ void                 gimp_image_set_icc_profile      (GimpImage           *image
 
 GimpColorProfile     gimp_image_get_color_profile    (GimpImage           *image,
                                                       GError             **error);
+gboolean             gimp_image_set_color_profile    (GimpImage           *image,
+                                                      GimpColorProfile     profile,
+                                                      GError             **error);
 
 
 #endif /* __GIMP_IMAGE_PROFILE_H__ */
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 508c0ef..ccdb55d 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -1395,6 +1395,13 @@ gimp_image_color_managed_get_color_profile (GimpColorManaged *managed)
 
   if (! profile)
     {
+      GimpColorConfig *config = image->gimp->config->color_management;
+
+      profile = gimp_color_config_get_rgb_profile (config, NULL);
+    }
+
+  if (! profile)
+    {
       const Babl *format = gimp_image_get_layer_format (image, FALSE);
 
       if (gimp_babl_format_get_linear (format))


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