Issue #3057 - Retain last user-chosen ICC profile information...

...when generating "TRC variants"

When creating a new profile with different TRC from an existing
profile, keep all the original profile's description, model,
manufacturer and copyright strings around, but prefix them with "GIMP
from " or similar to indicate that they are different. Also make sure
we don't prefix strings with GIMP stuff multiple times when profiles
are generated repeatedly.
This commit is contained in:
Michael Natterer 2019-05-31 15:44:07 +02:00
parent add4500a16
commit 3cad4aa4c2
1 changed files with 73 additions and 27 deletions

View File

@ -836,6 +836,57 @@ gimp_color_profile_get_rgb_matrix_colorants (GimpColorProfile *profile,
return FALSE;
}
static void
gimp_color_profile_make_tag (cmsHPROFILE profile,
cmsTagSignature sig,
const gchar *gimp_tag,
const gchar *gimp_prefix,
const gchar *gimp_prefix_alt,
const gchar *original_tag)
{
if (! original_tag || ! strlen (original_tag) ||
! strcmp (original_tag, gimp_tag))
{
/* if there is no original tag (or it is the same as the new
* tag), just use the new tag
*/
gimp_color_profile_set_tag (profile, sig, gimp_tag);
}
else
{
/* otherwise prefix the existing tag with a gimp prefix
* indicating that the profile has been generated
*/
if (g_str_has_prefix (original_tag, gimp_prefix))
{
/* don't add multiple GIMP prefixes */
gimp_color_profile_set_tag (profile, sig, original_tag);
}
else if (gimp_prefix_alt &&
g_str_has_prefix (original_tag, gimp_prefix_alt))
{
/* replace GIMP prefix_alt by prefix */
gchar *new_tag = g_strconcat (gimp_prefix,
original_tag + strlen (gimp_prefix_alt),
NULL);
gimp_color_profile_set_tag (profile, sig, new_tag);
g_free (new_tag);
}
else
{
gchar *new_tag = g_strconcat (gimp_prefix,
original_tag,
NULL);
gimp_color_profile_set_tag (profile, sig, new_tag);
g_free (new_tag);
}
}
}
static GimpColorProfile *
gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
gboolean linear)
@ -845,8 +896,6 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
GimpMatrix3 matrix = { { { 0, } } };
cmsCIEXYZ *whitepoint;
cmsToneCurve *curve;
const gchar *model;
gchar *new_model;
g_return_val_if_fail (GIMP_IS_COLOR_PROFILE (profile), NULL);
@ -876,8 +925,11 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
/* linear light */
curve = cmsBuildGamma (NULL, 1.00);
gimp_color_profile_set_tag (target_profile, cmsSigProfileDescriptionTag,
"linear TRC variant generated by GIMP");
gimp_color_profile_make_tag (target_profile, cmsSigProfileDescriptionTag,
"linear TRC from unnamed profile",
"linear TRC from ",
"sRGB TRC from ",
gimp_color_profile_get_description (profile));
}
else
{
@ -887,8 +939,11 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
/* sRGB curve */
curve = cmsBuildParametricToneCurve (NULL, 4, srgb_parameters);
gimp_color_profile_set_tag (target_profile, cmsSigProfileDescriptionTag,
"sRGB TRC variant generated by GIMP");
gimp_color_profile_make_tag (target_profile, cmsSigProfileDescriptionTag,
"sRGB TRC from unnamed profile",
"sRGB TRC from ",
"linear TRC from ",
gimp_color_profile_get_description (profile));
}
if (gimp_color_profile_is_rgb (profile))
@ -928,27 +983,18 @@ gimp_color_profile_new_from_color_profile (GimpColorProfile *profile,
cmsFreeToneCurve (curve);
model = gimp_color_profile_get_model (profile);
if (model && g_str_has_prefix (model, "Generated from '"))
{
/* don't add multiple "Generated from 'foo'" */
new_model = g_strdup (model);
}
else
{
new_model = g_strdup_printf ("Generated from '%s'",
gimp_color_profile_get_description (profile));
}
gimp_color_profile_set_tag (target_profile, cmsSigDeviceMfgDescTag,
"GIMP");
gimp_color_profile_set_tag (target_profile, cmsSigDeviceModelDescTag,
new_model);
gimp_color_profile_set_tag (target_profile, cmsSigCopyrightTag,
"Public Domain");
g_free (new_model);
gimp_color_profile_make_tag (target_profile, cmsSigDeviceMfgDescTag,
"GIMP",
"GIMP from ", NULL,
gimp_color_profile_get_manufacturer (profile));
gimp_color_profile_make_tag (target_profile, cmsSigDeviceModelDescTag,
"Generated by GIMP",
"GIMP from ", NULL,
gimp_color_profile_get_model (profile));
gimp_color_profile_make_tag (target_profile, cmsSigCopyrightTag,
"Public Domain",
"GIMP from ", NULL,
gimp_color_profile_get_copyright (profile));
new_profile = gimp_color_profile_new_from_lcms_profile (target_profile, NULL);