[gimp] libgimpcolor: add a new gimp_color_profile_get_format()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpcolor: add a new gimp_color_profile_get_format()
- Date: Sat, 2 Sep 2017 18:32:15 +0000 (UTC)
commit d092ee9102cfcf1dc4266682c6ee1df01c2eeb9c
Author: Michael Natterer <mitch gimp org>
Date: Sat Sep 2 20:29:29 2017 +0200
libgimpcolor: add a new gimp_color_profile_get_format()
which takes a GimpColorProfile and a Babl format, and returns a new
format which uses the profile's RGB primaries and TRC, and the
original format's pixel layout; or NULL if babl couldn't create a
space from the profile's ICC data.
libgimpcolor/gimpcolor.def | 1 +
libgimpcolor/gimpcolorprofile.c | 49 ++++++++++++++++++++++++++++++++++++--
libgimpcolor/gimpcolorprofile.h | 3 ++
3 files changed, 50 insertions(+), 3 deletions(-)
---
diff --git a/libgimpcolor/gimpcolor.def b/libgimpcolor/gimpcolor.def
index 3d9a074..5bd160b 100644
--- a/libgimpcolor/gimpcolor.def
+++ b/libgimpcolor/gimpcolor.def
@@ -27,6 +27,7 @@ EXPORTS
gimp_color_managed_profile_changed
gimp_color_profile_get_copyright
gimp_color_profile_get_description
+ gimp_color_profile_get_format
gimp_color_profile_get_icc_profile
gimp_color_profile_get_label
gimp_color_profile_get_lcms_format
diff --git a/libgimpcolor/gimpcolorprofile.c b/libgimpcolor/gimpcolorprofile.c
index 5e408d0..e042217 100644
--- a/libgimpcolor/gimpcolorprofile.c
+++ b/libgimpcolor/gimpcolorprofile.c
@@ -113,6 +113,8 @@ G_DEFINE_TYPE (GimpColorProfile, gimp_color_profile,
#define parent_class gimp_color_profile_parent_class
+#define GIMP_COLOR_PROFILE_ERROR gimp_color_profile_error_quark ()
+
static GQuark
gimp_color_profile_error_quark (void)
{
@@ -265,7 +267,7 @@ gimp_color_profile_new_from_file (GFile *file,
if (error && *error == NULL)
{
- g_set_error (error, gimp_color_profile_error_quark (), 0,
+ g_set_error (error, GIMP_COLOR_PROFILE_ERROR, 0,
_("'%s' does not appear to be an ICC color profile"),
gimp_file_get_utf8_name (file));
}
@@ -311,7 +313,7 @@ gimp_color_profile_new_from_icc_profile (const guint8 *data,
}
else
{
- g_set_error_literal (error, gimp_color_profile_error_quark (), 0,
+ g_set_error_literal (error, GIMP_COLOR_PROFILE_ERROR, 0,
_("Data does not appear to be an ICC color profile"));
}
@@ -368,7 +370,7 @@ gimp_color_profile_new_from_lcms_profile (gpointer lcms_profile,
g_free (data);
}
- g_set_error_literal (error, gimp_color_profile_error_quark (), 0,
+ g_set_error_literal (error, GIMP_COLOR_PROFILE_ERROR, 0,
_("Could not save color profile to memory"));
return NULL;
@@ -1458,6 +1460,47 @@ gimp_color_profile_new_d50_gray_lab_trc (void)
}
/**
+ * gimp_color_profile_get_format:
+ * @profile: a #GimpColorProfile
+ * @format: a #Babl format
+ * @error: return location for #GError
+ *
+ * This function takes a #GimpColorProfile and a #Babl format and
+ * returns a new #Babl format with @profile's RGB primaries and TRC,
+ * and @format's pixel layout.
+ *
+ * Return value: the new #Babl format.
+ *
+ * Since: 2.10
+ **/
+const Babl *
+gimp_color_profile_get_format (GimpColorProfile *profile,
+ const Babl *format,
+ GError **error)
+{
+ const Babl *space;
+ gchar *babl_error = NULL;
+
+ g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
+ g_return_val_if_fail (format != NULL, NULL);
+ g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+ space = babl_space_from_icc ((const gchar *) profile->priv->data,
+ profile->priv->length,
+ &babl_error);
+
+ if (! space)
+ {
+ g_set_error (error, GIMP_COLOR_PROFILE_ERROR, 0,
+ "%s: %s",
+ gimp_color_profile_get_label (profile), babl_error);
+ return NULL;
+ }
+
+ return babl_format_with_space (babl_get_name (format), space);
+}
+
+/**
* gimp_color_profile_get_lcms_format:
* @format: a #Babl format
* @lcms_format: return location for an lcms format
diff --git a/libgimpcolor/gimpcolorprofile.h b/libgimpcolor/gimpcolorprofile.h
index 598b2b1..56173f1 100644
--- a/libgimpcolor/gimpcolorprofile.h
+++ b/libgimpcolor/gimpcolorprofile.h
@@ -111,6 +111,9 @@ gboolean gimp_color_profile_is_cmyk (GimpColorProfile *
gboolean gimp_color_profile_is_linear (GimpColorProfile *profile);
+const Babl * gimp_color_profile_get_format (GimpColorProfile *profile,
+ const Babl *format,
+ GError **error);
const Babl * gimp_color_profile_get_lcms_format (const Babl *format,
guint32 *lcms_format);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]