[gimp] app: add gimp_image_validate_color_profile_by_format()



commit 33adec2a3eaaec8569b34a49ff68d50ce87b0a56
Author: Michael Natterer <mitch gimp org>
Date:   Sat Apr 30 17:39:02 2016 +0200

    app: add gimp_image_validate_color_profile_by_format()
    
    which checks if a color profile is suited for pixels of a Babl format.

 app/core/gimpimage-color-profile.c |   79 ++++++++++++++++++++++--------------
 app/core/gimpimage-color-profile.h |    6 +++
 2 files changed, 55 insertions(+), 30 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 61372f8..d99cecd 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -240,41 +240,17 @@ gimp_image_validate_color_profile (GimpImage        *image,
                                    gboolean         *is_builtin,
                                    GError          **error)
 {
+  const Babl *format;
+
   g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
   g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), FALSE);
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
 
-  if (gimp_image_get_base_type (image) == GIMP_GRAY)
-    {
-      if (! gimp_color_profile_is_gray (profile))
-        {
-          g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                               _("ICC profile validation failed: "
-                                 "Color profile is not for GRAY color space"));
-          return FALSE;
-        }
-    }
-  else
-    {
-      if (! gimp_color_profile_is_rgb (profile))
-        {
-          g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
-                               _("ICC profile validation failed: "
-                                 "Color profile is not for RGB color space"));
-          return FALSE;
-        }
-    }
-
-  if (is_builtin)
-    {
-      GimpColorProfile *builtin;
-
-      builtin = gimp_image_get_builtin_color_profile (image);
-
-      *is_builtin = gimp_color_profile_is_equal (profile, builtin);
-    }
+  format = gimp_image_get_layer_format (image, TRUE);
 
-  return TRUE;
+  return gimp_image_validate_color_profile_by_format (format,
+                                                      profile, is_builtin,
+                                                      error);
 }
 
 GimpColorProfile *
@@ -304,6 +280,49 @@ gimp_image_set_color_profile (GimpImage         *image,
   return gimp_image_set_icc_profile (image, data, length, error);
 }
 
+gboolean
+gimp_image_validate_color_profile_by_format (const Babl         *format,
+                                             GimpColorProfile   *profile,
+                                             gboolean           *is_builtin,
+                                             GError            **error)
+{
+  g_return_val_if_fail (format != NULL, FALSE);
+  g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), FALSE);
+  g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+  if (gimp_babl_format_get_base_type (format) == GIMP_GRAY)
+    {
+      if (! gimp_color_profile_is_gray (profile))
+        {
+          g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+                               _("ICC profile validation failed: "
+                                 "Color profile is not for grayscale color space"));
+          return FALSE;
+        }
+    }
+  else
+    {
+      if (! gimp_color_profile_is_rgb (profile))
+        {
+          g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+                               _("ICC profile validation failed: "
+                                 "Color profile is not for RGB color space"));
+          return FALSE;
+        }
+    }
+
+  if (is_builtin)
+    {
+      GimpColorProfile *builtin;
+
+      builtin = gimp_babl_format_get_color_profile (format);
+
+      *is_builtin = gimp_color_profile_is_equal (profile, builtin);
+    }
+
+  return TRUE;
+}
+
 GimpColorProfile *
 gimp_image_get_builtin_color_profile (GimpImage *image)
 {
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index e7aaf28..d6de955 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -54,6 +54,12 @@ gboolean             gimp_image_set_color_profile      (GimpImage           *ima
                                                         GimpColorProfile    *profile,
                                                         GError             **error);
 
+gboolean             gimp_image_validate_color_profile_by_format
+                                                       (const Babl          *format,
+                                                        GimpColorProfile    *profile,
+                                                        gboolean            *is_builtin,
+                                                        GError             **error);
+
 GimpColorProfile   * gimp_image_get_builtin_color_profile
                                                        (GimpImage           *image);
 


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