[gimp] app: add gimp_image_validate_color_profile()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app: add gimp_image_validate_color_profile()
- Date: Tue, 9 Jun 2015 16:56:17 +0000 (UTC)
commit 685f883f3e52856d17e8e15dd4eed90cb9e63ab3
Author: Michael Natterer <mitch gimp org>
Date: Tue Jun 9 18:55:07 2015 +0200
app: add gimp_image_validate_color_profile()
and use it from gimp_image_set_icc_profile() and from
gimp_image_set_color_profile().
app/core/gimpimage-profile.c | 50 ++++++++++++++++++++++++++---------------
app/core/gimpimage-profile.h | 27 ++++++++++++----------
2 files changed, 47 insertions(+), 30 deletions(-)
---
diff --git a/app/core/gimpimage-profile.c b/app/core/gimpimage-profile.c
index 03136d1..87142f4 100644
--- a/app/core/gimpimage-profile.c
+++ b/app/core/gimpimage-profile.c
@@ -70,14 +70,6 @@ gimp_image_validate_icc_profile (GimpImage *image,
return FALSE;
}
- if (gimp_image_get_base_type (image) == GIMP_GRAY)
- {
- g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
- _("ICC profile validation failed: "
- "Cannot attach a color profile to a GRAY image"));
- return FALSE;
- }
-
profile = gimp_color_profile_open_from_data (gimp_parasite_data (icc_profile),
gimp_parasite_data_size (icc_profile),
error);
@@ -88,11 +80,8 @@ gimp_image_validate_icc_profile (GimpImage *image,
return FALSE;
}
- if (! gimp_color_profile_is_rgb (profile))
+ if (! gimp_image_validate_color_profile (image, profile, error))
{
- g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
- _("ICC profile validation failed: "
- "Color profile is not for RGB color space"));
gimp_color_profile_close (profile);
return FALSE;
}
@@ -129,6 +118,34 @@ gimp_image_set_icc_profile (GimpImage *image,
}
}
+gboolean
+gimp_image_validate_color_profile (GimpImage *image,
+ GimpColorProfile profile,
+ GError **error)
+{
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (profile != NULL, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (gimp_image_get_base_type (image) == GIMP_GRAY)
+ {
+ g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+ _("ICC profile validation failed: "
+ "Cannot attach a color profile to a GRAY image"));
+ return FALSE;
+ }
+
+ 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;
+ }
+
+ return TRUE;
+}
+
GimpColorProfile
gimp_image_get_color_profile (GimpImage *image,
GError **error)
@@ -163,6 +180,9 @@ gimp_image_set_color_profile (GimpImage *image,
guint8 *data;
gsize length;
+ if (! gimp_image_validate_color_profile (image, profile, error))
+ return FALSE;
+
data = gimp_color_profile_save_to_data (profile, &length, error);
if (! data)
return FALSE;
@@ -172,12 +192,6 @@ gimp_image_set_color_profile (GimpImage *image,
GIMP_PARASITE_UNDOABLE,
length, data);
g_free (data);
-
- if (! gimp_image_validate_icc_profile (image, parasite, error))
- {
- gimp_parasite_free (parasite);
- return FALSE;
- }
}
gimp_image_set_icc_profile (image, parasite);
diff --git a/app/core/gimpimage-profile.h b/app/core/gimpimage-profile.h
index 73e5aa2..b321b8b 100644
--- a/app/core/gimpimage-profile.h
+++ b/app/core/gimpimage-profile.h
@@ -22,18 +22,21 @@
#define GIMP_ICC_PROFILE_PARASITE_NAME "icc-profile"
-gboolean gimp_image_validate_icc_profile (GimpImage *image,
- const GimpParasite *icc_profile,
- GError **error);
-const GimpParasite * gimp_image_get_icc_profile (GimpImage *image);
-void gimp_image_set_icc_profile (GimpImage *image,
- const GimpParasite *icc_profile);
-
-GimpColorProfile gimp_image_get_color_profile (GimpImage *image,
- GError **error);
-gboolean gimp_image_set_color_profile (GimpImage *image,
- GimpColorProfile profile,
- GError **error);
+gboolean gimp_image_validate_icc_profile (GimpImage *image,
+ const GimpParasite *icc_profile,
+ GError **error);
+const GimpParasite * gimp_image_get_icc_profile (GimpImage *image);
+void gimp_image_set_icc_profile (GimpImage *image,
+ const GimpParasite *icc_profile);
+
+gboolean gimp_image_validate_color_profile (GimpImage *image,
+ GimpColorProfile profile,
+ GError **error);
+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__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]