[gimp/alxsa-softproof-in-xcf] core: Save/load soft-proofing profile in Image
- From: Alx Sa <sawyeralex src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/alxsa-softproof-in-xcf] core: Save/load soft-proofing profile in Image
- Date: Tue, 26 Jul 2022 12:18:41 +0000 (UTC)
commit 0ad1e4c6a7b43841eac68118abc3a5bf774245fa
Author: Alx Sa <cmyk student gmail com>
Date: Tue Jul 26 12:18:40 2022 +0000
core: Save/load soft-proofing profile in Image
Adds a parasite to .xcf that stores the soft-proofing profile.
Existing color profile saving/loading functions now take in a
parasite name parameter so they can be used for either profile.
app/core/gimpimage-color-profile.c | 120 +++++++++++++++++++++++++++++++++----
app/core/gimpimage-color-profile.h | 19 +++++-
app/core/gimpimage-new.c | 4 +-
app/core/gimpimage.c | 19 +++++-
4 files changed, 143 insertions(+), 19 deletions(-)
---
diff --git a/app/core/gimpimage-color-profile.c b/app/core/gimpimage-color-profile.c
index 64f868818d..c8a2d8061c 100644
--- a/app/core/gimpimage-color-profile.c
+++ b/app/core/gimpimage-color-profile.c
@@ -181,6 +181,7 @@ _gimp_image_set_hidden_profile (GimpImage *image,
gboolean
gimp_image_validate_icc_parasite (GimpImage *image,
const GimpParasite *icc_parasite,
+ const gchar *profile_type,
gboolean *is_builtin,
GError **error)
{
@@ -192,11 +193,19 @@ gimp_image_validate_icc_parasite (GimpImage *image,
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
if (strcmp (gimp_parasite_get_name (icc_parasite),
- GIMP_ICC_PROFILE_PARASITE_NAME) != 0)
+ profile_type) != 0)
{
+ gchar *invalid_parasite_name;
+
+ invalid_parasite_name =
+ g_strdup_printf (_("ICC profile validation failed: "
+ "Parasite's name is not '%s'"),
+ profile_type);
+
g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
- _("ICC profile validation failed: "
- "Parasite's name is not 'icc-profile'"));
+ invalid_parasite_name);
+
+ g_free (invalid_parasite_name);
return FALSE;
}
@@ -210,6 +219,12 @@ gimp_image_validate_icc_parasite (GimpImage *image,
}
data = gimp_parasite_get_data (icc_parasite, &data_size);
+
+ if (strcmp (gimp_parasite_get_name (icc_parasite),
+ GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+ return gimp_image_validate_simulation_icc_profile (image, data, data_size,
+ is_builtin, error);
+
return gimp_image_validate_icc_profile (image, data, data_size, is_builtin, error);
}
@@ -223,20 +238,22 @@ gimp_image_get_icc_parasite (GimpImage *image)
void
gimp_image_set_icc_parasite (GimpImage *image,
- const GimpParasite *icc_parasite)
+ const GimpParasite *icc_parasite,
+ const gchar *profile_type)
{
g_return_if_fail (GIMP_IS_IMAGE (image));
if (icc_parasite)
{
g_return_if_fail (gimp_image_validate_icc_parasite (image, icc_parasite,
+ gimp_parasite_get_name (icc_parasite),
NULL, NULL) == TRUE);
gimp_image_parasite_attach (image, icc_parasite, TRUE);
}
else
{
- gimp_image_parasite_detach (image, GIMP_ICC_PROFILE_PARASITE_NAME, TRUE);
+ gimp_image_parasite_detach (image, profile_type, TRUE);
}
}
@@ -272,6 +289,49 @@ gimp_image_validate_icc_profile (GimpImage *image,
return TRUE;
}
+gboolean
+gimp_image_validate_simulation_icc_profile (GimpImage *image,
+ const guint8 *data,
+ gsize length,
+ gboolean *invalid_profile,
+ GError **error)
+{
+ GimpColorProfile *profile;
+
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (data != NULL || length == 0, FALSE);
+ g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+ if (invalid_profile)
+ *invalid_profile = TRUE;
+
+ profile = gimp_color_profile_new_from_icc_profile (data, length, error);
+
+ if (! profile)
+ {
+ g_prefix_error (error, _("ICC profile validation failed: "));
+ if (invalid_profile)
+ *invalid_profile = FALSE;
+ return FALSE;
+ }
+
+ if (! gimp_color_profile_is_cmyk (profile))
+ {
+ g_set_error_literal (error, GIMP_ERROR, GIMP_FAILED,
+ _("ICC profile validation failed: "
+ "Simulation color profile is not for "
+ "CMYK color space"));
+ if (invalid_profile)
+ *invalid_profile = FALSE;
+ return FALSE;
+ }
+
+ if (invalid_profile)
+ *invalid_profile = FALSE;
+
+ return TRUE;
+}
+
const guint8 *
gimp_image_get_icc_profile (GimpImage *image,
gsize *length)
@@ -305,6 +365,7 @@ gboolean
gimp_image_set_icc_profile (GimpImage *image,
const guint8 *data,
gsize length,
+ const gchar *profile_type,
GError **error)
{
GimpParasite *parasite = NULL;
@@ -317,13 +378,13 @@ gimp_image_set_icc_profile (GimpImage *image,
{
gboolean is_builtin;
- parasite = gimp_parasite_new (GIMP_ICC_PROFILE_PARASITE_NAME,
+ parasite = gimp_parasite_new (profile_type,
GIMP_PARASITE_PERSISTENT |
GIMP_PARASITE_UNDOABLE,
length, data);
- if (! gimp_image_validate_icc_parasite (image, parasite, &is_builtin,
- error))
+ if (! gimp_image_validate_icc_parasite (image, parasite, profile_type,
+ &is_builtin, error))
{
gimp_parasite_free (parasite);
return FALSE;
@@ -337,7 +398,7 @@ gimp_image_set_icc_profile (GimpImage *image,
}
}
- gimp_image_set_icc_parasite (image, parasite);
+ gimp_image_set_icc_parasite (image, parasite, profile_type);
if (parasite)
gimp_parasite_free (parasite);
@@ -388,7 +449,9 @@ gimp_image_set_color_profile (GimpImage *image,
if (profile)
data = gimp_color_profile_get_icc_profile (profile, &length);
- return gimp_image_set_icc_profile (image, data, length, error);
+ return gimp_image_set_icc_profile (image, data, length,
+ GIMP_ICC_PROFILE_PARASITE_NAME,
+ error);
}
GimpColorProfile *
@@ -399,14 +462,17 @@ gimp_image_get_simulation_profile (GimpImage *image)
return GIMP_IMAGE_GET_PRIVATE (image)->simulation_profile;
}
-void
+gboolean
gimp_image_set_simulation_profile (GimpImage *image,
GimpColorProfile *profile)
{
GimpImagePrivate *private;
+ const guint8 *data = NULL;
+ gsize length = 0;
- g_return_if_fail (GIMP_IS_IMAGE (image));
- g_return_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile));
+ g_return_val_if_fail (GIMP_IS_IMAGE (image), FALSE);
+ g_return_val_if_fail (profile == NULL || GIMP_IS_COLOR_PROFILE (profile),
+ FALSE);
private = GIMP_IMAGE_GET_PRIVATE (image);
@@ -415,6 +481,13 @@ gimp_image_set_simulation_profile (GimpImage *image,
g_set_object (&private->simulation_profile, profile);
gimp_color_managed_simulation_profile_changed (GIMP_COLOR_MANAGED (image));
}
+
+ if (profile)
+ data = gimp_color_profile_get_icc_profile (profile, &length);
+
+ return gimp_image_set_icc_profile (image, data, length,
+ GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME,
+ NULL);
}
gboolean
@@ -861,6 +934,27 @@ _gimp_image_update_color_profile (GimpImage *image,
gimp_color_managed_profile_changed (GIMP_COLOR_MANAGED (image));
}
+void
+_gimp_image_update_simulation_profile (GimpImage *image,
+ const GimpParasite *icc_parasite)
+{
+ GimpImagePrivate *private = GIMP_IMAGE_GET_PRIVATE (image);
+
+ g_clear_object (&private->simulation_profile);
+
+ if (icc_parasite)
+ {
+ const guint8 *data;
+ guint32 data_size;
+
+ data = gimp_parasite_get_data (icc_parasite, &data_size);
+ private->simulation_profile =
+ gimp_color_profile_new_from_icc_profile (data, data_size, NULL);
+ }
+
+ gimp_color_managed_simulation_profile_changed (GIMP_COLOR_MANAGED (image));
+}
+
/* private functions */
diff --git a/app/core/gimpimage-color-profile.h b/app/core/gimpimage-color-profile.h
index 6548d36c1e..6aaf99ccd1 100644
--- a/app/core/gimpimage-color-profile.h
+++ b/app/core/gimpimage-color-profile.h
@@ -22,7 +22,8 @@
#define __GIMP_IMAGE_COLOR_PROFILE_H__
-#define GIMP_ICC_PROFILE_PARASITE_NAME "icc-profile"
+#define GIMP_ICC_PROFILE_PARASITE_NAME "icc-profile"
+#define GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME "simulation-icc-profile"
gboolean gimp_image_get_use_srgb_profile (GimpImage *image,
@@ -37,22 +38,31 @@ void _gimp_image_set_hidden_profile (GimpImage *ima
gboolean gimp_image_validate_icc_parasite (GimpImage *image,
const GimpParasite *icc_parasite,
+ const gchar *profile_type,
gboolean *is_builtin,
GError **error);
const GimpParasite * gimp_image_get_icc_parasite (GimpImage *image);
void gimp_image_set_icc_parasite (GimpImage *image,
- const GimpParasite *icc_parasite);
+ const GimpParasite *icc_parasite,
+ const gchar *profile_type);
gboolean gimp_image_validate_icc_profile (GimpImage *image,
const guint8 *data,
gsize length,
gboolean *is_builtin,
GError **error);
+gboolean gimp_image_validate_simulation_icc_profile
+ (GimpImage *image,
+ const guint8 *data,
+ gsize length,
+ gboolean *is_builtin,
+ GError **error);
const guint8 * gimp_image_get_icc_profile (GimpImage *image,
gsize *length);
gboolean gimp_image_set_icc_profile (GimpImage *image,
const guint8 *data,
gsize length,
+ const gchar *profile_type,
GError **error);
gboolean gimp_image_validate_color_profile (GimpImage *image,
@@ -65,7 +75,7 @@ gboolean gimp_image_set_color_profile (GimpImage *ima
GError **error);
GimpColorProfile * gimp_image_get_simulation_profile (GimpImage *image);
-void gimp_image_set_simulation_profile (GimpImage *image,
+gboolean gimp_image_set_simulation_profile (GimpImage *image,
GimpColorProfile *profile);
gboolean gimp_image_validate_color_profile_by_format
@@ -122,6 +132,9 @@ void _gimp_image_free_color_profile (GimpImage *ima
void _gimp_image_free_color_transforms (GimpImage *image);
void _gimp_image_update_color_profile (GimpImage *image,
const GimpParasite *icc_parasite);
+void _gimp_image_update_simulation_profile
+ (GimpImage *image,
+ const GimpParasite *icc_parasite);
#endif /* __GIMP_IMAGE_COLOR_PROFILE_H__ */
diff --git a/app/core/gimpimage-new.c b/app/core/gimpimage-new.c
index bc8d50cdcf..bd442d1072 100644
--- a/app/core/gimpimage-new.c
+++ b/app/core/gimpimage-new.c
@@ -556,7 +556,9 @@ gimp_image_new_from_pixbuf (Gimp *gimp,
icc_data = gimp_pixbuf_get_icc_profile (pixbuf, &icc_len);
if (icc_data)
{
- gimp_image_set_icc_profile (new_image, icc_data, icc_len, NULL);
+ gimp_image_set_icc_profile (new_image, icc_data, icc_len,
+ GIMP_ICC_PROFILE_PARASITE_NAME,
+ NULL);
g_free (icc_data);
}
diff --git a/app/core/gimpimage.c b/app/core/gimpimage.c
index 1e5d4d9b00..a5c2b42661 100644
--- a/app/core/gimpimage.c
+++ b/app/core/gimpimage.c
@@ -4182,7 +4182,15 @@ gimp_image_parasite_validate (GimpImage *image,
if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
{
- return gimp_image_validate_icc_parasite (image, parasite, NULL, error);
+ return gimp_image_validate_icc_parasite (image, parasite,
+ GIMP_ICC_PROFILE_PARASITE_NAME,
+ NULL, error);
+ }
+ else if (strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+ {
+ return gimp_image_validate_icc_parasite (image, parasite,
+ GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME,
+ NULL, error);
}
else if (strcmp (name, "gimp-comment") == 0)
{
@@ -4228,7 +4236,8 @@ gimp_image_parasite_attach (GimpImage *image,
name = gimp_parasite_get_name (parasite);
/* this is so ugly and is only for the PDB */
- if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
+ if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0 ||
+ strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
{
GimpColorProfile *profile;
GimpColorProfile *builtin;
@@ -4283,6 +4292,9 @@ gimp_image_parasite_attach (GimpImage *image,
if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
_gimp_image_update_color_profile (image, parasite);
+ if (strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+ _gimp_image_update_simulation_profile (image, parasite);
+
g_signal_emit (image, gimp_image_signals[PARASITE_ATTACHED], 0,
name);
}
@@ -4313,6 +4325,9 @@ gimp_image_parasite_detach (GimpImage *image,
if (strcmp (name, GIMP_ICC_PROFILE_PARASITE_NAME) == 0)
_gimp_image_update_color_profile (image, NULL);
+ if (strcmp (name, GIMP_SIMULATION_ICC_PROFILE_PARASITE_NAME) == 0)
+ _gimp_image_update_simulation_profile (image, NULL);
+
g_signal_emit (image, gimp_image_signals[PARASITE_DETACHED], 0,
name);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]