libgimpcolor: add gimp_lcms_profile_get_summary()

Which returns an "executive summary" of the profile, much like lcms1's
"profile info" API. Refactor common code out of the other string
getters.
This commit is contained in:
Michael Natterer
2014-03-14 18:37:07 +01:00
parent 60014630fa
commit 6f62d6b11b
3 changed files with 61 additions and 61 deletions

View File

@ -42,6 +42,7 @@ EXPORTS
gimp_lcms_profile_get_description gimp_lcms_profile_get_description
gimp_lcms_profile_get_manufacturer gimp_lcms_profile_get_manufacturer
gimp_lcms_profile_get_model gimp_lcms_profile_get_model
gimp_lcms_profile_get_summary
gimp_param_rgb_get_type gimp_param_rgb_get_type
gimp_param_spec_rgb gimp_param_spec_rgb
gimp_param_spec_rgb_has_alpha gimp_param_spec_rgb_has_alpha

View File

@ -45,104 +45,101 @@
**/ **/
gchar * static gchar *
gimp_lcms_profile_get_description (GimpColorProfile profile) gimp_lcms_profile_get_info (GimpColorProfile profile,
cmsInfoType info)
{ {
cmsUInt32Number size; cmsUInt32Number size;
gchar *desc = NULL; gchar *text = NULL;
g_return_val_if_fail (profile != NULL, NULL); g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoDescription, size = cmsGetProfileInfoASCII (profile, info,
"en", "US", NULL, 0); "en", "US", NULL, 0);
if (size > 0) if (size > 0)
{ {
gchar *data = g_new (gchar, size + 1); gchar *data = g_new (gchar, size + 1);
size = cmsGetProfileInfoASCII (profile, cmsInfoDescription, size = cmsGetProfileInfoASCII (profile, info,
"en", "US", data, size); "en", "US", data, size);
if (size > 0) if (size > 0)
desc = gimp_any_to_utf8 (data, -1, NULL); text = gimp_any_to_utf8 (data, -1, NULL);
g_free (data); g_free (data);
} }
return desc; return text;
}
gchar *
gimp_lcms_profile_get_description (GimpColorProfile profile)
{
return gimp_lcms_profile_get_info (profile, cmsInfoDescription);
} }
gchar * gchar *
gimp_lcms_profile_get_manufacturer (GimpColorProfile profile) gimp_lcms_profile_get_manufacturer (GimpColorProfile profile)
{ {
cmsUInt32Number size; return gimp_lcms_profile_get_info (profile, cmsInfoManufacturer);
gchar *info = NULL;
g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
"en", "US", NULL, 0);
if (size > 0)
{
gchar *data = g_new (gchar, size + 1);
size = cmsGetProfileInfoASCII (profile, cmsInfoManufacturer,
"en", "US", data, size);
if (size > 0)
info = gimp_any_to_utf8 (data, -1, NULL);
g_free (data);
}
return info;
} }
gchar * gchar *
gimp_lcms_profile_get_model (GimpColorProfile profile) gimp_lcms_profile_get_model (GimpColorProfile profile)
{ {
cmsUInt32Number size; return gimp_lcms_profile_get_info (profile, cmsInfoModel);
gchar *name = NULL;
g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", NULL, 0);
if (size > 0)
{
gchar *data = g_new (gchar, size + 1);
size = cmsGetProfileInfoASCII (profile, cmsInfoModel,
"en", "US", data, size);
if (size > 0)
name = gimp_any_to_utf8 (data, -1, NULL);
g_free (data);
}
return name;
} }
gchar * gchar *
gimp_lcms_profile_get_copyright (GimpColorProfile profile) gimp_lcms_profile_get_copyright (GimpColorProfile profile)
{ {
cmsUInt32Number size; return gimp_lcms_profile_get_info (profile, cmsInfoCopyright);
gchar *info = NULL; }
gchar *
gimp_lcms_profile_get_summary (GimpColorProfile profile)
{
GString *string;
gchar *text;
g_return_val_if_fail (profile != NULL, NULL); g_return_val_if_fail (profile != NULL, NULL);
size = cmsGetProfileInfoASCII (profile, cmsInfoCopyright, string = g_string_new (NULL);
"en", "US", NULL, 0);
if (size > 0) text = gimp_lcms_profile_get_description (profile);
if (text)
{ {
gchar *data = g_new (gchar, size + 1); g_string_append (string, text);
g_free (text);
size = cmsGetProfileInfoASCII (profile, cmsInfoCopyright,
"en", "US", data, size);
if (size > 0)
info = gimp_any_to_utf8 (data, -1, NULL);
g_free (data);
} }
return info; text = gimp_lcms_profile_get_model (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
g_string_append (string, text);
}
text = gimp_lcms_profile_get_manufacturer (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
g_string_append (string, text);
}
text = gimp_lcms_profile_get_copyright (profile);
if (text)
{
if (string->len > 0)
g_string_append (string, "\n");
g_string_append (string, text);
}
return g_string_free (string, FALSE);
} }
/** /**

View File

@ -40,6 +40,8 @@ gchar * gimp_lcms_profile_get_manufacturer (GimpColorProfile profile)
gchar * gimp_lcms_profile_get_model (GimpColorProfile profile); gchar * gimp_lcms_profile_get_model (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_copyright (GimpColorProfile profile); gchar * gimp_lcms_profile_get_copyright (GimpColorProfile profile);
gchar * gimp_lcms_profile_get_summary (GimpColorProfile profile);
GimpColorProfile gimp_lcms_create_srgb_profile (void); GimpColorProfile gimp_lcms_create_srgb_profile (void);